Skip to content

Commit

Permalink
Merge pull request #26 from IanVzs/dev
Browse files Browse the repository at this point in the history
fork开发规范
  • Loading branch information
IanVzs authored Sep 25, 2024
2 parents 3c86275 + f4b68db commit 9bd1d6e
Show file tree
Hide file tree
Showing 16 changed files with 1,823 additions and 1,655 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: "${{ matrix.os }}"
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: [3.8, 3.9]
os: [windows-latest, ubuntu-latest, macos-latest]
env:
OS: ${{ matrix.os }}
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.7
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip poetry
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: "${{ matrix.os }}"
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: [3.8, 3.9]
os: [windows-latest, ubuntu-latest, macos-latest]
env:
OS: ${{ matrix.os }}
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.7
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip poetry
Expand All @@ -71,7 +71,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: 3.7
python-version: 3.8
- name: Install dependencies
run: |
python -m pip install --upgrade pip poetry
Expand Down
6 changes: 4 additions & 2 deletions DesktopTools/app/msg_systray.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def showMenu(self):
"""
self.menuMain = QMenu()

self.action_test = QAction("测试休息提醒消息", self, triggered=self.showYouNeedRest)
self.action_test = QAction(
"测试休息提醒消息", self, triggered=self.showYouNeedRest
)
self.subMenu = QMenu()
self.subMenu.setTitle("测试菜单")
self.subMenu.addAction(self.action_test)
Expand All @@ -33,7 +35,7 @@ def showMenu(self):
self.action_search_bar = QAction("搜索", self, triggered=self.show_search_bar)
self.menuMain.addAction(self.action_search_bar)
self.menuMain.addAction(self.action_quit)

self.setContextMenu(self.menuMain)

def initConnect(self):
Expand Down
17 changes: 14 additions & 3 deletions DesktopTools/feather_hotkey/clip_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import random
import re
import shutil
from zoneinfo import ZoneInfo

# from PySide6.QtCore import Qt
from PySide6.QtGui import QClipboard
Expand All @@ -27,7 +28,7 @@ def incremental_copy_files(source_path: str, dest_path: str, number: int):
source_file = random.choice(file_list)
# 构建目标文件路径
file_name = os.path.basename(source_file)
dest_file = os.path.join(dest_path, f"{i+1}_{file_name}")
dest_file = os.path.join(dest_path, f"{i + 1}_{file_name}")
# 复制文件
shutil.copy(source_file, dest_file)

Expand Down Expand Up @@ -87,7 +88,7 @@ def extract_float(string):
return numbers


def unixtime_to_datetime_str(unixtime_str):
def unixtime_to_datetime_str(unixtime_str, tz=ZoneInfo("Asia/Shanghai")):
list_float = extract_float(unixtime_str)
logger.debug(f"unixtime_str: {unixtime_str} - list_float: {list_float}")
unixtime = 0
Expand All @@ -100,7 +101,7 @@ def unixtime_to_datetime_str(unixtime_str):
unixtime = int(unixtime_str)
dt_str = ""
try:
dt = datetime.datetime.fromtimestamp(unixtime)
dt = datetime.datetime.fromtimestamp(unixtime, tz=tz)
dt_str = dt.strftime("%Y-%m-%d %H:%M:%S")
except Exception:
pass
Expand Down Expand Up @@ -132,6 +133,9 @@ def __init__(self, clipboard: QClipboard) -> None:
FuncClass(desc="连续空格替换为指定符号", func=self.replace_spaces),
FuncClass(desc="data转为JSON字符串", func=self.data2json),
FuncClass(desc="unixtime转datetime", func=self.unixtime_to_datetime_str),
FuncClass(
desc="unixtime转datetime(UTC)", func=self.unixtime_to_datetime_utc_str
),
FuncClass(desc="路径转python导入import语句", func=self.modify_import_path),
]

Expand All @@ -149,6 +153,13 @@ def list_all_result(self, text: str) -> list[FuncClass]:
def set_clipboard(self, content):
self.clipboard.setText(content)

def unixtime_to_datetime_utc_str(self, text):
content = unixtime_to_datetime_str(text or 0, tz=ZoneInfo("UTC"))
if not content:
return False, "非unix时间"
# self.set_clipboard(content)
return True, content

def unixtime_to_datetime_str(self, text):
content = unixtime_to_datetime_str(text or 0)
if not content:
Expand Down
28 changes: 28 additions & 0 deletions DesktopTools/feather_hotkey/custom_list_widget.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from PySide6.QtGui import QColor, QFont
from PySide6.QtWidgets import QStyledItemDelegate


class CustomItemDelegate(QStyledItemDelegate):
def __init__(self, parent=None):
super().__init__(parent)

def paint(self, painter, option, index):
# 绘制默认项
super().paint(painter, option, index)

# 获取当前项的文本
# item = self.parent().item(index.row())
# text = item.text()

# 设置半透明的颜色
painter.setPen(QColor(150, 150, 150, 150)) # 半透明的灰色
painter.setFont(QFont("Helvetica Neue", 12))

# 计算并绘制快捷键提示,确保其右对齐
shortcut_text = f" (Ctrl+{index.row() + 1})"
text_width = painter.fontMetrics().horizontalAdvance(shortcut_text)

# 绘制文本
painter.drawText(
option.rect.right() - text_width - 10, option.rect.top() + 15, shortcut_text
)
36 changes: 18 additions & 18 deletions DesktopTools/feather_hotkey/searchbar.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
<string>小命令工具</string>
</property>
<property name="styleSheet">
<string notr="true"> background-color: #F9F9F9;
<string notr="true">background-color: #F0F0F0;
color: #333333;
font-size: 16px;
font-family: Arial, sans-serif;</string>
font-family: 'Helvetica Neue', Arial, sans-serif;</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
Expand All @@ -30,12 +30,12 @@
<item>
<widget class="QLineEdit" name="lineEdit">
<property name="styleSheet">
<string notr="true"> background-color: #FFFFFF;
border-radius: 40px;
border: 2px solid #CCCCCC;
padding: 20px;
<string notr="true">background-color: #FFFFFF;
border-radius: 20px;
border: 1px solid #CCCCCC;
padding: 10px;
font-size: 18px;
font-family: Arial, sans-serif;</string>
font-family: 'Helvetica Neue', Arial, sans-serif;</string>
</property>
<property name="placeholderText">
<string>开始输入命令...</string>
Expand All @@ -45,12 +45,12 @@
<item>
<widget class="QPushButton" name="pushButton">
<property name="styleSheet">
<string notr="true"> background-color: #008CBA;
border-radius: 40px;
<string notr="true">background-color: #007BFF;
border-radius: 20px;
border: none;
padding: 20px 40px;
padding: 10px 20px;
font-size: 18px;
font-family: Arial, sans-serif;
font-family: 'Helvetica Neue', Arial, sans-serif;
color: #FFFFFF;</string>
</property>
<property name="text">
Expand All @@ -67,16 +67,16 @@
</property>
<property name="styleSheet">
<string notr="true">background-color: #FFFFFF;
selection-background-color: rgb(255, 163, 72);
border-radius: 16px;
border: 2px solid #CCCCCC;
padding: 20px;
selection-background-color: #FFCA72;
border-radius: 10px;
border: 1px solid #CCCCCC;
padding: 10px;
font-size: 20px;
font-family: Arial, sans-serif;
line-height: 2.5;
font-family: 'Helvetica Neue', Arial, sans-serif;
line-height: 1.5;
margin-bottom: 10px;
margin: 1px;
background: rgba(255, 255, 255, 180);</string>
background: rgba(255, 255, 255, 0.9);</string>
</property>
<property name="currentRow">
<number>0</number>
Expand Down
13 changes: 11 additions & 2 deletions DesktopTools/feather_hotkey/thread.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import sys

from pynput import keyboard
from PySide6.QtCore import QByteArray, QThread, Signal, QAbstractNativeEventFilter
from PySide6.QtCore import QAbstractNativeEventFilter, QByteArray, QThread, Signal

from ..logger import logger

if sys.platform == "win32":
import ctypes

import win32con

user32 = ctypes.windll.user32


class NativeEvent(QAbstractNativeEventFilter):
def __init__(self, hotkey) -> None:
super().__init__()
Expand All @@ -16,7 +21,9 @@ def __init__(self, hotkey) -> None:
def nativeEventFilter(self, eventType: QByteArray | bytes, message: int) -> object:
if sys.platform == "win32":
from ctypes import wintypes

import win32con

msg = wintypes.MSG.from_address(message.__init__())
if eventType == "windows_generic_MSG" and msg.message == win32con.WM_HOTKEY:
self.hotkey.on_activate()
Expand All @@ -34,7 +41,9 @@ def __init__(self):

def register(self):
if sys.platform == "win32":
sign = user32.RegisterHotKey(None, self.hotkey_id, win32con.MOD_ALT, self.hotkey_vk)
sign = user32.RegisterHotKey(
None, self.hotkey_id, win32con.MOD_ALT, self.hotkey_vk
)
# https://learn.microsoft.com/zh-cn/windows/win32/api/winuser/nf-winuser-registerhotkey
logger.info(f"Hotkey Registration {sign}")
self.parent().installEventFilter(NativeEvent(hotkey=self))
Expand Down
Loading

0 comments on commit 9bd1d6e

Please sign in to comment.