Fix a couple bugs/niggles

This commit is contained in:
Raoul Snyman 2017-08-11 10:36:03 -07:00
parent 10145545cb
commit f477495977
3 changed files with 51 additions and 10 deletions

View File

@ -1,12 +1,21 @@
Changelog
=========
Version 0.3
-----------
Released: 2017-08-11
- Shorten the time the tray icon message shows to 5 seconds
- Force the window to raise above other applications when clicking on the tray icon
- Toggle between showing and hiding the window when clicking on the tray icon
Version 0.2
-----------
Released: 2017-06-13
- Added the ability tpo minimize to a system tray icon
- Added the ability to minimize to a system tray icon
- Moved the module into a file instead of a directory
- Updated setup.py for the module move

View File

@ -13,7 +13,7 @@ with open(os.path.join(HERE, 'README.rst'), encoding='utf8') as f:
setup(
name='WebAppify',
version='0.2',
version='0.3',
description='Create desktop apps of your favourite websites',
long_description=LONG_DESCRIPTION,
url='https://launchpad.net/webappify',

View File

@ -26,6 +26,8 @@ import platform
from PyQt5 import QtCore, QtGui, QtWidgets
IS_PY2 = sys.version_info[0] == 2
try:
from PyQt5 import QtWebEngineWidgets
HAS_WEBENGINE = True
@ -79,10 +81,10 @@ class WebWindow(QtWidgets.QWidget):
super(WebWindow, self).__init__(None)
self.hasShownWarning = False
self.app = app
self.icon = icon
self.icon = QtGui.QIcon(icon)
self.canMinimizeToTray = canMinimizeToTray
self.setWindowTitle(title)
self.setWindowIcon(QtGui.QIcon(self.icon))
self.setWindowIcon(self.icon)
self.setContentsMargins(0, 0, 0, 0)
self.layout = QtWidgets.QVBoxLayout(self)
self.layout.setContentsMargins(0, 0, 0, 0)
@ -102,7 +104,7 @@ class WebWindow(QtWidgets.QWidget):
if not self.hasShownWarning:
self.trayIcon.showMessage(self.windowTitle(), 'This program will continue running in the system tray. '
'To close the program, choose <b>Quit</b> in the context menu of the system '
'tray icon.')
'tray icon.', QtWidgets.QSystemTrayIcon.Information, 5000)
self.hasShownWarning = True
def _updateTrayMenu(self):
@ -115,17 +117,44 @@ class WebWindow(QtWidgets.QWidget):
self.minimizeAction.setEnabled(self.isVisible() and not self.isMinimized())
self.maximizeAction.setEnabled(self.isVisible() and not self.isMaximized())
def _raiseWindow(self):
"""
Raise the Window, depending on the version of Python
"""
# Get the "raise" method depending on Python 2 or 3
if IS_PY2:
raiser = getattr(self, 'raise_')
else:
raiser = getattr(self, 'raise')
raiser()
def _restoreWindow(self):
"""
Restore the window and activate it
"""
self.showNormal()
self.activateWindow()
self._raiseWindow()
def _maximizeWindow(self):
"""
Restore the window and activate it
"""
self.showMaximized()
self.activateWindow()
self._raiseWindow()
def _getTrayMenu(self):
"""
Create and return the menu for the tray icon
"""
# Create the actions for the menu
self.restoreAction = QtWidgets.QAction('&Restore', self)
self.restoreAction.triggered.connect(self.showNormal)
self.restoreAction.triggered.connect(self._restoreWindow)
self.minimizeAction = QtWidgets.QAction('Mi&nimize', self)
self.minimizeAction.triggered.connect(self.close)
self.maximizeAction = QtWidgets.QAction('Ma&ximize', self)
self.maximizeAction.triggered.connect(self.showMaximized)
self.maximizeAction.triggered.connect(self._maximizeWindow)
self.quitAction = QtWidgets.QAction('&Quit', self)
self.quitAction.triggered.connect(self.app.quit)
# Create the menu and add the actions
@ -141,7 +170,7 @@ class WebWindow(QtWidgets.QWidget):
"""
Set up the tray icon
"""
self.trayIcon = QtWidgets.QSystemTrayIcon(QtGui.QIcon(self.icon), self)
self.trayIcon = QtWidgets.QSystemTrayIcon(self.icon, self)
self.trayIcon.setContextMenu(self._getTrayMenu())
self.trayIcon.activated.connect(self.onTrayIconActivated)
self.trayIcon.show()
@ -201,7 +230,10 @@ class WebWindow(QtWidgets.QWidget):
React to the tray icon being activated
"""
if reason == QtWidgets.QSystemTrayIcon.Trigger:
self.showNormal()
if self.isVisible():
self.close()
else:
self.showNormal()
class WebApp(QtWidgets.QApplication):
@ -234,7 +266,7 @@ class WebApp(QtWidgets.QApplication):
self.window.setupTrayIcon()
self.window.showMaximized()
# Get the "exec" method depending on Python 2 or 3
if sys.version_info[0] == 2:
if IS_PY2:
runner = getattr(self, 'exec_')
else:
runner = getattr(self, 'exec')