📄 gui.py
字号:
if self.vscrolltimeout is not None: gobject.source_remove(self.vscrolltimeout) self.vscrolltimeout = gobject.timeout_add(100, self.scroll_and_wait, amount, False) #print "adding timeout", self.vscrolltimeout, amount def start_scrolling(self, amount): if self.vscrolltimeout is not None: gobject.source_remove(self.vscrolltimeout) self.scroll_and_wait(amount, True) def stop_scrolling(self): if self.vscrolltimeout is not None: #print "removing timeout", self.vscrolltimeout gobject.source_remove(self.vscrolltimeout) self.vscrolltimeout = Noneclass MessageDialog(gtk.MessageDialog): flags = gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT def __init__(self, parent, title, message, type=gtk.MESSAGE_ERROR, buttons=gtk.BUTTONS_OK, yesfunc=None, nofunc=None, default=None ): gtk.MessageDialog.__init__(self, parent, self.flags, type, buttons, message) self.set_size_request(-1, -1) self.set_resizable(gtk.FALSE) self.set_title(title) if default is not None: self.set_default_response(default) self.label.set_line_wrap(gtk.TRUE) self.connect('response', self.callback) self.yesfunc = yesfunc self.nofunc = nofunc self.show_all() def callback(self, widget, response_id, *args): if ((response_id == gtk.RESPONSE_OK or response_id == gtk.RESPONSE_YES) and self.yesfunc is not None): self.yesfunc() if ((response_id == gtk.RESPONSE_CANCEL or response_id == gtk.RESPONSE_NO ) and self.nofunc is not None): self.nofunc() self.destroy()class ErrorMessageDialog(MessageDialog): flags = gtk.DIALOG_DESTROY_WITH_PARENTclass FileSelection(gtk.FileSelection): def __init__(self, main, title='', fullname='', got_location_func=None, no_location_func=None, got_multiple_location_func=None, show=True): gtk.FileSelection.__init__(self) self.main = main self.set_modal(gtk.TRUE) self.set_destroy_with_parent(gtk.TRUE) self.set_title(title) if (got_location_func is None and got_multiple_location_func is not None): self.set_select_multiple(True) self.got_location_func = got_location_func self.no_location_func = no_location_func self.got_multiple_location_func = got_multiple_location_func self.cancel_button.connect("clicked", self.destroy) self.d_handle = self.connect('destroy', self.no_location) self.ok_button.connect("clicked", self.done) self.set_filename(fullname) if show: self.show() def no_location(self, widget=None): if self.no_location_func is not None: self.no_location_func() def done(self, widget=None): if self.get_select_multiple(): self.got_multiple_location() else: self.got_location() self.disconnect(self.d_handle) self.destroy() def got_location(self): if self.got_location_func is not None: name = self.get_filename() self.got_location_func(name) def got_multiple_location(self): if self.got_multiple_location_func is not None: names = self.get_selections() self.got_multiple_location_func(names) def destroy(self, widget=None): gtk.FileSelection.destroy(self) def close_child_windows(self): self.no_location() def close(self, widget=None): self.destroy()class OpenFileSelection(FileSelection): passclass SaveFileSelection(FileSelection): passclass ChooseFolderSelection(FileSelection): passif os.name == 'nt': from venster import comdlg class BaseFileSelection: _klass = None _flags = 0 _filter = '' def __init__(self, main, title='', fullname='', got_location_func=None, no_location_func=None, got_multiple_location_func=None, show=True): self.main = main self.bfs = self._klass() self.bfs.Flags = self._flags self.bfs.filter = self._filter self.got_location_func = got_location_func self.no_location_func = no_location_func self.got_multiple_location_func = got_multiple_location_func if (got_location_func is None and got_multiple_location_func is not None): self.bfs.Flags |= comdlg.OFN_ALLOWMULTISELECT path, filename = os.path.split(fullname) self.bfs.lpstrInitialDir = path self.bfs.lpstrFile = filename self.bfs.lpstrTitle = title self.thread = threading.Thread(target=self.run) if show: self.show() def show(self): self.thread.start() def run(self): result = self.bfs.DoModal(parent=self.main.mainwindow.window.handle) self.done(result) def done(self, result): if result is not None: if self.got_location_func is not None: self.got_location_func(result) elif self.got_multiple_location_func is not None: print result, type(result) # this is broken self.got_multiple_location_func((result,)) else: if self.no_location_func is not None: self.no_location_func() def close_child_windows(self): self.destroy() def destroy(self): pass def close(self): self.destroy() class OpenFileSelection(BaseFileSelection): _klass = comdlg.OpenFileDialog _flags = comdlg.OFN_FILEMUSTEXIST|comdlg.OFN_PATHMUSTEXIST _filter = "Torrent files|*.torrent|All files (*.*)|*.*" class SaveFileSelection(BaseFileSelection): _klass = comdlg.SaveFileDialog _filter = "All files (*.*)|*.*"class PaddedHSeparator(gtk.VBox): def __init__(self, spacing=SPACING): gtk.VBox.__init__(self) self.sep = gtk.HSeparator() self.pack_start(self.sep, expand=False, fill=False, padding=spacing) self.show_all() class HSeparatedBox(gtk.VBox): def new_separator(self): return PaddedHSeparator() def _get_children(self): return gtk.VBox.get_children(self) def get_children(self): return self._get_children()[0::2] def _reorder_child(self, child, index): gtk.VBox.reorder_child(self, child, index) def reorder_child(self, child, index): children = self._get_children() oldindex = children.index(child) sep = None if oldindex == len(children) - 1: sep = children[oldindex-1] else: sep = children[oldindex+1] newindex = index*2 if newindex == len(children) -1: self._reorder_child(sep, newindex-1) self._reorder_child(child, newindex) else: self._reorder_child(child, newindex) self._reorder_child(sep, newindex+1) def pack_start(self, widget, *args, **kwargs): if len(self._get_children()): s = self.new_separator() gtk.VBox.pack_start(self, s, *args, **kwargs) s.show() gtk.VBox.pack_start(self, widget, *args, **kwargs) def pack_end(self, widget, *args, **kwargs): if len(self._get_children()): s = self.new_separator() gtk.VBox.pack_start(self, s, *args, **kwargs) s.show() gtk.VBox.pack_end(self, widget, *args, **kwargs) def remove(self, widget): children = self._get_children() if len(children) > 1: index = children.index(widget) if index == 0: sep = children[index+1] else: sep = children[index-1] sep.destroy() gtk.VBox.remove(self, widget)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -