Merge pull request #942 from MikeTheWatchGuy/Dev-latest

Dev latest
This commit is contained in:
MikeTheWatchGuy 2018-12-17 11:36:11 -05:00 committed by GitHub
commit a39737ae04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 126 additions and 49 deletions

View File

@ -901,8 +901,7 @@ Check = Checkbox
class Spin(Element):
# Values = None
# TKSpinBox = None
def __init__(self, values, initial_value=None, disabled=False, change_submits=False,enable_events=False , size=(None, None), auto_size_text=None, font=None, background_color=None, text_color=None, key=None, pad=None,
tooltip=None, visible=True):
def __init__(self, values, initial_value=None, disabled=False, change_submits=False,enable_events=False , size=(None, None), auto_size_text=None, font=None, background_color=None, text_color=None, key=None, pad=None, tooltip=None, visible=True):
'''
Spinner Element
:param values:
@ -3086,7 +3085,7 @@ class Window:
progress_bar_color=(None, None), background_color=None, border_depth=None, auto_close=False,
auto_close_duration=DEFAULT_AUTOCLOSE_TIME, icon=DEFAULT_WINDOW_ICON, force_toplevel=False,
alpha_channel=1, return_keyboard_events=False, use_default_focus=True, text_justification=None,
no_titlebar=False, grab_anywhere=False, keep_on_top=False, resizable=False, disable_close=False):
no_titlebar=False, grab_anywhere=False, keep_on_top=False, resizable=False, disable_close=False, disable_minimize=False):
'''
Main window object where Elements will be laid out in rows
:param title:
@ -3162,6 +3161,7 @@ class Window:
self.TimeoutKey = '_timeout_'
self.TimerCancelled = False
self.DisableClose = disable_close
self.DisableMinimize = disable_minimize
self._Hidden = False
self._Size = size
self.XFound = False
@ -5411,6 +5411,9 @@ def StartupTK(my_flex_form):
if not my_flex_form.Resizable:
root.resizable(False, False)
if my_flex_form.DisableMinimize:
root.attributes("-toolwindow", 1)
if my_flex_form.KeepOnTop:
root.wm_attributes("-topmost", 1)
@ -5625,24 +5628,33 @@ def GetComplimentaryHex(color):
# ======================== EasyPrint =====#
# ===================================================#
_easy_print_data = None # global variable... I'm cheating
class DebugWin():
debug_window = None
def __init__(self, size=(None, None), location=(None, None), font=None, no_titlebar=False, no_button=False, grab_anywhere=False, keep_on_top=False):
def __init__(self, size=(None, None), location=(None, None), font=None, no_titlebar=False, no_button=False,
grab_anywhere=False, keep_on_top=False, do_not_reroute_stdout=True):
# Show a form that's a running counter
self.size = size
self.location = location
self.font = font
self.no_titlebar = no_titlebar
self.no_button = no_button
self.grab_anywhere = grab_anywhere
self.keep_on_top = keep_on_top
self.do_not_reroute_stdout = do_not_reroute_stdout
win_size = size if size != (None, None) else DEFAULT_DEBUG_WINDOW_SIZE
self.window = Window('Debug Window', no_titlebar=no_titlebar, auto_size_text=True, location=location, font=font or ('Courier New', 10), grab_anywhere=grab_anywhere, keep_on_top=keep_on_top)
self.output_element = Output(size=win_size)
self.window = Window('Debug Window', no_titlebar=no_titlebar, auto_size_text=True, location=location,
font=font or ('Courier New', 10), grab_anywhere=grab_anywhere, keep_on_top=keep_on_top)
self.output_element = Multiline(size=win_size, autoscroll=True, key='_MULTILINE_') if do_not_reroute_stdout else Output(size=win_size)
if no_button:
self.layout = [[self.output_element]]
self.layout = [[self.output_element]]
else:
self.layout = [
[self.output_element],
[DummyButton('Quit')]
]
self.layout = [
[self.output_element],
[DummyButton('Quit'), Stretch()]
]
self.window.AddRows(self.layout)
self.window.Read(timeout=0) # Show a non-blocking form, returns immediately
return
@ -5651,38 +5663,100 @@ class DebugWin():
sepchar = sep if sep is not None else ' '
endchar = end if end is not None else '\n'
if self.window is None: # if window was destroyed already, just print
self.__init__()
print(*args, sep=sepchar, end=endchar)
return
if self.window is None: # if window was destroyed alread re-open it
self.__init__(size=self.size, location=self.location, font=self.font, no_titlebar=self.no_titlebar, no_button=self.no_button, grab_anywhere=self.grab_anywhere, keep_on_top=self.keep_on_top, do_not_reroute_stdout=self.do_not_reroute_stdout)
event, values = self.window.Read(timeout=0)
if event == 'Quit' or event is None:
self.Close()
print(*args, sep=sepchar, end=endchar)
# Add extra check to see if the window was closed... if closed by X sometimes am not told
# try:
# state = self.window.TKroot.state()
# except:
# self.Close()
self.__init__(size=self.size, location=self.location, font=self.font, no_titlebar=self.no_titlebar, no_button=self.no_button, grab_anywhere=self.grab_anywhere, keep_on_top=self.keep_on_top, do_not_reroute_stdout=self.do_not_reroute_stdout)
if self.do_not_reroute_stdout:
outstring = ''
for arg in args:
outstring += str(arg) + sepchar
outstring += endchar
self.output_element.Update(outstring, append=True)
else:
print(*args, sep=sepchar, end=endchar)
def Close(self):
if self.window is None:
return
self.window.Close()
self.window.__del__()
self.window = None
def PrintClose():
EasyPrintClose()
def EasyPrint(*args, size=(None, None), end=None, sep=None, location=(None, None), font=None, no_titlebar=False, no_button=False, grab_anywhere=False, keep_on_top=False):
def EasyPrint(*args, size=(None, None), end=None, sep=None, location=(None, None), font=None, no_titlebar=False,
no_button=False, grab_anywhere=False, keep_on_top=False, do_not_reroute_stdout=False):
if DebugWin.debug_window is None:
DebugWin.debug_window = DebugWin(size=size, location=location, font=font, no_titlebar=no_titlebar, no_button=no_button, grab_anywhere=grab_anywhere, keep_on_top=keep_on_top)
DebugWin.debug_window = DebugWin(size=size, location=location, font=font, no_titlebar=no_titlebar,
no_button=no_button, grab_anywhere=grab_anywhere, keep_on_top=keep_on_top, do_not_reroute_stdout=do_not_reroute_stdout)
DebugWin.debug_window.Print(*args, end=end, sep=sep)
#
#
#
#
#
# class DebugWin():
# debug_window = None
#
# def __init__(self, size=(None, None), location=(None, None), font=None, no_titlebar=False, no_button=False, grab_anywhere=False, keep_on_top=False):
# # Show a form that's a running counter
# win_size = size if size != (None, None) else DEFAULT_DEBUG_WINDOW_SIZE
# self.window = Window('Debug Window', no_titlebar=no_titlebar, auto_size_text=True, location=location, font=font or ('Courier New', 10), grab_anywhere=grab_anywhere, keep_on_top=keep_on_top)
# self.output_element = Output(size=win_size)
# if no_button:
# self.layout = [[self.output_element]]
# else:
# self.layout = [
# [self.output_element],
# [DummyButton('Quit')]
# ]
# self.window.AddRows(self.layout)
# self.window.Read(timeout=0) # Show a non-blocking form, returns immediately
# return
#
# def Print(self, *args, end=None, sep=None):
# sepchar = sep if sep is not None else ' '
# endchar = end if end is not None else '\n'
#
# if self.window is None: # if window was destroyed already, just print
# self.__init__()
# print(*args, sep=sepchar, end=endchar)
# return
#
# event, values = self.window.Read(timeout=0)
# if event == 'Quit' or event is None:
# self.Close()
# print(*args, sep=sepchar, end=endchar)
# # Add extra check to see if the window was closed... if closed by X sometimes am not told
# # try:
# # state = self.window.TKroot.state()
# # except:
# # self.Close()
#
# def Close(self):
# if self.window is None:
# return
# self.window.Close()
# self.window.__del__()
# self.window = None
#
# def PrintClose():
# EasyPrintClose()
#
#
# def EasyPrint(*args, size=(None, None), end=None, sep=None, location=(None, None), font=None, no_titlebar=False, no_button=False, grab_anywhere=False, keep_on_top=False):
#
#
# if DebugWin.debug_window is None:
# DebugWin.debug_window = DebugWin(size=size, location=location, font=font, no_titlebar=no_titlebar, no_button=no_button, grab_anywhere=grab_anywhere, keep_on_top=keep_on_top)
# DebugWin.debug_window.Print(*args, end=end, sep=sep)
Print = EasyPrint

