3 """Module used to configure plugin from an easy-to-use widget
5 :author: Sébastien CHAZALLET <s.chazallet@gmail.com>
6 :organization: InsPyration EURL
7 :copyright: Copyright © InsPyration EURL <www.inspyration.org>
8 :license: GPL 3 <http://www.gnu.org/licenses/gpl.html>
13 from gettext import gettext as _
15 from gi.repository import Gtk
21 class GeditFlake8ConfigWidget(Gtk.Box):
23 def __init__(self, settings):
24 """Initialize the configuration widget from SettingsManager properties
26 :type self: GeditFlake8ConfigWidget
27 :param self: Current widget
29 :type settings: SettingsManager
30 :param settings: Object used to define all configurable properties
35 # the current widget is a box
36 Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL, spacing=6)
38 # reference to settings
39 self.settings = settings
41 # store useful entries into a dictionary
42 # in order to get their values later
45 # Add a label on the top ot widget
46 self.pack_start(Gtk.Label(_("Add to ignore list")), True, True, 0)
48 # create one checkbox for each warning that can be ignored
49 for key, option in self.settings.get_ignore_items():
50 button = Gtk.CheckButton(option)
51 button.set_active(self.settings.is_in_ignore_list(key))
52 self.pack_start(button, True, True, 0)
53 # add the check button to entries
54 self.entries[key] = button
56 # create an Hbox to get the label and the entry on the same line
57 hbox = Gtk.Box(spacing=3)
58 self.pack_start(hbox, True, True, 0)
60 # label for complexity entry
61 hbox.pack_start(Gtk.Label(_("Complexity")), True, True, 0)
63 # complexity entry is an widget allowing us to be sure to have an int
64 complexity_entry = Gtk.SpinButton()
65 complexity_entry.set_adjustment(Gtk.Adjustment(
66 self.settings.get_complexity(), -1, 21, 1, 1, 1))
67 hbox.pack_start(complexity_entry, True, True, 0)
68 # add the widget to entries
69 self.entries[self.settings.get_complexity_key()] = complexity_entry
71 # add an event to get back values and use them
72 self.connect("destroy", self.on_configure_destroy)
74 def on_configure_destroy(self, widget):
75 """Called when the widget is destroyed
77 :type self: GeditFlake8ConfigWidget
78 :param self: Current widget
80 :type widget: GeditFlake8ConfigWidget
81 :param widget: Current widget
86 # extract complexity form element and get complexity value
88 self.entries.pop(self.settings.get_complexity_key()).get_text())
90 # extract all other values
91 values = {k: v.get_active() for k, v in self.entries.items()}
93 # add back complexity value
94 values[self.settings.get_complexity_key()] = complexity
97 self.settings.update_setting(values)