python版本3.8.10
- 方便做窗口设计的利器desinger,安装之后pyqt5-tools不会创建快捷方式的问题,pyqt的desinger路径: **\Python38\Lib\site-packages\qt5_applications\Qt\bin\designer.exe
- 在desinger设计加载静态资源(网页,本地html)找不到QWebEngineView控件,先创建一个QWidget然后将其提升为QWebEngineView,头文件为PyQt5.QtWebEngineWidgets
- 客户端无法拖动的问题,在继承QWidget类下重写鼠标动作函数
self.m_Position = None
self.m_flag = None
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.m_flag = True
self.m_Position = event.globalPos() - self.pos()
event.accept()
self.setCursor(QCursor(Qt.OpenHandCursor))
def mouseMoveEvent(self, QMouseEvent):
if Qt.LeftButton and self.m_flag:
self.move(QMouseEvent.globalPos() - self.m_Position)
QMouseEvent.accept()
def mouseReleaseEvent(self, QMouseEvent):
self.m_flag = False
self.setCursor(QCursor(Qt.ArrowCursor))
- 客户端显示位置问题,显示在屏幕中央
screen = QDesktopWidget().screenGeometry()
size = clientInstance.geometry()
widgetInstance.move(int((screen.width() - size.width()) / 2), int((screen.height() - size.height()) / 2))
- 客户端可以启动多个exe的问题,使用共享内存变量,相当于一把锁同时只能一个exe占用
share = QSharedMemory()
share.setKey("main_window")
if share.attach():
logger.warning("程序已启动,请勿重复启动!")
sys.exit(-1)
if share.create(1):
goto('regular process step...')
- 启动客户端的时候创建快捷方式
def set_shortcut():
mainpath = os.path.dirname(__file__)
try:
filename = mainpath + r"\client.exe"
iconname = app_path() + r"\images\client.ico"
desktop = os.path.join(os.path.expanduser('~'), "Desktop")
lnkname = desktop + r"\client.lnk"
shortcut = pythoncom.CoCreateInstance(
shell.CLSID_ShellLink, None,
pythoncom.CLSCTX_INPROC_SERVER, shell.IID_IShellLink)
shortcut.SetPath(filename)
shortcut.SetWorkingDirectory(mainpath)
shortcut.SetIconLocation(iconname, 0)
if os.path.splitext(lnkname)[-1] != '.lnk':
lnkname += ".lnk"
shortcut.QueryInterface(pythoncom.IID_IPersistFile).Save(lnkname, 0)
return True
except Exception as e:
logger.warning("创建桌面快捷方式失败:{}", e.args)
return False
|