コード例 #1
0
 def filter_cb(self, widget, *args):
     """called when the filter changes"""
     import string
     filter = string.strip(widget.get_text())
     if filter == '':
         self.filter = FilterSpec( nls.get("filedlg-default-filter", "All Files (*.*)|*.*"))
     else:
         self.filter = self.filters[filter]
     self.refresh_directory()
コード例 #2
0
    def set_filter(self, filter):
        """programmatically set the filename filter"""
        
        self.filters = {}
        self.filter_keys = []
        self.filter = None
        #build the filters
        if filter != None and len(filter) > 0:
            filterSpecs = filter.split( "|" )
            if len(filterSpecs) % 2 != 0:
                gdal.Debug( "OpenEV", "invalid filter spec: %s" % filter )
                pass
            else:
                for i in range(0, len(filterSpecs), 2):
                    spec = FilterSpec(filterSpecs[i] + "|" + filterSpecs[i+1])
                    self.filters[spec.name] = spec
                    self.filter_keys.append( spec.name )
        else:
            self.filters[nls.get("filedlg-default-filter", "All Files (*.*)|*.*")] = FilterSpec( nls.get("filedlg-default-filter", "All Files (*.*)|*.*") )

        self.cmb_filter.set_popdown_strings( self.filter_keys )
        self.filter = self.filters[self.cmb_filter.entry.get_text()]
コード例 #3
0
    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'