11#!/usr/bin/python3
2- version = __version__ = "0.16.0 Released 06-May-2020 "
2+ version = __version__ = "0.16.0.1 Unreleased - Finally addition of element_justification to Window & Container elements "
33
44port = 'PySimpleGUIWx'
55
1717import time
1818from random import randint
1919
20+ RUN_INSPECTION_TOOL = False
21+
22+
23+
2024###### ##### ##### # # ### # #
2125# # # # # # # # # ##### # ###### # # # # # # # # # #
2226# # # # # # ## ## # # # # # # # # # # # # #
5357g_time_end = 0
5458g_time_delta = 0
5559
56- RUN_INSPECTION_TOOL = False
5760
5861# Because looks matter...
5962DEFAULT_BASE64_ICON = b'iVBORw0KGgoAAAANSUhEUgAAACEAAAAgCAMAAACrZuH4AAAABGdBTUEAALGPC/xhBQAAAwBQTFRFAAAAMGmYMGqZMWqaMmubMmycM22dNGuZNm2bNm6bNG2dN26cNG6dNG6eNW+fN3CfOHCeOXGfNXCgNnGhN3KiOHOjOXSjOHSkOnWmOnamOnanPHSiPXakPnalO3eoPnimO3ioPHioPHmpPHmqPXqqPnurPnusPnytP3yuQHimQnurQn2sQH2uQX6uQH6vR32qRn+sSXujSHynTH2mTn+nSX6pQH6wTIGsTYKuTYSvQoCxQoCyRIK0R4S1RYS2Roa4SIe4SIe6SIi7Soq7SYm8SYq8Sou+TY2/UYStUYWvVIWtUYeyVoewUIi0VIizUI6+Vo+8WImxXJG5YI2xZI+xZ5CzZJC0ZpG1b5a3apW4aZm/cZi4dJ2/eJ69fJ+9XZfEZZnCZJzHaZ/Jdp/AeKTI/tM8/9Q7/9Q8/9Q9/9Q+/tQ//9VA/9ZA/9ZB/9ZC/9dD/9ZE/tdJ/9dK/9hF/9hG/9hH/9hI/9hJ/9hK/9lL/9pK/9pL/thO/9pM/9pN/9tO/9tP/9xP/tpR/9xQ/9xR/9xS/9xT/91U/91V/t1W/95W/95X/95Y/95Z/99a/99b/txf/txh/txk/t5l/t1q/t5v/+Bb/+Bc/+Bd/+Be/+Bf/+Bg/+Fh/+Fi/+Jh/+Ji/uJk/uJl/+Jm/+Rm/uJo/+Ro/+Rr/+Zr/+Vs/+Vu/+Zs/+Zu/uF0/uVw/+dw/+dz/+d2/uB5/uB6/uJ9/uR7/uR+/uV//+hx/+hy/+h0/+h2/+l4/+l7/+h8gKXDg6vLgazOhKzMiqrEj6/KhK/Qka/Hk7HJlLHJlLPMmLTLmbbOkLXSmLvXn77XoLrPpr/Tn8DaocLdpcHYrcjdssfZus/g/uOC/uOH/uaB/uWE/uaF/uWK/+qA/uqH/uqI/uuN/uyM/ueS/ueW/ueY/umQ/uqQ/uuS/uuW/uyU/uyX/uqa/uue/uye/uyf/u6f/uyq/u+r/u+t/vCm/vCp/vCu/vCy/vC2/vK2/vO8/vO/wtTjwtXlzdrl/vTA/vPQAAAAiNpY5gAAAQB0Uk5T////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////AFP3ByUAAAAJcEhZcwAAFw8AABcPASe7rwsAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjEuMWMqnEsAAAKUSURBVDhPhdB3WE1xHMdxt5JV0dANoUiyd8kqkey996xclUuTlEKidO3qVnTbhIyMW/bee5NskjJLmR/f3++cK/94vP76Ps/n/Zx7z6mE/6koJowcK154vvHOL/GsKCZXkUgkWlf4vWGWq5tsDz+JWIzSokAiqXGe7nWu3HxhEYof7fhOqp1GtptQuMruVhQdxZ05U5G47tYUHbQ4oah6Fg9Z4ubm7i57JhQjdHS0RSzUPoG17u6zZTKZh8c8XlytqW9YWUOH1LqFOZ6enl5ec+XybFb0rweM1tPTM6yuq6vLs0lYJJfLvb19fHwDWGF0jh5lYNAe4/QFemOwxtfXz8/fPyBgwVMqzAcCF4ybAZ2MRCexJGBhYGBQUHDw4u1UHDG1G2ZqB/Q1MTHmzAE+kpCwL1RghlTaBt/6SaXS2kx9YH1IaOjSZST8vfA9JtoDnSngGgL7wkg4WVkofA9mcF1Sx8zMzBK4v3wFiYiMVLxlEy9u21syFhYNmgN7IyJXEYViNZvEYoCVVWOmUVvgQVSUQqGIjolRFvOAFd8HWVs34VoA+6OjY2JjY5Vxm4BC1UuhGG5jY9OUaQXci1MqlfHx8YmqjyhOViW9ZsUN29akJRmPFwkJCZsTSXIpilJffXiTzorLXYgtcxRJKpUqKTklJQ0oSt9FP/EonxVdNY4jla1kK4q2ZB6mIr+AipvduzFUzMSOtLT09IyMzMxtJKug/F0u/6dTexAWDcXXLGEjapKjfsILOLKEuYiSnTQeYCt3UHhbwEHjGMrETfBJU5zq5dSTcXC8hLJccSWP2cgLXHPu7cQNAcpyxF1dyjehAKb0cSYUAOXCUw6V8OFPgevTXFymC+fPPLU677Nw/1X8A/AbfAKGulaqFlIAAAAASUVORK5CYII='
@@ -1857,7 +1860,7 @@ def MotionCallBack(self, event):
18571860# Frame #
18581861# ---------------------------------------------------------------------- #
18591862class Frame (Element ):
1860- def __init__ (self , title , layout , title_color = None , background_color = None , title_location = None ,
1863+ def __init__ (self , title , layout , title_color = None , background_color = None , title_location = None ,element_justification = 'left' ,
18611864 relief = DEFAULT_FRAME_RELIEF , size = (None , None ), size_px = (None ,None ), font = None , pad = None , border_width = None , key = None ,
18621865 tooltip = None ):
18631866 '''
@@ -1889,6 +1892,7 @@ def __init__(self, title, layout, title_color=None, background_color=None, title
18891892 self .TitleLocation = title_location
18901893 self .BorderWidth = border_width
18911894 self .BackgroundColor = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR
1895+ self .ElementJustification = element_justification
18921896
18931897 self ._Layout (layout )
18941898
@@ -1973,7 +1977,7 @@ def __init__(self, pad=None, size=(None, None), size_px=(None,None)):
19731977# Tab #
19741978# ---------------------------------------------------------------------- #
19751979class Tab (Element ):
1976- def __init__ (self , title , layout , title_color = None , background_color = None , font = None , pad = None , disabled = False ,
1980+ def __init__ (self , title , layout , title_color = None , background_color = None , font = None , element_justification = 'left' , pad = None , disabled = False ,
19771981 border_width = None , key = None , tooltip = None ):
19781982 '''
19791983 Tab Element
@@ -2002,6 +2006,7 @@ def __init__(self, title, layout, title_color=None, background_color=None, font=
20022006 self .ParentNotebook = None
20032007 self .TabID = None
20042008 self .BackgroundColor = background_color if background_color is not None else DEFAULT_BACKGROUND_COLOR
2009+ self .ElementJustification = element_justification
20052010
20062011 self ._Layout (layout )
20072012
@@ -2191,7 +2196,7 @@ def Update(self, value=None, range=(None, None), disabled=None):
21912196# Column #
21922197# ---------------------------------------------------------------------- #
21932198class Column (Element ):
2194- def __init__ (self , layout , background_color = None , size = (None , None ), size_px = (None , None ), pad = None , scrollable = False , vertical_scroll_only = False , right_click_menu = None , key = None , visible = True ):
2199+ def __init__ (self , layout , background_color = None , element_justification = 'left' , size = (None , None ), size_px = (None , None ), pad = None , scrollable = False , vertical_scroll_only = False , right_click_menu = None , key = None , visible = True ):
21952200 '''
21962201 Column Element
21972202 :param layout:
@@ -2215,6 +2220,7 @@ def __init__(self, layout, background_color=None, size=(None, None), size_px=(No
22152220 self .WxBoxSizer = None # type: wx.BoxSizer
22162221 self .WxHSizer = None # type: wx.BoxSizer
22172222 self ._Layout (layout )
2223+ self .ElementJustification = element_justification
22182224 tsize = size_px if size_px != (None , None ) else size
22192225
22202226 super ().__init__ (ELEM_TYPE_COLUMN , background_color = background_color , size_px = tsize , pad = pad , key = key , visible = visible )
@@ -2790,7 +2796,7 @@ class Window:
27902796 def __init__ (self , title , layout = None , default_element_size = DEFAULT_ELEMENT_SIZE , default_button_element_size = (None , None ),
27912797 auto_size_text = None , auto_size_buttons = None , location = (None , None ), size = (None , None ), element_padding = None , button_color = None , font = None ,
27922798 progress_bar_color = (None , None ), background_color = None , border_depth = None , auto_close = False ,
2793- auto_close_duration = None , icon = DEFAULT_BASE64_ICON , force_toplevel = False ,
2799+ auto_close_duration = None , icon = DEFAULT_BASE64_ICON , force_toplevel = False , element_justification = 'left' ,
27942800 alpha_channel = 1 , return_keyboard_events = False , use_default_focus = True , text_justification = None ,
27952801 no_titlebar = False , grab_anywhere = False , keep_on_top = False , resizable = True , disable_close = False , disable_minimize = False , background_image = None , finalize = False ):
27962802 '''
@@ -2876,6 +2882,7 @@ def __init__(self, title, layout=None, default_element_size=DEFAULT_ELEMENT_SIZE
28762882 self ._Size = size
28772883 self .ElementPadding = element_padding or DEFAULT_ELEMENT_PADDING
28782884 self .FocusElement = None
2885+ self .ElementJustification = element_justification
28792886 self .BackgroundImage = background_image
28802887 self .XFound = False
28812888 self .DisableMinimize = disable_minimize
@@ -4303,7 +4310,17 @@ def AddMenuItem(top_menu, sub_menu_info, element, is_sub_menu=False, skip=False)
43034310# ------------------------------------------------------------------------------------------------------------------ #
43044311# ------------------------------------------------------------------------------------------------------------------ #
43054312
4306- def PackFormIntoFrame (form , containing_frame , toplevel_form ):
4313+ def PackFormIntoFrame (container_elem , containing_frame , toplevel_form ):
4314+ """
4315+
4316+ :param container_elem:
4317+ :type container_elem: Window or Column or Tab or Frame
4318+ :param containing_frame:
4319+ :type containing_frame: wx.BoxSizer
4320+ :param toplevel_form:
4321+ :type toplevel_form: Window
4322+ :return:
4323+ """
43074324 def pad_widget (widget ):
43084325 lrsizer = wx .BoxSizer (wx .HORIZONTAL )
43094326 if full_element_pad [1 ] == full_element_pad [3 ]: # if right = left
@@ -4351,7 +4368,7 @@ def CharWidthInPixels():
43514368 focus_set = False
43524369 ######################### LOOP THROUGH ROWS #########################
43534370 # *********** ------- Loop through ROWS ------- ***********#
4354- for row_num , flex_row in enumerate (form .Rows ):
4371+ for row_num , flex_row in enumerate (container_elem .Rows ):
43554372 ######################### LOOP THROUGH ELEMENTS ON ROW #########################
43564373 # *********** ------- Loop through ELEMENTS ------- ***********#
43574374 # *********** Make TK Row ***********#
@@ -5322,17 +5339,18 @@ def CharWidthInPixels():
53225339 sizer = pad_widget (static_line )
53235340
53245341 hsizer .Add (sizer , 0 )
5325- # separator = ttk.Separator(tk_row_frame, orient=element.Orientation, )
5326- # separator.pack(side=tk.LEFT, padx=element.Pad[0], pady=element.Pad[1], fill='both', expand=True)
5327- #
5328- # # ............................DONE WITH ROW pack the row of widgets ..........................#
5329- # done with row, pack the row of widgets
5330- containing_frame .Add (hsizer ,0 , wx .TOP | wx .BOTTOM , border = 0 )
5331- # tk_row_frame.grid(row=row_num+2, sticky=tk.NW, padx=DEFAULT_MARGINS[0])
5332- # tk_row_frame.pack(side=tk.TOP, anchor='nw', padx=DEFAULT_MARGINS[0], expand=False)
5333- # if form.BackgroundColor is not None and form.BackgroundColor != COLOR_SYSTEM_DEFAULT:
5334- # tk_row_frame.configure(background=form.BackgroundColor)
5335- # toplevel_form.TKroot.configure(padx=DEFAULT_MARGINS[0], pady=DEFAULT_MARGINS[1])
5342+
5343+ #.................DONE WITH ROW pack the row of widgets ..................#
5344+
5345+ # Add the row to the layout. Justify the row depending on the settings for its container
5346+ if container_elem .ElementJustification .startswith ('c' ):
5347+ containing_frame .Add (hsizer , 0 ,wx .ALIGN_CENTER , border = 0 )
5348+ elif container_elem .ElementJustification .startswith ('r' ):
5349+ containing_frame .Add (hsizer ,0 , wx .ALIGN_RIGHT , border = 0 )
5350+ else :
5351+ containing_frame .Add (hsizer , 0 , wx .TOP | wx .BOTTOM , border = 0 )
5352+
5353+
53365354 return
53375355
53385356
@@ -7955,13 +7973,14 @@ def PopupGetText(message, title=None, default_text='', password_char='', size=(N
79557973def main ():
79567974 # ChangeLookAndFeel('Light Brown 11')
79577975 frame_contents = [[T ('Inside my frame' )],
7958- [CB ('Checkbox in the frame too' )]]
7976+ [Input (size = (5 ,1 ))],
7977+ [Input ()]]
79597978 layout = [
79607979 [Text ('Welcome to PySimpleGUI!' , font = 'Arial 15' , text_color = 'red' )],
79617980 [Text ('You are running version {}' .format (version ), font = 'Arial 20' , text_color = 'red' )],
79627981 [Text ('You should be importing this module rather than running it' , justification = 'l' , size = (50 , 1 ))],
79637982 [Text ('Here is your sample input window....' )],
7964- [Frame ('This is a FRAME! ' , frame_contents )],
7983+ [Frame ('FRAME with Centered Contents ' , frame_contents , element_justification = 'c' )],
79657984 [InputText ('Source' , focus = True , size_px = (200 ,80 )), FileBrowse ()],
79667985 [InputText ('Dest' ), FolderBrowse ()],
79677986 [Checkbox ('Checkbox 1' , size = (15 ,1 )), Checkbox ('Checkbox 2' )],
@@ -7983,6 +8002,7 @@ def main():
79838002 disable_close = False ,
79848003 disable_minimize = True ,
79858004 grab_anywhere = True ,
8005+ # element_justification='r'
79868006 )
79878007
79888008 while True :
0 commit comments