OneLineProgressMeter with text updates

This commit is contained in:
MikeTheWatchGuy 2019-02-18 20:10:21 -05:00
parent bf41ebdf76
commit 85dfc451a9
3 changed files with 123 additions and 22 deletions

View File

@ -6162,7 +6162,7 @@ class QuickMeter(object):
layout = [] layout = []
if self.orientation.lower().startswith('h'): if self.orientation.lower().startswith('h'):
col = [] col = []
col += [[T(arg)] for arg in args] col += [[T(''.join(map(lambda x: str(x)+'\n',args)),key='_OPTMSG_')]] ### convert all *args into one string that can be updated
col += [[T('', size=(30,10), key='_STATS_')], col += [[T('', size=(30,10), key='_STATS_')],
[ProgressBar(max_value=self.max_value, orientation='h', key='_PROG_', size=self.size, bar_color=self.bar_color)], [ProgressBar(max_value=self.max_value, orientation='h', key='_PROG_', size=self.size, bar_color=self.bar_color)],
[Cancel(button_color=self.button_color), Stretch()]] [Cancel(button_color=self.button_color), Stretch()]]
@ -6170,7 +6170,7 @@ class QuickMeter(object):
else: else:
col = [[ProgressBar(max_value=self.max_value, orientation='v', key='_PROG_', size=self.size, bar_color=self.bar_color)]] col = [[ProgressBar(max_value=self.max_value, orientation='v', key='_PROG_', size=self.size, bar_color=self.bar_color)]]
col2 = [] col2 = []
col2 += [[T(arg)] for arg in args] col2 += [[T(''.join(map(lambda x: str(x)+'\n',args)),key='_OPTMSG_')]] ### convert all *args into one string that can be updated
col2 += [[T('', size=(30,10), key='_STATS_')], col2 += [[T('', size=(30,10), key='_STATS_')],
[Cancel(button_color=self.button_color), Stretch()]] [Cancel(button_color=self.button_color), Stretch()]]
layout = [Column(col), Column(col2)] layout = [Column(col), Column(col2)]
@ -6179,11 +6179,12 @@ class QuickMeter(object):
return self.window return self.window
def UpdateMeter(self, current_value, max_value): def UpdateMeter(self, current_value, max_value,*args): ### support for *args when updating
self.current_value = current_value self.current_value = current_value
self.max_value = max_value self.max_value = max_value
self.window.Element('_PROG_').UpdateBar(self.current_value, self.max_value) self.window.Element('_PROG_').UpdateBar(self.current_value, self.max_value)
self.window.Element('_STATS_').Update('\n'.join(self.ComputeProgressStats())) self.window.Element('_STATS_').Update('\n'.join(self.ComputeProgressStats()))
self.window.Element('_OPTMSG_').Update(value=''.join(map(lambda x: str(x)+'\n',args))) ### update the string with the args
event, values = self.window.Read(timeout=0) event, values = self.window.Read(timeout=0)
if event in('Cancel', None) or current_value >= max_value: if event in('Cancel', None) or current_value >= max_value:
self.window.Close() self.window.Close()
@ -6231,10 +6232,11 @@ def OneLineProgressMeter(title, current_value, max_value, key, *args, orientatio
else: else:
meter = QuickMeter.active_meters[key] meter = QuickMeter.active_meters[key]
rc = meter.UpdateMeter(current_value, max_value) rc = meter.UpdateMeter(current_value, max_value,*args) ### pass the *args to to UpdateMeter function
OneLineProgressMeter.exit_reasons = getattr(OneLineProgressMeter,'exit_reasons', QuickMeter.exit_reasons) OneLineProgressMeter.exit_reasons = getattr(OneLineProgressMeter,'exit_reasons', QuickMeter.exit_reasons)
return rc == METER_OK return rc == METER_OK
def OneLineProgressMeterCancel(key): def OneLineProgressMeterCancel(key):
try: try:
meter = QuickMeter.active_meters[key] meter = QuickMeter.active_meters[key]

View File

@ -8,6 +8,16 @@ import base64
import calendar import calendar
from random import randint from random import randint
###### ##### ##### # # ### #####
# # # # # # # # # ##### # ###### # # # # # # # #####
# # # # # # ## ## # # # # # # # # # # #
###### # ##### # # ## # # # # ##### # #### # # # # # #
# # # # # # ##### # # # # # # # # # # #
# # # # # # # # # # # # # # # # # #
# # ##### # # # # ###### ###### ##### ##### ### #### # #
FORCE_PYQT5 = False FORCE_PYQT5 = False
if not FORCE_PYQT5: if not FORCE_PYQT5:
@ -4404,9 +4414,48 @@ def AddMenuItem(top_menu, sub_menu_info, element, is_sub_menu=False, skip=False)
AddMenuItem(top_menu, item, element) AddMenuItem(top_menu, item, element)
i += 1 i += 1
"""
QQQQQQQQQ tttt
QQ:::::::::QQ ttt:::t
QQ:::::::::::::QQ t:::::t
Q:::::::QQQ:::::::Q t:::::t
Q::::::O Q::::::Qttttttt:::::ttttttt
Q:::::O Q:::::Qt:::::::::::::::::t
Q:::::O Q:::::Qt:::::::::::::::::t
Q:::::O Q:::::Qtttttt:::::::tttttt
Q:::::O Q:::::Q t:::::t
Q:::::O Q:::::Q t:::::t
Q:::::O QQQQ:::::Q t:::::t
Q::::::O Q::::::::Q t:::::t tttttt
Q:::::::QQ::::::::Q t::::::tttt:::::t
QQ::::::::::::::Q tt::::::::::::::t
QQ:::::::::::Q tt:::::::::::tt
QQQQQQQQ::::QQ ttttttttttt
Q:::::Q
QQQQQQ
"""
# My crappy Qt code starts here
# ░░░░░░░░░░░█▀▀░░█░░░░░░
# ░░░░░░▄▀▀▀▀░░░░░█▄▄░░░░
# ░░░░░░█░█░░░░░░░░░░▐░░░
# ░░░░░░▐▐░░░░░░░░░▄░▐░░░
# ░░░░░░█░░░░░░░░▄▀▀░▐░░░
# ░░░░▄▀░░░░░░░░▐░▄▄▀░░░░
# ░░▄▀░░░▐░░░░░█▄▀░▐░░░░░
# ░░█░░░▐░░░░░░░░▄░█░░░░░
# ░░░█▄░░▀▄░░░░▄▀▐░█░░░░░
# ░░░█▐▀▀▀░▀▀▀▀░░▐░█░░░░░
# ░░▐█▐▄░░▀░░░░░░▐░█▄▄░░░
# ░░░▀▀▄░░░░░░░░▄▐▄▄▄▀░░░
# ░░░░░░░░░░░░░░░░░░░░░░░
# ------------------------------------------------------------------------------------------------------------------ # # ------------------------------------------------------------------------------------------------------------------ #
# ------------------------------------------------------------------------------------------------------------------ # # ------------------------------------------------------------------------------------------------------------------ #
# ===================================== TK CODE STARTS HERE ====================================================== # # ===================================== Qt CODE STARTS HERE ====================================================== #
# ------------------------------------------------------------------------------------------------------------------ # # ------------------------------------------------------------------------------------------------------------------ #
# ------------------------------------------------------------------------------------------------------------------ # # ------------------------------------------------------------------------------------------------------------------ #
def style_entry(**kwargs): def style_entry(**kwargs):
@ -5735,27 +5784,28 @@ class QuickMeter(object):
def BuildWindow(self, *args): def BuildWindow(self, *args):
layout = [] layout = []
if self.orientation.lower().startswith('h'): if self.orientation.lower().startswith('h'):
col = [*[[T(arg)] for arg in args], col = [[T(''.join(map(lambda x: str(x)+'\n',args)),key='_OPTMSG_')]] ### convert all *args into one string that can be updated
[T('', size=(25,8), key='_STATS_')], col += [[T('', size=(25,5), key='_STATS_')],
[ProgressBar(max_value=self.max_value, orientation='h', key='_PROG_', size=self.size, [ProgressBar(max_value=self.max_value, orientation='h', key='_PROG_', size=self.size,
bar_color=self.bar_color)], bar_color=self.bar_color)],
[Cancel(button_color=self.button_color), Stretch()] ] [Cancel(button_color=self.button_color), Stretch()]]
layout += [Column(col)] layout += [Column(col)]
else: else:
col = [[ProgressBar(max_value=self.max_value, orientation='v', key='_PROG_', size=self.size, bar_color=self.bar_color)]] col = [[ProgressBar(max_value=self.max_value, orientation='v', key='_PROG_', size=self.size, bar_color=self.bar_color)]]
col2 = [*[[T(arg)] for arg in args], col2 = [[T(''.join(map(lambda x: str(x)+'\n',args)),key='_OPTMSG_')]] ### convert all *args into one string that can be updated
[T('', size=(25, 8), key='_STATS_')],[Cancel(button_color=self.button_color), Stretch()] ] col2 += [[T('', size=(25,5), key='_STATS_')],[Cancel(button_color=self.button_color), Stretch()]]
layout += [Column(col), Column(col2)] layout += [Column(col), Column(col2)]
self.window = Window(self.title, grab_anywhere=self.grab_anywhere, border_depth=self.border_width) self.window = Window(self.title, grab_anywhere=self.grab_anywhere, border_depth=self.border_width)
self.window.Layout([layout]).Finalize() self.window.Layout([layout]).Finalize()
return self.window return self.window
def UpdateMeter(self, current_value, max_value): def UpdateMeter(self, current_value, max_value, *args):
self.current_value = current_value self.current_value = current_value
self.max_value = max_value self.max_value = max_value
self.window.Element('_PROG_').UpdateBar(self.current_value, self.max_value) self.window.Element('_PROG_').UpdateBar(self.current_value, self.max_value)
self.window.Element('_STATS_').Update('\n'.join(self.ComputeProgressStats())) self.window.Element('_STATS_').Update('\n'.join(self.ComputeProgressStats()))
self.window.Element('_OPTMSG_').Update(value=''.join(map(lambda x: str(x)+'\n',args))) ### update the string with the args
event, values = self.window.Read(timeout=0) event, values = self.window.Read(timeout=0)
if event in('Cancel', None) or current_value >= max_value: if event in('Cancel', None) or current_value >= max_value:
self.window.Close() self.window.Close()
@ -5803,7 +5853,7 @@ def OneLineProgressMeter(title, current_value, max_value, key, *args, orientatio
else: else:
meter = QuickMeter.active_meters[key] meter = QuickMeter.active_meters[key]
rc = meter.UpdateMeter(current_value, max_value) rc = meter.UpdateMeter(current_value, max_value, *args)
OneLineProgressMeter.exit_reasons = getattr(OneLineProgressMeter,'exit_reasons', QuickMeter.exit_reasons) OneLineProgressMeter.exit_reasons = getattr(OneLineProgressMeter,'exit_reasons', QuickMeter.exit_reasons)
return rc == METER_OK return rc == METER_OK

View File

@ -1,6 +1,4 @@
#!/usr/bin/python3 #!/usr/bin/python3
#!/usr/bin/python3
#!/usr/bin/python3
import sys import sys
import wx import wx
@ -15,12 +13,30 @@ import pickle
import os import os
import time import time
###### ##### ##### # # ### # #
# # # # # # # # # ##### # ###### # # # # # # # # # #
# # # # # # ## ## # # # # # # # # # # # # #
###### # ##### # # ## # # # # ##### # #### # # # # # # ##
# # # # # # ##### # # # # # # # # # # ##
# # # # # # # # # # # # # # # # # # # #
# # ##### # # # # ###### ###### ##### ##### ### ## ## # #
""" """
21-Dec-2018 21-Dec-2018
Welcome to the "core" PySimpleGUIWx port! Welcome to the "core" PySimpleGUIWx port!
'##:::::'##:'##::::'##:'########::'##:::'##:'########:'##::::'##::'#######::'##::: ##:
##:'##: ##:. ##::'##:: ##.... ##:. ##:'##::... ##..:: ##:::: ##:'##.... ##: ###:: ##:
##: ##: ##::. ##'##::: ##:::: ##::. ####:::::: ##:::: ##:::: ##: ##:::: ##: ####: ##:
##: ##: ##:::. ###:::: ########::::. ##::::::: ##:::: #########: ##:::: ##: ## ## ##:
##: ##: ##::: ## ##::: ##.....:::::: ##::::::: ##:::: ##.... ##: ##:::: ##: ##. ####:
##: ##: ##:: ##:. ##:: ##::::::::::: ##::::::: ##:::: ##:::: ##: ##:::: ##: ##:. ###:
. ###. ###:: ##:::. ##: ##::::::::::: ##::::::: ##:::: ##:::: ##:. #######:: ##::. ##:
:...::...:::..:::::..::..::::::::::::..::::::::..:::::..:::::..:::.......:::..::::..::
This marks the 3rd port of the PySimpleGUI GUI SDK. Each port gets a little better than This marks the 3rd port of the PySimpleGUI GUI SDK. Each port gets a little better than
the previous. the previous, in theory.
It will take a while for this Wx port to be completed, but should be running with a fully selection It will take a while for this Wx port to be completed, but should be running with a fully selection
of widgets fairly quickly. The Qt port required 1 week to get to "Alpha" condition of widgets fairly quickly. The Qt port required 1 week to get to "Alpha" condition
@ -1186,8 +1202,8 @@ class Text(Element):
if self.ParentForm.TKrootDestroyed: if self.ParentForm.TKrootDestroyed:
return return
if value is not None: if value is not None:
self.WxStaticText.SetLabel(value) self.WxStaticText.SetLabel(str(value))
self.DisplayText = value self.DisplayText = str(value)
if background_color is not None: if background_color is not None:
self.WxStaticText.SetBackgroundColour(background_color) self.WxStaticText.SetBackgroundColour(background_color)
if text_color is not None: if text_color is not None:
@ -4254,9 +4270,18 @@ else:
i += 1 i += 1
# # ######
# # # # # # # # # ##### # # #### # #
# # # # # # # # # # # # # # ## #
# # # ## ###### # # ###### # # # # #
# # # ## # # # # # # # # # #
# # # # # # # # # # # # # ##
## ## # # # # # # # #### # #
# ------------------------------------------------------------------------------------------------------------------ # # ------------------------------------------------------------------------------------------------------------------ #
# ------------------------------------------------------------------------------------------------------------------ # # ------------------------------------------------------------------------------------------------------------------ #
# ===================================== TK CODE STARTS HERE ====================================================== # # ===================================== WxPython CODE STARTS HERE ================================================ #
# ------------------------------------------------------------------------------------------------------------------ # # ------------------------------------------------------------------------------------------------------------------ #
# ------------------------------------------------------------------------------------------------------------------ # # ------------------------------------------------------------------------------------------------------------------ #
@ -5479,7 +5504,7 @@ class QuickMeter(object):
layout = [] layout = []
if self.orientation.lower().startswith('h'): if self.orientation.lower().startswith('h'):
col = [] col = []
col += [[T(arg)] for arg in args] col += [[T(''.join(map(lambda x: str(x)+'\n',args)),key='_OPTMSG_')]] ### convert all *args into one string that can be updated
col += [[T('', size=(25,8), key='_STATS_')], col += [[T('', size=(25,8), key='_STATS_')],
[ProgressBar(max_value=self.max_value, orientation='h', key='_PROG_', size=self.size)], [ProgressBar(max_value=self.max_value, orientation='h', key='_PROG_', size=self.size)],
[Cancel(button_color=self.button_color), Stretch()]] [Cancel(button_color=self.button_color), Stretch()]]
@ -5487,7 +5512,7 @@ class QuickMeter(object):
else: else:
col = [[ProgressBar(max_value=self.max_value, orientation='v', key='_PROG_', size=self.size)]] col = [[ProgressBar(max_value=self.max_value, orientation='v', key='_PROG_', size=self.size)]]
col2 = [] col2 = []
col2 += [[T(arg)] for arg in args] col2 += [[T(''.join(map(lambda x: str(x)+'\n',args)),key='_OPTMSG_')]] ### convert all *args into one string that can be updated
col2 += [[T('', size=(25,8), key='_STATS_')], col2 += [[T('', size=(25,8), key='_STATS_')],
[Cancel(button_color=self.button_color), Stretch()]] [Cancel(button_color=self.button_color), Stretch()]]
layout = [Column(col), Column(col2)] layout = [Column(col), Column(col2)]
@ -5496,11 +5521,12 @@ class QuickMeter(object):
return self.window return self.window
def UpdateMeter(self, current_value, max_value): def UpdateMeter(self, current_value, max_value, *args):
self.current_value = current_value self.current_value = current_value
self.max_value = max_value self.max_value = max_value
self.window.Element('_PROG_').UpdateBar(self.current_value, self.max_value) self.window.Element('_PROG_').UpdateBar(self.current_value, self.max_value)
self.window.Element('_STATS_').Update('\n'.join(self.ComputeProgressStats())) self.window.Element('_STATS_').Update('\n'.join(self.ComputeProgressStats()))
self.window.Element('_OPTMSG_').Update(value=''.join(map(lambda x: str(x)+'\n',args))) ### update the string with the args
event, values = self.window.Read(timeout=0) event, values = self.window.Read(timeout=0)
if event in('Cancel', None) or current_value >= max_value: if event in('Cancel', None) or current_value >= max_value:
self.window.Close() self.window.Close()
@ -5548,7 +5574,7 @@ def OneLineProgressMeter(title, current_value, max_value, key, *args, orientatio
else: else:
meter = QuickMeter.active_meters[key] meter = QuickMeter.active_meters[key]
rc = meter.UpdateMeter(current_value, max_value) rc = meter.UpdateMeter(current_value, max_value, *args)
OneLineProgressMeter.exit_reasons = getattr(OneLineProgressMeter,'exit_reasons', QuickMeter.exit_reasons) OneLineProgressMeter.exit_reasons = getattr(OneLineProgressMeter,'exit_reasons', QuickMeter.exit_reasons)
return rc == METER_OK return rc == METER_OK
@ -6219,6 +6245,16 @@ def ObjToString(obj, extra=' '):
# Pre-built dialog boxes for all your needs These are the "high level API calls # # Pre-built dialog boxes for all your needs These are the "high level API calls #
# ------------------------------------------------------------------------------------------------------------------ # # ------------------------------------------------------------------------------------------------------------------ #
######
# # #### ##### # # ##### ####
# # # # # # # # # # #
###### # # # # # # # # ####
# # # ##### # # ##### #
# # # # # # # # #
# #### # #### # ####
# ----------------------------------- The mighty Popup! ------------------------------------------------------------ # # ----------------------------------- The mighty Popup! ------------------------------------------------------------ #
@ -6827,6 +6863,19 @@ def PopupGetText(message, title=None, default_text='', password_char='', size=(N
return input_values[0] return input_values[0]
"""
d8b
Y8P
88888b.d88b. 8888b. 888 88888b.
888 "888 "88b "88b 888 888 "88b
888 888 888 .d888888 888 888 888
888 888 888 888 888 888 888 888
888 888 888 "Y888888 888 888 888
"""
def main(): def main():
ChangeLookAndFeel('GreenTan') ChangeLookAndFeel('GreenTan')
layout = [ layout = [