?? btdownloadgui.py
字號:
self.cancelbutton = gtk.Button() self.cancelimage = gtk.Image() if self.completion is not None and self.completion >= 1: self.cancelimage.set_from_stock('bt-remove', gtk.ICON_SIZE_BUTTON) self.main.tooltips.set_tip(self.cancelbutton, 'Remove torrent') else: self.cancelimage.set_from_stock(gtk.STOCK_CANCEL, gtk.ICON_SIZE_BUTTON) self.main.tooltips.set_tip(self.cancelbutton, 'Abort torrent') self.cancelbutton.add(self.cancelimage) self.cancelbutton.connect('clicked', self.confirm_remove) self.buttonbox.pack_start(self.cancelbutton, expand=True, fill=False) self.buttonevbox.add(self.buttonbox) vbuttonbox = gtk.VBox(homogeneous=False) vbuttonbox.pack_start(self.buttonevbox, expand=False, fill=False) self.hbox.pack_end(vbuttonbox, expand=False, fill=False) self.infobox.pack_start(self.progressbarbox, expand=False, fill=False) self.hbox.pack_start(self.infobox, expand=True, fill=True) self.add( self.vbox ) self.drag_source_set(gtk.gdk.BUTTON1_MASK, [BT_TARGET], gtk.gdk.ACTION_MOVE) self.connect('drag_data_get', self.drag_data_get) self.connect('drag_begin' , self.drag_begin ) self.connect('drag_end' , self.drag_end ) self.cursor_handler_id = self.connect('enter_notify_event', self.change_cursors) def reset_progressbar_color(self): # Hack around broken GTK-Wimp theme: # make progress bar text always black # see task #694 if is_frozen_exe and self.main.config['progressbar_hack']: style = self.progressbar.get_style().copy() black = style.black self.progressbar.modify_fg(gtk.STATE_PRELIGHT, black) def change_cursors(self, *args): # BUG: this is in a handler that is disconnected because the # window attributes are None until after show_all() is called self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND2)) self.buttonevbox.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.LEFT_PTR)) self.disconnect(self.cursor_handler_id) def drag_data_get(self, widget, context, selection, targetType, eventTime): selection.set(selection.target, 8, self.infohash) def drag_begin(self, *args): pass def drag_end(self, *args): self.main.drag_end() def make_done_label(self, statistics=None): s = '' if statistics and statistics['timeEst'] is not None: s = ', will seed for %s' % Duration(statistics['timeEst']) elif statistics: s = ', will seed indefinitely.' if self.up_down_ratio is not None: done_label = 'Done, share ratio: %d%%' % \ (self.up_down_ratio*100) + s elif statistics is not None: done_label = 'Done, %s uploaded' % \ Size(statistics['upTotal']) + s else: done_label = 'Done' return done_label def set_name(self): max_title_width = 560 self.label.set_text(self.metainfo.name) if self.label.size_request()[0] > max_title_width: self.label.set_size_request(max_title_width, -1) def make_menu(self): filelistfunc = None if self.is_batch: filelistfunc = self.open_filelist menu_items = [("Torrent _info", self.open_info),] if OpenPath.can_open_files: func = None if self.can_open_dir(): func = self.open_dir menu_items += [('_Open directory', func), ] menu_items += [('----', None), ("_File list" , filelistfunc),] self.menu = build_menu(menu_items+self.menu_items) self.menu_handler = self.connect_object("event", self.show_menu, self.menu) def open_info(self, widget=None): if self.infowindow is None: self.infowindow = TorrentInfoWindow(self, self.infoclosed) def infoclosed(self, widget=None): self.infowindow = None def close_info(self): if self.infowindow is not None: self.infowindow.close() def open_filelist(self, widget): if not self.is_batch: return if self.filelistwindow is None: self.filelistwindow = FileListWindow(self.metainfo, self.filelistclosed) self.main.torrentqueue.check_completion(self.infohash, True) def filelistclosed(self, widget): self.filelistwindow = None def close_filelist(self): if self.filelistwindow is not None: self.filelistwindow.close() def close_child_windows(self): self.close_info() self.close_filelist() def destroy(self): if self.menu is not None: self.menu.destroy() self.menu = None gtk.EventBox.destroy(self) def show_menu(self, widget, event): if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3: widget.popup(None, None, None, event.button, event.time) return gtk.TRUE return gtk.FALSE def _short_path(self, dlpath): path_length = 40 sep = '...' ret = os.path.split(dlpath)[0] if len(ret) > path_length+len(sep): return ret[:int(path_length/2)]+sep+ret[-int(path_length/2):] else: return ret def get_path_to_open(self): path = self.dlpath if not self.is_batch: path = os.path.split(self.dlpath)[0] return path def can_open_dir(self): return os.access(self.get_path_to_open(), os.F_OK|os.R_OK) def open_dir(self, widget): OpenPath.opendir(self.get_path_to_open()) def confirm_remove(self, widget): message = 'Are you sure you want to remove "%s"?' % self.metainfo.name if self.completion >= 1: if self.up_down_ratio is not None: message = 'Your share ratio for this torrent is %d%%. '%(self.up_down_ratio*100) + message else: message = 'You have uploaded %s to this torrent. '%(Size(self.uptotal)) + message d = MessageDialog(self.main.mainwindow, 'Remove this torrent?', message, type=gtk.MESSAGE_QUESTION, buttons=gtk.BUTTONS_OK_CANCEL, yesfunc=self.remove, ) def remove(self): self.main.torrentqueue.remove_torrent(self.infohash)class KnownTorrentBox(TorrentBox): def __init__(self, infohash, metainfo, dlpath, completion, main): TorrentBox.__init__(self, infohash, metainfo, dlpath, completion, main) status_tip = '' if completion >= 1: self.icon.set_from_stock('bt-finished', gtk.ICON_SIZE_LARGE_TOOLBAR) status_tip = 'Finished' known_torrent_dnd_tip = 'drag into list to seed' else: self.icon.set_from_stock('bt-broken', gtk.ICON_SIZE_LARGE_TOOLBAR) status_tip = 'Failed' known_torrent_dnd_tip = 'drag into list to resume' self.main.tooltips.set_tip(self.iconevbox, torrent_tip_format % (status_tip, known_torrent_dnd_tip, torrent_menu_tip)) self.menu_items = [('----', None), #('Move to _start', self.move_to_start), ('Re_start' , self.move_to_end ), ('_Remove' , self.confirm_remove), ] self.make_menu() self.show_all() def move_to_end(self, widget): self.main.change_torrent_state(self.infohash, QUEUED) class DroppableTorrentBox(TorrentBox): def __init__(self, infohash, metainfo, dlpath, completion, main): TorrentBox.__init__(self, infohash, metainfo, dlpath, completion, main) self.drag_dest_set(gtk.DEST_DEFAULT_DROP, [BT_TARGET,], gtk.gdk.ACTION_MOVE) self.connect('drag_data_received', self.drag_data_received) self.connect('drag_motion', self.drag_motion) self.index = None def drag_data_received(self, widget, context, x, y, selection, targetType, time): half_height = self.size_request()[1] // 2 where = cmp(y, half_height) if where == 0: where = 1 self.parent.put_infohash_at_child(selection.data, self, where) def drag_motion(self, widget, context, x, y, time): self.get_current_index() half_height = self.size_request()[1] // 2 if y < half_height: self.parent.highlight_before_index(self.index) else: self.parent.highlight_after_index(self.index) return gtk.FALSE def drag_end(self, *args): self.parent.highlight_child() TorrentBox.drag_end(self, *args) def get_current_index(self): self.index = self.parent.get_index_from_child(self)class QueuedTorrentBox(DroppableTorrentBox): icon_name = 'bt-queued' state_name = 'Waiting' def __init__(self, infohash, metainfo, dlpath, completion, main): DroppableTorrentBox.__init__(self, infohash, metainfo, dlpath, completion, main) self.main.tooltips.set_tip(self.iconevbox, torrent_tip_format % (self.state_name, main_torrent_dnd_tip, torrent_menu_tip)) self.icon.set_from_stock(self.icon_name, gtk.ICON_SIZE_LARGE_TOOLBAR) self.menu_items = [#('----', None), #("Change _location" , None), #("Start hash check", None), ("----" , None), ('Download _now', self.start), ] if self.completion is not None and self.completion >= 1: self.menu_items += [('_Finish', self.finish),] self.menu_items += [('_Remove', self.confirm_remove),] else: self.menu_items += [('_Abort', self.confirm_remove),] self.make_menu() self.show_all() def start(self, widget): self.main.runbox.put_infohash_last(self.infohash) def finish(self, widget): self.main.change_torrent_state(self.infohash, KNOWN)class PausedTorrentBox(DroppableTorrentBox): icon_name = 'bt-paused' state_name = 'Paused' def __init__(self, infohash, metainfo, dlpath, completion, main): DroppableTorrentBox.__init__(self, infohash, metainfo, dlpath, completion, main) self.main.tooltips.set_tip(self.iconevbox, torrent_tip_format % (self.state_name, main_torrent_dnd_tip, torrent_menu_tip)) self.icon.set_from_stock(self.icon_name, gtk.ICON_SIZE_LARGE_TOOLBAR) menu_items = [("Download _later", self.move_to_end ), ("_Abort" , self.confirm_remove), ] if self.completion >= 1: menu_items = [("_Finish", self.finish), ("_Remove", self.confirm_remove), ] self.menu_items = [("----", None), ] + menu_items self.make_menu() self.show_all() def move_to_end(self, widget): self.main.change_torrent_state(self.infohash, QUEUED) def finish(self, widget): self.main.change_torrent_state(self.infohash, KNOWN)class RunningTorrentBox(DroppableTorrentBox): def __init__(self, infohash, metainfo, dlpath, completion, main): DroppableTorrentBox.__init__(self, infohash, metainfo, dlpath, completion, main) self.main.tooltips.set_tip(self.iconevbox, torrent_tip_format % ('Running', main_torrent_dnd_tip,
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -