def update(self, node): self.treeview.get_model().clear() self.node = node if node is None or node.all_attrs_fixed(): self.set_property("visible", False) else: self.set_property("visible", True) for key in node.attrs.keys(): model = self.treeview.get_model() cell_model = gtk.ListStore(gobject.TYPE_STRING) iter = model.append() model.set_value(iter, 0, key) model.set_value(iter, 2, cell_model) if isinstance(node.attrs[key][0], tuple): if node.attrs[key][1] is None: if isinstance(node.attrs[key][0][0], tuple): model.set_value( iter, 1, "Select " + datatype.print_type(node.attrs[key][0][1]) + "...") else: model.set_value(iter, 1, "Select...") else: model.set_value(iter, 1, node.attrs[key][1]) if isinstance(node.attrs[key][0][0], tuple): opts = node.attrs[key][0][0] else: opts = node.attrs[key][0] for opt in opts: cell_iter = cell_model.append() cell_model.set_value(cell_iter, 0, opt) self.treeview.get_column(2).set_property("visible", True) elif node.attrs[key][0] is None: model.set_value(iter, 1, "No data") elif node.attrs[key][1] is None: model.set_value(iter, 1, datatype.print_type(node.attrs[key][0])) else: model.set_value(iter, 1, node.attrs[key][1]) self.treeview.queue_resize() return
def update(self, node): self.treeview.get_model().clear() self.node = node if node is None or node.all_attrs_fixed(): self.set_property("visible", False) else: self.set_property("visible", True) for key in node.attrs.keys(): model = self.treeview.get_model() cell_model = gtk.ListStore(gobject.TYPE_STRING) iter = model.append() model.set_value(iter, 0, key) model.set_value(iter, 2, cell_model) if isinstance(node.attrs[key][0], tuple): if node.attrs[key][1] is None: if isinstance(node.attrs[key][0][0], tuple): model.set_value(iter, 1, "Select " + datatype.print_type(node.attrs[key][0][1]) + "...") else: model.set_value(iter, 1, "Select...") else: model.set_value(iter, 1, node.attrs[key][1]) if isinstance(node.attrs[key][0][0], tuple): opts = node.attrs[key][0][0] else: opts = node.attrs[key][0] for opt in opts: cell_iter = cell_model.append() cell_model.set_value(cell_iter, 0, opt) self.treeview.get_column(2).set_property("visible", True) elif node.attrs[key][0] is None: model.set_value(iter, 1, "No data") elif node.attrs[key][1] is None: model.set_value(iter, 1, datatype.print_type(node.attrs[key][0])) else: model.set_value(iter, 1, node.attrs[key][1]) self.treeview.queue_resize() return
def set_data_entry(self): """ Create a text view for data entry in the data frame. """ self.set_data_empty() self.data = self.add_text_view() self.data.get_buffer().create_tag("tag") text_tag = self.data.get_buffer().get_tag_table().lookup("tag") self.data.set_cursor_visible(True) self.data.set_editable(True) self.buttons.show() if self.node.data is None: self.data.get_buffer().set_text(datatype.print_type(self.node.datatype)) text_tag.set_property("foreground", "blue") else: self.data.get_buffer().set_text(self.node.data) buffer_bounds = self.data.get_buffer().get_bounds() self.data.get_buffer().apply_tag(text_tag, buffer_bounds[0], buffer_bounds[1]) return
def set_data_entry(self): """ Create a text view for data entry in the data frame. """ self.set_data_empty() self.data = self.add_text_view() self.data.get_buffer().create_tag("tag") text_tag = self.data.get_buffer().get_tag_table().lookup("tag") self.data.set_cursor_visible(True) self.data.set_editable(True) self.buttons.show() if self.node.data is None: self.data.get_buffer().set_text( datatype.print_type(self.node.datatype)) text_tag.set_property("foreground", "blue") else: self.data.get_buffer().set_text(self.node.data) buffer_bounds = self.data.get_buffer().get_bounds() self.data.get_buffer().apply_tag(text_tag, buffer_bounds[0], buffer_bounds[1]) return
def set_data_combo(self): """ Create a combo box for node data selection in the node data frame. Add an entry if required. """ self.set_data_empty() if isinstance(self.node.datatype[0], tuple): self.data = gtk.combo_box_entry_new_text() else: self.data = gtk.combo_box_new_text() self.frame.add(self.data) self.data.show() self.data.connect("set-focus-child", self.combo_focus_child) self.set_child_packing(self.frame, False, False, 0, gtk.PACK_START) if isinstance(self.node.datatype[0], tuple): self.buttons.show() else: self.buttons.hide() if self.node.data is None: if isinstance(self.node.datatype[0], tuple): self.data.child.set_text( "Select " + datatype.print_type(self.node.datatype[1]) + "...") else: self.data.append_text("Select...") self.data.set_active(0) self.data.child.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("blue")) self.data.child.modify_text(gtk.STATE_PRELIGHT, gtk.gdk.color_parse("blue")) if isinstance(self.node.datatype[0], tuple): options = self.node.datatype[0] else: options = self.node.datatype for (i, opt) in enumerate(options): self.data.append_text(opt) if self.node.data == opt: self.data.set_active(i) if (isinstance(self.node.datatype[0], tuple) and self.node.data is not None and self.node.data not in self.node.datatype[0]): self.data.child.set_text(self.node.data) self.data.connect("changed", self.combo_changed) return
def set_data_combo(self): """ Create a combo box for node data selection in the node data frame. Add an entry if required. """ self.set_data_empty() if isinstance(self.node.datatype[0], tuple): self.data = gtk.combo_box_entry_new_text() else: self.data = gtk.combo_box_new_text() self.frame.add(self.data) self.data.show() self.data.connect("set-focus-child", self.combo_focus_child) self.set_child_packing(self.frame, False, False, 0, gtk.PACK_START) if isinstance(self.node.datatype[0], tuple): self.buttons.show() else: self.buttons.hide() if self.node.data is None: if isinstance(self.node.datatype[0], tuple): self.data.child.set_text("Select " + datatype.print_type(self.node.datatype[1]) + "...") else: self.data.append_text("Select...") self.data.set_active(0) self.data.child.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("blue")) self.data.child.modify_text(gtk.STATE_PRELIGHT, gtk.gdk.color_parse("blue")) if isinstance(self.node.datatype[0], tuple): options = self.node.datatype[0] else: options = self.node.datatype for (i, opt) in enumerate(options): self.data.append_text(opt) if self.node.data == opt: self.data.set_active(i) if (isinstance(self.node.datatype[0], tuple) and self.node.data is not None and self.node.data not in self.node.datatype[0]): self.data.child.set_text(self.node.data) self.data.connect("changed", self.combo_changed) return
def set_data_tensor(self): """ Create a table container packed with appropriate widgets for tensor data entry in the node data frame. """ self.set_data_empty() scrolledWindow = self.add_scrolled_window() dim1, dim2 = self.node.tensor_shape(self.geometry_dim_tree) self.data = gtk.Table(dim1, dim2) scrolledWindow.add_with_viewport(self.data) scrolledWindow.child.set_property("shadow-type", gtk.SHADOW_NONE) self.set_child_packing(self.frame, True, True, 0, gtk.PACK_START) self.show_all() self.buttons.show() is_symmetric = self.node.is_symmetric_tensor(self.geometry_dim_tree) for i in range(dim1): for j in range(dim2): iindex = dim1 - i - 1 jindex = dim2 - j - 1 entry = gtk.Entry() self.data.attach(entry, jindex, jindex + 1, iindex, iindex + 1) if not is_symmetric or i >= j: entry.show() entry.connect("focus-in-event", self.tensor_element_focus_in, jindex, iindex) if self.node.data is None: entry.set_text( datatype.print_type(self.node.datatype.datatype)) entry.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("blue")) else: entry.set_text( self.node.data.split(" ")[jindex + iindex * dim2]) self.interacted = [False for i in range(dim1 * dim2)] return
def set_data_tensor(self): """ Create a table container packed with appropriate widgets for tensor data entry in the node data frame. """ self.set_data_empty() scrolledWindow = self.add_scrolled_window() dim1, dim2 = self.node.tensor_shape(self.geometry_dim_tree) self.data = gtk.Table(dim1, dim2) scrolledWindow.add_with_viewport(self.data) scrolledWindow.child.set_property("shadow-type", gtk.SHADOW_NONE) self.set_child_packing(self.frame, True, True, 0, gtk.PACK_START) self.show_all() self.buttons.show() is_symmetric = self.node.is_symmetric_tensor(self.geometry_dim_tree) for i in range(dim1): for j in range(dim2): iindex = dim1 - i - 1 jindex = dim2 - j - 1 entry = gtk.Entry() self.data.attach(entry, jindex, jindex + 1, iindex, iindex + 1) if not is_symmetric or i >= j: entry.show() entry.connect("focus-in-event", self.tensor_element_focus_in, jindex, iindex) if self.node.data is None: entry.set_text(datatype.print_type(self.node.datatype.datatype)) entry.modify_text(gtk.STATE_NORMAL, gtk.gdk.color_parse("blue")) else: entry.set_text(self.node.data.split(" ")[jindex + iindex * dim2]) self.interacted = [False for i in range(dim1 * dim2)] return