Logo Search packages:      
Sourcecode: catfish version File versions  Download package

def catfish::catfish::__init__ (   self )
Create the main window.

Definition at line 127 of file catfish.py.

                      :
        """Create the main window."""

        # Check for a desktop environment
        desktop = os.environ.get('DESKTOP_SESSION', os.environ.get('GDMSESSION', ''))
        if desktop[:4] == 'xfce':
            # We assume this is Xfce4
            default_fileman = 'Thunar'
            self.open_wrapper = 'exo-open'
        elif desktop[:5] == 'gnome':
            # We assume this is Gnome
            default_fileman = 'Nautilus'
            self.open_wrapper = 'gnome-open'
        else:
            # Unknown desktop? Just see what we have then
            # Guess suitable fileman
            commands = ['Nautilus', 'Thunar', 'konqueror']
            default_fileman = ''
            for path in os.environ.get('PATH', '/usr/bin').split(os.pathsep):
                for command in commands:
                    if os.path.exists(os.path.join(path, command)):
                        default_fileman = command
                        break
            commands = ['gnome-open', 'exo-open', 'xdg-open']
            self.open_wrapper = ''
            # Guess suitable file open wrapper
            for path in os.environ.get('PATH', '/usr/bin').split(os.pathsep):
                for command in commands:
                    if os.path.exists(os.path.join(path, command)):
                        self.open_wrapper = command
                        break

        # Parse command line options
        parser = optparse.OptionParser(usage='usage: ' + app_name + ' [options] keywords',
            version=app_name + ' v' + app_version)
        parser.add_option('', '--large-icons', action='store_true'
            , dest='icons_large', help='Use large icons')
        parser.add_option('', '--thumbnails', action='store_true'
            , dest='thumbnails', help='Use thumbnails')
        parser.add_option('', '--iso-time', action='store_true'
            , dest='time_iso', help='Display time in iso format')
        parser.add_option('', '--limit', type='int', metavar='LIMIT'
            , dest='limit_results', help='Limit number of results')
        parser.add_option('', '--path', help='Search in folder PATH')
        parser.add_option('', '--fileman', help='Use FILEMAN as filemanager')
        parser.add_option('', '--wrapper', metavar='WRAPPER'
            , dest='open_wrapper', help='Use WRAPPER to open files')
        parser.add_option('', '--method', help='Use METHOD to search')
        parser.add_option('', '--exact', action='store_true'
            , help='Perform exact match')
        parser.add_option('', '--hidden', action='store_true'
            , help='Include hidden files')
        parser.add_option('', '--fulltext', action='store_true'
            , help='Perform fulltext search')
        parser.add_option('', '--file-action', metavar='ACTION'
            , dest='file_action', help='File action: "open" or "folder"')
        parser.add_option('', '--debug', action='store_true'
            , help='Show debugging messages.')
        parser.set_defaults(icons_large=0, thumbnails=0, time_iso=0, method='find'
            , limit_results=0, path='~', fileman=default_fileman, exact=0
            , hidden=0, fulltext=0, file_action='open', debug=0, open_wrapper=self.open_wrapper)
        self.options, args = parser.parse_args()
        keywords = ' '.join(args)

        if not self.options.file_action in ('open', 'folder'):
            print 'Error: Invalid value for "file-action".\n'
            print 'Use either "open" to open files by default or'
            print 'use "folder" to open the containing folder.'
            print '(The default is "open".)'
            sys.exit(1)

        if not self.options.fileman:
            print 'Warning: No file manager was found or specified.'

        # Prepare i18n using gettext
        try:
            locale.setlocale(locale.LC_ALL, '')
            gettext.bindtextdomain(app_name, 'locale')
            gettext.textdomain(app_name)
            gtk.glade.bindtextdomain(app_name, 'locale')
            gtk.glade.textdomain(app_name)
        except Exception, msg:
            if self.options.debug: print 'Debug:', msg
            print 'Warning: Invalid locale, i18n is disabled.'

        # Guess location of glade file
        glade_file = app_name + '.glade'
        glade_path = os.getcwd()
        if not os.path.exists(os.path.join(glade_path, glade_file)):
            glade_path = os.path.dirname(sys.argv[0])
            if not os.path.exists(os.path.join(glade_path, glade_file)):
                print 'Error: The glade file could not be found.'
                sys.exit()

        # Load interface from glade file and retrieve widgets
        self.load_interface(os.path.join(glade_path, glade_file))

        # Fetch stock labels for the menu items manually
        # Note that this is needed to workaround a bug in glade
        for menu in self.menu_file.get_children():
            if menu.child:
                label = menu.child.get_label()
                if label[:4] == 'gtk-':
                    stock = gtk.stock_lookup(label)
                    menu.child.set_label(stock[1])

        # Add markup to labels
        for label in (self.label_find_type, self.label_find_method,
            self.label_find_folder):
            label.set_markup('<i>%s</i>' % label.get_text())

        # Set some initial values
        self.icon_cache = {}
        self.icon_theme = gtk.icon_theme_get_default()
        self.tooltips = gtk.Tooltips()
        self.checkbox_find_exact.set_active(self.options.exact)
        self.checkbox_find_hidden.set_active(self.options.hidden)
        self.checkbox_find_fulltext.set_active(self.options.fulltext)
        if self.options.limit_results:
            self.checkbox_find_limit.set_active(1)
            self.checkbox_find_limit.toggled()
            self.spin_find_limit.set_value(self.options.limit_results)
        self.folder_thumbnails = os.path.expanduser('~/.thumbnails/normal/')
      self.options.path = os.path.abspath(self.options.path)
        self.button_find_folder.set_filename(os.path.expanduser(self.options.path))
        try:
            self.link_color = self.treeview_files.style_get_property('link-color')
        except:
            self.link_color = None
        if self.link_color == None:
            self.link_color = 'blue'

        # Set up keywords completion
        completion = gtk.EntryCompletion()
        self.entry_find_text.set_completion(completion)
        listmodel = gtk.ListStore(str)
        completion.set_model(listmodel)
        completion.set_text_column(0)

        # Retrieve available search methods
        methods = ['find', 'locate', 'slocate', 'tracker', 'doodle', 'beagle']
        # DBus allows us to have two more methods
        if 'dbus' in globals():
            for method in ('strigi', 'pinot'):
                methods.append(method)
        bin_dirs = os.environ.get('PATH', '/usr/bin').split(os.pathsep)
        listmodel = gtk.ListStore(gtk.gdk.Pixbuf, str)
        method_default = -1
        icon = self.get_icon_pixbuf(gtk.STOCK_EXECUTE)
        for method_name in methods:
            method_binary = self.get_find_options(method_name)[0]
            for path in bin_dirs:
                if os.path.exists(os.path.join(path, method_binary)):
                    listmodel.append([icon, method_name])
                    if self.options.method == method_name:
                        method_default = len(listmodel) - 1
                    break
        if method_default < 0:
            print 'Warning:', ('Method "%s" is not available.' %
             self.options.method)
            method_default = 0
        self.combobox_find_method.set_sensitive(len(listmodel) > 1)

        # Prepare method combobox
        cell = gtk.CellRendererPixbuf()
        cell.set_property('xalign', 0)
        self.combobox_find_method.pack_start(cell, True)
        self.combobox_find_method.add_attribute(cell, 'pixbuf', 0)
        cell = gtk.CellRendererText()
        self.combobox_find_method.pack_start(cell, True)
        self.combobox_find_method.add_attribute(cell, 'text', 1)
        self.combobox_find_method.set_model(listmodel)
        self.combobox_find_method.set_active(method_default)

        # Prepare type toolbar
        if 'xdg' in globals():
            # This feature requires xdg
            for label, mime in ((_('Documents'), 'text'), (_('Images'), 'image'),
                (_('Music'), 'audio'), (_('Videos'), 'video')):
                self.toolbar_find_type.insert(self.new_toggle_button(label, mime), -1)
            self.toolbar_find_type.show_all()
        else:
            # If xdg is unavailable we hide the type toolbar
            self.label_find_type.hide()
            self.toolbar_find_type.hide()

        if self.options.icons_large or self.options.thumbnails:
            self.treeview_files.append_column(gtk.TreeViewColumn(_('Preview'),
                gtk.CellRendererPixbuf(), pixbuf=0))
            self.treeview_files.append_column(self.new_column(_('Filename'), 1, markup=1))
        else:
            self.treeview_files.append_column(self.new_column(_('Filename'), 1, 'icon', 1))
            self.treeview_files.append_column(self.new_column(_('Size'), 2, 'filesize'))
            self.treeview_files.append_column(self.new_column(_('Location'), 3, 'ellipsize'))
            self.treeview_files.append_column(self.new_column(_('Last modified'), 4, markup=1))

        self.entry_find_text.set_text(keywords)
        self.button_find.activate()

# -- helper functions --


Generated by  Doxygen 1.6.0   Back to index