def update_comboboxtext_choices(cb: Gtk.ComboBoxText, choices: List[str], default=None, set_to=None): """Update the choices of the combo box while keeping the current selection, if possible.""" logger.debug('Updating comboboxtext choices.') prevselected = cb.get_active_text() logger.debug('Previously selected: {}'.format(prevselected)) if set_to is not None: logger.debug('Set_to is not None, but {}'.format(set_to)) prevselected = set_to cb.remove_all() defaultindex = None logger.debug('Adding choices:') active_index = None for i, k in enumerate(choices): cb.append_text(k) if k == prevselected: active_index = i if k == default: defaultindex = i logger.debug( ' #{:d}: '.format(i) + k + ['', ' (active) '][active_index == i] + ['', ' (default) '][defaultindex == i]) if defaultindex is None: defaultindex = 0 if active_index is None: logger.debug('Setting to default, cannot activate original.') active_index = defaultindex cb.set_active(active_index) logger.debug('Activated index {:d}: {}'.format(active_index, cb.get_active_text()))
def on_change_clipping_method(self, widget: Gtk.ComboBoxText): METHODS = { 'Cohen Sutherland': LineClippingMethod.COHEN_SUTHERLAND, 'Liang Barsky': LineClippingMethod.LIANG_BARSKY, } self.clipping_method = METHODS[widget.get_active_text()] self.window.queue_draw()
def on_prefix_changed(self, prefixselector: Gtk.ComboBoxText): prefix = prefixselector.get_active_text() try: self.on_lastfsn_changed(self.instrument.services['filesequence'], prefix, self.instrument.services['filesequence'].get_lastfsn(prefix)) except KeyError: pass
def on_motorselector_changed(self, combobox: Gtk.ComboBoxText): if self.widget.get_visible(): self.motorname = combobox.get_active_text() self.required_devices = ['Motor_' + self.motorname] self.on_mainwidget_map(self.widget) # for re-connecting the signal handlers self.builder.get_object('currentpos_label').set_text( '%.3f' % self.instrument.motors[self.motorname].where()) self.adjust_limits() return False
def on_peak_selector_changed(self, psel: Gtk.ComboBoxText): calibrant = self.builder.get_object('calibrant_selector').get_active_text() if calibrant is None: return peak = psel.get_active_text() if peak is None: return self.builder.get_object('calval_adjustment').set_value( self.instrument.config['calibrants'][calibrant][peak]['val']) self.builder.get_object('calerr_adjustment').set_value( self.instrument.config['calibrants'][calibrant][peak]['err']) logger.debug('Set from calibrant.')
def apply_resolution(widget: Gtk.ComboBoxText): """ @brief Apply selected resolution from the combobox. @param widget Gtk.ComboBoxText @return None """ # apply resolution for all displays in the xfce settings res_str = widget.get_active_text() cmd = XfceCommand("-c", "displays", "-p", "/ActiveProfile") cmd_res = cmd.execute() print("Walking through active display profiles") for cr in cmd_res: print(f"Profile: {cr}") cmd_2 = XfceCommand("-c", "displays", "-p", f"/{cr}", "-l") cmd_res_2 = cmd_2.execute() print("Walking through profile keys") for cr2 in cmd_res_2: if "Resolution" in cr2: print(f"Found resolution in {cr2}") cmd_3 = XfceCommand( "-c", "displays", "-p", cr2, "-s", res_str, ) cmd_3.execute() # also use xrandr to change current resolution xrandr_cmd = ShellCommand("xrandr", "-s", res_str) xrandr_cmd.execute()
def _combobox_changed_cb(self, combobox: Gtk.ComboBoxText, param_name: str): self._params[param_name] = combobox.get_active_text()
def view_switched(self, combo: Gtk.ComboBoxText) -> None: self.choices['View'] = combo.get_active_text()
def on_calibrant_selector_changed(self, csel: Gtk.ComboBoxText): update_comboboxtext_choices( self.builder.get_object('peak_selector'), sorted(self.instrument.config['calibrants'][csel.get_active_text()]))