diff --git a/PySimpleGUIQt/Demo Programs/Qt_Demo_System_Tray_Icon.py b/PySimpleGUIQt/Demo Programs/Qt_Demo_System_Tray_Icon.py index ac0813ed..8d97274d 100644 --- a/PySimpleGUIQt/Demo Programs/Qt_Demo_System_Tray_Icon.py +++ b/PySimpleGUIQt/Demo Programs/Qt_Demo_System_Tray_Icon.py @@ -1,20 +1,41 @@ -import PySimpleGUIQt as sg logo = b'iVBORw0KGgoAAAANSUhEUgAAADIAAAAtCAMAAADbYcjNAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMAUExURQAAADBpmDFqmDBqmTFqmjJrmzJsmzJsnDNtnTRrmjVtmjZsmzRunTRunjVvnzdwnjVwnzpxnzVwoDZxoTdyojlyoThzozhzpDh0pDp1pjp2pj51ozt3qDt4qDx4qDx5qj16qj57rD58rT98rkF1oEB4pUB4pkR6pkJ6qEN8q0B9rUB9rkB+rkV7qUZ8qUp9p0x+p0h/rEB+sEeArkqArEqBr0uCrkKAsUKAskOCs0OCtESCtEWEtkaFuEaGuE2FsUiHukiIukmJvEmKvEqLvkuMvk2KuUyLvEyMv1OErVWDqlWHr1qHrVaIsVCMvFSPvV2LsViOuVSQvmyUtmyXuXKbvXefv3ugv06NwE6OwFmUwl2XxGScyGmbw22hynikxnmmyv/UO//UPP/VPf/UPv/VP//UQP/VQf/VQv/WQP/WQf/WQv/WQ//XRP/WRf/WSf/YRf/YRv/YR//YSP/ZSf/ZSv/aS//aTP/aTf/bTv/YUf/ZUv/bUP/cUP/cUv/dVP/dVv/eVv/bW//dWf/cWv/eWP/fWv/dXf/fXf/eXv/cYP/fYP/dZP/dZv/eZf/fZv/eaP/gW//gXP/gXv/gYP/iYf/iYv/hZP/jZP/iZv/kZv/jaf/ja//kaP/lav/kbP/lb//mbP/mbv/ncP/mcv/iff/ocv/odP/odv/oeP/of//qf4GnxYOox4SoxYSpx4asyo+ux4isyouuyouvzIyuyYyvy4yvzI6wy46wzIyz0pCuyJSxyZWyy5u3zZ24zpW30pG52J250J+60aC60KS90aDC3a3E163F2K3F2bPI2bvO3rzP3qvJ4LHN4rnR5P/qgf/qgv/qiP/sif/sjf/sj//olf/ql//ulv/omf/qnv/tnP/qoP/ro//qpP/sov/upf/tqP/uqP/vrf/vrv/us//wpP/wpv/xrf/wsP/wsv/ys//xtP/ytf/ytv/zuf/zuv/0vP/0vsDS38XZ6cnb6f/xw//zwv/yxf/1w//zyP/1yf/2zP/3z//30wAAAM55ho4AAAEAdFJOU////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////wBT9wclAAAACXBIWXMAABcQAAAXEAEYYRHbAAAAGHRFWHRTb2Z0d2FyZQBwYWludC5uZXQgNC4xLjFjKpxLAAADnElEQVRIS62OeVhUZRSHw6IosQzGBgoIszKXqGylghKwbHErNVPbEFQQTXYogzZtt2SmiSEHnBHJPdM2Ldv3xbW91Pay0tT29dc53znfvTP809Pz9P7x3Xvu8773fHvhP/M/JBce0GX/8/WduX3ipDt/1nclNrk4TnhR5y1FVzHX/KqzISY5Uou4uLVm/sgEzF1mFqKTruozL9D8gfrM1aIwbvJaF7WFJ4FJqgtb1XOTN1R1eBqYrLbwvpo2+SF2B/NEbFNY+IWoNum6t0UD4imgTO3CCROKiqaJqsnx8fHx+7ho/RBALsnFxcUlJSWlNxpXkkv2I/a1uPnLWEA626WlU6aUlf3uJomJiccdlJDAoQvFBwPsklw2deq06dNnO8nIbj3oHE4hkWDQ7HVcSzLb5eXlFRWVTtKj+/P8OJDojfO6Wahfi3uMW1FZWVVVVV39jk2Skl6RR9JhwOjunDJUPYfZ1q6uqampvcUmWZ4sOpcnJ9Pj8WQqHYAZ4tbW1tXV19ffbJNXPZ6sUUM8nqOBRzweT7LDBQDZdcYmZlz3rk2wNCUlxes9iXYcwlBmOAq4W12moeE2liXBg9QcA6yiB+P1eqk8FtgmdoOh8SbjaoJlqacAj6ZqYqBffCJyo+GGO0S1CVYDKw8VUg0nAJ87NnOrmk4CPJYmSNeHdjQ2Xm/kmcx9qkUlKzKU9PT0tLSTaYeVZ84i/KpFJQ9nZmYermRknAh8qu6sOU1EUDXCJit6UuJwFu1gm+WmJp/PR7f6xr9NVE2eOYLoaeEdVvb5/H7/XOC7QCDwoXE16d+L4IzpC3xmZLb99wYC9wPbm5mP2ZVkRH9DP0OvK/CLcUkmmpvn0Y5gsKWlJRRykwEOXAJBI5NNBNtoRyhEJxa3bnKS005ltBoAqGz+3E47Qq2tO9gLR+jQJAbaItdgWhdje1tbOPwHe5GFdEhyuiE7O1sTkQ1t4fZwOBKJbCTt6/lfOsllZ0TzE9rZpV8bORKZz2z46q2ODpYlwZmCJFfiTyuL3WHZzK4ma7QRgJ2dZcG4mmBoriEnJ4eSc4BvO9vMe0a1CQZKIwwDdqkWxRIxnWT9QOJsITd3KN1NRRc1nQTrzs3L40y4CNitprLwbxXdBD/mM3nCWPoQs+cBkYioBLi8oMBk+flcAHtUJ942HwwxCd4cM2hQATFO5+81WPSbfmBiE+Cl8ZcOHvusDsBfG+hKm/foJHRO/hXgH831bVAP1oP5AAAAAElFTkSuQmCC' +import PySimpleGUIQt as sg + + +layout = [ + [sg.Text('Press Message to show message using bubble in system tray') ], + [sg.Text('Note that on some windows configurations these message are blocked') ], + [sg.Button('Message'), sg.Button('Hide'), sg.Button('UnHide')] + ] + +window = sg.Window('My window').Layout(layout) -menu_def = ['File', ['&Open', '&Save',['1', '2', ['a','b']], '&Properties', 'E&xit']] +menu_def = ['File', ['Hide', '&Open', '&Save',['1', '2', ['a','b']], '&Properties', 'E&xit']] tray = sg.SystemTray('My Tray', menu=menu_def, data_base64=logo) while True: + event, values = window.Read(timeout=200) + if event == 'Message': + print('showing message') + tray.ShowMessage('Title', 'message goes here', data_base64=logo) + elif event is None: + break + elif event == 'Hide': + tray.Hide() + elif event == 'UnHide': + tray.UnHide() + menu_item = tray.Read(timeout=0) if menu_item is not None: print(menu_item) if menu_item == 'Exit': break + if menu_item == 'Hide': + tray.Hide() + if menu_item == 'Open': - window = sg.Window('My win').Layout([[sg.Text('My layout')]]) - event, values = window.Read() - print(event, values) \ No newline at end of file + tray.ShowMessage('Title', 'message goes here',filename= r'C:\Python\PycharmProjects\GooeyGUI\Qt\logo500.png') diff --git a/PySimpleGUIQt/PySimpleGUIQt.py b/PySimpleGUIQt/PySimpleGUIQt.py index 851fea2a..bc7ef597 100644 --- a/PySimpleGUIQt/PySimpleGUIQt.py +++ b/PySimpleGUIQt/PySimpleGUIQt.py @@ -2656,6 +2656,14 @@ class ErrorElement(Element): # ------------------------------------------------------------------------- # class SystemTray: def __init__(self, title, filename=None, menu=None, data=None, data_base64=None): + ''' + SystemTray - create an icon in the system tray + :param title: + :param filename: + :param menu: + :param data: + :param data_base64: + ''' self.Title = title self.Menu = menu self.TrayIcon = None @@ -2700,6 +2708,11 @@ class SystemTray: def Read(self, timeout=None): + ''' + Reads the context menu + :param timeout: Optional. Any value other than None indicates a non-blocking read + :return: + ''' if not self.Shown: self.Shown = True self.TrayIcon.show() @@ -2714,9 +2727,46 @@ class SystemTray: self.MenuItemChosen = None return item + def Hide(self): + self.TrayIcon.hide() + + def UnHide(self): + self.TrayIcon.show() + + def ShowMessage(self, title, message, filename=None, data=None, data_base64=None, time=10000): + ''' + Shows a balloon above icon in system tray + :param title: Title shown in balloon + :param message: Message to be displayed + :param filename: Optional icon filename + :param data: Optional in-ram icon + :param data_base64: Optional base64 icon + :param time: How long to display message in milliseconds + :return: + ''' + qicon = None + if filename is not None: + qicon = QIcon(filename) + elif data is not None: + ba = QtCore.QByteArray.fromRawData(data) + pixmap = QtGui.QPixmap() + pixmap.loadFromData(ba) + qicon = QIcon(pixmap) + elif data_base64 is not None: + ba = QtCore.QByteArray.fromBase64(data_base64) + pixmap = QtGui.QPixmap() + pixmap.loadFromData(ba) + qicon = QIcon(pixmap) + + if qicon is not None: + self.TrayIcon.showMessage(title, message, qicon, time) + else: + self.TrayIcon.showMessage(title, message) + + return self def Close(self): - self.App.__del__() + self.App.quit() # ------------------------------------------------------------------------- # diff --git a/PySimpleGUIQt/readme.md b/PySimpleGUIQt/readme.md index 2d4eba85..dda35e6b 100644 --- a/PySimpleGUIQt/readme.md +++ b/PySimpleGUIQt/readme.md @@ -133,7 +133,7 @@ These Elements are "complete" (a relative term... more are more complete than ot * Fonts * Colors for text and background * Timeouts for Read calls -* Change Submits parametes for most Elements +* Change Submits parameters for most Elements * Table * Basic display * Read selected rows @@ -145,6 +145,7 @@ These Elements are "complete" (a relative term... more are more complete than ot * Tree Element * Tabs * Menus +* Menu Button Element @@ -153,12 +154,114 @@ These Elements are "complete" (a relative term... more are more complete than ot Notable MISSING features at the moment include: * Graphs Element Methods - erasing, draw arc, etc -## Release Notes: +# New PySimpleGUI Features + +There are a number of new features that are only available in PySimpleGUIQt. These include: +* ButtonMenu Element +* Dial Element +* Stretcher Element +* SystemTray feature + +## SystemTray + +In addition to running normal windows, it's now also possible to have an icon down in the system tray that you can read to get menu events. There is a new SystemTray object that is used much like a Window object. You first get one, then you perform Reads in order to get events. In this case the only events you'll receive are menu selections and timeouts. + +Here is the definition of the SystemTray object. + +```python +SystemTray:(title, filename=None, menu=None, data=None, data_base64=None): + ''' + SystemTray - create an icon in the system tray + :param title: Not currently used. A placeholder / name reminder + :param filename: PNG/ICO/? file that will be used for icon + :param menu: + :param data: In-RAM image to be used for icon + :param data_base64: Base64 data to be used for icon + ''' +``` + +You'll notice that there are 3 different ways to specify the icon image. The base-64 parameter allows you to define a variable in your .py code that is the encoded image so that you do not need any additional files. Very handy feature. + +### System Tray Design Pattern + +Here is a design pattern you can use to get a jump-start. + +This program will create a system tray icon and perform a blocking Read. If the item "Open" is chosen from the system tray, then a window is shown on the screen. + +```python +import PySimpleGUIQt as sg + +menu_def = ['File', ['&Open', '&Save',['1', '2', ['a','b']], '&Properties', 'E&xit']] + +tray = sg.SystemTray('My Tray', menu=menu_def, filename=r'default_icon.ico') + +while True: + menu_item = tray.Read() + if menu_item is not None: print(menu_item) + + if menu_item == 'Exit': + break + if menu_item == 'Open': + window = sg.Window('My win').Layout([[sg.Text('My layout')]]) + event, values = window.Read() + print(event, values) +``` +## SystemTray Methods + +### Read - Read the context menu + +```python +def Read(timeout=None): + ''' + Reads the context menu + :param timeout: Optional. Any value other than None indicates a non-blocking read + :return: String representing meny item chosen. None if nothing read. + ''' +``` + +### Hide + +Hides the icon + +```python +def Hide(): +``` + + +### UnHide + +Shows a previously hidden icon + +```python +def UnHide(): +``` + +### ShowMessage + +Shows a balloon above the icon in the system tray area + +```python +def ShowMessage(title, message, filename=None, data=None, data_base64=None, time=10000): + ''' + Shows a balloon above icon in system tray + :param title: Title shown in balloon + :param message: Message to be displayed + :param filename: Optional icon filename + :param data: Optional in-ram icon + :param data_base64: Optional base64 icon + :param time: How long to display message in milliseconds + :return: self (for call chaining) + ''' +``` + + + +# Release Notes: ### 0.12.0 - 20-Nov-2018 -Correctly restore stdout when OutputElement is deleted +Correctly restore stdout when Output Element is deleted Added Finalize ability -**Better multiwindow handling... maybe it's finally fixed!** +**Better multi-window handling... maybe it's finally fixed!** Radio button default value Dial element default value Show expanded option for trees @@ -223,14 +326,24 @@ Force window sizing should mean windows are better sized Popup - better layout - -## Design +### 0.15.0 24-Nov-2018 + +New SystemTray feature! +margin paramter for Text Element. Takes 4 ints +Corrected button colors when disabled. For now am restoring them to original colors +Border Depth for all elements that support it (inputs, slider, table, tree, etc) +Fix for Element padding done incorrectly!! Sorry about this one + + + + +# Design ## Author Mike B. -## Demo Code Contributors +# Demo Code Contributors - ## License +# License GNU Lesser General Public License (LGPL 3) + -## Acknowledgments \ No newline at end of file +# Acknowledgments \ No newline at end of file