def __init__(self, gui): Tab.__init__(self, gui, 'URLs') self._id = 'URLs' self._regexp = re.compile('(http://[^\s]+)', re.IGNORECASE) self._scrolled_win = gtk.GtkScrolledWindow() self._scrolled_win.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self._box.pack_start(self._scrolled_win) self._list = gtk.GtkList() self._list.set_selection_mode(gtk.SELECTION_BROWSE) self._scrolled_win.add_with_viewport(self._list) self._list.connect("select-child", self.selectCB) self._hbox = gtk.GtkHBox() self._open_button = gtk.GtkButton('open') self._hbox.pack_end(self._open_button, fill=gtk.FALSE, expand=gtk.FALSE) self._box.pack_end(self._hbox, fill=gtk.TRUE, expand=gtk.FALSE) self._box.show_all() self._addToNoteBook()
def make_lb(text, fn, box): lb = gtk.GtkList() lb.show() frame = gtk.GtkFrame(text) frame.add(lb) frame.show() box.pack_start(frame) lb.connect('selection-changed', fn) return lb
def __init__(self): gtk.GtkHBox.__init__(self, gtk.FALSE, 5) self.entry = gtk.GtkEntry() self.pack_start(self.entry) self.entry.show() self.button = gtk.GtkButton("...") self.button.connect("clicked", self.show_dialog) self.pack_start(self.button, expand=gtk.FALSE) self.button.show() self.dialog = gtk.GtkDialog() self.dialog.set_title(self.get_title()) def delete_event(win, event): win.hide() return gtk.TRUE self.dialog.connect("delete_event", delete_event) box = gtk.GtkVBox() box.set_border_width(5) self.dialog.vbox.pack_start(box) box.show() swin = gtk.GtkScrolledWindow() swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) box.pack_start(swin) swin.show() items = map(None, self.get_list()) list = gtk.GtkList() list.set_selection_mode(gtk.SELECTION_BROWSE) self.selected = self.get_default() self.entry.set_text(self.selected) items.sort() for s in items: item = gtk.GtkListItem(s) list.add(item) if s == self.selected: list.select_child(item) item.show() swin.add_with_viewport(list) list.show() b = gtk.GtkButton("OK") self.dialog.action_area.pack_start(b) b.set_flags(gtk.CAN_DEFAULT) b.grab_default() b.show() b.connect("clicked", self.selection_ok, list) b = gtk.GtkButton("Cancel") self.dialog.action_area.pack_start(b) b.set_flags(gtk.CAN_DEFAULT) b.show() b.connect("clicked", self.dialog.hide) self.dialog.set_usize(300, 225)
def __init__(self, master, jabberObj): gtk.GtkDialog.__init__(self) self.agents = jabberObj.requestAgents() self.done = None self.connect("delete_event", self.delete_event) self.master = master self.set_usize(200, 150) if self.master: self.set_transient_for(self.master) self.ok_button = gtk.GtkButton('Ok') self.ok_button.connect('clicked', self.okay) self.action_area.pack_start(self.ok_button, expand=gtk.FALSE) self.cancel_button = gtk.GtkButton('Cancel') self.cancel_button.connect('clicked', self.cancel) self.action_area.pack_start(self.cancel_button, expand=gtk.FALSE) self.scrolled_win = gtk.GtkScrolledWindow() self.scrolled_win.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self.vbox.pack_start(self.scrolled_win) self.list = gtk.GtkList() self.list.set_selection_mode(gtk.SELECTION_BROWSE) self.scrolled_win.add_with_viewport(self.list) for i in self.agents.keys(): if self.agents[i].has_key('transport'): list_item = gtk.GtkListItem(self.agents[i]['name']) list_item.set_data('jid', i) self.list.add(list_item) list_item.show() self.list.connect("select-child", self.selectCB) self.vbox.pack_start(self.scrolled_win) self.vbox.show_all() self.action_area.show_all() self.show() self.selected = None self.set_modal(gtk.TRUE)
def __init__(self): # Create a window to put all the widgets in # connect main_quit() to the "destroy" event of # the window to handle window manager close-window-events window = gtk.GtkWindow(gtk.WINDOW_TOPLEVEL) window.set_title("GtkList Example") window.connect("destroy", gtk.mainquit) # Inside the window we need a box to arrange the widgets # vertically vbox = gtk.GtkVBox(gtk.FALSE, 5) vbox.set_border_width(5) window.add(vbox) vbox.show() # This is the scrolled window to put the List widget inside scrolled_window = gtk.GtkScrolledWindow() scrolled_window.set_usize(250, 150) vbox.add(scrolled_window) scrolled_window.show() # Create the GtkList widget. # Connect the sigh_print_selection() signal handler # function to the "selection_changed" signal of the List # to print out the selected items each time the selection # has changed gtklist = gtk.GtkList() scrolled_window.add_with_viewport(gtklist) gtklist.show() gtklist.connect("selection_changed", self.sigh_print_selection) # We create a "Prison" to put a list item in ) frame = gtk.GtkFrame("Prison") frame.set_usize(200, 50) frame.set_border_width(5) frame.set_shadow_type(gtk.SHADOW_OUT) vbox.add(frame) frame.show() # Connect the sigh_button_event() signal handler to the List # which will handle the "arresting" of list items gtklist.connect("button_release_event", self.sigh_button_event, frame) # Create a separator separator = gtk.GtkHSeparator() vbox.add(separator) separator.show() # Finally create a button and connect its "clicked" signal # to the destruction of the window button = gtk.GtkButton("Close") vbox.add(button) button.show() button.connect_object("clicked", window.destroy, window) # Now we create 5 list items, each having its own # label and add them to the List using add() # Also we query the text string from the label and # associate it with the list_item_data_key for each list item for i in range(5): buffer = "ListItemContainer with Label #%d" % i label = gtk.GtkLabel(buffer) list_item = gtk.GtkListItem() list_item.add(label) label.show() gtklist.add(list_item) list_item.show() string = label.get() list_item.set_data(self.list_item_data_key, string) # Here, we are creating another 5 labels, this time # we use GtkListItem() for the creation # For adding of the list items we put them all into a # list, and then add them by a single call to # append_items(). dlist = [] for i in range(5, 10): buffer = "List Item with Label %d" % i list_item = gtk.GtkListItem(buffer) dlist.append(list_item) list_item.show() list_item.set_data(self.list_item_data_key, list_item.children()[0].get()) gtklist.append_items(dlist) # Finally we want to see the window, don't we? ) window.show()
def __init__(self, parent, tips): self.frame = gtk.GtkFrame('Raster Bands') self.tips = tips self.input_bands = get_list_of_bands_as_dict() self.output_bands = {} hbox1 = gtk.GtkHBox(spacing=spc) hbox1.set_border_width(spc) self.frame.add(hbox1) # source (input) srcvbox = gtk.GtkVBox(spacing=spc) label = gtk.GtkLabel('Input:') label.set_alignment(0, 0.5) srcvbox.pack_start(label, expand=gtk.FALSE) hbox1.pack_start(srcvbox) source_win = gtk.GtkScrolledWindow() source_win.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) source_win.set_usize(300, 200) srcvbox.pack_start(source_win) source_list = gtk.GtkList() source_list.set_selection_mode(gtk.SELECTION_MULTIPLE) source_win.add_with_viewport(source_list) source_list.append_items(self.input_bands.keys()) # signals sent up to top level so that defaults can # be updated. Defaults are updated whenever the output # bands are cleared, or the first one is specified. self.publish('output-bands-empty') self.publish('output-bands-notempty') def src_load(_button, *args): fname = GtkExtra.file_sel_box(title="Select GDAL Dataset") if fname is None: return ds = gdal.OpenShared(fname) if ds is None: gvutils.error('Not a valid gdal dataset!') return dict = {} for i in range(1, ds.RasterCount + 1): curband = fname + '.band[' + str(i) + ']' dict[gtk.GtkListItem(curband)] = (ds, i, curband) if srctoggle.get_active() == gtk.TRUE: slist = vrtutils.GetSimilarFiles(fname) for nname in slist: ds = gdal.OpenShared(nname) if ds is None: continue for i in range(1, ds.RasterCount + 1): curband = nname + '.band[' + str(i) + ']' dict[gtk.GtkListItem(curband)] = (ds, i, curband) self.add_input_bands(dict) def src_get_active_layers(_button, *args): size = None if len(self.input_bands) > 0: ckey = self.input_bands.keys()[0] size = (self.input_bands[ckey][0].RasterXSize, self.input_bands[ckey][0].RasterYSize) new_dict = get_list_of_bands_as_dict(size) self.add_input_bands(new_dict) def src_clear(_button, *args): self.clear_input_bands() self.source_list = source_list # source control buttons srcbbox = gtk.GtkHBox(spacing=spc) srcvbox.pack_start(srcbbox, expand=gtk.FALSE) load_btn = gtk.GtkButton("Load File") self.tips.set_tip(load_btn, 'Add bands from a file to the input list') srcbbox.pack_start(load_btn) load_btn.connect("clicked", src_load) act_btn = gtk.GtkButton("Views->List") self.tips.set_tip(act_btn, 'Add bands from views to the input list') srcbbox.pack_start(act_btn) act_btn.connect("clicked", src_get_active_layers) clear_btn = gtk.GtkButton("Clear") srcbbox.pack_start(clear_btn) clear_btn.connect("clicked", src_clear) srctoggle = gtk.GtkCheckButton("Include Similar") self.tips.set_tip( srctoggle, 'Include bands from same-size files ' + 'in the same directory when using Load File.') srcbbox.pack_start(srctoggle, expand=gtk.FALSE) srctoggle.set_active(gtk.TRUE) # destination btn_box = gtk.GtkVBox(spacing=10) btn_box.set_border_width(10) hbox1.pack_start(btn_box, expand=gtk.FALSE) btn_box.show() def dest_add(_button, *args): sel = source_list.get_selection() sel.reverse() # add in order of selection if len(self.output_bands.keys()) == 0: refreshflag = 1 else: refreshflag = 0 for i in sel: list_item = gtk.GtkListItem(self.input_bands[i][2]) self.dest_list.append_items([list_item]) list_item.show() self.dest_list.select_child(self.dest_list.children()[-1]) self.output_bands[list_item] = self.input_bands[i] if (refreshflag == 1) and (len(sel) > 0): self.notify('output-bands-notempty') def dest_del(_button, *args): selection = self.dest_list.get_selection() self.dest_list.remove_items(selection) for i in selection: del self.output_bands[i] i.destroy() rest = self.dest_list.children() if len(rest) > 0: self.dest_list.select_child(self.dest_list.children()[-1]) else: self.notify('output-bands-empty') def dest_raise(_button, *args): selection = self.dest_list.get_selection() if len(selection) != 1: return pos = self.dest_list.child_position(selection[0]) if pos < 1: return self.dest_list.remove_items(selection) self.dest_list.insert_items(selection, pos - 1) self.dest_list.select_item(pos - 1) def dest_lower(_button, *args): selection = self.dest_list.get_selection() if len(selection) != 1: return pos = self.dest_list.child_position(selection[0]) if pos > len(self.output_bands) - 2: return self.dest_list.remove_items(selection) self.dest_list.insert_items(selection, pos + 1) self.dest_list.select_item(pos + 1) add_btn = gtk.GtkButton("Add->") add_btn.connect("clicked", dest_add) # The label below just makes things align more nicely (adds space) btn_box.pack_start(gtk.GtkLabel(''), expand=gtk.FALSE) btn_box.pack_start(add_btn, expand=gtk.FALSE) destvbox = gtk.GtkVBox(spacing=spc) label = gtk.GtkLabel('Output:') label.set_alignment(0, 0.5) destvbox.pack_start(label, expand=gtk.FALSE) dest_win = gtk.GtkScrolledWindow() dest_win.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) dest_win.set_usize(300, 200) destvbox.pack_start(dest_win) hbox1.pack_start(destvbox) destbbox = gtk.GtkHBox(spacing=spc) destvbox.pack_start(destbbox, expand=gtk.FALSE) del_btn = gtk.GtkButton() del_btn.add( gtk.GtkPixmap(parent, os.path.join(gview.home_dir, 'pics', 'delete.xpm'))) del_btn.connect("clicked", dest_del) destbbox.pack_start(del_btn, expand=gtk.FALSE) r_btn = gtk.GtkButton() r_btn.add( gtk.GtkPixmap(parent, os.path.join(gview.home_dir, 'pics', 'raise.xpm'))) r_btn.connect("clicked", dest_raise) destbbox.pack_start(r_btn, expand=gtk.FALSE) l_btn = gtk.GtkButton() l_btn.add( gtk.GtkPixmap(parent, os.path.join(gview.home_dir, 'pics', 'lower.xpm'))) l_btn.connect("clicked", dest_lower) destbbox.pack_start(l_btn, expand=gtk.FALSE) self.dest_list = gtk.GtkList() self.dest_list.set_selection_mode(gtk.SELECTION_BROWSE) dest_win.add_with_viewport(self.dest_list) parent.shell.pack_start(self.frame)
def __init__(self, classification): """Initialize a GvClassificationDlg on a particular GvLayer""" gtk.GtkWindow.__init__(self) self.set_title('Layer Classification') self.set_usize(-1, 400) self.connect('delete-event', self.close) self.set_border_width(5) self.color_buttons = [] self.sym_menus = [] self.scale_spinners = [] self.view_mgr = None self.ranges = [] self.labels = [] self.reclassdlg = None self.updating = FALSE items = load_ramp_config_file() self.ramp = None if classification is None: self.classification = GvClassification() elif issubclass(classification.__class__, GvClassification): self.classification = classification else: raise TypeError, 'GvClassificationDlg now requires a \ GvClassification instance' if self.classification.count <= 0: self.ramp = items[0] self.classification.prepare_default() #d = self.classification.serialize() #main vertical box vbox = gtk.GtkVBox(spacing=3) save_box = gtk.GtkHButtonBox() btn_save = gtk.GtkButton('Save ...') btn_save.connect('clicked', self.save_cb) btn_load = gtk.GtkButton('Load ...') btn_load.connect('clicked', self.load_cb) save_box.pack_start(btn_load) save_box.pack_start(btn_save) try: import pgucombo self.property_list = pgucombo.pguCombo() except: self.property_list = gtk.GtkCombo() self.property_list.entry.connect('changed', self.property_select_cb) self.update_property_list() save_box.pack_start(self.property_list) vbox.pack_start(save_box, expand=gtk.FALSE) #classification frame class_frame = gtk.GtkFrame() frame_box = gtk.GtkVBox(spacing=3) title_box = gtk.GtkHBox() title_lbl = gtk.GtkLabel('Legend Title: ') self.title_txt = gtk.GtkEntry() self.title_txt.set_text(self.classification.get_title()) self.title_txt.connect('changed', self.title_changed_cb) title_box.pack_start(title_lbl, expand=gtk.FALSE) title_box.pack_start(self.title_txt) frame_box.pack_start(title_box, expand=gtk.FALSE) frame_box.set_border_width(5) #classification list class_box = gtk.GtkScrolledWindow() self.class_list = gtk.GtkList() self.class_list.connect('select-child', self.list_selected) class_box.add_with_viewport(self.class_list) frame_box.pack_start(class_box) self.reset_classification_list() class_frame.add(frame_box) vbox.pack_start(class_frame) ar_box = gtk.GtkHButtonBox() add_btn = gtk.GtkButton('Add class') add_btn.connect('clicked', self.add_class_cb) classify_btn = gtk.GtkButton('reclassify ...') classify_btn.connect('clicked', self.reclassify_cb) reset_btn = gtk.GtkButton('Revert') reset_btn.connect('clicked', self.reset_cb) ar_box.pack_start(add_btn) ar_box.pack_start(classify_btn) ar_box.pack_start(reset_btn) vbox.pack_start(ar_box, expand=gtk.FALSE) #Color Ramp choices ramp_table = gtk.GtkTable(rows=2, cols=2) ramp_table.show() ramp_lbl = gtk.GtkLabel('Color Ramps: ') ramp_lbl.show() ramp_table.attach(ramp_lbl, 0, 1, 0, 1) ramp_opt = gtk.GtkOptionMenu() ramp_opt.show() self.ramp_menu = gtk.GtkMenu() self.ramp_menu.show() ramp_item = gtk.GtkMenuItem() ramp_item.add(gtk.GtkHSeparator()) ramp_item.set_sensitive(gtk.FALSE) ramp_item.show_all self.ramp_menu.append(ramp_item) for n in items: ramp_item = gtk.GtkMenuItem() ramp_item.add(n) ramp_item.show_all() if issubclass(n.__class__, ColorRamp): ramp_item.connect('activate', self.ramp_cb, n) else: ramp_item.set_sensitive(gtk.FALSE) self.ramp_menu.append(ramp_item) ramp_opt.set_menu(self.ramp_menu) ramp_opt.show() ramp_opt.set_history(0) ramp_table.attach(ramp_opt, 1, 2, 0, 1) ramp_table.show_all() vbox.pack_start(ramp_table, expand=gtk.FALSE) #buttons button_box = gtk.GtkHButtonBox() #button_box.set_layout_default(gtk.BUTTONBOX_START) self.ok_button = gtk.GtkButton('OK') self.ok_button.connect('clicked', self.ok_cb) self.apply_button = gtk.GtkButton('Apply') self.apply_button.connect('clicked', self.apply_cb) self.cancel_button = gtk.GtkButton('Cancel') self.cancel_button.connect('clicked', self.cancel_cb) button_box.pack_start(self.ok_button, expand=gtk.FALSE) button_box.pack_start(self.apply_button, expand=gtk.FALSE) button_box.pack_start(self.cancel_button, expand=gtk.FALSE) vbox.pack_start(button_box, expand=gtk.FALSE) vbox.show_all() self.add(vbox) #make ok_button a default button ? why isn't it working ? self.ok_button.set_flags(gtk.CAN_DEFAULT) self.ok_button.grab_default() self.publish('classification-changed') self.update_property_list()