• R/O
  • SSH

tklayout: Commit

Default repository for tklayout.py.


Commit MetaInfo

Revisão4404375b60a36308c7cb6ff1261c9f32779ab8b2 (tree)
Hora2018-02-26 13:19:48
AutorDreas Nielsen <dreas.nielsen@gmai...>
CommiterDreas Nielsen

Mensagem de Log

Changes to prepare to allow panes to appear on separate notebook panes instead of just arranged vertically or horizontally.

Mudança Sumário

Diff

diff -r 956ae7e1de95 -r 4404375b60a3 setup.py
--- a/setup.py Wed Feb 07 21:03:00 2018 -0800
+++ b/setup.py Sun Feb 25 20:19:48 2018 -0800
@@ -2,7 +2,7 @@
22
33 setup(name='tklayout',
44 packages=['tklayout'],
5- version='0.8.0',
5+ version='0.9.0',
66 description="Simplifies the implementation of Tkinter UI layouts by allowing the developer to describe the hierarchy of UI elements from the inside out.",
77 author='Dreas Nielsen',
88 author_email='dreas.nielsen@gmail.com',
diff -r 956ae7e1de95 -r 4404375b60a3 tklayout/tklayout.py
--- a/tklayout/tklayout.py Wed Feb 07 21:03:00 2018 -0800
+++ b/tklayout/tklayout.py Sun Feb 25 20:19:48 2018 -0800
@@ -27,7 +27,7 @@
2727 other widgets to create a Tkinter UI.
2828 """
2929
30-__version__ = '0.8.0'
30+__version__ = '0.9.0'
3131
3232 try:
3333 import Tkinter as tk
@@ -56,7 +56,6 @@
5656 """Represents the structure of Tkinter widgets (e.g., frames) and provides
5757 methods to create and populate the nested set of frames.
5858 """
59-
6059 class Element(object):
6160 """An Element object describes one Tkinter element--a Frame or other widget.
6261
@@ -64,7 +63,7 @@
6463 * A list of component names (names are strings).
6564 * A dictionary of configuration values for the frame that will contain the components.
6665 * A dictionary of gridding options for the frame that will contain the components.
67- * A flag indicating whether the component elements are arranged horizontally or vertically.
66+ * A string indicating whether the component elements are arranged horizontally, vertically, or on parallel pages.
6867 * A weight or list of weights for the rows or columns represented
6968 by the components. If this list is shorter than the list of
7069 components, its members will be recycled as many times as necessary
@@ -72,12 +71,16 @@
7271 * The weight for the column or row in which all of the elements appear.
7372 """
7473
75- def __init__(self, components, config_dict=None, grid_opts=None, vertical=True, component_weights=[1], element_weight=1):
74+ arrangements = {"vertical", "horizontal", "paged"}
75+
76+ def __init__(self, components, config_dict=None, grid_opts=None, arrangement="vertical", component_weights=[1], element_weight=1):
7677 """Assign all data values to the new Element object."""
78+ if arrangement not in self.arrangements:
79+ raise AppLayoutError("Unrecognized arrangement: %s." % arrangement)
7780 self.components = components
7881 self.config_dict = config_dict
7982 self.grid_opts = grid_opts
80- self.vertical = vertical
83+ self.arrangement = arrangement
8184 self.component_weights = component_weights
8285 self.element_weight = element_weight
8386 self.frame = None # Will be assigned by create_layout()
@@ -117,10 +120,11 @@
117120 the named elements.
118121 :return: A name (string) that is automatically assigned to the element that is created
119122 to contain the named elements. This name may be used in the *element_names*
120- argument to subsequent calls to *column_elements()* or *row_elements()*.
123+ argument to subsequent calls to *column_elements()*, *row_elements()*.
124+ or *page_elements*.
121125 """
122126 wts = replist(row_weights, len(element_names))
123- el = self.Element(element_names, config_dict, grid_dict, True, component_weights=wts, element_weight=column_weight)
127+ el = self.Element(element_names, config_dict, grid_dict, "vertical", component_weights=wts, element_weight=column_weight)
124128 el_id = uuid.uuid4()
125129 self.partslist[el_id] = el
126130 self.synthnames.append(el_id)
@@ -129,8 +133,9 @@
129133 el_n = self.Element(None)
130134 self.partslist[n] = el_n
131135 return el_id
136+
132137 def row_elements(self, element_names, config_dict=None, grid_dict=None, column_weights=[1], row_weight=1):
133- """Takes a list of names of elements to be vertically arranged, creates a new element
138+ """Takes a list of names of elements to be horizontally arranged, creates a new element
134139 that encloses those, and returns a synthesized name for the element that is created.
135140
136141 :param element_names: A list of names (strings) of elements.
@@ -145,10 +150,11 @@
145150 the named elements.
146151 :return: A name (string) that is automatically assigned to the element that is created
147152 to contain the named elements. This name may be used in the *element_names*
148- argument to subsequent calls to *column_elements()* or *row_elements()*.
153+ argument to subsequent calls to *column_elements()*, *row_elements()*.
154+ or *page_elements*.
149155 """
150156 wts = replist(column_weights, len(element_names))
151- el = self.Element(element_names, config_dict, grid_dict, False, component_weights=wts, element_weight=row_weight)
157+ el = self.Element(element_names, config_dict, grid_dict, "horizontal", component_weights=wts, element_weight=row_weight)
152158 el_id = uuid.uuid4()
153159 self.partslist[el_id] = el
154160 self.synthnames.append(el_id)
@@ -157,11 +163,37 @@
157163 el_n = self.Element(None)
158164 self.partslist[n] = el_n
159165 return el_id
166+
167+ def page_elements(self, element_names, config_dict=None, grid_dict=None):
168+ """Takes a list of names of elements to be arranged on separate pages or panes
169+ (e.g., pages of a Notebook widget), creates a new element that contains
170+ those, and returns a synthesized name for the element that is created.
171+
172+ :param element_names: A list of names (strings) of elements.
173+ :param config_dict: A dictionary of configuration specifications for the frame that will
174+ contain the named elements.
175+ :param grid_dict: A dictionary of gridding options for the frame that will contain
176+ the named elements.
177+ :return: A name (string) that is automatically assigned to the element that is created
178+ to contain the named elements. This name may be used in the *element_names*
179+ argument to subsequent calls to *column_elements()*, *row_elements()*,
180+ or *page_elements*.
181+ """
182+ el = self.Element(element_names, config_dict, grid_dict, "paged")
183+ el_id = uuid.uuid4()
184+ self.partslist[el_id] = el
185+ self.synthnames.append(el_id)
186+ for n in element_names:
187+ if n not in self.synthnames:
188+ el_n = self.Element(None)
189+ self.partslist[n] = el_n
190+ return el_id
191+
160192 def create_layout(self, master_widget, master_element_name, row=0, column=0, row_weight=1, column_weight=1):
161193 """Creates a nested set of frames corresponding to the application layout that has been specified.
162194
163- The application layout must have been previously described by calls to the 'column_elements()' and
164- 'row_elements()' methods.
195+ The application layout must have been previously described by calls to the ``column_elements``,
196+ ``row_elements``, and ``page_elements`` methods.
165197
166198 :param master_widget: A container widget (e.g., Frame) that will serve as the root for all the frames to be created.
167199 :param master_element_name: The name of the element to be placed in the top-level frame. This name must be one of those supplied to 'row_elements()' or 'column_elements()', or returned by those methods.
@@ -184,15 +216,15 @@
184216 for i, comp in enumerate(el.components):
185217 layout_element(el.frame, comp)
186218 compframe = self.partslist[comp].frame
187- if el.vertical:
219+ if el.arrangement == "vertical":
188220 compframe.grid(row=i, column=0)
189221 el.frame.rowconfigure(i, weight=el.component_weights[i])
190- else:
222+ elif el.arrangement == "horizontal":
191223 compframe.grid(row=0, column=i)
192224 el.frame.columnconfigure(i, weight=el.component_weights[i])
193- if el.vertical:
225+ if el.arrangement == "vertical":
194226 el.frame.columnconfigure(0, weight=el.element_weight)
195- else:
227+ elif el.arrangement == "horizontal":
196228 el.frame.rowconfigure(0, weight=el.element_weight)
197229 layout_element(master_widget, master_element_name)
198230 master_widget.rowconfigure(row, weight=row_weight)
@@ -271,7 +303,7 @@
271303 if el.components and len(el.components) > 0:
272304 json_str += u","
273305 if el.components and len(el.components) > 0:
274- json_str = u'%s\n%s"orientation": "%s",\n' % (json_str, indentstr * (indent+1), u"vertical" if el.vertical else u"horizontal")
306+ json_str = u'%s\n%s"orientation": "%s",\n' % (json_str, indentstr * (indent+1), el.arrangement)
275307 json_str = u'\n%s%s"elements": {' % (json_str, indentstr * (indent+1))
276308 for i, comp in enumerate(el.components):
277309 json_str = describe_element(json_str, comp, i, len(el.components), indent+2, show_attributes)
Show on old repository browser