我们从Python开源项目中,提取了以下16个代码示例,用于说明如何使用gtk.combo_box_new_text()。
def create_option_hbox(self, label, value, trace, sensitivity_group, constraints=None): hbox_main = gtk.HBox() label_options = gtk.Label(label.title()) label_options.set_alignment(0, 0.5) label_options.set_padding(8,8) combobox_options = gtk.combo_box_new_text() if constraints is None: options = [] else: options = constraints for option in options: combobox_options.append_text(option) selected_index = options.index(value) combobox_options.set_active(selected_index) hbox_main.pack_start(label_options) hbox_main.pack_start(combobox_options) self.plugin_config_widgets.append(combobox_options) self.plugin_config_traces.append(trace) sensitivity_group.append(label_options) sensitivity_group.append(combobox_options) return hbox_main
def make_choice(options, editable=True, default=None): if editable: sel = gtk.combo_box_entry_new_text() else: sel = gtk.combo_box_new_text() for opt in options: sel.append_text(opt) if default: try: idx = options.index(default) sel.set_active(idx) except: pass return sel
def make_choice(options, editable=True, default=None): if editable: sel = gtk.combo_box_entry_new_text() else: sel = gtk.combo_box_new_text() for o in options: sel.append_text(o) if default: try: idx = options.index(default) sel.set_active(idx) except: pass return sel
def create_time_hbox(self, label, value, trace, sensitivity_group, constraints=None): hbox_main = gtk.HBox() label_text = gtk.Label(label.title()) label_text.set_alignment(0, 0.5) label_text.set_padding(8,8) adjustment = gtk.Adjustment(value, 0, sys.maxint, 1) spinbutton_value = gtk.SpinButton(adjustment) combobox_units = gtk.combo_box_new_text() t_value, units = self.get_time_value_and_units(value) spinbutton_value.set_value(t_value) options = ["seconds", "minutes", "hours", "days", "weeks"] for option in options: combobox_units.append_text(option) selected_index = options.index(units) combobox_units.set_active(selected_index) hbox_main.pack_start(label_text) hbox_main.pack_start(spinbutton_value) hbox_main.pack_start(combobox_units) self.plugin_config_widgets.append([spinbutton_value, combobox_units]) self.plugin_config_traces.append(trace) sensitivity_group.append(label_text) sensitivity_group.append(spinbutton_value) return hbox_main #TODO: Refactor these
def create_task_combo(self): self.task_combo = gtk.combo_box_new_text() self.taskmenubox = self.builder.get_object("taskmenubox") self.taskmenubox.add(self.task_combo) self.task_combo.append_text("1 - Communication Dish") self.task_combo.append_text("2 - Solar Array") self.task_combo.append_text("3 - Air Leak") self.task_combo.set_active(0) self.task_combo.connect('changed', self.task_changed_cb)
def create_macro_combo(self): self.macro_combo = gtk.combo_box_new_text() self.macromenubox = self.builder.get_object("macrocombobox") self.macromenubox.add(self.macro_combo) self.macro_combo.append_text('--- Select a macro ---') self.macro_combo.set_active(0)
def create_checkpoint_combo(self): self.checkpoint_combo = gtk.combo_box_new_text() self.checkpointmenubox = self.builder.get_object("checkpointmenubox") self.checkpointmenubox.add(self.checkpoint_combo)
def create_arm_controls(self): self.arm_combo_box = self.builder.get_object("armcombobox") self.arm_side_combo = gtk.combo_box_new_text() self.arm_combo_box.add(self.arm_side_combo) self.arm_side_combo.append_text("left") self.arm_side_combo.append_text("right") self.arm_side_combo.set_active(0) self.arm_combo = gtk.combo_box_new_text() self.arm_combo_box.add(self.arm_combo) self.arm_combo.append_text('--- Select an arm configuration ---') for style in sorted(LimbTypes.arm_styles.iterkeys()): self.arm_combo.append_text(style) self.arm_combo.set_active(0) self.arm_combo.connect('changed', self.arm_style_changed_cb) self.arm_text_boxes = [] for arm_entry in self.limbtypes.arm_descriptions: arm_text_box = self.builder.get_object(arm_entry[0]) arm_text_box.set_text('0.0') arm_text_box.connect('changed', self.float_entry_changed) self.arm_text_boxes.append(arm_text_box) self.arm_configuration_button = self.builder.get_object("armconfigurationbutton") self.arm_configuration_button.connect('clicked', self.arm_configuration_cb) self.arm_configuration_load_button = self.builder.get_object("armconfigurationloadbutton") self.arm_configuration_load_button.connect('clicked', self.arm_configuration_load_cb)
def create_movepalm_controls(self): self.movepalm_combo_box = self.builder.get_object("movepalmcombobox") self.movepalm_side_combo = gtk.combo_box_new_text() self.movepalm_combo_box.add(self.movepalm_side_combo) self.movepalm_side_combo.append_text("left") self.movepalm_side_combo.append_text("right") self.movepalm_side_combo.set_active(0) self.relative_checkbox = self.builder.get_object("handrelativecheck") self.handx = self.builder.get_object("handx") self.handx.set_text('0.0') self.handx.connect('changed', self.float_entry_changed) self.handy = self.builder.get_object("handy") self.handy.set_text('0.0') self.handy.connect('changed', self.float_entry_changed) self.handz = self.builder.get_object("handz") self.handz.set_text('0.0') self.handz.connect('changed', self.float_entry_changed) self.palmyaw = self.builder.get_object("palmyaw") self.palmyaw.set_text('0.0') self.palmyaw.connect('changed', self.float_entry_changed) self.palmpitch = self.builder.get_object("palmpitch") self.palmpitch.set_text('0.0') self.palmpitch.connect('changed', self.float_entry_changed) self.palmroll = self.builder.get_object("palmroll") self.palmroll.set_text('0.0') self.palmroll.connect('changed', self.float_entry_changed) self.move_palm_button = self.builder.get_object("movepalmcenter") self.move_palm_button.connect('clicked', self.move_palm_cb) self.get_palm_button = self.builder.get_object("getpalmcenter") self.get_palm_button.connect('clicked', self.get_palm_cb)
def get_filename(self, w): def set_filename(w): self.filename = box.get_filename() self.parser = getattr(parsers, 'Parse' + parser_lst[button.get_active()]) box.destroy() Thread(target = self._announce_fileparser).start() parser_lst = [] #Get the names for key in parsers.__dict__: if key.find('Parse') == 0: pname = key[5:] if pname == 'Normal': #Pretty sleazy way of hardcoding default parser_lst.insert(0, pname) else: parser_lst.append(pname) box = gtk.FileSelection("Select file") box.ok_button.connect("clicked", set_filename) box.cancel_button.connect("clicked", lambda w: box.destroy()) box.set_resizable(False) button = gtk.combo_box_new_text() for text in parser_lst: button.append_text(text) button.set_active(0) parserbox = gtk.HBox(False) buttonlabel = gtk.Label('Select a Parser:') for obj in (buttonlabel, button): parserbox.pack_start(obj) box.action_area.pack_start(parserbox) box.show_all()
def createComboBox(parent, choices=["null"], active=0, gridX=0, gridY=0, sizeX=1, sizeY=1, xExpand=True, yExpand=True, handler=None): """Creates a combo box with text choices and adds it to a parent widget.""" temp = gtk.combo_box_new_text() for choice in choices: temp.append_text(choice) temp.set_active(active) if handler != None: temp.connect("changed", handler) parent.attach(temp, gridX, gridX+sizeX, gridY, gridY+sizeY, xoptions=gtk.EXPAND if xExpand else 0, yoptions=gtk.EXPAND if yExpand else 0) return temp
def add_query_widget(container, field_names, sel_qf='title', sel_comm='contains', text=''): hbox = gtk.HBox() cb = gtk.combo_box_new_text() select = 0 for i, field in enumerate(QUERY_FIELDS): if sel_qf == field: select = i cb.append_text(field_names[field]) cb.set_active(select) action_cb = gtk.combo_box_new_text() select = 0 for i, command in enumerate(QUERY_COMMANDS): if sel_comm == command: select = i action_cb.append_text(QUERY_COMMAND_NAMES[command]) action_cb.set_active(select) entry = gtk.Entry() entry.set_text(text) button = gtk.Button(stock=gtk.STOCK_DELETE) button.connect("clicked", lambda w: hbox.destroy()) hbox.pack_start(cb, expand=False) hbox.pack_start(action_cb, expand=False) hbox.pack_start(entry, expand=True, padding=8) hbox.pack_start(button, expand=False, fill=False) hbox.show_all() container.pack_start(hbox)
def __init__(self, parent, notebook): Dialog.__init__(self, parent, _('Pages By Number Of Links'), # T: dialog title buttons=gtk.BUTTONS_CLOSE ) self.notebook = notebook self.direction_input = gtk.combo_box_new_text() for dir in sorted(self.LABELS): self.direction_input.append_text(self.LABELS[dir]) self.uistate.setdefault('link_direction', LINK_DIR_BACKWARD, self.LABELS.keys()) gtk_combobox_set_active_text( self.direction_input, self.LABELS[self.uistate['link_direction']] ) self.direction_input.connect('changed', self.on_direction_input_changed) hbox = gtk.HBox() hbox.pack_start(gtk.Label(_('Trace Links')+':'), False) hbox.add(self.direction_input) self.vbox.pack_start(hbox, False) self.listview = SingleClickTreeView(gtk.ListStore(int, str)) self.listview.set_reorderable(True) for i, label in enumerate((_('#'), _('Page'))): column = gtk.TreeViewColumn(label, gtk.CellRendererText(), text=i) column.set_sort_column_id(i) self.listview.append_column(column) # TODO: self.listview.connect('row-activated', self.on_row_activated()) self.vbox.add(ScrolledWindow(self.listview)) self.populate_listview()
def __init__(self, parent, plugins): super(PluginConfigGUI, self).__init__() self.main_gui = parent #TODO: Add one for compression format self.value_type_create = { "text": self.create_text_hbox, "number": self.create_number_hbox, "checkbox": self.create_checkbox_hbox, "radio": self.create_radio_hbox, "option": self.create_option_hbox, "options": self.create_options_hbox, "time": self.create_time_hbox, "netiface": self.create_netiface_hbox, "netifaces": self.create_netifaces_hbox, "filepath": self.create_filepath_hbox, "path": self.create_path_hbox } self.set_title("Plugin Configurations") self.set_modal(True) self.set_transient_for(self.main_gui) self.set_position(gtk.WIN_POS_CENTER_ON_PARENT) #self.set_size_request(500, 700) self.set_border_width(6) self.set_resizable(False) self.plugins = plugins plugin_names = [plugin.name for plugin in self.plugins] vbox_main = gtk.VBox() hbox_plugins = gtk.HBox() frame_plugin_confs = gtk.Frame("Plugin Configurations:") self.vbox_plugin_main = None label_plugins = gtk.Label("Plugin") combobox_plugins = gtk.combo_box_new_text() for label in plugin_names: combobox_plugins.append_text(label) combobox_plugins.set_active(0) combobox_plugins.connect('changed', self.select_plugin, combobox_plugins, frame_plugin_confs) button_close = gtk.Button("Close") button_close.connect("clicked", self.close_plugin_config_dialog) hbox_plugins.pack_start(label_plugins) hbox_plugins.pack_start(combobox_plugins) vbox_main.pack_start(hbox_plugins) vbox_main.pack_start(frame_plugin_confs) vbox_main.pack_start(button_close) self.show_plugin_configs(combobox_plugins.get_active_text(), frame_plugin_confs) self.add(vbox_main) self.show_all()
def create_camera_controls(self): self.clickedx = self.builder.get_object("clickedx") self.clickedx.set_text('0.0') self.clickedy = self.builder.get_object("clickedy") self.clickedy.set_text('0.0') self.clickedz = self.builder.get_object("clickedz") self.clickedz.set_text('0.0') self.anchor_combo = gtk.combo_box_new_text() self.anchormenubox = self.builder.get_object("anchorcombobox") self.anchormenubox.add(self.anchor_combo) self.anchor_combo.connect('changed', self.anchor_changed_cb) self.anchor_combo.append_text('--- Select an anchor ---') for anchor in sorted(Anchor.list()): self.anchor_combo.append_text(anchor) self.anchor_combo.set_active(0) self.adjustedx = self.builder.get_object("adjustedx") self.adjustedx.set_text('0.0') self.adjustedy = self.builder.get_object("adjustedy") self.adjustedy.set_text('0.0') self.adjustedz = self.builder.get_object("adjustedz") self.adjustedz.set_text('0.0') self.adjustedangle = self.builder.get_object("adjustedangle") self.adjustedangle.set_text('0.0') self.request_image_button = self.builder.get_object("requestimagebutton") self.request_image_button.connect('clicked', self.request_image_cb) self.picture_interval = self.builder.get_object("pictureinterval") self.picture_interval.set_text('0.0') self.picture_interval.connect('changed', self.float_entry_changed) self.picture_interval_button = self.builder.get_object("pictureintervalbutton") self.picture_interval_button.connect('clicked', self.pictureinterval_cb) self.request_regular_image_button = self.builder.get_object("requestregularbutton") self.request_regular_image_button.connect('clicked', self.request_regular_image_cb) self.hazard_regular_image_button = self.builder.get_object("requesthazardbutton") self.hazard_regular_image_button.connect('clicked', self.request_hazard_image_cb) self.request_lidar_button = self.builder.get_object("requestlidarbutton") self.request_lidar_button.connect('clicked', self.request_lidar_cb)
def addParam(self, name, field, ptype, *args): x = self.tblGeneral.rows self.tblGeneral.rows += 1 value = eval(field) if ptype==bool: obj = gtk.CheckButton() obj.set_label(name) obj.set_active(value) obj.set_alignment(0, 0.5) obj.show() obj.field=field self.tblGeneral.attach(obj, 0, 2, x, x+1, gtk.EXPAND|gtk.FILL, 0) elif ptype==int: obj = gtk.SpinButton(climb_rate=10) if len(args)==2: obj.set_range(args[0], args[1]) obj.set_increments(1, 10) obj.set_numeric(True) obj.set_value(value) obj.show() obj.field=field lbl = gtk.Label(name) lbl.set_alignment(0, 0.5) lbl.show() self.tblGeneral.attach(lbl, 0, 1, x, x+1, gtk.FILL, 0) self.tblGeneral.attach(obj, 1, 2, x, x+1, gtk.EXPAND|gtk.FILL, 0) elif ptype==list: obj = gtk.combo_box_new_text() for s in args[0]: obj.append_text(s) obj.set_active(value) obj.show() obj.field=field lbl = gtk.Label(name) lbl.set_alignment(0, 0.5) lbl.show() self.tblGeneral.attach(lbl, 0, 1, x, x+1, gtk.FILL, 0) self.tblGeneral.attach(obj, 1, 2, x, x+1, gtk.EXPAND|gtk.FILL, 0) else: obj = gtk.Entry() obj.set_text(value) obj.show() obj.field=field lbl = gtk.Label(name) lbl.set_alignment(0, 0.5) lbl.show() self.tblGeneral.attach(lbl, 0, 1, x, x+1, gtk.FILL, 0) self.tblGeneral.attach(obj, 1, 2, x, x+1, gtk.EXPAND|gtk.FILL, 0)