def update_exp_treeview(self, tv): """ Updates the experimental pattern TreeView layout """ model = self.get_experimental_pattern_tree_model() for column in tv.get_columns(): tv.remove_column(column) def get_num(column, cell, model, itr, col_id): cell.set_property('text', '%.3f' % model.get_value(itr, col_id)) n_columns = model.get_n_columns() if n_columns > 2: for i in range(n_columns): tv.append_column(new_text_column( self.model.calculated_pattern.get_y_name(i), editable=True, edited_callback=(self.on_xy_data_cell_edited, (self.model.experimental_pattern, i)), data_func=(get_num, (i,)) )) else: # X Column: tv.append_column(new_text_column( '°2θ', editable=True, data_func=(get_num, (model.c_x,)), edited_callback=(self.on_xy_data_cell_edited, (self.model.experimental_pattern, 0)))) # Y Column: tv.append_column(new_text_column( 'Intensity', editable=True, data_func=(get_num, (model.c_y,)), edited_callback=(self.on_xy_data_cell_edited, (self.model.experimental_pattern, 1))))
def setup_exclusion_ranges_tree_view(self, store, widget): """ Creates the exclusion ranges TreeView layout and behavior """ setup_treeview( widget, store, on_cursor_changed=self.on_exclusion_ranges_tv_cursor_changed, sel_mode='MULTIPLE') def data_func(col, cell, model, iter, colnr): cell.set_property("text", "%g" % model.get(iter, colnr)[0]) widget.append_column( new_text_column('From [°2θ]', text_col=store.c_x, editable=True, data_func=(data_func, (store.c_x, )), edited_callback=(self.on_xy_data_cell_edited, (self.model.exclusion_ranges, 0)), resizable=True, expand=True)) widget.append_column( new_text_column('To [°2θ]', text_col=store.c_y, editable=True, data_func=(data_func, (store.c_y, )), edited_callback=(self.on_xy_data_cell_edited, (self.model.exclusion_ranges, 1)), resizable=True, expand=True))
def register_view(self, view): super(MatchMineralController, self).register_view(view) if view is not None: # MATCHES Treeview: tv = self.view["tv_matches"] setup_treeview(tv, None, reset=True, on_selection_changed=self.selection_changed) tv.append_column(new_text_column("Name", markup_col=0, xalign=0)) tv.append_column(new_text_column("Abbr.", markup_col=1, expand=False)) def get_value(column, cell, model, itr, *args): value = model.get_value(itr, column.get_col_attr("markup")) try: value = "%.5f" % value except TypeError: value = "" cell.set_property("markup", value) return tv.append_column(new_text_column("Score", markup_col=4, expand=False, data_func=get_value)) # ALL MINERALS Treeview: tv = self.view["tv_minerals"] setup_treeview(tv, None, reset=True, on_selection_changed=self.selection_changed) tv.append_column(new_text_column("Name", markup_col=0, xalign=0)) tv.append_column(new_text_column("Abbr.", markup_col=1, expand=False))
def setup_raw_pattern_tree_view(self, store, widget): """ Creates the raw pattern TreeView layout and behavior """ setup_treeview(widget, store, on_cursor_changed=self.on_raw_pattern_tv_cursor_changed, sel_mode=gtk.SELECTION_MULTIPLE) # X Column: widget.append_column( new_text_column(u'°2θ', text_col=store.c_x, editable=True, edited_callback=(self.on_xy_data_cell_edited, (self.model.raw_pattern, 0)), resizable=True, expand=True)) # Y Column: widget.append_column( new_text_column(u'Intensity', text_col=store.c_y, editable=True, edited_callback=(self.on_xy_data_cell_edited, (self.model.raw_pattern, 1)), resizable=True, expand=True))
def _setup_method_options_treeview(self): """ Initial method options tree view layout & behavior setup """ # Update the method options store to match the currently selected # refinement method tv = self._update_method_options_store() # The name of the option: tv.append_column(new_text_column("Name", text_col=1)) # The value of the option: def get_value(column, cell, model, itr, *args): option_name, = tv.get_model().get(itr, 0) method = self.model.get_refinement_method() cell.set_property("sensitive", True) cell.set_property("editable", True) cell.set_property("markup", "%g" % getattr(method, option_name)) return def on_value_edited(rend, path, new_text, col): store = tv.get_model() itr = store.get_iter(path) option_name, = store.get(itr, 0) method = self.model.get_refinement_method() try: setattr(method, option_name, new_text) except ValueError: pass return True tv.append_column(new_text_column( "Value", text_col=0, data_func=get_value, edited_callback=(on_value_edited, (0,)), ))
def setup_wavelength_distribution_tree_view(self, store, widget): """ Creates the wavelength distribution TreeView layout and behavior """ setup_treeview(widget, store, on_cursor_changed=self.on_wld_tv_cursor_changed, sel_mode='MULTIPLE') widget.set_model(store) def data_func(col, cell, model, iter, colnr): cell.set_property("text", "%g" % model.get(iter, colnr)[0]) # X Column: widget.append_column( new_text_column( 'Wavelength (nm)', text_col=store.c_x, editable=True, data_func=(data_func, (store.c_x, )), edited_callback=(self.on_xy_data_cell_edited, (self.model.wavelength_distribution, 0)))) # Y Column: widget.append_column( new_text_column( 'Fraction', text_col=store.c_y, editable=True, data_func=(data_func, (store.c_y, )), edited_callback=(self.on_xy_data_cell_edited, (self.model.wavelength_distribution, 1))))
def setup_experimental_pattern_tree_view(self, store, widget): """ Creates the experimental data TreeView layout and behavior """ setup_treeview(widget, store, on_cursor_changed=self.on_exp_data_tv_cursor_changed, sel_mode=gtk.SELECTION_MULTIPLE) # X Column: widget.append_column( new_text_column('°2θ', text_col=store.c_x, editable=True, edited_callback=(self.on_xy_data_cell_edited, (self.model.experimental_pattern, 0)))) # Y Column: widget.append_column( new_text_column('Intensity', text_col=store.c_y, editable=True, edited_callback=(self.on_xy_data_cell_edited, (self.model.experimental_pattern, 1)))) # Other properties: self.exp_line_ctrl = LinePropertiesController( model=self.model.experimental_pattern, view=self.view.exp_line_view, parent=self)
def setup_exclusion_ranges_tree_view(self, store, widget): """ Creates the exclusion ranges TreeView layout and behavior """ setup_treeview( widget, store, on_cursor_changed=self.on_exclusion_ranges_tv_cursor_changed, sel_mode=gtk.SELECTION_MULTIPLE) widget.append_column( new_text_column('From [°2θ]', text_col=store.c_x, editable=True, edited_callback=(self.on_xy_data_cell_edited, (self.model.exclusion_ranges, 0)), resizable=True, expand=True)) widget.append_column( new_text_column('To [°2θ]', text_col=store.c_y, editable=True, edited_callback=(self.on_xy_data_cell_edited, (self.model.exclusion_ranges, 1)), resizable=True, expand=True))
def _reset_treeview(self, tv, model): setup_treeview(tv, model, sel_mode='MULTIPLE', reset=True) tv.set_model(model) # Name column: def text_renderer(column, cell, model, itr, args=None): driven_by_other = model.get_value(itr, model.c_driven_by_other) cell.set_property('editable', not driven_by_other) cell.set_property( 'style', Pango.Style.ITALIC if driven_by_other else Pango.Style.NORMAL) col = new_text_column('Name', data_func=text_renderer, editable=True, edited_callback=(self.on_item_cell_edited, (model, model.c_name)), resizable=False, text_col=model.c_name) setattr(col, "col_descr", 'Name') tv.append_column(col) # Value of the relation: float_rend = create_float_data_func() def data_renderer(column, cell, model, itr, args=None): text_renderer(column, cell, model, itr, args) float_rend(column, cell, model, itr, args) col = new_text_column('Value', data_func=data_renderer, editable=True, edited_callback=(self.on_item_cell_edited, (model, model.c_value)), resizable=False, text_col=model.c_value) setattr(col, "col_descr", 'Value') tv.append_column(col) # Up, down and edit arrows: def setup_image_button(image, colnr): col = new_pb_column(" ", resizable=False, expand=False, stock_id=image) setattr(col, "col_descr", colnr) tv.append_column(col) setup_image_button("213-up-arrow", "Up") setup_image_button("212-down-arrow", "Down") setup_image_button("030-pencil", "Edit")
def setup_exclusion_ranges_tree_view(self, store, widget): """ Creates the exclusion ranges TreeView layout and behavior """ setup_treeview(widget, store, on_cursor_changed=self.on_exclusion_ranges_tv_cursor_changed, sel_mode=gtk.SELECTION_MULTIPLE) widget.append_column(new_text_column( u'From [°2θ]', text_col=store.c_x, editable=True, edited_callback=(self.on_xy_data_cell_edited, (self.model.exclusion_ranges, 0)), resizable=True, expand=True)) widget.append_column(new_text_column( u'To [°2θ]', text_col=store.c_y, editable=True, edited_callback=(self.on_xy_data_cell_edited, (self.model.exclusion_ranges, 1)), resizable=True, expand=True))
class ContentsListController(InlineObjectListStoreController): """ Controller for the atom contents ListStore """ new_val = None auto_adapt = False # FIXME treemodel_class_type = AtomContentObject def _reset_treeview(self, tv, model): setup_treeview(tv, model, sel_mode=gtk.SELECTION_MULTIPLE, reset=True) tv.set_model(model) # Atom column: def atom_renderer(column, cell, model, itr, (obj_col, lbl_col)): obj = model.get_value(itr, obj_col) if lbl_col is not None: lbl = model.get_value(itr, lbl_col) if callable(lbl): lbl = lbl(obj) cell.set_property("text", lbl) else: if hasattr(obj, "name"): cell.set_property('text', obj.name) else: cell.set_property('text', '#NA#') def adjust_combo(cell, editable, path, data=None): if editable is not None: rend = gtk.CellRendererText() editable.clear() editable.pack_start(rend) editable.set_cell_data_func(rend, atom_renderer, (0, 2)) tv.append_column( new_combo_column("Atoms", changed_callback=self.on_atom_changed, edited_callback=self.on_atom_edited, editing_started_callback=adjust_combo, xalign=0.0, model=self.model.create_prop_store(), data_func=(atom_renderer, (0, None)), text_column=0, editable=True)) # Content column: def on_float_edited(rend, path, new_text, col): itr = model.get_iter(path) try: model.set_value(itr, col, float(new_text)) except ValueError: logger.exception("Invalid value entered ('%s')!" % new_text) return True tv.append_column( new_text_column('Default contents', text_col=2, xalign=0.0, editable=True, data_func=create_float_data_func(), edited_callback=(on_float_edited, (2, ))))
def update_calc_treeview(self, tv): """ Updates the calculated pattern TreeView layout """ model = self.get_calculated_pattern_tree_model() for column in tv.get_columns(): tv.remove_column(column) def get_num(column, cell, model, itr, *data): cell.set_property('text', '%.3f' % model.get_value(itr, column.get_col_attr('text'))) tv.append_column(new_text_column(u'2θ', text_col=model.c_x, data_func=get_num)) tv.append_column(new_text_column(u'Cal', text_col=model.c_y, data_func=get_num)) for i in range(model.get_n_columns() - 2): tv.append_column(new_text_column( self.model.calculated_pattern.get_y_name(i), text_col=i + 2, data_func=get_num))
def setup_experimental_pattern_tree_view(self, store, widget): """ Creates the experimental data TreeView layout and behavior """ setup_treeview(widget, store, on_cursor_changed=self.on_exp_data_tv_cursor_changed, sel_mode=gtk.SELECTION_MULTIPLE) # X Column: widget.append_column(new_text_column( u'°2θ', text_col=store.c_x, editable=True, edited_callback=(self.on_xy_data_cell_edited, (self.model.experimental_pattern, 0)))) # Y Column: widget.append_column(new_text_column( u'Intensity', text_col=store.c_y, editable=True, edited_callback=(self.on_xy_data_cell_edited, (self.model.experimental_pattern, 1)))) # Other properties: self.exp_line_ctrl = LinePropertiesController(model=self.model.experimental_pattern, view=self.view.exp_line_view, parent=self)
def add_text_col(title, colnr, is_float=True, editable=True): tv.append_column(new_text_column( title, data_func=create_float_data_func() if is_float else None, editable=editable, edited_callback=(self.on_item_cell_edited, (model, colnr)) if editable else None, resizable=True, text_col=colnr))
def setup_treeview(self, widget): super(ProjectController, self).setup_treeview(widget) store = self.treemodel widget.connect('button-press-event', self.specimen_tv_button_press) # First reset & then (re)create the columns of the treeview: for col in widget.get_columns(): widget.remove_column(col) # Name column: col = new_text_column('Name', text_col=store.c_name, min_width=125, xalign=0.0, ellipsize=pango.ELLIPSIZE_END) col.set_data("colnr", store.c_name) widget.append_column(col) # Check boxes: def toggle_renderer(column, cell, model, itr, data=None): active = False if model.iter_is_valid(itr): col = column.get_col_attr("active") active = model.get_value(itr, col) cell.set_property('active', active) return def setup_check_column(title, colnr): col = new_toggle_column(title, toggled_callback=(self.specimen_tv_toggled, (store, colnr)), data_func=toggle_renderer, resizable=False, expand=False, activatable=True, active_col=colnr) col.set_data("colnr", colnr) widget.append_column(col) setup_check_column('Exp', store.c_display_experimental) if self.model.layout_mode == "FULL": setup_check_column('Cal', store.c_display_calculated) setup_check_column('Sep', store.c_display_phases) # Up and down arrows: def setup_image_button(image, colnr): col = new_pb_column("", resizable=False, expand=False, stock_id=image) col.set_data("colnr", colnr) widget.append_column(col) setup_image_button("213-up-arrow", 501) setup_image_button("212-down-arrow", 502)
def _reset_treeview(self, tv, model): setup_treeview(tv, model, sel_mode=gtk.SELECTION_MULTIPLE, reset=True) tv.set_model(model) # Name column: def text_renderer(column, cell, model, itr, args=None): driven_by_other = model.get_value(itr, model.c_driven_by_other) cell.set_property('editable', not driven_by_other) cell.set_property('style', pango.STYLE_ITALIC if driven_by_other else pango.STYLE_NORMAL) col = new_text_column( 'Name', data_func=text_renderer, editable=True, edited_callback=(self.on_item_cell_edited, (model, model.c_name)), resizable=False, text_col=model.c_name) col.set_data("col_descr", 'Name') tv.append_column(col) # Value of the relation: float_rend = create_float_data_func() def data_renderer(column, cell, model, itr, args=None): text_renderer(column, cell, model, itr, args) float_rend(column, cell, model, itr, args) col = new_text_column( 'Value', data_func=data_renderer, editable=True, edited_callback=(self.on_item_cell_edited, (model, model.c_value)), resizable=False, text_col=model.c_value) col.set_data("col_descr", 'Value') tv.append_column(col) # Up, down and edit arrows: def setup_image_button(image, colnr): col = new_pb_column(" ", resizable=False, expand=False, stock_id=image) col.set_data("col_descr", colnr) tv.append_column(col) setup_image_button("213-up-arrow", "Up") setup_image_button("212-down-arrow", "Down") setup_image_button("030-pencil", "Edit")
def setup_raw_pattern_tree_view(self, store, widget): """ Creates the raw pattern TreeView layout and behavior """ print "CALLED!!" setup_treeview(widget, store, on_cursor_changed=self.on_raw_pattern_tv_cursor_changed, sel_mode=gtk.SELECTION_MULTIPLE) # X Column: widget.append_column(new_text_column( u'°2θ', text_col=store.c_x, editable=True, edited_callback=(self.on_xy_data_cell_edited, (self.model.raw_pattern, 0)), resizable=True, expand=True)) # Y Column: widget.append_column(new_text_column( u'Intensity', text_col=store.c_y, editable=True, edited_callback=(self.on_xy_data_cell_edited, (self.model.raw_pattern, 1)), resizable=True, expand=True))
def update_calc_treeview(self, tv): """ Updates the calculated pattern TreeView layout """ model = self.get_calculated_pattern_tree_model() for column in tv.get_columns(): tv.remove_column(column) def get_num(column, cell, model, itr, col_id): cell.set_property('text', '%.3f' % model.get_value(itr, col_id)) tv.append_column( new_text_column('2θ', data_func=(get_num, (model.c_x, )))) tv.append_column( new_text_column('Cal', data_func=(get_num, (model.c_y, )))) for i in range(model.get_n_columns() - 2): tv.append_column( new_text_column(self.model.calculated_pattern.get_y_name(i), data_func=(get_num, (i + 2, ))))
def setup_exclusion_ranges_tree_view(self, store, widget): """ Creates the exclusion ranges TreeView layout and behavior """ setup_treeview(widget, store, on_cursor_changed=self.on_exclusion_ranges_tv_cursor_changed, sel_mode='MULTIPLE') def data_func(col, cell, model, iter, colnr): cell.set_property("text", "%g" % model.get(iter, colnr)[0]) widget.append_column(new_text_column( 'From [°2θ]', text_col=store.c_x, editable=True, data_func = (data_func, (store.c_x,)), edited_callback=(self.on_xy_data_cell_edited, (self.model.exclusion_ranges, 0)), resizable=True, expand=True)) widget.append_column(new_text_column( 'To [°2θ]', text_col=store.c_y, editable=True, data_func = (data_func, (store.c_y,)), edited_callback=(self.on_xy_data_cell_edited, (self.model.exclusion_ranges, 1)), resizable=True, expand=True))
def update_exp_treeview(self, tv): """ Updates the experimental pattern TreeView layout """ model = self.get_experimental_pattern_tree_model() for column in tv.get_columns(): tv.remove_column(column) def get_num(column, cell, model, itr, col_id): cell.set_property('text', '%.3f' % model.get_value(itr, col_id)) n_columns = model.get_n_columns() if n_columns > 2: for i in range(n_columns): tv.append_column( new_text_column( self.model.calculated_pattern.get_y_name(i), editable=True, edited_callback=(self.on_xy_data_cell_edited, (self.model.experimental_pattern, i)), data_func=(get_num, (i, )))) else: # X Column: tv.append_column( new_text_column( '°2θ', editable=True, data_func=(get_num, (model.c_x, )), edited_callback=(self.on_xy_data_cell_edited, (self.model.experimental_pattern, 0)))) # Y Column: tv.append_column( new_text_column( 'Intensity', editable=True, data_func=(get_num, (model.c_y, )), edited_callback=(self.on_xy_data_cell_edited, (self.model.experimental_pattern, 1))))
def setup_treeview(self, tv): """ Sets up the treeview with columns based on the columns-tuple passed to the __init__ or set in the class definition. Subclasses can override either this method completely or provide custom column creation code on a per-column basis. To do this, create a method for e.g. column with colnr = 2: def setup_treeview_col_2(self, treeview, name, col_descr, col_index, tv_col_nr): ... If a string description of the column number was given, e.g. for the column c_name the definition should be: def setup_treeview_col_c_name(self, treeview, name, col_descr, col_index, tv_col_nr): ... The method should return True upon success or False otherwise. """ sel_mode = gtk.SELECTION_MULTIPLE if self.multi_selection else gtk.SELECTION_SINGLE # @UndefinedVariable setup_treeview(tv, self.treemodel, sel_mode=sel_mode, on_selection_changed=self.objects_tv_selection_changed) tv.set_model(self.treemodel) # reset: for col in tv.get_columns(): tv.remove_column(col) # add columns for tv_col_nr, (name, col_descr) in enumerate(self.columns): try: col_index = int(col_descr) except: col_index = getattr(self.treemodel, str(col_descr), col_descr) handled = False if hasattr(self, "setup_treeview_col_%s" % str(col_descr)): handler = getattr(self, "setup_treeview_col_%s" % str(col_descr)) if isinstance(handler, collections.Callable): handled = handler(tv, name, col_descr, col_index, tv_col_nr) # custom handler failed or not present, default text column: if not handled: tv.append_column( new_text_column(name, text_col=col_index, resizable=(tv_col_nr == 0), expand=(tv_col_nr == 0), xalign=0.0 if tv_col_nr == 0 else 0.5)) return True
def setup_treeview(self, widget): super(ProjectController, self).setup_treeview(widget) store = self.treemodel widget.connect('button-press-event', self.specimen_tv_button_press) # First reset & then (re)create the columns of the treeview: for col in widget.get_columns(): widget.remove_column(col) # Name column: col = new_text_column('Name', text_col=store.c_name, min_width=125, xalign=0.0, ellipsize=Pango.EllipsizeMode.END) setattr(col, "colnr", store.c_name) widget.append_column(col) # Check boxes: def toggle_renderer(column, cell, model, itr, data=None): active = False if model.iter_is_valid(itr): col = column.get_col_attr("active") active = model.get_value(itr, col) cell.set_property('active', active) return def setup_check_column(title, colnr): col = new_toggle_column(title, toggled_callback=(self.specimen_tv_toggled, (store, colnr)), data_func=toggle_renderer, resizable=False, expand=False, activatable=True, active_col=colnr) setattr(col, "colnr", colnr) widget.append_column(col) setup_check_column('Exp', store.c_display_experimental) if self.model.layout_mode == "FULL": setup_check_column('Cal', store.c_display_calculated) setup_check_column('Sep', store.c_display_phases) # Up and down arrows: def setup_image_button(image, colnr): col = new_pb_column("", resizable=False, expand=False, stock_id=image) setattr(col, "colnr", colnr) widget.append_column(col) setup_image_button("213-up-arrow", 501) setup_image_button("212-down-arrow", 502)
def setup_wavelength_distribution_tree_view(self, store, widget): """ Creates the wavelength distribution TreeView layout and behavior """ setup_treeview(widget, store, on_cursor_changed=self.on_wld_tv_cursor_changed, sel_mode=gtk.SELECTION_MULTIPLE) # X Column: widget.append_column( new_text_column( 'Wavelength (nm)', text_col=store.c_x, editable=True, edited_callback=(self.on_xy_data_cell_edited, (self.model.wavelength_distribution, 0)))) # Y Column: widget.append_column( new_text_column( 'Fraction', text_col=store.c_y, editable=True, edited_callback=(self.on_xy_data_cell_edited, (self.model.wavelength_distribution, 1))))
def setup_treeview(self, tv): """ Sets up the treeview with columns based on the columns-tuple passed to the __init__ or set in the class definition. Subclasses can override either this method completely or provide custom column creation code on a per-column basis. To do this, create a method for e.g. column with colnr = 2: def setup_treeview_col_2(self, treeview, name, col_descr, col_index, tv_col_nr): ... If a string description of the column number was given, e.g. for the column c_name the definition should be: def setup_treeview_col_c_name(self, treeview, name, col_descr, col_index, tv_col_nr): ... The method should return True upon success or False otherwise. """ sel_mode = gtk.SELECTION_MULTIPLE if self.multi_selection else gtk.SELECTION_SINGLE # @UndefinedVariable setup_treeview( tv, self.treemodel, sel_mode=sel_mode, on_selection_changed=self.objects_tv_selection_changed) tv.set_model(self.treemodel) # reset: for col in tv.get_columns(): tv.remove_column(col) # add columns for tv_col_nr, (name, col_descr) in enumerate(self.columns): try: col_index = int(col_descr) except: col_index = getattr(self.treemodel, str(col_descr), col_descr) handled = False if hasattr(self, "setup_treeview_col_%s" % str(col_descr)): handler = getattr(self, "setup_treeview_col_%s" % str(col_descr)) if callable(handler): handled = handler(tv, name, col_descr, col_index, tv_col_nr) # custom handler failed or not present, default text column: if not handled: tv.append_column(new_text_column( name, text_col=col_index, resizable=(tv_col_nr == 0), expand=(tv_col_nr == 0), xalign=0.0 if tv_col_nr == 0 else 0.5)) return True
def _reset_treeview(self, tv, model): setup_treeview(tv, model, sel_mode='MULTIPLE', reset=True) tv.set_model(model) # Atom column: self.combo_model = self.model.create_prop_store() self.combo_model2 = Gtk.ListStore(str) for row in self.combo_model: self.combo_model2.append(row[2:3]) def atom_renderer(column, cell, model, itr, *args): obj = model.get_value(itr, 0) if hasattr(obj, "name"): cell.set_property('text', obj.name) else: cell.set_property('text', '#NA#') tv.append_column( new_combo_column("Atoms", data_func=atom_renderer, changed_callback=self.on_atom_changed, edited_callback=self.on_atom_edited, xalign=0.0, expand=False, has_entry=False, model=self.combo_model2, text_column=0, editable=True)) # Content column: def on_float_edited(rend, path, new_text, col): itr = model.get_iter(path) try: model.set_value(itr, col, float(new_text)) except ValueError: logger.exception("Invalid value entered ('%s')!" % new_text) return True tv.append_column( new_text_column('Default contents', text_col=2, xalign=0.0, editable=True, data_func=create_float_data_func(), edited_callback=(on_float_edited, (2, ))))
def setup_treeview_col_c_display_color(self, treeview, name, col_descr, col_index, tv_col_nr): def set_background(column, cell_renderer, tree_model, iter, col_index): try: color = tree_model.get_value(iter, col_index) except TypeError: pass # invalid iter else: cell_renderer.set_property('background', color) cell_renderer.set_property('text', "") treeview.append_column(new_text_column( name, data_func=(set_background, (col_index,)), text_col=col_index, resizable=False, expand=False)) return True
def setup_treeview_col_c_display_color(self, treeview, name, col_descr, col_index, tv_col_nr): def set_background(column, cell_renderer, tree_model, iter, col_index): try: color = tree_model.get_value(iter, col_index) except TypeError: pass # invalid iter else: cell_renderer.set_property('background', color) cell_renderer.set_property('text', "") treeview.append_column( new_text_column(name, data_func=(set_background, (col_index, )), text_col=col_index, resizable=False, expand=False)) return True
def setup_refinables_tree_view(self, store, widget): """ Setup refinables TreeView layout """ widget.set_show_expanders(True) if sys.platform == "win32": def get_label(column, cell, model, itr, user_data=None): ref_prop = model.get_tree_node_object(itr) cell.set_property("text", ref_prop.get_text_title()) return widget.append_column(new_text_column('Name/Prop', xalign=0.0, data_func=get_label)) else: # Labels are parsed for mathtext markup into pb's: def get_pb(column, cell, model, itr, user_data=None): ref_prop = model.get_tree_node_object(itr) try: if not hasattr(ref_prop, "pb") or not ref_prop.pb: ref_prop.pb = create_pb_from_mathtext( ref_prop.title, align='left', weight='medium' ) cell.set_property("pixbuf", ref_prop.pb) except RuntimeError: logger.warning("An error occured when trying to convert a property title to a PixBuf") raise return widget.append_column(new_pb_column('Name/Prop', xalign=0.0, data_func=get_pb)) # Editable floats: def get_value(column, cell, model, itr, *args): col = column.get_col_attr('markup') try: value = model.get_value(itr, col) value = "%.5f" % value except TypeError: value = "" cell.set_property("markup", value) return def on_float_edited(rend, path, new_text, model, col): itr = model.get_iter(path) try: model.set_value(itr, col, float(new_text)) except ValueError: return False return True def_float_args = { "sensitive_col": store.c_refinable, "editable_col": store.c_refinable, "visible_col": store.c_refinable, "data_func": get_value } widget.append_column(new_text_column( "Value", markup_col=store.c_value, edited_callback=( on_float_edited, (store, store.c_value,) ), **def_float_args )) widget.append_column(new_text_column( "Min", markup_col=store.c_value_min, edited_callback=( on_float_edited, (store, store.c_value_min,) ), **def_float_args )) widget.append_column(new_text_column( "Max", markup_col=store.c_value_max, edited_callback=( on_float_edited, (store, store.c_value_max,) ), **def_float_args )) # The 'refine' checkbox: widget.append_column(new_toggle_column( "Refine", toggled_callback=(self.refine_toggled, (store,)), resizable=False, expand=False, active_col=store.c_refine, sensitive_col=store.c_refinable, activatable_col=store.c_refinable, visible_col=store.c_refinable ))
def setup_refinables_tree_view(self, store, widget): """ Setup refinables TreeView layout """ widget.set_show_expanders(True) if sys.platform == "win32": def get_label(column, cell, model, itr, user_data=None): ref_prop = model.get_tree_node_object(itr) cell.set_property("text", ref_prop.text_title) return widget.append_column(new_text_column('Name/Prop', xalign=0.0, data_func=get_label)) else: # Labels are parsed for mathtext markup into pb's: def get_pb(column, cell, model, itr, user_data=None): ref_prop = model.get_tree_node_object(itr) try: if not hasattr(ref_prop, "pb") or not ref_prop.pb: ref_prop.pb = create_pb_from_mathtext( ref_prop.title, align='left', weight='medium' ) cell.set_property("pixbuf", ref_prop.pb) except RuntimeError: logger.warning("An error occured when trying to convert a property title to a PixBuf") raise return widget.append_column(new_pb_column('Name/Prop', xalign=0.0, data_func=get_pb)) # Editable floats: def get_value(column, cell, model, itr, *args): col = column.get_col_attr('markup') try: value = model.get_value(itr, col) value = "%.5f" % value except TypeError: value = "" cell.set_property("markup", value) return def on_float_edited(rend, path, new_text, model, col): itr = model.get_iter(path) try: model.set_value(itr, col, float(new_text)) except ValueError: return False return True def_float_args = { "sensitive_col": store.c_refinable, "editable_col": store.c_refinable, "visible_col": store.c_refinable, "data_func": get_value } widget.append_column(new_text_column( "Value", markup_col=store.c_value, edited_callback=( on_float_edited, (store, store.c_value,) ), **def_float_args )) widget.append_column(new_text_column( "Min", markup_col=store.c_value_min, edited_callback=( on_float_edited, (store, store.c_value_min,) ), **def_float_args )) widget.append_column(new_text_column( "Max", markup_col=store.c_value_max, edited_callback=( on_float_edited, (store, store.c_value_max,) ), **def_float_args )) # The 'refine' checkbox: widget.append_column(new_toggle_column( "Refine", toggled_callback=(self.refine_toggled, (store,)), resizable=False, expand=False, active_col=store.c_refine, sensitive_col=store.c_refinable, activatable_col=store.c_refinable, visible_col=store.c_refinable ))
def register_view(self, view): super(MatchMineralController, self).register_view(view) if view is not None: # MATCHES Treeview: tv = self.view['tv_matches'] setup_treeview( tv, None, reset=True, on_selection_changed=self.selection_changed, ) tv.append_column(new_text_column( "Name", markup_col=0, xalign=0, )) tv.append_column( new_text_column( "Abbr.", markup_col=1, expand=False, )) def get_value(column, cell, model, itr, *args): value = model.get_value(itr, column.get_col_attr('markup')) try: value = "%.5f" % value except TypeError: value = "" cell.set_property("markup", value) return tv.append_column( new_text_column("Score", markup_col=4, expand=False, data_func=get_value)) # ALL MINERALS Treeview: tv = self.view['tv_minerals'] setup_treeview( tv, None, reset=True, on_selection_changed=self.selection_changed, ) tv.append_column(new_text_column( "Name", markup_col=0, xalign=0, )) tv.append_column( new_text_column( "Abbr.", markup_col=1, expand=False, ))