def __init__(self, gui, jid, title='a tab'): Tab.__init__(self, gui, title) self._id = str(jid.getStripped()) self._scroll = gtk.GtkScrolledWindow() self._txt = gtk.GtkText() self._txt.set_word_wrap(gtk.TRUE) self._scroll.add(self._txt) self._scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self._box.pack_start(self._scroll, fill=gtk.TRUE, expand=gtk.TRUE) self._hbox = gtk.GtkHBox() self._entry = gtk.GtkEntry() self._hbox.pack_start(self._entry, fill=gtk.TRUE, expand=gtk.TRUE) self._send_button = gtk.GtkButton('send') #self._send_button.connect('clicked', self._cb, self) #self._entry.connect('activate', self._cb, self ) self._hbox.pack_end(self._send_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() self._entry.grab_focus()
def __init__(self, imgui, *args, **kw): apply(gtk.GtkWindow.__init__, (self, ) + args, kw) self.imgui = imgui self.accounts = [] vbox = gtk.GtkVBox(gtk.FALSE, 5) vbox.set_border_width(5) self.add(vbox) titles = ['Username', 'Online', 'Auto-Login', 'Gateway'] clist = gtk.GtkCList(len(titles), titles) clist.signal_connect("select_row", self.rowSelected) clist.set_shadow_type(gtk.SHADOW_OUT) scrolled = gtk.GtkScrolledWindow(None, None) scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS) vbox.pack_start(scrolled, gtk.TRUE, gtk.TRUE, 0) scrolled.add(clist) hb = gtk.GtkHBox(gtk.FALSE, 0) vbox.pack_start(hb, gtk.FALSE, gtk.TRUE, 0) addB = gtk.GtkButton("Add") modifyB = gtk.GtkButton("Modify") loginB = gtk.GtkButton("Logon") deleteB = gtk.GtkButton("Delete") map(hb.add, [addB, modifyB, loginB, deleteB]) self.imgui.im.connect(self.event_attach, "attach") self.imgui.im.connect(self.event_detach, "detach") self.signal_connect('destroy', gtk.mainquit, None)
def scrollify(widget): #widget.set_word_wrap(gtk.TRUE) scrl = gtk.GtkScrolledWindow() scrl.add(widget) scrl.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS) # scrl.set_update_policy(gtk.POLICY_AUTOMATIC) return scrl
def __init__(self, gui, title): Tab.__init__(self, gui, title) self._roster_selected = None self._online_icon, self._online_mask = \ gtk.create_pixmap_from_xpm( gui.get_window(), None,"online.xpm" ) self._offline_icon, self._offline_mask = \ gtk.create_pixmap_from_xpm( gui.get_window(), None,"offline.xpm" ) self._pending_icon, self._pending_mask = \ gtk.create_pixmap_from_xpm( gui.get_window(), None,"pending.xpm" ) self._rows = [] self._scroll = gtk.GtkScrolledWindow() self._ctree = gtk.GtkCTree(1, 0) self._ctree.set_column_width(0, 200) self._ctree.set_line_style(gtk.CTREE_LINES_NONE) self._ctree.set_expander_style(gtk.CTREE_EXPANDER_CIRCULAR) self._ctree.connect("select_row", self.rosterSelectCB) self.paint_tree() self._scroll.add(self._ctree) self._scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.FALSE) self._box.pack_start(self._scroll, fill=gtk.TRUE, expand=gtk.TRUE) self._hbox = gtk.GtkHBox() self._box.pack_end(self._hbox, fill=gtk.TRUE, expand=gtk.FALSE) self._box.show_all() self._addToNoteBook()
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 init_customize_gui_panel(self): # Inherit all the usual stuff... General_POIToolDlg.init_customize_gui_panel(self) # Add new frame with pixel info, keeping track of # the frame and text object... self.frame_dict['pixel_info_frame'] = gtk.GtkFrame() self.show_list.append(self.frame_dict['pixel_info_frame']) pixel_vbox = gtk.GtkVBox() self.show_list.append(pixel_vbox) self.frame_dict['pixel_info_frame'].add(pixel_vbox) pixel_scroll = gtk.GtkScrolledWindow() self.show_list.append(pixel_scroll) pixel_vbox.pack_start(pixel_scroll,expand = gtk.TRUE) self.entry_dict['pixel_info_text'] = gtk.GtkText() self.show_list.append(self.entry_dict['pixel_info_text']) self.entry_dict['pixel_info_text'].set_line_wrap(gtk.FALSE) self.entry_dict['pixel_info_text'].set_word_wrap(gtk.FALSE) self.entry_dict['pixel_info_text'].set_editable(gtk.FALSE) pixel_scroll.add(self.entry_dict['pixel_info_text']) self.entry_dict['pixel_info_text'].insert_defaults('') self.main_panel.pack_start(self.frame_dict['pixel_info_frame'],gtk.TRUE,gtk.TRUE,0)
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, strings=[""]): """Initialize the combo box, default strings can be passed. """ GtkComboBox.__init__(self) self.items = strings self.current_item = 0 #widgets to go into the combo box self.list = gtk.GtkCList(cols=1) self.list.set_selection_mode(gtk.SELECTION_SINGLE) self.entry = gtk.GtkEntry() self.entry.set_editable(gtk.FALSE) #fix up the style of the entry #style = self.entry.get_style().copy() #fake a background color the same as the button widget #for i in range(5): # style.base[i] = self.button.get_style().bg[i] #self.entry.set_style( style ) self._scrolled_win = gtk.GtkScrolledWindow() self._scrolled_win.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self._scrolled_win.add(self.list) ################################# # # TODO: figure out how to resize this on the fly # ################################# self._scrolled_win.set_usize(150, 175) self._scrolled_win.show_all() #frame is the popdown window frame self.frame.add(self._scrolled_win) #button is the main area to the left of the dropdown arrow self.button.add(self.entry) #initialize the widgets self.set_popdown_strings(self.items) self.select_item(self.current_item) #connect up signals self.list.connect('select-row', self.list_row_selected) self.list.add_events(gtk.GDK.KEY_PRESS_MASK) self.list.connect('key-press-event', self.key_press_cb) self.arrow.connect('toggled', self.toggle_cb) #make sure they all get shown self.show_all()
def functions_help_window(*args): if gui["fhelp_window"] == 0: win = gtk.GtkWindow() gui["fhelp_window"] = win win.set_policy(gtk.TRUE, gtk.TRUE, gtk.FALSE) win.set_title("Available functions and constants") win.set_usize(500, 300) win.connect("delete_event", fhelp_window_close) win.set_border_width(4) window_pos_mode(win) vbox = gtk.GtkVBox(spacing=5) win.add(vbox) vbox.show() scrolled_window = gtk.GtkScrolledWindow() vbox.pack_start(scrolled_window, expand=gtk.TRUE) scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolled_window.show() clist = gtk.GtkCList(2) clist.set_row_height(18) clist.set_column_width(0, 180) clist.set_column_width(1, 520) clist.set_selection_mode(gtk.SELECTION_BROWSE) set_font(clist) scrolled_window.add(clist) clist.show() mlist = map(lambda i: "", range(2)) clist.freeze() for i in range(len(flist) / 2): mlist[0] = flist[i * 2] mlist[1] = flist[i * 2 + 1] clist.append(mlist) clist.thaw() button = gtk.GtkButton("Close") button.connect("clicked", fhelp_window_close) vbox.pack_start(button, expand=gtk.FALSE) button.set_flags(gtk.CAN_DEFAULT) button.grab_default() button.show() gui["fhelp_window"].show() else: gui["fhelp_window"].get_window()._raise()
def __init__(self, gui, title='DEBUG'): Tab.__init__(self, gui, title) self._id = "DEBUG" self._scroll = gtk.GtkScrolledWindow() self._txt = gtk.GtkText() self._txt.set_word_wrap(gtk.TRUE) self._scroll.add(self._txt) self._scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) self._box.pack_start(self._scroll, fill=gtk.TRUE, expand=gtk.TRUE) self._hbox = gtk.GtkHBox() self._box.show_all() self._addToNoteBook()
def create_default_frame(self): self.frames['Default'] = gtk.GtkFrame('') self.frames['Default'].set_shadow_type(gtk.SHADOW_NONE) vbox = gtk.GtkVBox() vbox.set_spacing(spc) self.frames['Default'].add(vbox) self.default_scrolled_text = gtk.GtkText() self.default_scrolled_text.set_line_wrap(gtk.FALSE) self.default_scrolled_text.set_word_wrap(gtk.FALSE) self.default_scrolled_text.set_editable(gtk.FALSE) self.default_scrolled_win = gtk.GtkScrolledWindow() self.default_scrolled_win.set_usize(200, 200) self.default_scrolled_win.add(self.default_scrolled_text) vbox.pack_start(self.default_scrolled_win, expand=gtk.TRUE) self.frames['Default'].show_all() self.pack_start(self.frames['Default'])
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, title): top = gtk.GtkDialog() top.set_title(title) # set up the text widget at the top: scrwin = gtk.GtkScrolledWindow() scrwin.set_border_width(10) scrwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS) text = self.__text = gtk.GtkText(vadj=scrwin.get_vadjustment()) text.freeze() scrwin.add(text) top.vbox.pack_start(scrwin) # set up the dismiss button: button = gtk.GtkButton("Dismiss") button.connect("clicked", lambda button, top=top: top.destroy()) bbox = gtk.GtkHButtonBox() bbox.set_layout(gtk.BUTTONBOX_END) bbox.pack_end(button) top.action_area.pack_end(bbox) # all done! top.set_default_size(500, 300) top.show_all()
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()
def __init__(self): itemnames = ["Foo", "Bar", "Baz", "Quux", "Maurice"] # a generic toplevel window window = gtk.GtkWindow(gtk.WINDOW_TOPLEVEL) window.connect("delete_event", gtk.mainquit) window.set_border_width(5) # A generic scrolled window scrolled_win = gtk.GtkScrolledWindow() scrolled_win.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolled_win.set_usize(150, 200) window.add(scrolled_win) scrolled_win.show() # Create the root tree tree = gtk.GtkTree() print "root tree is %s" % tree # connect all GtkTree:: signals tree.connect("select_child", self.cb_select_child, tree) tree.connect("unselect_child", self.cb_unselect_child, tree) tree.connect("selection_changed", self.cb_selection_changed) # Add it to the scrolled window scrolled_win.add_with_viewport(tree) # Set the selection mode tree.set_selection_mode(gtk.SELECTION_MULTIPLE) # Show it tree.show() for i in range(5): # Create a tree item item = gtk.GtkTreeItem(itemnames[i]) # Connect all GtkItem:: and GtkTreeItem:: signals item.connect("select", self.cb_itemsignal, "select") item.connect("deselect", self.cb_itemsignal, "deselect") item.connect("toggle", self.cb_itemsignal, "toggle") item.connect("expand", self.cb_itemsignal, "expand") item.connect("collapse", self.cb_itemsignal, "collapse") # Add it to the parent tree tree.append(item) # Show it - this can be done at any time item.show() # Create this item's subtree subtree = gtk.GtkTree() print "-> item %s->%s, subtree %s" % (itemnames[i], item, subtree) # This is still necessary if you want these signals to be called # for the subtree's children. Note that selection_change will be # signalled for the root tree regardless. subtree.connect("select_child", self.cb_select_child, subtree) subtree.connect("unselect_child", self.cb_unselect_child, subtree) # This has absolutely no effect, because it is completely ignored # in subtrees subtree.set_selection_mode(gtk.SELECTION_SINGLE) # Neither does this, but for a rather different reason - the # view_mode and view_line values of a tree are propagated to # subtrees when they are mapped. So, setting it later on would # actually have a (somewhat unpredictable) effect subtree.set_view_mode(gtk.TREE_VIEW_ITEM) # Set this item's subtree - note that you cannot do this until # AFTER the item has been added to its parent tree! item.set_subtree(subtree) for j in range(5): # Create a subtree item, in much the same way subitem = gtk.GtkTreeItem(itemnames[j]) # Connect all GtkItem:: and GtkTreeItem:: signals subitem.connect("select", self.cb_itemsignal, "select") subitem.connect("deselect", self.cb_itemsignal, "deselect") subitem.connect("toggle", self.cb_itemsignal, "toggle") subitem.connect("expand", self.cb_itemsignal, "expand") subitem.connect("collapse", self.cb_itemsignal, "collapse") print "-> -> item %s->%s\n" % (itemnames[j], subitem) # Add it to its parent tree subtree.append(subitem) # Show it subitem.show() # Show the window and loop endlessly window.show()
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): titles = ["Ingredients", "Amount"] self.flag = 0 window = gtk.GtkWindow(gtk.WINDOW_TOPLEVEL) window.set_usize(300, 150) window.set_title("GtkCList Example") window.connect("destroy", gtk.mainquit) vbox = gtk.GtkVBox(gtk.FALSE, 5) vbox.set_border_width(5) window.add(vbox) vbox.show() # Create a scrolled window to pack the CList widget into scrolled_window = gtk.GtkScrolledWindow() scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS) vbox.pack_start(scrolled_window, gtk.TRUE, gtk.TRUE, 0) scrolled_window.show() # Create the CList. For this example we use 2 columns clist = gtk.GtkCList(2, titles) # When a selection is made, we want to know about it. The callback # used is selection_made, and its code can be found further down clist.connect("select_row", self.selection_made) # It isn't necessary to shadow the border, but it looks nice :) clist.set_shadow_type(gtk.SHADOW_OUT) # What however is important, is that we set the column widths as # they will never be right otherwise. Note that the columns are # numbered from 0 and up (to 1 in this case). clist.set_column_width(0, 150) # Add the CList widget to the vertical box and show it. scrolled_window.add(clist) clist.show() # Create the buttons and add them to the window. See the button # tutorial for more examples and comments on this. hbox = gtk.GtkHBox(gtk.FALSE, 0) vbox.pack_start(hbox, gtk.FALSE, gtk.TRUE, 0) hbox.show() button_add = gtk.GtkButton("Add List") button_clear = gtk.GtkButton("Clear List") button_hide_show = gtk.GtkButton("Hide/Show titles") hbox.pack_start(button_add, gtk.TRUE, gtk.TRUE, 0) hbox.pack_start(button_clear, gtk.TRUE, gtk.TRUE, 0) hbox.pack_start(button_hide_show, gtk.TRUE, gtk.TRUE, 0) # Connect our callbacks to the three buttons button_add.connect_object("clicked", self.button_add_clicked, clist) button_clear.connect_object("clicked", self.button_clear_clicked, clist) button_hide_show.connect_object("clicked", self.button_hide_show_clicked, clist) button_add.show() button_clear.show() button_hide_show.show() # The interface is completely set up so we show the window and # enter the gtk_main loop. window.show()
def __init__(self, title=None, cwd=None, dialog_type=FILE_OPEN, filter=None, app=None, multiselect=0): gtk.GtkWindow.__init__(self) if dialog_type >= FILE_OPEN and dialog_type <= DIRECTORY_SELECT: self.dialog_type = dialog_type else: self.dialog_type = FILE_OPEN self.filter = None #current filter self.filters = {} #active filter objects self.filter_keys = [] #ordered list of the names of the filters self.file_selection = [] self.multiselect = multiselect self.set_border_width(5) self.set_policy(as=gtk.FALSE, ag=gtk.FALSE, autos=gtk.TRUE) self.drives = None if title == None: if dialog_type == FILE_OPEN: title = nls.get('filedlg-title-open-file', 'Open File ...') elif dialog_type == FILE_SAVE: title = nls.get('filedlg-title-save-file', 'Save File ...') elif dialog_type == DIRECTORY_SELECT: title = nls.get('filedlg-title-select-directory', 'Select Directory ...') self.set_title(title) #setup the current working directory if cwd is None or not os.path.exists(cwd): cwd = gview.get_preference('working-directory') if cwd is None: cwd = os.getcwd() self.cwd = cwd #widgets vbox = gtk.GtkVBox(spacing=5) if dialog_type == FILE_OPEN or dialog_type == DIRECTORY_SELECT: lbl = gtk.GtkLabel(nls.get('filedlg-label-open-from', 'Open From:')) elif dialog_type == FILE_SAVE: lbl = gtk.GtkLabel(nls.get('filedlg-label-save-in', 'Save In:')) self.opt_menu = gtk.GtkOptionMenu() self.opt_menu.set_menu(gtk.GtkMenu()) hbox = gtk.GtkHBox() hbox.pack_start(lbl, expand=gtk.FALSE) hbox.pack_start(self.opt_menu) vbox.pack_start(hbox, expand = gtk.FALSE) self.list_directory = gtk.GtkCList() scr_directories = gtk.GtkScrolledWindow() scr_directories.add(self.list_directory) self.list_directory.connect('button-press-event', self.directory_selected_cb) if dialog_type == DIRECTORY_SELECT: self.list_files = None vbox.pack_start(scr_directories) else: self.list_files = gtk.GtkCList() if self.multiselect: self.list_files.set_selection_mode( gtk.SELECTION_EXTENDED ) scr_files = gtk.GtkScrolledWindow() scr_files.add(self.list_files) self.list_files.connect('button-press-event', self.file_clicked_cb) self.list_files.connect('select-row', self.file_selected_cb ) self.list_files.connect('unselect-row', self.file_unselected_cb ) pane = gtk.GtkHPaned() scr_directories.set_usize(100, -1) scr_files.set_usize(100, -1) pane.add1(scr_directories) pane.add2(scr_files) pane.set_position(200) vbox.pack_start(pane) widget = None if dialog_type == FILE_SAVE: self.txt_filename = gtk.GtkEntry() widget = self.txt_filename elif dialog_type == FILE_OPEN: combo = gtk.GtkCombo() combo.set_value_in_list(gtk.FALSE, gtk.FALSE) combo.disable_activate() if app is not None: rfl = app.get_rfl() rfl.insert(0, '') combo.set_popdown_strings( rfl ) self.txt_filename = combo.entry widget = combo if widget is not None: table = gtk.GtkTable(rows=2, cols=2) lbl = gtk.GtkLabel(nls.get('filedlg-label-file-name', 'File Name:')) self.txt_filename.connect('focus-out-event', self.map_path_cb) self.txt_filename.connect('key-press-event', self.map_path_cb) table.attach(lbl, 0, 1, 0, 1) table.attach(widget, 1, 2, 0, 1) lbl = gtk.GtkLabel(nls.get('filedlg-label-filter-extension', 'Filter extension:')) self.cmb_filter = pguCombo() self.set_filter(filter) self.cmb_filter.entry.connect('changed', self.filter_cb) table.attach(lbl, 0, 1, 1, 2) table.attach(self.cmb_filter, 1, 2, 1, 2) vbox.pack_start(table, expand=gtk.FALSE) if dialog_type == FILE_SAVE: self.ok_button = gtk.GtkButton(nls.get('filedlg-button-ok', 'OK')) elif dialog_type == FILE_OPEN: self.ok_button = gtk.GtkButton(nls.get('filedlg-button-open', 'Open')) elif dialog_type == DIRECTORY_SELECT: self.ok_button = gtk.GtkButton(nls.get('filedlg-button-ok', 'OK')) self.cancel_button = gtk.GtkButton(nls.get('filedlg-button-cancel', 'Cancel')) self.ok_button.connect('clicked', self.remove_grab) self.ok_button.connect('clicked', self.update_cwd) self.cancel_button.connect('clicked', self.remove_grab) btn_box = gtk.GtkHButtonBox() btn_box.pack_start(self.ok_button) btn_box.pack_start(self.cancel_button) vbox.pack_start(btn_box, expand=gtk.FALSE) self.add(vbox) self.show_all() #make modal gtk.grab_add(self) self.ok_button.set_flags(gtk.CAN_DEFAULT) self.ok_button.grab_default() self.set_usize(400, 400) self.menu_update = gtk.FALSE while gtk.events_pending(): gtk.mainiteration(FALSE) self.refresh_directory() self.connect('delete-event', self.quit) self.ok_button.connect('clicked', self.quit) self.cancel_button.connect('clicked', self.quit) self.publish('quit') self.add_events(gtk.GDK.KEY_PRESS_MASK) self.connect('key-press-event', self.key_press_cb) self.result = 'cancel'
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_dialog(self): self.dialog = gtk.GtkWindow() self.dialog.set_title('Available Image Formats') self.dialog.set_usize(300, 500) self.dialog.set_border_width(10) self.dialog.set_policy(gtk.FALSE, gtk.TRUE, gtk.TRUE) self.tooltips = gtk.GtkTooltips() self.button_dict = {} # main shell mainshell = gtk.GtkVBox(spacing=1, homogeneous=gtk.FALSE) self.dialog.add(mainshell) self.show_list = [] self.show_list.append(mainshell) #frame1=gtk.GtkFrame('Supported') #self.show_list.append(frame1) #mainshell.pack_start(frame1,expand=gtk.FALSE) #num_s=len(self.supported_list) #if num_s > 0: # s_table = gtk.GtkTable(num_s,3) # row=0 # for fmt_list in self.supported_list: # clabel=gtk.GtkEntry() # clabel.set_editable(gtk.FALSE) # clabel.set_text(fmt_list[0]) # self.show_list.append(clabel) # self._make_tooltip(clabel,fmt_list) # s_table.attach(clabel,0,1,row,row+1) # if fmt_list[4] is not None: # self.button_dict[fmt_list[1]]=gtk.GtkButton('Help') # self.button_dict[fmt_list[1]].connect('clicked',self.help_clicked_cb,fmt_list[4]) # s_table.attach(self.button_dict[fmt_list[1]],1,2,row,row+1) # row=row+1 # frame1.add(s_table) # self.show_list.append(s_table) num_us = len(self.unsupported_list) frame2 = gtk.GtkFrame() pixel_scroll = gtk.GtkScrolledWindow() self.show_list.append(pixel_scroll) self.show_list.append(frame2) mainshell.pack_start(frame2) frame2.add(pixel_scroll) num_us = len(self.unsupported_list) if num_us > 0: us_table = gtk.GtkTable(num_us, 3) row = 0 for fmt_list in self.unsupported_list: clabel = gtk.GtkEntry() clabel.set_editable(gtk.FALSE) clabel.set_text(fmt_list[0]) self.show_list.append(clabel) self._make_tooltip(clabel, fmt_list) us_table.attach(clabel, 0, 1, row, row + 1) if fmt_list[4] is not None: self.button_dict[fmt_list[1]] = gtk.GtkButton('Help') self.button_dict[fmt_list[1]].connect( 'clicked', self.help_clicked_cb, fmt_list[4]) us_table.attach(self.button_dict[fmt_list[1]], 1, 2, row, row + 1) row = row + 1 pixel_scroll.add_with_viewport(us_table) self.show_list.append(us_table) self.button_dict['close'] = gtk.GtkButton('Close') self.button_dict['close'].connect('clicked', self.close) mainshell.pack_start(self.button_dict['close'], expand=gtk.FALSE) self.show_list.append(self.button_dict['close']) self.dialog.connect('delete-event', self.close) for item in self.show_list: item.show()
def init_customize_gui_panel(self): # Inherit all the usual stuff... General_ROIToolDlg.init_customize_gui_panel(self) # Add new frame with pixel info, keeping track of # the frame and text object... self.frame_dict['region_info_frame'] = gtk.GtkFrame() self.show_list.append(self.frame_dict['region_info_frame']) pixel_vbox = gtk.GtkVBox() self.show_list.append(pixel_vbox) self.frame_dict['region_info_frame'].add(pixel_vbox) pixel_scroll = gtk.GtkScrolledWindow() self.show_list.append(pixel_scroll) pixel_vbox.pack_start(pixel_scroll,expand = gtk.TRUE) self.entry_dict['region_info_text'] = gtk.GtkText() self.show_list.append(self.entry_dict['region_info_text']) self.entry_dict['region_info_text'].set_line_wrap(gtk.FALSE) self.entry_dict['region_info_text'].set_word_wrap(gtk.FALSE) self.entry_dict['region_info_text'].set_editable(gtk.FALSE) pixel_scroll.add(self.entry_dict['region_info_text']) self.entry_dict['region_info_text'].insert_defaults('') # Add a frame with the log file options self.frame_dict['log_frame']=gtk.GtkFrame() self.show_list.append(self.frame_dict['log_frame']) log_table = gtk.GtkTable(2,4,gtk.FALSE) self.show_list.append(log_table) self.frame_dict['log_frame'].add(log_table) log_table.set_border_width(5) log_table.set_col_spacings(5) log_table.set_col_spacing(1, 20) self.button_dict['Log To File'] = gtk.GtkCheckButton('Log To File') self.show_list.append(self.button_dict['Log To File']) log_table.attach(self.button_dict['Log To File'], 0,1, 0, 1) self.button_dict['Select Log'] = gtk.GtkButton('Select Log') self.show_list.append(self.button_dict['Select Log']) log_table.attach(self.button_dict['Select Log'], 3,4, 0, 1) log_label = gtk.GtkLabel('Log File (full path): ') log_label.set_alignment(0, 0.5) log_table.attach(log_label, 0,1, 1, 2) self.entry_dict['log_file'] = gtk.GtkEntry() self.entry_dict['log_file'].set_editable(gtk.TRUE) self.entry_dict['log_file'].set_usize(400,25) self.entry_dict['log_file'].set_text('') log_table.attach(self.entry_dict['log_file'], 1,4, 1,2) self.main_panel.pack_start(self.frame_dict['region_info_frame'],gtk.TRUE,gtk.TRUE,0) self.main_panel.pack_start(self.frame_dict['log_frame'],gtk.FALSE,gtk.FALSE,0) # Customized connections self.button_dict['Select Log'].connect('clicked',self.select_log_cb) # Set default sensitivities for customized tool self.button_dict['Log To File'].set_active(gtk.FALSE) self.button_dict['Log To File'].set_sensitive(gtk.TRUE) self.button_dict['Select Log'].set_sensitive(gtk.TRUE)