commit
4e970f0e4e
|
@ -0,0 +1,43 @@
|
|||
import PySimpleGUI as sg
|
||||
|
||||
'''
|
||||
IP Address entry window with digit validation and auto advance
|
||||
If not a digit or ., the ignored
|
||||
. will advance the focus to the next entry
|
||||
On the last input, once it's complete the focus moves to the OK button
|
||||
Pressing spacebar with focus on OK generates an _OK_ event
|
||||
'''
|
||||
|
||||
# create a short-cut element so don't have to type this in over and over
|
||||
InIp = lambda key: sg.Input(do_not_clear=True, size=(3, 1), key=key, pad=(0, 2))
|
||||
|
||||
layout = [[sg.Text('Your typed chars appear here:'), sg.Text('', key='_OUTPUT_')],
|
||||
[InIp(0), sg.T('.'), InIp(1), sg.T('.'), InIp(2), sg.T('.'), InIp(3)],
|
||||
[sg.Button('Ok', key='_OK_', bind_return_key=True), sg.Button('Exit')]]
|
||||
|
||||
window = sg.Window('Window Title', return_keyboard_events=True).Layout(layout)
|
||||
|
||||
while True: # Event Loop
|
||||
event, values = window.Read()
|
||||
print(event)
|
||||
if event is None or event == 'Exit':
|
||||
break
|
||||
elem = window.FindElementWithFocus()
|
||||
if elem is not None:
|
||||
key = elem.Key
|
||||
value = values[key] # get value of input field that has focus
|
||||
if event == '.' and key!= '_OK_': # if a ., then advance to next field
|
||||
elem.Update(value[:-1])
|
||||
value = value[:-1]
|
||||
next_elem = window.Element(key+1)
|
||||
next_elem.SetFocus()
|
||||
elif event not in '0123456789':
|
||||
elem.Update(value[:-1])
|
||||
elif len(value) > 2 and key < 3: # if 2 digits typed in, move on to next input
|
||||
next_elem = window.Element(key+1)
|
||||
next_elem.SetFocus()
|
||||
elif len(value)> 2 and key == 3:
|
||||
window.Element('_OK_').SetFocus()
|
||||
print('You entered IP Address {}.{}.{}.{}'.format(*values.values()))
|
||||
|
||||
window.Close()
|
|
@ -2,6 +2,7 @@
|
|||
import sys
|
||||
if sys.version_info[0] >= 3:
|
||||
import PySimpleGUI as sg
|
||||
# import PySimpleGUIQt as sg # portable to QT
|
||||
else:
|
||||
import PySimpleGUI27 as sg
|
||||
|
||||
|
@ -23,31 +24,18 @@ def MediaPlayerGUI():
|
|||
|
||||
# A text element that will be changed to display messages in the GUI
|
||||
|
||||
ImageButton = lambda key:sg.Button('', button_color=(background,background), image_filename=image_restart, image_size=(50, 50), image_subsample=2, border_width=0, key=key)
|
||||
|
||||
# define layout of the rows
|
||||
layout= [[sg.Text('Media File Player',size=(17,1), font=("Helvetica", 25))],
|
||||
[sg.Text('', size=(15, 2), font=("Helvetica", 14), key='output')],
|
||||
[sg.Button('', button_color=(background,background),
|
||||
image_filename=image_restart, image_size=(50, 50), image_subsample=2, border_width=0, key='Restart Song'),
|
||||
[ImageButton(key='Restart Song'), sg.Text(' ' * 2),
|
||||
ImageButton(key='Pause'),
|
||||
sg.Text(' ' * 2),
|
||||
sg.Button('', button_color=(background,background),
|
||||
image_filename=image_pause, image_size=(50, 50), image_subsample=2, border_width=0, key='Pause'),
|
||||
ImageButton(key='Next'),
|
||||
sg.Text(' ' * 2),
|
||||
sg.Button('', button_color=(background,background), image_filename=image_next, image_size=(50, 50), image_subsample=2, border_width=0, key='Next'),
|
||||
sg.Text(' ' * 2),
|
||||
sg.Text(' ' * 2), sg.Button('', button_color=(background,background),
|
||||
image_filename=image_exit, image_size=(50, 50), image_subsample=2, border_width=0, key='Exit')],
|
||||
sg.Text(' ' * 2),ImageButton(key='Exit')],
|
||||
[sg.Text('_'*20)],
|
||||
[sg.Text(' '*30)],
|
||||
[
|
||||
sg.Slider(range=(-10, 10), default_value=0, size=(10, 20), orientation='vertical', font=("Helvetica", 15)),
|
||||
sg.Text(' ' * 2),
|
||||
sg.Slider(range=(-10, 10), default_value=0, size=(10, 20), orientation='vertical', font=("Helvetica", 15)),
|
||||
sg.Text(' ' * 2),
|
||||
sg.Slider(range=(-10, 10), default_value=0, size=(10, 20), orientation='vertical', font=("Helvetica", 15))],
|
||||
[sg.Text(' Bass', font=("Helvetica", 15), size=(9, 1)),
|
||||
sg.Text('Treble', font=("Helvetica", 15), size=(7, 1)),
|
||||
sg.Text('Volume', font=("Helvetica", 15), size=(7, 1))]
|
||||
]
|
||||
|
||||
# Open a form, note that context manager can't be used generally speaking for async forms
|
||||
|
|
|
@ -1514,6 +1514,14 @@ class Button(Element):
|
|||
def GetText(self):
|
||||
return self.ButtonText
|
||||
|
||||
|
||||
def SetFocus(self):
|
||||
try:
|
||||
self.TKButton.focus_set()
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def __del__(self):
|
||||
try:
|
||||
self.TKButton.__del__()
|
||||
|
|
|
@ -1472,6 +1472,10 @@ class Button(Element):
|
|||
def GetText(self):
|
||||
return self.ButtonText
|
||||
|
||||
def SetFocus(self):
|
||||
self.QT_QPushButton.setFocus()
|
||||
|
||||
|
||||
def __del__(self):
|
||||
super().__del__()
|
||||
|
||||
|
@ -4484,6 +4488,24 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
|
|||
if element_size[1] is not None:
|
||||
element.QT_QPushButton.setFixedHeight(element_size[1])
|
||||
|
||||
|
||||
#
|
||||
# elif element.Data is not None:
|
||||
# qlabel.setText('')
|
||||
# ba = QtCore.QByteArray.fromRawData(element.Data)
|
||||
# pixmap = QtGui.QPixmap()
|
||||
# pixmap.loadFromData(ba)
|
||||
# qlabel.setPixmap(pixmap)
|
||||
# elif element.DataBase64:
|
||||
# qlabel.setText('')
|
||||
# ba = QtCore.QByteArray.fromBase64(element.DataBase64)
|
||||
# pixmap = QtGui.QPixmap()
|
||||
# pixmap.loadFromData(ba)
|
||||
# qlabel.setPixmap(pixmap)
|
||||
|
||||
if element.ImageFilename is not None:
|
||||
element.QT_QPushButton.setIcon(QtGui.QPixmap(element.ImageFilename))
|
||||
element.QT_QPushButton.setIconSize(QtGui.QPixmap(element.ImageFilename).rect().size())
|
||||
if element.ImageData:
|
||||
ba = QtCore.QByteArray.fromBase64(element.ImageData)
|
||||
pixmap = QtGui.QPixmap()
|
||||
|
|
Loading…
Reference in New Issue