Disable element, Release 0.2.0
This commit is contained in:
parent
538e469723
commit
698849d9b4
|
@ -0,0 +1,53 @@
|
|||
#!/usr/bin/env python
|
||||
import PySimpleGUIWeb as sg
|
||||
import time
|
||||
|
||||
# ---------------- Create Form ----------------
|
||||
layout = [
|
||||
[sg.Text('', background_color='black')],
|
||||
[sg.Text('test', size=(20, 1), font=('Helvetica', 30), justification='center', text_color='white', key='text', background_color='black')],
|
||||
[sg.Text('', background_color='black')],
|
||||
[sg.Button('Pause', key='button', button_color=('white', '#001480')),
|
||||
sg.Button('Reset', button_color=('white', '#007339'), key='Reset'),
|
||||
sg.Exit(button_color=('white', '#8B1A1A'), key='Exit')]
|
||||
]
|
||||
|
||||
window = sg.Window('Running Timer', background_color='black', font='Helvetica 18').Layout(layout)
|
||||
|
||||
# ---------------- main loop ----------------
|
||||
current_time = 0
|
||||
paused = False
|
||||
start_time = int(round(time.time() * 100))
|
||||
while (True):
|
||||
# --------- Read and update window --------
|
||||
if not paused:
|
||||
event, values = window.Read(timeout=0)
|
||||
current_time = int(round(time.time() * 100)) - start_time
|
||||
else:
|
||||
event, values = window.Read()
|
||||
if event == 'button':
|
||||
event = window.FindElement(event).GetText()
|
||||
# --------- Do Button Operations --------
|
||||
if event is None or event == 'Exit': # ALWAYS give a way out of program
|
||||
break
|
||||
if event is 'Reset':
|
||||
start_time = int(round(time.time() * 100))
|
||||
current_time = 0
|
||||
paused_time = start_time
|
||||
elif event == 'Pause':
|
||||
paused = True
|
||||
paused_time = int(round(time.time() * 100))
|
||||
element = window.FindElement('button')
|
||||
element.Update(text='Run')
|
||||
elif event == 'Run':
|
||||
paused = False
|
||||
start_time = start_time + int(round(time.time() * 100)) - paused_time
|
||||
element = window.FindElement('button')
|
||||
element.Update(text='Pause')
|
||||
|
||||
# --------- Display timer in window --------
|
||||
window.FindElement('text').Update('{:02d}:{:02d}.{:02d}'.format((current_time // 100) // 60,
|
||||
(current_time // 100) % 60,
|
||||
current_time % 100))
|
||||
# --------- After loop --------
|
||||
window.Close()
|
|
@ -494,8 +494,7 @@ class Element():
|
|||
class InputText(Element):
|
||||
def __init__(self, default_text='', size=(None, None), disabled=False, password_char='',
|
||||
justification=None, background_color=None, text_color=None, font=None, tooltip=None,
|
||||
change_submits=False,
|
||||
do_not_clear=False, key=None, focus=False, pad=None):
|
||||
change_submits=False, do_not_clear=False, key=None, focus=False, pad=None):
|
||||
'''
|
||||
Input a line of text Element
|
||||
:param default_text: Default value to display
|
||||
|
@ -1061,6 +1060,7 @@ class Text(Element):
|
|||
pixelsize = size[0]*10, size[1]*20
|
||||
self.WxStaticText:wx.StaticText = None # wx.StaticText(form.MasterPanel, -1, element.DisplayText)
|
||||
self.BorderWidth = border_width if border_width is not None else DEFAULT_BORDER_WIDTH
|
||||
self.Disabled = False
|
||||
|
||||
super().__init__(ELEM_TYPE_TEXT, pixelsize, auto_size_text, background_color=bg, font=font if font else DEFAULT_FONT,
|
||||
text_color=self.TextColor, pad=pad, key=key, tooltip=tooltip, size_px=size_px, visible=visible)
|
||||
|
@ -3897,8 +3897,11 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
|
|||
widget.style['color'] = element.TextColor
|
||||
widget.style['font-size'] = '{}px'.format(font_info[1])
|
||||
size = convert_tkinter_size_to_Wx(element_size)
|
||||
# if not auto_size_text:
|
||||
widget.style['height'] = '{}px'.format(size[1])
|
||||
widget.style['width'] = '{}px'.format(size[0])
|
||||
if element.Disabled:
|
||||
widget.set_enabled(False)
|
||||
#
|
||||
# widget.SetMinSize(element_size)
|
||||
# if element.Disabled:
|
||||
|
@ -3992,7 +3995,6 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
|
|||
element.Widget.style['text-align'] = 'center'
|
||||
elif element.Justification.startswith('r'):
|
||||
element.Widget.style['text-align'] = 'right'
|
||||
|
||||
tk_row_frame.append(element.Widget)
|
||||
|
||||
# auto_size_text = element.AutoSizeText
|
||||
|
@ -6458,18 +6460,18 @@ def PopupGetText(message, default_text='', password_char='', size=(None, None),
|
|||
def main():
|
||||
SetOptions(background_color='blue', text_element_background_color='blue', text_color='white')
|
||||
layout = [[Text('You are running the PySimpleGUI.py file itself', background_color='blue', font='Courier 20')],
|
||||
[Text('You should be importing it rather than running it', size=(50, 2))],
|
||||
[Text('You should be importing it rather than running it', size=(60, 1))],
|
||||
[Text('Here is your sample input window....')],
|
||||
[Text('Source Folder',justification='right'), InputText('Source', focus=True),
|
||||
[Text('Source Folder',justification='right', size=(40,1)), InputText('Source', focus=True, disabled=True),
|
||||
FolderBrowse()],
|
||||
[Text('Destination Folder', justification='right'), InputText('Dest'), FolderBrowse()],
|
||||
[Ok(), Cancel()]]
|
||||
[Text('Destination Folder', justification='right', size=(40,1)), InputText('Dest'), FolderBrowse()],
|
||||
[Ok(), Cancel(disabled=True), Exit()]]
|
||||
|
||||
window = Window('Demo window..', background_color='blue', font='Courier 18').Layout(layout)
|
||||
while True:
|
||||
event, values = window.Read()
|
||||
print(event, values)
|
||||
if event is None:
|
||||
if event in (None, 'Exit'):
|
||||
break
|
||||
window.Close()
|
||||
|
||||
|
|
Loading…
Reference in New Issue