View File

@ -4392,7 +4392,7 @@ def style_entry(**kwargs):
# generated_style += "}"
return generated_style
def generate_style(qt_element_type, entries):
def style_generate(qt_element_type, entries):
generated_style = qt_element_type + " {\n"
generated_style += entries
generated_style += "}"
@ -4466,12 +4466,13 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
column_widget = QGroupBox()
element.QT_QGroupBox = column_widget
# column_widget.setFrameShape(QtWidgets.QFrame.NoFrame)
style = 'QGroupBox {'
style += create_style_from_font(font)
style = create_style_from_font(font)
if element.BackgroundColor is not None:
style = style_entry(background_color=element.BackgroundColor)
style += 'background-color: %s;' % element.BackgroundColor
style += 'border: 0px solid gray; '
style += '}'
style += style_entry(border='0px solid gray')
# style += 'border: 0px solid gray; '
style = style_generate('QGroupBox', style)
column_widget.setStyleSheet(style)
column_layout = QFormLayout()
@ -4482,7 +4483,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
column_vbox.addLayout(column_layout)
column_widget.setLayout(column_vbox)
column_widget.setStyleSheet(style)
# column_widget.setStyleSheet(style)
if not element.Visible:
column_widget.setVisible(False)
@ -4615,7 +4616,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
style += style_entry(background_color=element.BackgroundColor)
style += style_entry(margin ='{}px {}px {}px {}px;'.format(*full_element_pad),
border='{}px solid gray; '.format(border_depth))
style = generate_style('QLineEdit', style)
style = style_generate('QLineEdit', style)
element.QT_QLineEdit.setStyleSheet(style)
if element.AutoSizeText is False or toplevel_win.AutoSizeText is False or element.Size[0] is not None:
@ -5795,7 +5796,7 @@ class DebugWin():
debug_window = None
def __init__(self, size=(None, None), location=(None, None), font=None, no_titlebar=False, no_button=False,
grab_anywhere=False, keep_on_top=False, do_not_reroute_stdout=False):
grab_anywhere=False, keep_on_top=False, title=None, do_not_reroute_stdout=False):
# Show a form that's a running counter
self.size = size
self.location = location
@ -5807,7 +5808,7 @@ class DebugWin():
self.do_not_reroute_stdout = do_not_reroute_stdout
win_size = size if size != (None, None) else DEFAULT_DEBUG_WINDOW_SIZE
self.window = Window('Debug Window', no_titlebar=no_titlebar, auto_size_text=True, location=location,
self.window = Window(title=title or 'Debug Window', no_titlebar=no_titlebar, auto_size_text=True, location=location,
font=font or ('Courier New', 10), grab_anywhere=grab_anywhere, keep_on_top=keep_on_top)
self.output_element = MultilineOutput(size=win_size, key='_MULTILINE_') if do_not_reroute_stdout else Output(size=win_size)
@ -5854,7 +5855,7 @@ def PrintClose():
def EasyPrint(*args, size=(None, None), end=None, sep=None, location=(None, None), font=None, no_titlebar=False,
no_button=False, grab_anywhere=False, keep_on_top=False, do_not_reroute_stdout=False):
no_button=False, grab_anywhere=False, keep_on_top=False, do_not_reroute_stdout=True):
if DebugWin.debug_window is None:
@ -5876,11 +5877,11 @@ def EasyPrintClose():
# ======================== Scrolled Text Box =====#
# ===================================================#
def PopupScrolled(*args, button_color=None, yes_no=False, auto_close=False, auto_close_duration=None,
size=(None, None), location=(None, None)):
size=(None, None), location=(None, None), title=None, non_blocking=False):
if not args: return
width, height = size
width = width if width else MESSAGE_BOX_LINE_WIDTH
form = Window(args[0], auto_size_text=True, button_color=button_color, auto_close=auto_close,
window = Window(title=title or args[0], auto_size_text=True, button_color=button_color, auto_close=auto_close,
auto_close_duration=auto_close_duration, location=location)
max_line_total, max_line_width, total_lines, height_computed = 0, 0, 0, 0
complete_output = ''
@ -5900,18 +5901,20 @@ def PopupScrolled(*args, button_color=None, yes_no=False, auto_close=False, auto
if height:
height_computed = height
computed_size = (max_line_width*10, height_computed*16)
form.AddRow(MultilineOutput(complete_output, size=computed_size))
window.AddRow(MultilineOutput(complete_output, size=computed_size))
pad = max_line_total - 15 if max_line_total > 15 else 1
# show either an OK or Yes/No depending on paramater
button = DummyButton if non_blocking else Button
if yes_no:
form.AddRow(Text('', size=(pad, 1), auto_size_text=False), Yes(), No())
button, values = form.Read()
form.Close()
return button
window.AddRow(Text('', size=(pad, 1), auto_size_text=False), button('Yes'), button('No'))
else:
form.AddRow(Text('', size=(pad, 1), auto_size_text=False), Button('OK', size=(5, 1), button_color=button_color))
button, values = form.Read()
form.Close()
window.AddRow(Text('', size=(pad, 1), auto_size_text=False), button('OK', size=(5, 1), button_color=button_color))
if non_blocking:
button, values = window.Read(timeout=0)
Window.active_popups[window] = title
else:
button, values = window.Read()
return button