Merge pull request #1041 from PySimpleGUI/Dev-latest

Visible / Invisible fields - input & button.  Input - Get, SetFocus
This commit is contained in:
MikeTheWatchGuy 2019-01-05 11:26:42 -05:00 committed by GitHub
commit 72a68c1dee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 54 additions and 31 deletions

View File

@ -487,10 +487,11 @@ class Element():
if background_color not in (None, COLOR_SYSTEM_DEFAULT): if background_color not in (None, COLOR_SYSTEM_DEFAULT):
widget.SetBackgroundColour(background_color) widget.SetBackgroundColour(background_color)
if visible is True: if visible is True:
widget.Enable(True) widget.Show()
self.ParentForm.VisibilityChanged()
elif visible is False: elif visible is False:
widget.Enable(False) widget.Hide()
self.ParentForm.VisibilityChanged()
def __del__(self): def __del__(self):
@ -565,16 +566,19 @@ class InputText(Element):
self.DefaultText = value self.DefaultText = value
if select: if select:
self.WxTextControl.SelectAll() self.WxTextControl.SelectAll()
# if visible:
# self.WxTextControl.Show()
# self.ParentForm.VisibilityChanged()
# elif visible is False:
# self.WxTextControl.Hide()
super().Update(self.WxTextControl, background_color=background_color, text_color=text_color, font=font, visible=visible) super().Update(self.WxTextControl, background_color=background_color, text_color=text_color, font=font, visible=visible)
def Get(self): def Get(self):
return self.QT_QLineEdit.text() return self.WxTextControl.GetValue()
# return self.TKStringVar.get()
def SetFocus(self): def SetFocus(self):
self.QT_QLineEdit.setFocus() self.WxTextControl.SetFocus()
def __del__(self): def __del__(self):
super().__del__() super().__del__()
@ -1064,28 +1068,34 @@ class Multiline(Element):
# Text # # Text #
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
class Text(Element): class Text(Element):
def __init__(self, text, size=(None, None), auto_size_text=None, click_submits=None, relief=None, font=None, def __init__(self, text, size=(None, None), auto_size_text=None, click_submits=None, enable_events=False, relief=None, font=None, text_color=None, background_color=None, justification=None, pad=None, margins=None, key=None, tooltip=None, visible=True, size_px=(None,None)):
text_color=None, background_color=None, justification=None, pad=None, key=None, tooltip=None): """
''' Text
Text Element
:param text: :param text:
:param size: :param size:
:param auto_size_text: :param auto_size_text:
:param click_submits: :param click_submits:
:param enable_events:
:param relief: :param relief:
:param font: :param font:
:param text_color: :param text_color:
:param background_color: :param background_color:
:param justification: :param justification:
:param pad: :param pad:
:param margins:
:param key: :param key:
:param tooltip: :param tooltip:
''' :param visible:
:param size_px:
"""
self.DisplayText = text self.DisplayText = text
self.TextColor = text_color if text_color else DEFAULT_TEXT_COLOR self.TextColor = text_color if text_color else DEFAULT_TEXT_COLOR
self.Justification = justification self.Justification = justification
self.Relief = relief self.Relief = relief
self.ClickSubmits = click_submits self.ClickSubmits = click_submits or enable_events
self.Margins = margins
self.Visible = visible
self.size_px = size_px
if background_color is None: if background_color is None:
bg = DEFAULT_TEXT_ELEMENT_BACKGROUND_COLOR bg = DEFAULT_TEXT_ELEMENT_BACKGROUND_COLOR
else: else:
@ -1096,10 +1106,10 @@ class Text(Element):
self.WxStaticText = None # wx.StaticText(form.MasterPanel, -1, element.DisplayText) self.WxStaticText = None # wx.StaticText(form.MasterPanel, -1, element.DisplayText)
super().__init__(ELEM_TYPE_TEXT, pixelsize, auto_size_text, background_color=bg, font=font if font else DEFAULT_FONT, 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) text_color=self.TextColor, pad=pad, key=key, tooltip=tooltip, size_px=size_px)
return return
def Update(self, value=None, background_color=None, text_color=None, font=None): def Update(self, value=None, background_color=None, text_color=None, font=None, visible=None):
if value is not None: if value is not None:
self.WxStaticText.SetLabel(value) self.WxStaticText.SetLabel(value)
self.DisplayText = value self.DisplayText = value
@ -1109,6 +1119,9 @@ class Text(Element):
self.WxStaticText.SetForegroundColour(text_color) self.WxStaticText.SetForegroundColour(text_color)
if font is not None: if font is not None:
self.WxStaticText.SetFont(font) self.WxStaticText.SetFont(font)
super().Update(self.WxStaticText, background_color=background_color, text_color=text_color, font=font, visible=visible)
def __del__(self): def __del__(self):
super().__del__() super().__del__()
@ -1519,7 +1532,7 @@ class Button(Element):
self.QT_QPushButton.setDisabled(False) self.QT_QPushButton.setDisabled(False)
# fg, bg = self.ButtonColor # fg, bg = self.ButtonColor
# print(f'Button update fg, bg {fg}, {bg}') # print(f'Button update fg, bg {fg}, {bg}')
super().Update(self.QT_QPushButton, background_color=bg, text_color=fg, font=font, visible=visible) super().Update(self.WxButton, background_color=bg, text_color=fg, font=font, visible=visible)
def GetText(self): def GetText(self):
@ -3196,11 +3209,7 @@ class Window:
return self return self
def VisibilityChanged(self): def VisibilityChanged(self):
self.Refresh() self.SizeChanged()
self.Size = self.Size
self.Refresh()
self.Size = self.Size
self.Refresh()
return self return self
def Fill(self, values_dict): def Fill(self, values_dict):
@ -3463,14 +3472,21 @@ class Window:
@property @property
def Size(self): def Size(self):
size = self.QT_QMainWindow.sizeHint() size = self.MasterFrame.GetSize()
return [size.width(), size.height()] return size
@Size.setter @Size.setter
def Size(self, size): def Size(self, size):
self.QT_QMainWindow.resize(QSize(size[0], size[1])) self.MasterFrame.SetSize(size[0], size[1])
def SizeChanged(self):
size = self.Size
self.Size = size[0]+1, size[1]+1
self.Size = size
self.MasterFrame.SetSizer(self.OuterSizer)
self.OuterSizer.Fit(self.MasterFrame)
def __enter__(self): def __enter__(self):
return self return self
@ -4378,6 +4394,8 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
statictext.SetMinSize((width,height)) statictext.SetMinSize((width,height))
if element.Tooltip: if element.Tooltip:
statictext.SetToolTip(element.Tooltip) statictext.SetToolTip(element.Tooltip)
if not element.Visible:
statictext.Hide()
# ---===--- LABEL widget create and place --- # # ---===--- LABEL widget create and place --- #
# stringvar = tk.StringVar() # stringvar = tk.StringVar()
# element.TKStringVar = stringvar # element.TKStringVar = stringvar
@ -4449,6 +4467,8 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
sizer = pad_widget(button) sizer = pad_widget(button)
hsizer.Add(sizer, 0) hsizer.Add(sizer, 0)
if not element.Visible:
button.Hide()
# border_depth = element.BorderWidth # border_depth = element.BorderWidth
# if btype != BUTTON_TYPE_REALTIME: # if btype != BUTTON_TYPE_REALTIME:
@ -4504,7 +4524,7 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
# element.TooltipObject = ToolTip(element.TKButton, text=element.Tooltip, # element.TooltipObject = ToolTip(element.TKButton, text=element.Tooltip,
# timeout=DEFAULT_TOOLTIP_TIME) # timeout=DEFAULT_TOOLTIP_TIME)
# # ------------------------- INPUT (Single Line) element ------------------------- # # # ------------------------- INPUT element ------------------------- #
elif element_type == ELEM_TYPE_INPUT_TEXT: elif element_type == ELEM_TYPE_INPUT_TEXT:
element.WxTextControl = text_ctrl = wx.TextCtrl(form.MasterPanel) element.WxTextControl = text_ctrl = wx.TextCtrl(form.MasterPanel)
if font: if font:
@ -4516,11 +4536,14 @@ def PackFormIntoFrame(form, containing_frame, toplevel_form):
text_ctrl.SetMinSize(element_size) text_ctrl.SetMinSize(element_size)
if element.Disabled:
text_ctrl.Enable(False)
sizer = pad_widget(text_ctrl) sizer = pad_widget(text_ctrl)
hsizer.Add(sizer, 0) hsizer.Add(sizer, 0)
if not element.Visible:
text_ctrl.Hide()
# default_text = element.DefaultText # default_text = element.DefaultText
@ -5251,13 +5274,13 @@ def StartupTK(window):
outersizer.Fit(window.MasterFrame) outersizer.Fit(window.MasterFrame)
outersizer.Add(vsizer, 1, wx.TOP|wx.BOTTOM|wx.EXPAND, border=DEFAULT_MARGINS[1]) outersizer.Add(vsizer, 1, wx.TOP|wx.BOTTOM|wx.EXPAND, border=DEFAULT_MARGINS[1])
outer2 = wx.BoxSizer(wx.VERTICAL) window.OuterSizer = wx.BoxSizer(wx.VERTICAL)
outer2.Fit(window.MasterFrame) window.OuterSizer.Fit(window.MasterFrame)
outer2.Add(outersizer, 1, wx.LEFT|wx.RIGHT|wx.EXPAND, border=DEFAULT_MARGINS[0]) window.OuterSizer.Add(outersizer, 1, wx.LEFT|wx.RIGHT|wx.EXPAND, border=DEFAULT_MARGINS[0])
window.MasterPanel.SetSizer(outer2) window.MasterPanel.SetSizer(window.OuterSizer)
outer2.Fit(window.MasterFrame) window.OuterSizer.Fit(window.MasterFrame)
if window.Location != (None, None): if window.Location != (None, None):
window.MasterFrame.Move(window.Location[0], window.Location[1]) window.MasterFrame.Move(window.Location[0], window.Location[1])