commit
d35760d650
|
@ -1,46 +1,72 @@
|
||||||
|
"""
|
||||||
|
Demonstrates how to use a window in conjunction with a system tray icon to simulate the typical
|
||||||
|
windows program that uses the system tray
|
||||||
|
|
||||||
|
When the window is showing, there is no system tray icon shown.
|
||||||
|
When closing the window with X button, the system tray is activated
|
||||||
|
Clicking the "Minimize to Tray" button causes the window to disappear and the tray icon to appear
|
||||||
|
Double clicking tray icon causes window to re-appear
|
||||||
|
Choosing "Restore" from system tray right click menu will retore the window
|
||||||
|
"""
|
||||||
|
|
||||||
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+/P8OJDojfO6Wahfi3uMW1FZWVVVVV39jk2Skl6RR9JhwOjunDJUPYfZ1q6uqampvcUmWZ4sOpcnJ9Pj8WQqHYAZ4tbW1tXV19ffbJNXPZ6sUUM8nqOBRzweT7LDBQDZdcYmZlz3rk2wNCUlxes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vkuMvk2KuUyLvEyMv1OErVWDqlWHr1qHrVaIsVCMvFSPvV2LsViOuVSQvmyUtmyXuXKbvXefv3ugv06NwE6OwFmUwl2XxGScyGmbw22hynikxnmmyv/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/1nclN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sBfG+hKm/foJHRO/hXgH831bVAP1oP5AAAAAElFTkSuQmCC'
|
||||||
|
|
||||||
|
|
||||||
import PySimpleGUIQt as sg
|
import PySimpleGUIQt as sg
|
||||||
|
|
||||||
|
# create and then hide the tray icon
|
||||||
|
menu_def = ['My Menu Def', ['&Restore', '&Open', '&Save',['1', '2', ['a','b']], '&Properties', 'E&xit']]
|
||||||
|
tray = sg.SystemTray('Title', menu=menu_def, data_base64=logo)
|
||||||
|
tray.Hide()
|
||||||
|
|
||||||
|
# create the window
|
||||||
layout = [
|
layout = [
|
||||||
[sg.Text('Press Message to show message using bubble in system tray') ],
|
[sg.Text('Tray Icon Demo') ],
|
||||||
[sg.Text('Note that on some windows configurations these message are blocked') ],
|
[sg.Button('Minimize to Tray')]
|
||||||
[sg.Button('Message'), sg.Button('Hide'), sg.Button('UnHide')]
|
|
||||||
]
|
]
|
||||||
|
|
||||||
window = sg.Window('My window').Layout(layout)
|
window = sg.Window('My window').Layout(layout)
|
||||||
|
|
||||||
import PySimpleGUIQt as sg
|
tray_visible = False
|
||||||
|
window_visible = True
|
||||||
menu_def = ['File', ['Hide::key', '&Open::key', '&Save',['1', '2', ['a','b']], '&Properties', 'E&xit']]
|
window_closed = False
|
||||||
|
while True: # the event loop
|
||||||
tray = sg.SystemTray('My Tray', menu=menu_def, data_base64=logo, tooltip='My PySimpleGUIQt tray icon')
|
# do normal window operations
|
||||||
while True:
|
if window_visible:
|
||||||
menu_item = tray.Read(timeout=0)
|
|
||||||
if menu_item == sg.EVENT_SYSTEM_TRAY_ICON_ACTIVATED:
|
|
||||||
# tray.ShowMessage('Activation', 'You activated the icon', data_base64=logo)
|
|
||||||
pass
|
|
||||||
elif menu_item == sg.EVENT_SYSTEM_TRAY_MESSAGE_CLICKED:
|
|
||||||
tray.ShowMessage('Message Click', 'You clicked the message', data_base64=logo)
|
|
||||||
elif menu_item == sg.EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED:
|
|
||||||
tray.ShowMessage('Double click', 'Double clicked')
|
|
||||||
elif menu_item == 'Exit':
|
|
||||||
break
|
|
||||||
elif menu_item != sg.TIMEOUT_KEY:
|
|
||||||
print('Tray menu item = {}'.format(menu_item))
|
|
||||||
|
|
||||||
event, values = window.Read()
|
event, values = window.Read()
|
||||||
if event == 'Message':
|
print(event)
|
||||||
print('showing message')
|
if event is None: # if window closed with X
|
||||||
tray.ShowMessage('Title', 'message goes here', data_base64=logo)
|
|
||||||
elif event is None:
|
|
||||||
break
|
|
||||||
elif event == 'Hide':
|
|
||||||
tray.Hide()
|
|
||||||
elif event == 'UnHide':
|
|
||||||
tray.UnHide()
|
tray.UnHide()
|
||||||
#
|
tray_visible = True
|
||||||
# if menu_item == 'Open':
|
window_visible = False
|
||||||
# tray.ShowMessage('Title', 'message goes here',filename= r'C:\Python\PycharmProjects\GooeyGUI\Qt\logo500.png')
|
window_closed = True
|
||||||
print("EXITING PROGRAM")
|
elif event == 'Minimize to Tray':
|
||||||
|
print('Minimizing to tray')
|
||||||
|
window.Hide()
|
||||||
|
tray.UnHide()
|
||||||
|
tray_visible = True
|
||||||
|
window_visible = False
|
||||||
|
elif event == 'Message':
|
||||||
|
tray.ShowMessage('Title of message', 'This is a tray message')
|
||||||
|
# do tray icon stuff. Tray events will cause the window.Read call to return with a Timeout event
|
||||||
|
if tray_visible:
|
||||||
|
menu_item = tray.Read()
|
||||||
|
if menu_item == 'Restore' or menu_item == sg.EVENT_SYSTEM_TRAY_ICON_DOUBLE_CLICKED:
|
||||||
|
print('Restoring')
|
||||||
|
tray.Hide()
|
||||||
|
tray_visible = False
|
||||||
|
window_visible = True
|
||||||
|
# If the window was completely closed, must get a BRAND NEW WINDOW MADE from scratch. No re-use allowed
|
||||||
|
if window_closed:
|
||||||
|
window_closed = False
|
||||||
|
layout = [
|
||||||
|
[sg.Text('Tray Icon Demo')],
|
||||||
|
[sg.Button('Minimize to Tray')]
|
||||||
|
]
|
||||||
|
window = sg.Window('My window').Layout(layout)
|
||||||
|
else:
|
||||||
|
window.UnHide()
|
||||||
|
else: # some other tray command was received
|
||||||
|
print('Menu item %s'%menu_item)
|
||||||
|
if menu_item == 'Exit':
|
||||||
|
break
|
||||||
|
|
||||||
|
|
|
@ -2730,6 +2730,7 @@ class SystemTray:
|
||||||
self.TrayIcon.activated.connect(self.doubleClicked)
|
self.TrayIcon.activated.connect(self.doubleClicked)
|
||||||
self.TrayIcon.setContextMenu(qmenu)
|
self.TrayIcon.setContextMenu(qmenu)
|
||||||
|
|
||||||
|
self.TrayIcon.show()
|
||||||
|
|
||||||
def QT_MenuItemChosenCallback(self, item_chosen):
|
def QT_MenuItemChosenCallback(self, item_chosen):
|
||||||
self.MenuItemChosen = item_chosen.replace('&','')
|
self.MenuItemChosen = item_chosen.replace('&','')
|
||||||
|
@ -3093,7 +3094,7 @@ class Window:
|
||||||
else:
|
else:
|
||||||
if not self.XFound and self.Timeout != 0 and self.Timeout is not None and self.ReturnValues[0] is None: # Special Qt case because returning for no reason so fake timeout
|
if not self.XFound and self.Timeout != 0 and self.Timeout is not None and self.ReturnValues[0] is None: # Special Qt case because returning for no reason so fake timeout
|
||||||
self.ReturnValues = self.TimeoutKey, self.ReturnValues[1] # fake a timeout
|
self.ReturnValues = self.TimeoutKey, self.ReturnValues[1] # fake a timeout
|
||||||
elif not self.XFound: # TODO HIGHLY EXPERIMENTAL... added due to tray icon interaction
|
elif not self.XFound and self.ReturnValues[0] is None: # TODO HIGHLY EXPERIMENTAL... added due to tray icon interaction
|
||||||
# print("*** Faking timeout ***")
|
# print("*** Faking timeout ***")
|
||||||
self.ReturnValues = self.TimeoutKey, self.ReturnValues[1] # fake a timeout
|
self.ReturnValues = self.TimeoutKey, self.ReturnValues[1] # fake a timeout
|
||||||
return self.ReturnValues
|
return self.ReturnValues
|
||||||
|
@ -3277,12 +3278,13 @@ class Window:
|
||||||
|
|
||||||
def Hide(self):
|
def Hide(self):
|
||||||
self._Hidden = True
|
self._Hidden = True
|
||||||
|
self.QT_QMainWindow.hide()
|
||||||
# TODO
|
# TODO
|
||||||
return
|
return
|
||||||
|
|
||||||
def UnHide(self):
|
def UnHide(self):
|
||||||
if self._Hidden:
|
if self._Hidden:
|
||||||
# TODO
|
self.QT_QMainWindow.show()
|
||||||
self._Hidden = False
|
self._Hidden = False
|
||||||
|
|
||||||
def Disappear(self):
|
def Disappear(self):
|
||||||
|
@ -4507,6 +4509,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
|
||||||
style += 'border: {}px solid gray; '.format(border_depth)
|
style += 'border: {}px solid gray; '.format(border_depth)
|
||||||
element.QT_QProgressBar.setStyleSheet(style)
|
element.QT_QProgressBar.setStyleSheet(style)
|
||||||
|
|
||||||
|
element.QT_QProgressBar.setTextVisible(False)
|
||||||
|
|
||||||
qt_row_layout.addWidget(element.QT_QProgressBar)
|
qt_row_layout.addWidget(element.QT_QProgressBar)
|
||||||
# ------------------------- INPUT RADIO BUTTON element ------------------------- #
|
# ------------------------- INPUT RADIO BUTTON element ------------------------- #
|
||||||
|
|
Loading…
Reference in New Issue