• R/O
  • SSH

tkpane: Commit

Default repository for tkpane.py.


Commit MetaInfo

Revisãod1eb07ef9b5a64baf1fdfcfd9e6d38d810f82765 (tree)
Hora2018-03-15 03:25:34
Autoreshea
Commitereshea

Mensagem de Log

Modified radiobutton pane to pass radio options as list of tuples rathr than as a dictionary (to allow ordering).

Mudança Sumário

Diff

diff -r bc0b024d3889 -r d1eb07ef9b5a test/test_radiobutton.py
--- a/test/test_radiobutton.py Wed Mar 14 10:12:01 2018 -0700
+++ b/test/test_radiobutton.py Wed Mar 14 11:25:34 2018 -0700
@@ -59,7 +59,7 @@
5959 })
6060 tkpane.lib.current_panestyle = "closey"
6161 lo.build_elements({
62- "rb1": lambda p: tkpane.lib.RadiobuttonPane(p, "rb1", "Radiobutton1", {"Option1": 1, "Option2":2, "Option3": 3}, "Option1")
62+ "rb1": lambda p: tkpane.lib.RadiobuttonPane(p, "rb1", "Radiobutton1", [("Option1",1), ("Option2",2), ("Option3", 3)], "Option1")
6363 })
6464
6565
diff -r bc0b024d3889 -r d1eb07ef9b5a tkpane/lib.py
--- a/tkpane/lib.py Wed Mar 14 10:12:01 2018 -0700
+++ b/tkpane/lib.py Wed Mar 14 11:25:34 2018 -0700
@@ -1681,8 +1681,8 @@
16811681
16821682 :param pane_name: The name to be used to identify this pane in status messages.
16831683 :param prompt: The text associated with the set of radiobuttons.
1684- :param item_dict: The dictionary of items to be included as radiobutton options, consisting of labels and values as key/value pairs.
1685- :param default_item: They key name of the default value.
1684+ :param option_list: List of radiobutton options, consisting of tuples in the format: (label, value).
1685+ :param default_option: The label of the default option, e.g., "radioopt1" for ("radioopt", 1)
16861686 :param button_action: A callback to perform an action when a value is selected.
16871687 :param key_name: The name to be used with the internal data dictionary to identify the entry data; use to avoid name conflicts with other RadiobuttonPane panes on the same UI (optional).
16881688 :param config_opts: A dictionary of configuration options for the Radiobutton widget
@@ -1710,26 +1710,32 @@
17101710
17111711 """
17121712
1713- def __init__(self, parent, pane_name, prompt, item_dict, default_item=None, button_action=None, key_name=None, config_opts=None):
1713+ def __init__(self, parent, pane_name, prompt, option_list, default_option=None, button_action=None, key_name=None, config_opts=None):
17141714 def do_nothing(data_dict):
17151715 pass
17161716 tkpane.TkPane.__init__(self, parent, pane_name, frame_config_opts(), frame_grid_opts())
17171717 self.action = button_action if button_action is not None else do_nothing
1718- self.default_item = default_item
1718+ self.default_option = default_option
17191719 self.datakeyname = "radio" if key_name is None else key_name
17201720 self.datakeylist = [self.datakeyname]
17211721 self.prompt = ttk.Label(self, text=prompt, width=max(12, len(prompt)), anchor=tk.E)
17221722 self.prompt.grid(row=0, column=0, padx=3, pady=3, sticky=tk.EW)
17231723 self.columnconfigure(0, weight=0)
17241724 self.radio_var = tk.StringVar()
1725- self.radio_var.set(item_dict.get(default_item))
1725+ # Get the default option if it is on the list of options (if not set to None)
1726+ if default_option in [option[0] for option in option_list]:
1727+ default_index = [option[0] for option in option_list].index(default_option)
1728+ default_value = option_list[default_index][1]
1729+ else:
1730+ default_value = None
1731+ self.radio_var.set(default_value)
17261732 self.datadict[self.datakeyname] = self.radio_var.get()
1727- for i, item in enumerate(item_dict):
1733+ for i, option in enumerate(option_list):
17281734 if tkpane.use_ttk:
1729- radio_btn = ttk.Radiobutton(self, text=item, variable=self.radio_var, value=item_dict[item], command=self.do_button_action)
1735+ radio_btn = ttk.Radiobutton(self, text=option[0], variable=self.radio_var, value=option[1], command=self.do_button_action)
17301736 self.widget_type = "ttk"
17311737 else:
1732- radio_btn = tk.Radiobutton(self, text=item, variable=self.radio_var, value=item_dict[item], command=self.do_button_action)
1738+ radio_btn = tk.Radiobutton(self, text=option[0], variable=self.radio_var, value=option[1], command=self.do_button_action)
17331739 self.widget_type = "tk"
17341740 if config_opts is not None:
17351741 self.radio_btn.configure(**config_opts)
Show on old repository browser