Release 0.18.0 Qt
This commit is contained in:
parent
c8556d517f
commit
0c651c186c
4 changed files with 353 additions and 73 deletions
|
@ -26,7 +26,7 @@
|
|||
"Qt without the ugly"
|
||||
|
||||
|
||||
## The Alpha Release Version 0.13.0
|
||||
## The Alpha Release Version 0.18.0
|
||||
[Announcements of Latest Developments](https://github.com/MikeTheWatchGuy/PySimpleGUI/issues/142)
|
||||
|
||||
|
||||
|
@ -37,7 +37,7 @@ Welcome to the Alpha Release of PySimpleGUI for Qt!
|
|||
|
||||
You can use the exact same code that you are running on the older, tkinter, version of PySimpleGUI.
|
||||
|
||||
PySimpleGUIQt uses **PySide2** OR **PyQt5** for access to Qt.
|
||||
PySimpleGUIQt uses **PySide2** OR **PyQt5** for access to Qt. PyQt5 has been having a number of problems recently however so tread lightly.
|
||||
|
||||
## Porting your PySimpleGUI code to PySimpleGUIQt
|
||||
|
||||
|
@ -66,15 +66,15 @@ Fonts should be in the format (font family, size). You can use the older string
|
|||
On Linux systems you need to run pip3.
|
||||
|
||||
pip3 install --upgrade PySimpleGUIQt
|
||||
### Installing PySide2 or PyQt5 for Python 3
|
||||
### Installing PySide2 for Python 3
|
||||
|
||||
It is recommended that you use PySide2, however, if that cannot be found, then PyQt5 will be attempted. To install either of these:
|
||||
|
||||
```pip install PySide2```
|
||||
or
|
||||
|
||||
```pip install PyQt5```
|
||||
|
||||
|
||||
**Nov 26th - There has been a number of problems found using PyQt5 recently. Unclear how if it can be supported after all.**
|
||||
|
||||
## Testing your installation
|
||||
Once you have installed, or copied the .py file to your app folder, you can test the installation using python. At the command prompt start up Python.
|
||||
|
||||
|
@ -91,10 +91,9 @@ Here is the window you should see:
|
|||
|
||||
|
||||
## Prerequisites Python 3
|
||||
PySide2 or PyQt5
|
||||
|
||||
|
||||
PySide2 or PyQt5 (experimental)
|
||||
|
||||
|
||||
## Using - Python 3
|
||||
To use in your code, simply import....
|
||||
`import PySimpleGUIQt as sg`
|
||||
|
@ -164,60 +163,102 @@ There are a number of new features that are only available in PySimpleGUIQt. Th
|
|||
|
||||
## 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.
|
||||
This is a PySimpleGUIQt only feature. Don't know of a way to do it using tkinter. It looks likely to work on WxPython however.
|
||||
|
||||
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.
|
||||
|
||||
Here is the definition of the SystemTray object.
|
||||
|
||||
```python
|
||||
SystemTray:(title, filename=None, menu=None, data=None, data_base64=None):
|
||||
SystemTray(menu=None, filename=None, data=None, data_base64=None, tooltip=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
|
||||
'''
|
||||
:param menu: Menu definition
|
||||
:param filename: filename for icon
|
||||
:param data: in-ram image for icon
|
||||
:param data_base64: basee-64 data for icon
|
||||
:param tooltip: tooltip string '''
|
||||
```
|
||||
|
||||
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
|
||||
## 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.
|
||||
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 popup is shown.
|
||||
|
||||
```python
|
||||
import PySimpleGUIQt as sg
|
||||
|
||||
menu_def = ['File', ['&Open', '&Save',['1', '2', ['a','b']], '&Properties', 'E&xit']]
|
||||
menu_def = ['BLANK', ['&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)
|
||||
tray = sg.SystemTray(menu=menu_def, filename=r'default_icon.ico')
|
||||
|
||||
while True: # The event loop
|
||||
menu_item = tray.Read()
|
||||
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)
|
||||
elif menu_item == 'Open':
|
||||
sg.Popup('Menu item chosen', menu_item)
|
||||
|
||||
```
|
||||
The design pattern creates an icon that will display this menu:
|
||||

|
||||
|
||||
### Icons
|
||||
|
||||
When specifying "icons", you can use 3 different formats.
|
||||
* `filename`- filename
|
||||
* `data_base64` - base64 byte string
|
||||
* '`data` - in-ram bitmap or other "raw" image
|
||||
|
||||
You will find 3 parameters used to specify these 3 options on both the initialize statement and on the Update method.
|
||||
|
||||
## Menu Definition
|
||||
```python
|
||||
menu_def = ['BLANK', ['&Open', '&Save', ['1', '2', ['a', 'b']], '&Properties', 'E&xit']]
|
||||
```
|
||||
|
||||
A menu is defined using a list. A "Menu entry" is a string that specifies:
|
||||
* text shown
|
||||
* keyboard shortcut
|
||||
* key
|
||||
|
||||
See section on Menu Keys for more informatoin on using keys with menus.
|
||||
|
||||
An entry without a key and keyboard shortcut is a simple string
|
||||
`'Menu Item'`
|
||||
|
||||
If you want to make the "M" be a keyboard shortcut, place an `&` in front of the letter that is the shortcut.
|
||||
`'&Menu Item'`
|
||||
|
||||
You can add "keys" to make menu items unique or as another way of identifying a menu item than the text shown. The key is added to the text portion by placing `::` after the text.
|
||||
|
||||
`'Menu Item::key'`
|
||||
|
||||
The first entry can be ignored.`'BLANK`' was chosen for this example. It's this way because normally you would specify these menus under some heading on a menu-bar. But here there is no heading so it's filled in with any value you want.
|
||||
|
||||
**Separators**
|
||||
If you want a separator between 2 items, add the entry `'---'` and it will add a separator item at that place in your menu.
|
||||
|
||||
|
||||
## SystemTray Methods
|
||||
|
||||
### Read - Read the context menu or check for events
|
||||
|
||||
```python
|
||||
def Read(timeout=None):
|
||||
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.
|
||||
'''
|
||||
```
|
||||
The `timeout` parameter specifies how long to wait for an event to take place. If nothing happens within the timeout period, then a "timeout event" is returned. These types of reads make it possible to run asynchronously. To run non-blocked, specify `timeout=0`on the Read call.
|
||||
|
||||
Read returns the menu text, complete with key, for the menu item chosen. If you specified `Open::key` as the menu entry, and the user clicked on `Open`, then you will receive the string `Open::key` upon completion of the Read.
|
||||
|
||||
#### Read special return values
|
||||
|
||||
|
@ -228,12 +269,20 @@ EVENT_SYSTEM_TRAY_ICON_ACTIVATED - Tray icon was single clicked
|
|||
EVENT_SYSTEM_TRAY_MESSAGE_CLICKED - a message balloon was clicked
|
||||
TIMEOUT_KEY is returned if no events are available if the timeout value is set in the Read call
|
||||
|
||||
|
||||
### Hide
|
||||
|
||||
Hides the icon
|
||||
Hides the icon. Note that no message balloons are shown while an icon is hidden.
|
||||
|
||||
```python
|
||||
def Hide():
|
||||
def Hide()
|
||||
```
|
||||
|
||||
### Close
|
||||
|
||||
Does the same thing as hide
|
||||
```python
|
||||
def Close()
|
||||
```
|
||||
|
||||
|
||||
|
@ -242,15 +291,26 @@ def Hide():
|
|||
Shows a previously hidden icon
|
||||
|
||||
```python
|
||||
def UnHide():
|
||||
def UnHide()
|
||||
```
|
||||
|
||||
### ShowMessage
|
||||
|
||||
Shows a balloon above the icon in the system tray area
|
||||
Shows a balloon above the icon in the system tray area. You can specify your own icon to be shown in the balloon, or you can set `messageicon` to one of the preset values.
|
||||
|
||||
This message has a custom icon.
|
||||
|
||||

|
||||
|
||||
The preset `messageicon` values are:
|
||||
|
||||
SYSTEM_TRAY_MESSAGE_ICON_INFORMATION
|
||||
SYSTEM_TRAY_MESSAGE_ICON_WARNING
|
||||
SYSTEM_TRAY_MESSAGE_ICON_CRITICAL
|
||||
SYSTEM_TRAY_MESSAGE_ICON_NOICON
|
||||
|
||||
```python
|
||||
def ShowMessage(title, message, filename=None, data=None, data_base64=None, time=10000):
|
||||
ShowMessage(title, message, filename=None, data=None, data_base64=None, messageicon=None, time=10000):
|
||||
'''
|
||||
Shows a balloon above icon in system tray
|
||||
:param title: Title shown in balloon
|
||||
|
@ -258,11 +318,35 @@ def ShowMessage(title, message, filename=None, data=None, data_base64=None, time
|
|||
: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)
|
||||
'''
|
||||
:param time: How long to display message in milliseconds :return:
|
||||
'''
|
||||
```
|
||||
Note, on windows it may be necessary to make a registry change to enable message balloons to be seen. To fix this, you must create the DWORD you see in this screenshot.
|
||||
|
||||

|
||||
|
||||
|
||||
### Update
|
||||
|
||||
You can update any of these items within a SystemTray object
|
||||
* Menu definition
|
||||
* Icon
|
||||
* Tooltip
|
||||
|
||||
Change them all or just 1.
|
||||
|
||||
```python
|
||||
Update(menu=None, tooltip=None,filename=None, data=None, data_base64=None,)
|
||||
'''
|
||||
Updates the menu, tooltip or icon
|
||||
:param menu: menu defintion
|
||||
:param tooltip: string representing tooltip
|
||||
:param filename: icon filename
|
||||
:param data: icon raw image
|
||||
:param data_base64: icon base 64 image
|
||||
:return:
|
||||
'''
|
||||
```
|
||||
## Menus with Keys
|
||||
|
||||
PySimpleGUIQt offers the ability to add a key to your menu items. To do so, you add :: and the key value to the end of your menu definition.
|
||||
|
@ -373,6 +457,18 @@ Menubar now returns values as does the ButtonMenu
|
|||
|
||||
Window.Hide and UnHide methods
|
||||
|
||||
### 0.18.0 26-Nov-2018
|
||||
|
||||
Tooltips for all elements
|
||||
Completion of all SystemTray features
|
||||
Read with or without timeout
|
||||
Specify icons from 3 sources
|
||||
Show message with custom or preset icons
|
||||
Update
|
||||
* Menu
|
||||
* Tooltip
|
||||
* Icon
|
||||
PopupScrolled - new location parameter, fixed bug that wasn't closing window when completed
|
||||
|
||||
# Design
|
||||
## Author
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue