Added element_justification parameter to Window, Column, Frame, Tab just like the tkinter port has!! FINALLY!

This commit is contained in:
PySimpleGUI 2020-05-15 14:00:37 -04:00
parent 4f3566915c
commit 71cc2df719
1 changed files with 20 additions and 7 deletions

View File

@ -1992,7 +1992,7 @@ class Graph(Element):
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
class Frame(Element): class Frame(Element):
def __init__(self, title, layout, title_color=None, background_color=None, title_location=None, def __init__(self, title, layout, title_color=None, background_color=None, title_location=None,
relief=DEFAULT_FRAME_RELIEF, size=(None, None), font=None, pad=None, border_width=None, key=None, relief=DEFAULT_FRAME_RELIEF, element_justification='float', size=(None, None), font=None, pad=None, border_width=None, key=None,
tooltip=None, visible=True, size_px=(None,None), metadata=None): tooltip=None, visible=True, size_px=(None,None), metadata=None):
''' '''
Frame Element Frame Element
@ -2023,6 +2023,7 @@ class Frame(Element):
self.TitleLocation = title_location self.TitleLocation = title_location
self.BorderWidth = border_width self.BorderWidth = border_width
self.BackgroundColor = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR self.BackgroundColor = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR
self.ElementJustification = element_justification
self.Widget = self.QT_QGroupBox = None # type: QGroupBox self.Widget = self.QT_QGroupBox = None # type: QGroupBox
self.Layout(layout) self.Layout(layout)
@ -2107,7 +2108,7 @@ HSep = HorizontalSeparator
# Tab # # Tab #
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
class Tab(Element): class Tab(Element):
def __init__(self, title, layout, title_color=None, background_color=None, font=None, pad=None, disabled=False, def __init__(self, title, layout, title_color=None, element_justification='float', background_color=None, font=None, pad=None, disabled=False,
border_width=None, key=None, tooltip=None, visible=True, metadata=None): border_width=None, key=None, tooltip=None, visible=True, metadata=None):
''' '''
Tab Element Tab Element
@ -2135,9 +2136,12 @@ class Tab(Element):
self.Disabled = disabled self.Disabled = disabled
self.ParentTabGroup = None # type: TabGroup self.ParentTabGroup = None # type: TabGroup
self.TabID = None self.TabID = None
self.ElementJustification = element_justification
self.BackgroundColor = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR self.BackgroundColor = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR
self.Widget = self.QT_QWidget = None # type: QWidget self.Widget = self.QT_QWidget = None # type: QWidget
self.Layout(layout) self.Layout(layout)
super().__init__(ELEM_TYPE_TAB, background_color=background_color, text_color=title_color, font=font, pad=pad, super().__init__(ELEM_TYPE_TAB, background_color=background_color, text_color=title_color, font=font, pad=pad,
@ -2234,6 +2238,7 @@ class TabGroup(Element):
self.TabLocation = tab_location self.TabLocation = tab_location
self.TabList = [] # type: List[Tab] self.TabList = [] # type: List[Tab]
self.Widget = self.QT_QTabWidget = None # type: QTabWidget self.Widget = self.QT_QTabWidget = None # type: QTabWidget
self.ElementJustification = 'float' # not actually used, but needed for packer to work
self.Layout(layout) self.Layout(layout)
super().__init__(ELEM_TYPE_TAB_GROUP, background_color=self.BackgroundColor, text_color=title_color, font=font, super().__init__(ELEM_TYPE_TAB_GROUP, background_color=self.BackgroundColor, text_color=title_color, font=font,
@ -2468,7 +2473,7 @@ class Stretch(Element):
# Column # # Column #
# ---------------------------------------------------------------------- # # ---------------------------------------------------------------------- #
class Column(Element): class Column(Element):
def __init__(self, layout, background_color=None, size=(None, None), pad=None, scrollable=False, key=None, visible=True, metadata=None): def __init__(self, layout, background_color=None, element_justification='float', size=(None, None), pad=None, scrollable=False, key=None, visible=True, metadata=None):
''' '''
Column Element Column Element
:param layout: :param layout:
@ -2492,6 +2497,7 @@ class Column(Element):
# self.ImageSize = image_size # self.ImageSize = image_size
# self.ImageSubsample = image_subsample # self.ImageSubsample = image_subsample
bg = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR bg = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR
self.ElementJustification = element_justification
self.Widget = self.QT_QGroupBox = None # type: QGroupBox self.Widget = self.QT_QGroupBox = None # type: QGroupBox
self.vbox_layout = None # type: QVBoxLayout self.vbox_layout = None # type: QVBoxLayout
self.Layout(layout) self.Layout(layout)
@ -3174,7 +3180,7 @@ class Window:
progress_bar_color=(None, None), background_color=None, border_depth=None, auto_close=False, 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, 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, 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=True, disable_close=False, disable_minimize=False, background_image=None, finalize=False, metadata=None): element_justification='float', no_titlebar=False, grab_anywhere=False, keep_on_top=False, resizable=True, disable_close=False, disable_minimize=False, background_image=None, finalize=False, metadata=None):
''' '''
:param title: :param title:
@ -3264,6 +3270,7 @@ class Window:
self.DisableMinimize = disable_minimize self.DisableMinimize = disable_minimize
self.UniqueKeyCounter = 0 self.UniqueKeyCounter = 0
self.metadata = metadata self.metadata = metadata
self.ElementJustification = element_justification
if layout is not None: if layout is not None:
@ -4788,7 +4795,7 @@ class Style(object):
return self.content return self.content
def PackFormIntoFrame(window, containing_frame, toplevel_win): def PackFormIntoFrame(container_elem, containing_frame, toplevel_win):
border_depth = toplevel_win.BorderDepth if toplevel_win.BorderDepth is not None else DEFAULT_BORDER_WIDTH border_depth = toplevel_win.BorderDepth if toplevel_win.BorderDepth is not None else DEFAULT_BORDER_WIDTH
# --------------------------------------------------------------------------- # # --------------------------------------------------------------------------- #
@ -4798,11 +4805,17 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
focus_set = False focus_set = False
######################### LOOP THROUGH ROWS ######################### ######################### LOOP THROUGH ROWS #########################
# *********** ------- Loop through ROWS ------- ***********# # *********** ------- Loop through ROWS ------- ***********#
for row_num, flex_row in enumerate(window.Rows): for row_num, flex_row in enumerate(container_elem.Rows):
######################### LOOP THROUGH ELEMENTS ON ROW ######################### ######################### LOOP THROUGH ELEMENTS ON ROW #########################
# *********** ------- Loop through ELEMENTS ------- ***********# # *********** ------- Loop through ELEMENTS ------- ***********#
# *********** Make TK Row ***********# # *********** Make TK Row ***********#
qt_row_layout = QHBoxLayout() qt_row_layout = QHBoxLayout()
if container_elem.ElementJustification.startswith('c'):
qt_row_layout.setAlignment(Qt.AlignCenter)
elif container_elem.ElementJustification.startswith('r'):
qt_row_layout.setAlignment(Qt.AlignRight)
elif container_elem.ElementJustification.startswith('l'):
qt_row_layout.setAlignment(Qt.AlignLeft)
for col_num, element in enumerate(flex_row): for col_num, element in enumerate(flex_row):
element.ParentForm = toplevel_win # save the button's parent form object element.ParentForm = toplevel_win # save the button's parent form object
element.row_frame = qt_row_layout element.row_frame = qt_row_layout
@ -5598,7 +5611,7 @@ def PackFormIntoFrame(window, containing_frame, toplevel_win):
tab_widget.setToolTip(element.Tooltip) tab_widget.setToolTip(element.Tooltip)
if not element.Visible: if not element.Visible:
element.QT_QWidget.setVisible(False) element.QT_QWidget.setVisible(False)
window.QT_QTabWidget.addTab(tab_widget, element.Title) container_elem.QT_QTabWidget.addTab(tab_widget, element.Title)
# ------------------------- TabGroup placement element ------------------------- # # ------------------------- TabGroup placement element ------------------------- #
elif element_type == ELEM_TYPE_TAB_GROUP: elif element_type == ELEM_TYPE_TAB_GROUP:
element = element # type:TabGroup element = element # type:TabGroup