⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 local_view.py

📁 CoralFTP是一款用Python语言编写的工作在GTK2环境下的FTP客户端软件
💻 PY
📖 第 1 页 / 共 3 页
字号:
#!/usr/bin/env python# -*- coding: utf-8 -*-# Copyright (C) 1994  Ling Li## This program is free software; you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation; either version 2 of the License, or# (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the# GNU Library General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.import os, os.path, string, sys, time, re, statimport gobject, gtk, gtk.gdk, gnomefrom gtk import *from gnome import vfsfrom coralftp_globals import *from configuration import config_valuefrom general_input import *from transfer_view import *from utils import *class LocalFileInfo:    __name = None    __stat = None    def __init__(self, filepath):        self.__name = os.path.basename(filepath)        self.__stat = os.stat(filepath)        return    def __getattr__(self, name):        if name == 'name':            return self.__name        elif name == 'size':            return self.__stat[stat.ST_SIZE]        elif name == 'mtime':            return self.__stat[stat.ST_MTIME]        elif name == 'stat':            return self.__stat        else:            raise AttributeError, name    def is_dir(self):        return stat.S_ISDIR(self.__stat[stat.ST_MODE])    def is_regular(self):        return stat.S_ISREG(self.__stat[stat.ST_MODE])    def is_link(self):        return stat.S_ISLNK(self.__stat[stat.ST_MODE])class LocalView:    COL_ICON = 0    COL_FILENAME = 1    COL_FILESIZE = 2    COL_FILETYPE = 3    COL_FILEMTIME = 4    COL_INFO = 5    # this is used to store how many rows are selected in file list view    __selected_count = 0        __selections = []    __change_selection_now = False    __change_sort_menu_item = True    __use_custom_file_listing_font = False    __file_listing_font = None    __text_renderers = []        def __init__(self, main_window):        ACTIONS = {            'updir' : { 'sensitive' : TRUE,                        'update' : self.on_updir_action_update,                        'execute' : self.on_updir_action_execute },            'transfer' : { 'sensitive' : FALSE,                           'update' : self.on_transfer_queue_action_update,                           'execute' : self.on_transfer_action_execute },            'queue' : { 'sensitive' : FALSE,                        'update' : self.on_transfer_queue_action_update,                        'execute' : self.on_queue_action_execute },            'transfer_as' : { 'sensitive' : FALSE,                              'update' : self.on_transfer_queue_as_action_update,                              'execute' : self.on_transfer_as_action_execute },            'queue_as' : { 'sensitive' : FALSE,                           'update' : self.on_transfer_queue_as_action_update,                           'execute' : self.on_queue_as_action_execute },            'delete' : { 'sensitive' : FALSE,                         'update' : self.on_delete_action_update,                         'execute' : self.on_delete_action_execute },            'rename' : { 'sensitive' : FALSE,                         'update' : self.on_rename_action_update,                         'execute' : self.on_rename_action_execute },            'mkdir' : { 'sensitive' : TRUE,                        'execute' : self.on_mkdir_action_execute },            'chdir' : { 'sensitive' : TRUE,                        'execute' : self.on_chdir_action_execute },            'refresh' : { 'sensitive' : TRUE,                          'execute' : self.on_refresh_action_execute },            'sort' : { 'sensitive' : TRUE,                       'execute' : self.on_sort_action_execute },            'open' : { 'sensitive' : TRUE,                       'update' : self.on_open_action_update,                       'execute' : self.on_open_action_execute },            'save_path' : { 'sensitive' : FALSE },            'property' : { 'sensitive' : FALSE },                                        }        WIDGET_ACTIONS = {            'btn_local_updir' : 'updir',            'tbtn_local_refresh' : 'refresh',            }        MENU_ACTIONS = {            'mi_local_transfer' : 'transfer',            'mi_local_queue' : 'queue',            'mi_local_transfer_as' : 'transfer_as',            'mi_local_queue_as' : 'queue_as',            'mi_local_open' : 'open',            'mi_local_delete' : 'delete',            'mi_local_rename' : 'rename',            'mi_local_properties' : 'property',            'mi_local_save_path' : 'save_path',            'mi_local_make_folder' : 'mkdir',            'mi_local_change_folder' : 'chdir',            'mi_local_refresh' : 'refresh',            'mi_local_arr_by_name' : 'sort',            'mi_local_arr_by_type' : 'sort',            'mi_local_arr_by_size' : 'sort',            'mi_local_arr_by_date' : 'sort',            'mi_local_arr_ascending' : 'sort',            'mi_local_arr_descending' : 'sort',            }                self.__main_window = main_window        self.__xml = main_window.xml        self.__widget = self.__xml.get_widget('local_view')        self.__config = self.__main_window.config        self.__current_path = os.getcwdu()        self.actions = ActionList(ACTIONS)        self.__menu_xml = get_glade_xml('local_file_list_menu')        self.__menu = self.__menu_xml.get_widget('local_file_list_menu')        # prepare interface        self.__widget.connect('show', lambda obj: self.refresh())        # file list        self.__model = ListStore(gtk.gdk.Pixbuf,                                 gobject.TYPE_STRING,                                 gobject.TYPE_STRING,                                 gobject.TYPE_STRING,                                 gobject.TYPE_STRING,                                 gobject.TYPE_PYOBJECT)        self.__model.set_sort_func(LocalView.COL_ICON, self.filelist_sort)        self.__model.set_sort_func(LocalView.COL_FILENAME,                                   self.filelist_sort)        self.__model.set_sort_func(LocalView.COL_FILESIZE,                                   self.filelist_sort)        self.__model.set_sort_func(LocalView.COL_FILETYPE,                                   self.filelist_sort)        self.__model.set_sort_func(LocalView.COL_FILEMTIME,                                   self.filelist_sort)        self.__list = self.__xml.get_widget('tv_local_file_list')        self.__list.set_model(self.__model)        self.__list.get_selection().set_mode(gtk.SELECTION_MULTIPLE)        self.__list.get_selection().set_select_function(self.__select_func)        column = TreeViewColumn(_("Name"))        renderer = CellRendererPixbuf()        column.pack_start(renderer, expand=FALSE)        column.add_attribute(renderer, 'pixbuf', LocalView.COL_ICON)        renderer = CellRendererText()        self.__text_renderers.append(renderer)        column.pack_start(renderer, expand=TRUE)        column.add_attribute(renderer, 'text', LocalView.COL_FILENAME)        column.set_sort_column_id(LocalView.COL_FILENAME)        column.set_resizable(TRUE)        self.__list.append_column(column)        renderer = CellRendererText()        self.__text_renderers.append(renderer)        renderer.set_property('xalign', 1)        column = TreeViewColumn(_("Size"), renderer,                                text=LocalView.COL_FILESIZE)        column.set_resizable(TRUE)        column.set_sort_column_id(LocalView.COL_FILESIZE)        self.__list.append_column(column)        renderer = CellRendererText()        self.__text_renderers.append(renderer)        column = TreeViewColumn(_("Type"), renderer,                                text=LocalView.COL_FILETYPE)        column.set_resizable(TRUE)        column.set_sort_column_id(LocalView.COL_FILETYPE)        self.__list.append_column(column)        renderer = CellRendererText()        self.__text_renderers.append(renderer)        column = TreeViewColumn(_("Modified"), renderer,                                text=LocalView.COL_FILEMTIME)        column.set_sort_column_id(LocalView.COL_FILEMTIME)        column.set_resizable(TRUE)        self.__list.append_column(column)        self.__cmb_dir = self.__xml.get_widget('cmb_local_dir')        self.__cmb_dir.set_model(ListStore(gobject.TYPE_STRING))        cell = gtk.CellRendererText()        self.__cmb_dir.pack_start(cell, TRUE)        self.__cmb_dir.add_attribute(cell, 'text', 0)        self.__cmb_dir.connect('changed', self.on_cmb_dir_changed)        self.__cmb_dir.child.connect('activate',                                     self.on_local_dir_entry_activate)        self.__status1 = self.__xml.get_widget('label_local_status1')        self.__status2 = self.__xml.get_widget('label_local_status2')        self.active_indicator = self.__xml.get_widget('eb_local')        # set sort column & order        self.__model.connect('sort-column-changed',                             self.on_list_sort_column_changed)        value = config_value(self.__config, 'display', 'local_sort_by')        if value == 0:            sort_column = LocalView.COL_FILENAME        elif value == 1:            sort_column = LocalView.COL_FILETYPE        elif value == 2:            sort_column = LocalView.COL_FILESIZE        elif value == 3:            sort_column = LocalView.COL_FILEMTIME        else:            raise ValueError        value = config_value(self.__config, 'display', 'local_order')        sort_order = value        self.__model.set_sort_column_id(sort_column, sort_order)        # setup fonts        self.__use_custom_file_listing_font = config_value(            self.__config, 'display', 'use_custom_file_listing_font')        self.__file_listing_font = config_value(            self.__config, 'display', 'file_listing_font')        self.__change_font()        self.__config.notify_add(            config_key('display', 'use_custom_file_listing_font'),            self.on_use_custom_file_listing_font_change)        self.__config.notify_add(            config_key('display', 'file_listing_font'),            self.on_file_listing_font_change)        # setup column resize        self.__config.notify_add(            config_key('display', 'auto_size_file_list_columns'),            self.on_auto_size_file_list_columns_change)        auto_size_file_list_columns = config_value(            self.__config, 'display', 'auto_size_file_list_columns')        for column in self.__list.get_columns():            if auto_size_file_list_columns:                column.set_sizing(TREE_VIEW_COLUMN_AUTOSIZE)            else:                column.set_sizing(TREE_VIEW_COLUMN_GROW_ONLY)        # rules hint        self.__list.set_property('rules-hint',                                 config_value(self.__config, 'display',                                              'rules_hint'))        self.__config.notify_add(            config_key('display', 'rules_hint'),            lambda config, id, entry, *args: \            self.__list.set_property('rules-hint', entry.value.get_bool()))        self.__frame4 = self.__xml.get_widget('frame_local_4')        self.__frame5 = self.__xml.get_widget('frame_local_5')        self.active_indicator = self.__xml.get_widget('eb_local')        self.__status1 = self.__xml.get_widget('label_local_status1')        self.__status2 = self.__xml.get_widget('label_local_status2')        # connect some signals with handler        self.__list.connect("button-press-event",                            self.on_list_button_press)        self.__list.connect("button-release-event",                            self.on_list_button_release)        # connect widgets with actions        for widget_name, action_name in WIDGET_ACTIONS.items():            widget = self.__xml.get_widget(widget_name)            self.actions[action_name].attach(widget)        # connect menu items with actions        for widget_name, action_name in MENU_ACTIONS.items():            widget = self.__menu_xml.get_widget(widget_name)            self.actions[action_name].attach(widget)        # set current path        default_download_path = config_value(            self.__config, 'general', 'default_download_path')        if default_download_path:            default_download_path = utf8_to_unicode(default_download_path)        if default_download_path:            default_download_path = os.path.expanduser(default_download_path)        if default_download_path and os.path.isdir(default_download_path):            self.set_path(default_download_path)        else:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -