• R/O
  • SSH

tkpane: Commit

Default repository for tkpane.py.


Commit MetaInfo

Revisão843286eefadcf8a2ec40a34e780e254421e49b7c (tree)
Hora2018-03-02 02:56:57
AutorDreas Nielsen <dnielsen@inte...>
CommiterDreas Nielsen

Mensagem de Log

Expanded support for the 'on_save_change' callback list. Added 'set_filename_validator()' method to InputFilePane

Mudança Sumário

Diff

diff -r 5a2c4a08eea6 -r 843286eefadc CHANGELOG.rst
--- a/CHANGELOG.rst Wed Feb 28 22:26:13 2018 -0800
+++ b/CHANGELOG.rst Thu Mar 01 09:56:57 2018 -0800
@@ -4,6 +4,7 @@
44 ========== ======= =================================================================================
55 Date Version Revision
66 ========== ======= =================================================================================
7+2018-03-01 0.20.0 Improved support fo 'on_save_change' callback list. Added 'set_filename_validator()' method to InputFilePane.
78 2018-02-27 0.19.0 Added 'on_save_change' callback list. Added missing 'entry_widgets()' method to UserPasswordPane.
89 2018-02-27 0.18.0 Backwards-incompatible change since 0.14.0: changed object returned by 'build_ui()' to a dict. Added 'tab_frames()' method to NotebookPane. Set the CheckboxPane's value to False even when False is considered an invalid state.
910 2018-02-22 0.16.1 Changed method to set 'invalid' color for ttk widgets; correction to 'can_use()' method.
diff -r 5a2c4a08eea6 -r 843286eefadc doc/source/conf.py
--- a/doc/source/conf.py Wed Feb 28 22:26:13 2018 -0800
+++ b/doc/source/conf.py Thu Mar 01 09:56:57 2018 -0800
@@ -55,9 +55,9 @@
5555 # built documents.
5656 #
5757 # The short X.Y version.
58-version = u'0.19.0'
58+version = u'0.20.0'
5959 # The full version, including alpha/beta/rc tags.
60-release = u'0.19.0'
60+release = u'0.20.0'
6161
6262 # The language for content autogenerated by Sphinx. Refer to documentation
6363 # for a list of supported languages.
diff -r 5a2c4a08eea6 -r 843286eefadc doc/source/index.rst
--- a/doc/source/index.rst Wed Feb 28 22:26:13 2018 -0800
+++ b/doc/source/index.rst Thu Mar 01 09:56:57 2018 -0800
@@ -231,7 +231,7 @@
231231 mouse, and the data are valid (list ``on_exit_data_valid``).
232232 * The user leaves the pane by changing the keyboard focus or moving the
233233 mouse, and the data are invalid (list ``on_exit_data_invalid``).
234-* Data in the pane's data dictionary are changed.
234+* Data in the pane's data dictionary are changed (list ``on_save_change``).
235235 * The pane's ``enable()`` method is called (list ``on_enable``).
236236 * The pane's ``clear()`` method is called (list ``on_clear``).
237237 * The pane's ``disable()`` method is called (list ``on_disable``).
@@ -241,6 +241,11 @@
241241 *disable* actions the callback functions are called after the pane
242242 itself is enabled, cleared, or disabled, respectively.
243243
244+Some of these callback lists are automatically populated by the
245+``requires()`` and ``can_use()`` methods. All of the callback lists
246+can be directly modified by appending appropriate callback function
247+objects to them.
248+
244249 As described in the previous section, the ``enable()`` and
245250 ``disable()`` methods take different arguments: the first takes a
246251 dictionary, and the second takes a list. The ``clear()`` method takes
@@ -397,6 +402,24 @@
397402
398403
399404
405+Creating Custom Panes by Subclassing TkPane
406+==============================================================
407+
408+There are three general types of panes that might be created by
409+subclassing the TkPane class, and the ``tkpane.lib`` package
410+contains custom subclasses that illustrate these, and can be
411+used as templates for other custom subclasses:
412+
413+* Panes that handle user-entered data, where the data may be
414+ invalid (e.g., when required and missing). See
415+ ``tkpane.lib.EntryPane`` and Example 2.
416+* Panes that handle user-entered data where the data are
417+ constrained to never be invalid. See ``tkpane.lib.ScalePane``
418+ and ``tkpane.lib.UserPane``.
419+* Panes that do not handle user-entered data. See
420+ ```tkpane.lib.MessagePane`` and ``tkpane.lib.ButtonPane```.
421+
422+
400423 Package Contents
401424 ==============================================================
402425
diff -r 5a2c4a08eea6 -r 843286eefadc setup.py
--- a/setup.py Wed Feb 28 22:26:13 2018 -0800
+++ b/setup.py Thu Mar 01 09:56:57 2018 -0800
@@ -2,7 +2,7 @@
22
33 setup(name='tkpane',
44 packages=['tkpane'],
5- version='0.19.0',
5+ version='0.20.0',
66 description="Encapsulates Tkinter UI elements in 'panes' that can be combined into an overall UI, integrating them by specifying callback functions and data keys.",
77 author='Dreas Nielsen',
88 author_email='dreas.nielsen@gmail.com',
diff -r 5a2c4a08eea6 -r 843286eefadc tkpane/lib.py
--- a/tkpane/lib.py Wed Feb 28 22:26:13 2018 -0800
+++ b/tkpane/lib.py Thu Mar 01 09:56:57 2018 -0800
@@ -24,7 +24,7 @@
2424 for creation of other custom pane classes.
2525 """
2626
27-__version__ = "0.9.2"
27+__version__ = "0.10.0"
2828
2929
3030 try:
@@ -728,6 +728,7 @@
728728 self.optiondict = {} if optiondict is None else optiondict
729729 self.datakey = "input_filename"
730730 self.datakeylist = [self.datakey]
731+ self.filename_validator = None
731732 # Create, configure, and place widgets.
732733 self.dir_label = ttk.Label(self, text='Input file:', width=12, anchor=tk.E)
733734 self.file_var = tk.StringVar()
@@ -762,7 +763,10 @@
762763 if filename == "":
763764 return not self.required
764765 else:
765- return os.path.isfile(filename)
766+ if self.filename_validator is not None:
767+ return self.filename_validator(self.datadict[self.datakey])
768+ else:
769+ return os.path.isfile(filename)
766770
767771 def save_data(self, is_valid, entry_widget):
768772 """Update the pane's data dictionary with data from the entry widget.
@@ -836,6 +840,13 @@
836840 self.handle_change_validity(True, self.file_display)
837841 self.send_status_message(True)
838842
843+ def set_filename_validator(self, fn):
844+ """Set the callback function that will be used to check the entered filename.
845+
846+ This function must take the filename as an argument and return a Boolean.
847+ """
848+ self.filename_validator = fn
849+
839850
840851 class ListboxPane(tkpane.TkPane):
841852 """Display a Tkinter Listbox.
@@ -2444,13 +2455,16 @@
24442455 # Open a dialog box to prompt for the user's name and password.
24452456 dlg = self.GetUserDialog(self)
24462457 if dlg.result is not None:
2458+ prev_data = copy.deepcopy(self.datadict)
24472459 self.user_var.set(dlg.result["name"])
24482460 self.user_pw = dlg.result["password"]
24492461 self.datadict["name"] = dlg.result["name"]
24502462 self.datadict["password"] = dlg.result["password"]
2451- self.report_status(u"Name set to %s." % dlg.result[u"name"])
2452- self.handle_change_validity(True, None)
2453- self.send_status_message(True)
2463+ if self.datadict != prev_data:
2464+ self.call_handlers(self.on_save_change)
2465+ self.report_status(u"Name set to %s." % dlg.result[u"name"])
2466+ self.handle_change_validity(True, None)
2467+ #self.send_status_message(True)
24542468
24552469 def set_user_validator(self, fn):
24562470 """Set the callback function that will be used to check the entered user name and password.
diff -r 5a2c4a08eea6 -r 843286eefadc tkpane/tkpane.py
--- a/tkpane/tkpane.py Wed Feb 28 22:26:13 2018 -0800
+++ b/tkpane/tkpane.py Thu Mar 01 09:56:57 2018 -0800
@@ -27,7 +27,7 @@
2727 that pass specific data to allow communication between panes, and callback methods
2828 for reporting status and progress."""
2929
30-__version__ = "0.19.0"
30+__version__ = "0.20.0"
3131
3232
3333 try:
@@ -130,6 +130,9 @@
130130 pane loses focus and the data are valid.
131131 * on_exit_data_invalid: A list of CbHandler objects to be called when
132132 the pane loses focus and the data are invalid.
133+ * on_save_change: A list of CbHandler objects to be called when the
134+ values of the pane's own data keys are modified in the pane's internal
135+ data dictionary.
133136 * on_enable: A list of CbHandler objects to be called when this pane
134137 is enabled.
135138 * on_clear: A list of CbHandler objects to be called when this pane
@@ -215,8 +218,8 @@
215218 self.on_clear = []
216219 # Handlers that will be called when this pane is disabled.
217220 self.on_disable = []
218- # Handlers that will be called if the data dictionary is changed by the
219- # subclass' 'save_data()' method.
221+ # Handlers that will be called if the pane's own data key values in the
222+ # data dictionary are changed.
220223 self.on_save_change = []
221224 #=======================================================================
222225 # ASSIGNABLE ATTRIBUTES
@@ -534,15 +537,21 @@
534537 The incoming data will be merged into this pane's own data dictionary.
535538 """
536539 if incoming_data is not None:
540+ prev_data = self.values()
537541 self.datadict.update(incoming_data)
542+ if self.values() != prev_data:
543+ self.call_handlers(self.on_save_change)
538544 if self.can_enable():
539545 self.enable_pane()
540546 self.call_handlers(self.on_enable)
541547
542548 def __delete_data(self, keylist):
549+ prev_data = self.values()
543550 for k in keylist:
544551 if k in self.datadict:
545552 del self.datadict[k]
553+ if self.values() != prev_data:
554+ self.call_handlers(self.on_save_change)
546555
547556 def clear_own(self):
548557 """Clears the pane's own data from its data dictionary.
Show on old repository browser