diff --git a/DesktopTools/app/msg_systray.py b/DesktopTools/app/msg_systray.py
index 3bd9c44..3828ae0 100644
--- a/DesktopTools/app/msg_systray.py
+++ b/DesktopTools/app/msg_systray.py
@@ -20,17 +20,20 @@ def showMenu(self):
设计托盘的菜单
"""
self.menuMain = QMenu()
- self.subMenu = QMenu()
- self.showAction = QAction("测试休息提醒消息", self, triggered=self.showYouNeedRest)
- self.quitAction = QAction("退出", self, triggered=self.quit)
- self.subMenu.addAction(self.showAction)
+ self.action_test = QAction("测试休息提醒消息", self, triggered=self.showYouNeedRest)
+ self.subMenu = QMenu()
+ self.subMenu.setTitle("测试菜单")
+ self.subMenu.addAction(self.action_test)
self.menuMain.addMenu(
self.subMenu,
)
- self.menuMain.addAction(self.quitAction)
- self.subMenu.setTitle("测试菜单")
+ self.action_quit = QAction("退出", self, triggered=self.quit)
+ 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):
@@ -86,7 +89,10 @@ def showYouNeedRest(self, msg="主动点击测试", level=0):
}
vlevel = dict_msg[level]["value"]
txt = dict_msg[level]["desc"]
- self.showMessage(txt, msg, self.MessageIcon(vlevel))
+ self.showMessage(txt, msg or "", self.MessageIcon(vlevel))
+
+ def show_search_bar(self, msg="主动点击测试", level=0):
+ self.parent().open_search_bar()
def quit(self):
# TODO 完整的退出 不过注释掉几行也能退出,蛮奇怪,先这么吧.
diff --git a/DesktopTools/feather_hotkey/clip_string.py b/DesktopTools/feather_hotkey/clip_string.py
index bc4b49f..f1fae9d 100644
--- a/DesktopTools/feather_hotkey/clip_string.py
+++ b/DesktopTools/feather_hotkey/clip_string.py
@@ -3,6 +3,7 @@
import random
import re
import shutil
+from zoneinfo import ZoneInfo
# from PySide6.QtCore import Qt
from PySide6.QtGui import QClipboard
@@ -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
@@ -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
@@ -132,6 +133,7 @@ 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),
]
@@ -149,6 +151,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:
diff --git a/DesktopTools/feather_hotkey/custom_list_widget.py b/DesktopTools/feather_hotkey/custom_list_widget.py
new file mode 100644
index 0000000..786d9dd
--- /dev/null
+++ b/DesktopTools/feather_hotkey/custom_list_widget.py
@@ -0,0 +1,26 @@
+from PySide6.QtWidgets import QStyledItemDelegate
+from PySide6.QtGui import QColor, QFont
+
+
+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)
diff --git a/DesktopTools/feather_hotkey/searchbar.ui b/DesktopTools/feather_hotkey/searchbar.ui
index 982a2cb..9b806d8 100644
--- a/DesktopTools/feather_hotkey/searchbar.ui
+++ b/DesktopTools/feather_hotkey/searchbar.ui
@@ -17,10 +17,10 @@
小命令工具
- background-color: #F9F9F9;
+ background-color: #F0F0F0;
color: #333333;
font-size: 16px;
- font-family: Arial, sans-serif;
+ font-family: 'Helvetica Neue', Arial, sans-serif;
-
@@ -30,12 +30,12 @@
-
- background-color: #FFFFFF;
- border-radius: 40px;
- border: 2px solid #CCCCCC;
- padding: 20px;
+ background-color: #FFFFFF;
+ border-radius: 20px;
+ border: 1px solid #CCCCCC;
+ padding: 10px;
font-size: 18px;
- font-family: Arial, sans-serif;
+ font-family: 'Helvetica Neue', Arial, sans-serif;
开始输入命令...
@@ -45,12 +45,12 @@
-
- background-color: #008CBA;
- border-radius: 40px;
+ 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;
@@ -67,14 +67,16 @@
background-color: #FFFFFF;
-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;
+margin: 1px;
+background: rgba(255, 255, 255, 0.9);
0
diff --git a/DesktopTools/feather_hotkey/thread.py b/DesktopTools/feather_hotkey/thread.py
index f880796..0679282 100644
--- a/DesktopTools/feather_hotkey/thread.py
+++ b/DesktopTools/feather_hotkey/thread.py
@@ -1,5 +1,26 @@
+import sys
from pynput import keyboard
-from PySide6.QtCore import QThread, Signal
+from PySide6.QtCore import QByteArray, QThread, Signal, QAbstractNativeEventFilter
+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__()
+ self.hotkey = hotkey
+
+ 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()
+ return super().nativeEventFilter(eventType, message)
class SignalHotKey(QThread):
@@ -7,15 +28,33 @@ class SignalHotKey(QThread):
def __init__(self):
super().__init__()
+ self.hotkey_id = 1
+ self.hotkey_vk = 0x31
+ # win: https://learn.microsoft.com/zh-cn/windows/win32/inputdev/virtual-key-codes
+
+ def register(self):
+ if sys.platform == "win32":
+ 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))
+ else:
+ # sys.platform in ("linux", "darwin"):
+ # 还没原生的方法,只能用`pynput`啦
+ hotkey = keyboard.GlobalHotKeys(
+ {
+ "+<32>": self.on_activate,
+ # "++g": lambda: print("Goodbye"),
+ }
+ )
+ hotkey.start()
- def listen(self):
- hotkey = keyboard.GlobalHotKeys(
- {
- "++c": self.on_activate,
- # "++g": lambda: print("Goodbye"),
- }
- )
- hotkey.start()
+ def unregister(self):
+ if sys.platform == "win32" and self.hotkey_id:
+ sign = user32.UnregisterHotKey(None, self.hotkey_id)
+ logger.info(f"Hotkey unregistration {sign}")
+ else:
+ pass
def on_activate(self):
self._signal.emit()
diff --git a/DesktopTools/feather_hotkey/ui_searchbar.py b/DesktopTools/feather_hotkey/ui_searchbar.py
index d9a1b77..d4611e5 100644
--- a/DesktopTools/feather_hotkey/ui_searchbar.py
+++ b/DesktopTools/feather_hotkey/ui_searchbar.py
@@ -1,159 +1,109 @@
-# -*- coding: utf-8 -*-
-
-################################################################################
-## Form generated from reading UI file 'searchbar.ui'
-##
-## Created by: Qt User Interface Compiler version 6.5.0
-##
-## WARNING! All changes made in this file will be lost when recompiling UI file!
-################################################################################
-
-from PySide6.QtCore import (
- QCoreApplication,
- QDate,
- QDateTime,
- QLocale,
- QMetaObject,
- QObject,
- QPoint,
- QRect,
- QSize,
- Qt,
- QTime,
- QUrl,
-)
-from PySide6.QtGui import (
- QBrush,
- QColor,
- QConicalGradient,
- QCursor,
- QFont,
- QFontDatabase,
- QGradient,
- QIcon,
- QImage,
- QKeySequence,
- QLinearGradient,
- QPainter,
- QPalette,
- QPixmap,
- QRadialGradient,
- QTransform,
-)
-from PySide6.QtWidgets import (
- QApplication,
- QHBoxLayout,
- QLineEdit,
- QListWidget,
- QListWidgetItem,
- QPushButton,
- QSizePolicy,
- QVBoxLayout,
- QWidget,
-)
-
-
-class Ui_SearchBar(object):
- def setupUi(self, SearchBar):
- if not SearchBar.objectName():
- SearchBar.setObjectName("SearchBar")
- SearchBar.setEnabled(True)
- SearchBar.resize(701, 280)
- SearchBar.setStyleSheet(
- " background-color: #F9F9F9;\n"
- " color: #333333;\n"
- " font-size: 16px;\n"
- " font-family: Arial, sans-serif;"
- )
- self.horizontalLayout_2 = QHBoxLayout(SearchBar)
- self.horizontalLayout_2.setObjectName("horizontalLayout_2")
- self.verticalLayout = QVBoxLayout()
- self.verticalLayout.setObjectName("verticalLayout")
- self.horizontalLayout_3 = QHBoxLayout()
- self.horizontalLayout_3.setObjectName("horizontalLayout_3")
- self.lineEdit = QLineEdit(SearchBar)
- self.lineEdit.setObjectName("lineEdit")
- self.lineEdit.setStyleSheet(
- " background-color: #FFFFFF;\n"
- " border-radius: 40px;\n"
- " border: 2px solid #CCCCCC;\n"
- " padding: 20px;\n"
- " font-size: 18px;\n"
- " font-family: Arial, sans-serif;"
- )
-
- self.horizontalLayout_3.addWidget(self.lineEdit)
-
- self.pushButton = QPushButton(SearchBar)
- self.pushButton.setObjectName("pushButton")
- self.pushButton.setStyleSheet(
- " background-color: #008CBA;\n"
- " border-radius: 40px;\n"
- " border: none;\n"
- " padding: 20px 40px;\n"
- " font-size: 18px;\n"
- " font-family: Arial, sans-serif;\n"
- " color: #FFFFFF;"
- )
-
- self.horizontalLayout_3.addWidget(self.pushButton)
-
- self.verticalLayout.addLayout(self.horizontalLayout_3)
-
- self.listWidget = QListWidget(SearchBar)
- QListWidgetItem(self.listWidget)
- QListWidgetItem(self.listWidget)
- self.listWidget.setObjectName("listWidget")
- self.listWidget.setLayoutDirection(Qt.LeftToRight)
- self.listWidget.setStyleSheet(
- "background-color: #FFFFFF;\n"
- "border-radius: 16px;\n"
- "border: 2px solid #CCCCCC;\n"
- "padding: 20px;\n"
- "font-size: 20px;\n"
- "font-family: Arial, sans-serif;\n"
- "line-height: 2.5;\n"
- "margin-bottom: 10px; \n"
- "margin: 1px; "
- )
-
- self.verticalLayout.addWidget(self.listWidget)
-
- self.horizontalLayout_2.addLayout(self.verticalLayout)
-
- self.retranslateUi(SearchBar)
-
- self.listWidget.setCurrentRow(0)
-
- QMetaObject.connectSlotsByName(SearchBar)
-
- # setupUi
-
- def retranslateUi(self, SearchBar):
- SearchBar.setWindowTitle(
- QCoreApplication.translate(
- "SearchBar", "\u5c0f\u547d\u4ee4\u5de5\u5177", None
- )
- )
- self.lineEdit.setPlaceholderText(
- QCoreApplication.translate(
- "SearchBar", "\u5f00\u59cb\u8f93\u5165\u547d\u4ee4...", None
- )
- )
- self.pushButton.setText(
- QCoreApplication.translate("SearchBar", "\u786e\u5b9a", None)
- )
-
- __sortingEnabled = self.listWidget.isSortingEnabled()
- self.listWidget.setSortingEnabled(False)
- ___qlistwidgetitem = self.listWidget.item(0)
- ___qlistwidgetitem.setText(
- QCoreApplication.translate("SearchBar", "\u4f60\u597d", None)
- )
- ___qlistwidgetitem1 = self.listWidget.item(1)
- ___qlistwidgetitem1.setText(
- QCoreApplication.translate("SearchBar", "hello", None)
- )
- self.listWidget.setSortingEnabled(__sortingEnabled)
-
- # retranslateUi
+# -*- coding: utf-8 -*-
+
+################################################################################
+## Form generated from reading UI file 'searchbar.ui'
+##
+## Created by: Qt User Interface Compiler version 6.6.3
+##
+## WARNING! All changes made in this file will be lost when recompiling UI file!
+################################################################################
+
+from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
+ QMetaObject, QObject, QPoint, QRect,
+ QSize, QTime, QUrl, Qt)
+from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
+ QFont, QFontDatabase, QGradient, QIcon,
+ QImage, QKeySequence, QLinearGradient, QPainter,
+ QPalette, QPixmap, QRadialGradient, QTransform)
+from PySide6.QtWidgets import (QApplication, QHBoxLayout, QLineEdit, QListWidget,
+ QListWidgetItem, QPushButton, QSizePolicy, QVBoxLayout,
+ QWidget)
+
+class Ui_SearchBar(object):
+ def setupUi(self, SearchBar):
+ if not SearchBar.objectName():
+ SearchBar.setObjectName(u"SearchBar")
+ SearchBar.setEnabled(True)
+ SearchBar.resize(701, 280)
+ SearchBar.setStyleSheet(u"background-color: #F0F0F0;\n"
+" color: #333333;\n"
+" font-size: 16px;\n"
+" font-family: 'Helvetica Neue', Arial, sans-serif;")
+ self.horizontalLayout_2 = QHBoxLayout(SearchBar)
+ self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
+ self.verticalLayout = QVBoxLayout()
+ self.verticalLayout.setObjectName(u"verticalLayout")
+ self.horizontalLayout_3 = QHBoxLayout()
+ self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
+ self.lineEdit = QLineEdit(SearchBar)
+ self.lineEdit.setObjectName(u"lineEdit")
+ self.lineEdit.setStyleSheet(u"background-color: #FFFFFF;\n"
+" border-radius: 20px;\n"
+" border: 1px solid #CCCCCC;\n"
+" padding: 10px;\n"
+" font-size: 18px;\n"
+" font-family: 'Helvetica Neue', Arial, sans-serif;")
+
+ self.horizontalLayout_3.addWidget(self.lineEdit)
+
+ self.pushButton = QPushButton(SearchBar)
+ self.pushButton.setObjectName(u"pushButton")
+ self.pushButton.setStyleSheet(u"background-color: #007BFF;\n"
+" border-radius: 20px;\n"
+" border: none;\n"
+" padding: 10px 20px;\n"
+" font-size: 18px;\n"
+" font-family: 'Helvetica Neue', Arial, sans-serif;\n"
+" color: #FFFFFF;")
+
+ self.horizontalLayout_3.addWidget(self.pushButton)
+
+
+ self.verticalLayout.addLayout(self.horizontalLayout_3)
+
+ self.listWidget = QListWidget(SearchBar)
+ QListWidgetItem(self.listWidget)
+ QListWidgetItem(self.listWidget)
+ self.listWidget.setObjectName(u"listWidget")
+ self.listWidget.setLayoutDirection(Qt.LeftToRight)
+ self.listWidget.setStyleSheet(u"background-color: #FFFFFF;\n"
+"selection-background-color: #FFCA72;\n"
+"border-radius: 10px;\n"
+"border: 1px solid #CCCCCC;\n"
+"padding: 10px;\n"
+"font-size: 20px;\n"
+"font-family: 'Helvetica Neue', Arial, sans-serif;\n"
+"line-height: 1.5;\n"
+"margin-bottom: 10px; \n"
+"margin: 1px; \n"
+"background: rgba(255, 255, 255, 0.9);")
+
+ self.verticalLayout.addWidget(self.listWidget)
+
+
+ self.horizontalLayout_2.addLayout(self.verticalLayout)
+
+
+ self.retranslateUi(SearchBar)
+
+ self.listWidget.setCurrentRow(0)
+
+
+ QMetaObject.connectSlotsByName(SearchBar)
+ # setupUi
+
+ def retranslateUi(self, SearchBar):
+ SearchBar.setWindowTitle(QCoreApplication.translate("SearchBar", u"\u5c0f\u547d\u4ee4\u5de5\u5177", None))
+ self.lineEdit.setPlaceholderText(QCoreApplication.translate("SearchBar", u"\u5f00\u59cb\u8f93\u5165\u547d\u4ee4...", None))
+ self.pushButton.setText(QCoreApplication.translate("SearchBar", u"\u786e\u5b9a", None))
+
+ __sortingEnabled = self.listWidget.isSortingEnabled()
+ self.listWidget.setSortingEnabled(False)
+ ___qlistwidgetitem = self.listWidget.item(0)
+ ___qlistwidgetitem.setText(QCoreApplication.translate("SearchBar", u"\u4f60\u597d", None));
+ ___qlistwidgetitem1 = self.listWidget.item(1)
+ ___qlistwidgetitem1.setText(QCoreApplication.translate("SearchBar", u"hello", None));
+ self.listWidget.setSortingEnabled(__sortingEnabled)
+
+ # retranslateUi
+
diff --git a/DesktopTools/feather_hotkey/win_searchbar.py b/DesktopTools/feather_hotkey/win_searchbar.py
index 22a7ccc..7035d13 100644
--- a/DesktopTools/feather_hotkey/win_searchbar.py
+++ b/DesktopTools/feather_hotkey/win_searchbar.py
@@ -1,13 +1,14 @@
import os
import shelve
-from PySide6.QtCore import Qt
-from PySide6.QtGui import QIcon
-from PySide6.QtWidgets import QAbstractItemView, QCompleter, QWidget
+from PySide6.QtCore import Qt, QModelIndex
+from PySide6.QtGui import QIcon, QKeySequence, QShortcut
+from PySide6.QtWidgets import QAbstractItemView, QCompleter, QWidget, QListWidgetItem
from ..logger import logger
from .clip_string import ClipFuncs, safe_eval
from .ui_searchbar import Ui_SearchBar
+from .custom_list_widget import CustomItemDelegate
class FuzzyCompleter(QCompleter):
@@ -54,6 +55,7 @@ def __init__(self, app=None, tray=None, dict_windows={}, *args, **kwargs):
super().__init__(*args, **kwargs)
self.ui = Ui_SearchBar()
self.ui.setupUi(self)
+ self.ui.listWidget.setItemDelegate(CustomItemDelegate(self.ui.listWidget))
self.app = app
self.tray = tray
self.dict_windows = dict_windows
@@ -68,6 +70,12 @@ def __init__(self, app=None, tray=None, dict_windows={}, *args, **kwargs):
self.ui.pushButton.clicked.connect(self.clip_worker)
self.ui.lineEdit.textChanged.connect(self.handleTextChange)
self.ui.listWidget.clicked.connect(self.on_listWidget_clicked)
+ # 创建快捷键
+ self.shortcuts = []
+ for i in range(10): # 设置 Ctrl+1 到 Ctrl+9 的快捷键
+ shortcut = QShortcut(QKeySequence(f"Ctrl+{i + 1}"), self)
+ shortcut.activated.connect(lambda index=i: self.on_shortcut_activated(index))
+ self.shortcuts.append(shortcut)
self.command = None
self.shelve = shelve.open("spam")
self.set_icon()
@@ -88,17 +96,29 @@ def setStyle(self):
# self.setWindowFlags(self.windowFlags() | Qt.FramelessWindowHint)
self.setWindowFlags(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
+ self.ui.listWidget.setWordWrap(True)
+ self.update()
def unregistered_warning(self, *arg, **kwargs):
self.ui.lineEdit.setText("命令错误-没有匹配到处理方法")
return False, "命令错误-没有匹配到处理方法"
- def on_listWidget_clicked(self, index):
+ def on_shortcut_activated(self, index: int):
+ # 使用快捷键激活 需要将序号转为item类型
+ if index < self.ui.listWidget.count():
+ self.on_listWidget_clicked(self.ui.listWidget.item(index))
+
+ def on_listWidget_clicked(self, item):
"""
下拉候选项被点击时的处理动作
点击 下拉选项
"""
- completion_text = index.data()
+ if isinstance(item, QListWidgetItem):
+ completion_text = item.text()
+ elif isinstance(item, QModelIndex):
+ completion_text = item.data()
+ else:
+ logger.warning(f"错误的传入类型-在处理点击下拉选项时: {type(item)}")
if completion_text in set(self.dict_windows.keys()):
self.dict_windows[completion_text].show()
self.hide()
diff --git a/DesktopTools/feather_timer/halahayawa.py b/DesktopTools/feather_timer/halahayawa.py
index c7c7ed4..ae06b07 100644
--- a/DesktopTools/feather_timer/halahayawa.py
+++ b/DesktopTools/feather_timer/halahayawa.py
@@ -12,7 +12,8 @@
import os
import sys
import time
-
+import random
+import psutil
# from PyQt5.QtWidgets import QApplication, QWidget, QDesktopWidget
# from PyQt5.QtGui import QIcon, QFont
from PySide6.QtCore import Qt, QTimer
@@ -43,10 +44,11 @@
from . import input_counter
from .data_alchemy.models import WorkInfo
from .monitor import AlertDict, SignalKeyboard, SignalMouse, ThreadSignal, WorkDict
+from ..app.msg_systray import TrayIcon
class WinHowLongHadYouWork(QWidget):
- def __init__(self, screen=False, tray=None):
+ def __init__(self, screen=False, tray: TrayIcon=None):
super().__init__(None)
self.screen = screen
@@ -117,7 +119,7 @@ def initTimer(self):
self.timer.timeout.connect(self.timeWorking)
self.timerRest.timeout.connect(self.show_rest_msg)
self.timer.start(1 * 1000) # 1s
- self.timerRest.start(10 * 1000) # 10s
+ self.timerRest.start(60 * 1000) # 60s
def timeWorking(self):
self.work_dict.summarize()
@@ -138,7 +140,26 @@ def timeWorking(self):
self.dictLabels["restAll"].setText(
f"已经休息: {lenth_time(rest_tm)}\n本次总小憩: {lenth_time(self.work_dict.rest_time)}"
)
-
+ if random.random() < 0.3:
+ # 0.3的可能性计算电脑资源信息
+ # 获取系统内存信息
+ memory_info = psutil.virtual_memory()
+ memory_info_dict = {
+ "总内存": f"{memory_info.total / (1024 ** 3):.2f} GB",
+ "已用内存": f"{memory_info.used / (1024 ** 3):.2f} GB",
+ "可用内存": f"{memory_info.available / (1024 ** 3):.2f} GB",
+ "空闲内存": f"{memory_info.free / (1024 ** 3):.2f} GB",
+ "内存使用率": f"{memory_info.percent}%",
+ }
+ percpu_percent = psutil.cpu_percent(percpu=True, interval=0) # interval=1 表示计算1秒钟内的CPU使用率
+ warning_msg = ""
+ if memory_info_dict["内存使用率"] > "90%":
+ warning_msg += f"内存使用率过高,注意排查: {memory_info_dict['内存使用率']}"
+ if sum(percpu_percent) > len(percpu_percent) * 50:
+ warning_msg += f"cpu使用率过高,系统将操作缓慢: {percpu_percent.join(',')}"
+ if warning_msg:
+ slogger.warning(warning_msg)
+ self.tray.show_warning_msg(warning_msg)
def initUI(self):
# self.tooltip()
# self.setGeometry(300, 300, 300, 220)
diff --git a/DesktopTools/windows_main.py b/DesktopTools/windows_main.py
index 1427ca7..5092ea8 100644
--- a/DesktopTools/windows_main.py
+++ b/DesktopTools/windows_main.py
@@ -33,6 +33,7 @@ def __init__(self, screen=False, app=None):
super().__init__(None)
self.screen = screen
+ # 系统托盘图标
self.tray = TrayIcon(self)
self.win_timer = WinHowLongHadYouWork(screen, self.tray)
@@ -48,10 +49,10 @@ def initSearchBar(self):
"""
使用线程初始化SearchBar, 在线程中绑定热键
"""
- thread_hotkey = SignalHotKey()
- thread_hotkey._signal.connect(self.open_search_bar)
+ self.thread_hotkey = SignalHotKey()
+ self.thread_hotkey._signal.connect(self.open_search_bar)
time.sleep(0.5) # 此处继续sleep防止mac下出错 - 未验证
- thread_hotkey.listen()
+ self.thread_hotkey.register()
logger.debug("will show")
def open_search_bar(self):
@@ -64,6 +65,7 @@ def open_search_bar(self):
def closeEvent(self, event):
"""退出确认"""
# TODO 测试期嫌累
+ self.thread_hotkey.unregister()
self.win_searchbar.close()
self.win_timer.close()
return
diff --git a/Makefile b/Makefile
index 15fac52..073108e 100644
--- a/Makefile
+++ b/Makefile
@@ -18,4 +18,8 @@ build: # pip安装
pip install .[ui]
@echo "instal sucess: DesktopTools"
ui: # 编译.ui 到 .py
- cd DesktopTools/feather_hotkey && pyside6-uic searchbar.ui -o ui_searchbar.py
\ No newline at end of file
+ cd DesktopTools/feather_hotkey && pyside6-uic searchbar.ui -o ui_searchbar.py
+
+edit_ui:
+ find DesktopTools/ -name *.ui
+ pyside6-designer DesktopTools/feather_hotkey/searchbar.ui
\ No newline at end of file
diff --git a/pyproject.toml b/pyproject.toml
index 52a5933..3ffe3a2 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,6 +1,6 @@
[tool.poetry]
name = "DesktopTools"
-version = "0.0.7"
+version = "0.1.0"
description = "A desktop tool that includes some useful scripts."
authors = ["ianvzs ", "saint "]
readme = "README.md"
@@ -17,7 +17,7 @@ packages = [
DesktopTools = "DesktopTools:main"
[tool.poetry.dependencies]
-python = ">=3.7,<3.12"
+python >=3.7
PySide6 = { version = "^6.0.0", optional = true }
pynput = "^1.7.6"
loguru = "^0.6.0"
@@ -25,7 +25,7 @@ SQLAlchemy = "^2.0.0"
yapf = "^0.32.0"
wheel = "^0.40.0"
pydantic = "^1.10.7"
-
+psutil >=5.9.4
[tool.poetry.extras]
ui = ["PySide6"]
diff --git a/requirements.txt b/requirements.txt
index 5bfed4f..ee9ce60 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -5,3 +5,4 @@ sqlalchemy
yapf
pyinstaller
pydantic
+psutil