def test_params_constructor(self, simple_adjustment): """Make sure the widget can be set up via constructor.""" spin = HamsterSpinButton(simple_adjustment) adjustment = spin.get_adjustment() assert adjustment.get_lower() == simple_adjustment.min assert adjustment.get_upper() == simple_adjustment.max assert adjustment.get_step_increment() == simple_adjustment.step
def test_params_constructor(self, simple_adjustment): """Make sure the widget can be set up via constructor.""" spin = HamsterSpinButton(simple_adjustment) adjustment = spin.get_adjustment() assert adjustment.get_lower() == simple_adjustment.min assert adjustment.get_upper() == simple_adjustment.max assert adjustment.get_step_increment() == simple_adjustment.step
def test_params_constructor_invalid(self): """ Passing a value that is neither a :class:`Gtk.Adjustment`, nor a :class:`SimpleAdjustment` to the constructor should fail. """ with pytest.raises(ValueError): HamsterSpinButton(42)
def test_params_constructor_zero_step(self, simple_adjustment): """Passing zero as a step to the constructor should fail.""" new_adj = SimpleAdjustment(min=simple_adjustment.min, max=simple_adjustment.max, step=0) with pytest.raises(ValueError): HamsterSpinButton(new_adj)
def test_params_constructor_overlapping_bounds(self, simple_adjustment): """Passing lower bound greater than upper bound to the constructor should fail.""" new_adj = SimpleAdjustment(min=simple_adjustment.max, max=simple_adjustment.min, step=simple_adjustment.step) with pytest.raises(ValueError): HamsterSpinButton(new_adj)
def __init__(self, parent, app, initial, *args, **kwargs): """ Instantiate dialog. Args: parent (Gtk.Window): Dialog parent. app (HamsterGTK): Main app instance. Needed in order to retrieve and manipulate config values. """ super(PreferencesDialog, self).__init__(*args, **kwargs) self._parent = parent self._app = app self.set_transient_for(self._parent) db_engines = [('sqlite', _('SQLite')), ('postgresql', _('PostgreSQL')), ('mysql', _('MySQL')), ('oracle', _('Oracle')), ('mssql', _('MSSQL'))] stores = [(store, hamster_lib.REGISTERED_BACKENDS[store].verbose_name) for store in hamster_lib.REGISTERED_BACKENDS] # We use an ordered dict as the order reflects display order as well. self._fields = collections.OrderedDict([ ('day_start', (_('_Day Start (HH:MM:SS)'), TimeEntry())), ('fact_min_delta', (_('_Minimal Fact Duration'), HamsterSpinButton(SimpleAdjustment(0, GObject.G_MAXDOUBLE, 1)))), ('store', (_('_Store'), HamsterComboBoxText(stores))), ('db_engine', (_('DB _Engine'), HamsterComboBoxText(db_engines))), ('db_path', (_('DB _Path'), ComboFileChooser())), ('tmpfile_path', (_('_Temporary file'), ComboFileChooser())), ]) grid = Gtk.Grid() grid.set_hexpand(True) row = 0 for key, (label, widget) in self._fields.items(): label_widget = Gtk.Label(label) label_widget.set_use_underline(True) label_widget.set_mnemonic_widget(widget) grid.attach(label_widget, 0, row, 1, 1) grid.attach(widget, 1, row, 1, 1) row += 1 self._set_config(initial) self.get_content_area().add(grid) self.add_button(_('_Cancel'), Gtk.ResponseType.CANCEL) self.add_button(_('_Apply'), Gtk.ResponseType.APPLY) self.show_all()
def __init__(self, parent, app, initial, *args, **kwargs): """ Instantiate dialog. Args: parent (Gtk.Window): Dialog parent. app (HamsterGTK): Main app instance. Needed in order to retrieve and manipulate config values. initial (dict): Dictionary of initial config key/values. """ super(PreferencesDialog, self).__init__(*args, **kwargs) self._parent = parent self._app = app self.set_transient_for(self._parent) db_engines = [('sqlite', _("SQLite")), ('postgresql', _("PostgreSQL")), ('mysql', _("MySQL")), ('oracle', _("Oracle")), ('mssql', _("MSSQL"))] stores = [(store, hamster_lib.REGISTERED_BACKENDS[store].verbose_name) for store in hamster_lib.REGISTERED_BACKENDS] # We use an ordered dict as the order reflects display order as well. self._pages = [ (_('Tracking'), LabelledWidgetsGrid( collections.OrderedDict([ ('day_start', (_('_Day Start (HH:MM:SS)'), TimeEntry())), ('fact_min_delta', (_('_Minimal Fact Duration'), HamsterSpinButton( SimpleAdjustment(0, GObject.G_MAXDOUBLE, 1)))), ]))), (_('Storage'), LabelledWidgetsGrid( collections.OrderedDict([ ('store', (_('_Store'), HamsterComboBoxText(stores))), ('db_engine', (_('DB _Engine'), HamsterComboBoxText(db_engines))), ('db_path', (_('DB _Path'), ComboFileChooser())), ('tmpfile_path', (_('_Temporary file'), ComboFileChooser())), ]))), (_('Miscellaneous'), LabelledWidgetsGrid( collections.OrderedDict([ ('autocomplete_activities_range', (_("Autocomplete Activities Range"), HamsterSpinButton( SimpleAdjustment(0, GObject.G_MAXDOUBLE, 1)))), ('autocomplete_split_activity', (_("Autocomplete activities and categories separately"), HamsterSwitch())), ]))), ] notebook = Gtk.Notebook() notebook.set_name('PreferencesNotebook') for title, page in self._pages: notebook.append_page(page, Gtk.Label(title)) if initial: self._set_config(initial) self.get_content_area().add(notebook) self.add_button(_("_Cancel"), Gtk.ResponseType.CANCEL) self.add_button(_("_Apply"), Gtk.ResponseType.APPLY) self.show_all()
def test_params_constructor_adjustment(self, adjustment): """Make sure the widget can be set up by passing :class:`Gtk.Adjustment` to constructor.""" spin = HamsterSpinButton(adjustment) assert spin.get_adjustment() == adjustment
def test_params_constructor_adjustment(self, adjustment): """Make sure the widget can be set up by passing :class:`Gtk.Adjustment` to constructor.""" spin = HamsterSpinButton(adjustment) assert spin.get_adjustment() == adjustment
def test_instance(self): """Make sure the widget is still a SpinButton.""" spin = HamsterSpinButton() assert isinstance(spin, Gtk.SpinButton)
def test_init(self): """Make sure minimal initialisation works.""" spin = HamsterSpinButton() assert spin