?? btdownloadgui.py
字號:
self.newversionbutton = gtk.Button('Download _now') self.newversionbutton.connect('clicked', self.get_newversion) self.bbox.pack_end(self.newversionbutton, expand=gtk.FALSE, fill=gtk.FALSE) self.bbox.pack_end(self.closebutton , expand=gtk.FALSE, fill=gtk.FALSE) self.checkbox = gtk.CheckButton('_Remind me later') self.checkbox.set_active(True) self.checkbox.connect('toggled', self.remind_toggle) self.bbox.pack_start(self.checkbox, expand=gtk.FALSE, fill=gtk.FALSE) self.vbox.pack_start(self.bbox) self.add(self.vbox) self.show_all() def remind_toggle(self, widget): v = self.checkbox.get_active() notified = '' if v: notified = '' else: notified = self.newversion self.main.set_config('notified', notified) def close(self, widget): self.destroy() def get_newversion(self, widget): self.main.visit_url(self.download_url) self.destroy()class AboutWindow(object): def __init__(self, main, donatefunc): self.win = Window() self.win.set_title('About %s'%app_name) self.win.set_size_request(300,400) self.win.set_border_width(SPACING) self.win.set_resizable(False) self.win.connect('destroy', lambda w: main.window_closed('about')) self.scroll = gtk.ScrolledWindow() self.scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS) self.scroll.set_shadow_type(gtk.SHADOW_IN) self.outervbox = gtk.VBox() self.outervbox.pack_start(get_logo(96), expand=False, fill=False) self.outervbox.pack_start(gtk.Label('Version %s'%version), expand=False, fill=False) self.vbox = gtk.VBox() self.vbox.set_size_request(250, -1) credits_f = file(os.path.join(doc_root, 'credits.txt')) l = credits_f.read() credits_f.close() label = gtk.Label(l.strip()) label.set_line_wrap(gtk.TRUE) label.set_selectable(True) label.set_justify(gtk.JUSTIFY_CENTER) label.set_size_request(250,-1) self.vbox.pack_start(label, expand=False, fill=False) self.scroll.add_with_viewport(self.vbox) self.outervbox.pack_start(self.scroll, padding=SPACING) self.donatebutton = gtk.Button("Donate") self.donatebutton.connect('clicked', donatefunc) self.donatebuttonbox = gtk.HButtonBox() self.donatebuttonbox.pack_start(self.donatebutton, expand=False, fill=False) self.outervbox.pack_end(self.donatebuttonbox, expand=False, fill=False) self.win.add(self.outervbox) self.win.show_all() def close(self, widget): self.win.destroy() class LogWindow(object): def __init__(self, main, logbuffer, config): self.config = config self.main = main self.win = Window() self.win.set_title('%s Activity Log'%app_name) self.win.set_default_size(600, 200) self.win.set_border_width(SPACING) self.buffer = logbuffer self.text = gtk.TextView(self.buffer) self.text.set_editable(False) self.text.set_cursor_visible(False) self.text.set_wrap_mode(gtk.WRAP_WORD) self.scroll = gtk.ScrolledWindow() self.scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS) self.scroll.set_shadow_type(gtk.SHADOW_IN) self.scroll.add(self.text) self.vbox = gtk.VBox(spacing=SPACING) self.vbox.pack_start(self.scroll) self.buttonbox = gtk.HButtonBox() self.buttonbox.set_spacing(SPACING) self.closebutton = gtk.Button(stock='gtk-close') self.closebutton.connect('clicked', self.close) self.savebutton = gtk.Button(stock='gtk-save') self.savebutton.connect('clicked', self.save_log_file_selection) self.clearbutton = gtk.Button(stock='gtk-clear') self.clearbutton.connect('clicked', self.clear_log) self.buttonbox.pack_start(self.savebutton) self.buttonbox.pack_start(self.closebutton) self.hbox2 = gtk.HBox(homogeneous=False) self.hbox2.pack_end(self.buttonbox, expand=False, fill=False) bb = gtk.HButtonBox() bb.pack_start(self.clearbutton) self.hbox2.pack_start(bb, expand=False, fill=True) self.vbox.pack_end(self.hbox2, expand=False, fill=True) self.win.add(self.vbox) self.win.connect("destroy", lambda w: self.main.window_closed('log')) self.scroll_to_end() self.win.show_all() def scroll_to_end(self): mark = self.buffer.create_mark(None, self.buffer.get_end_iter()) self.text.scroll_mark_onscreen(mark) def save_log_file_selection(self, *args): name = 'bittorrent.log' path = smart_dir(self.config['save_in']) fullname = os.path.join(path, name) self.main.open_window('savefile', title="Save log in:", fullname=fullname, got_location_func=self.save_log, no_location_func=lambda: self.main.window_closed('savefile')) def save_log(self, saveas): self.main.window_closed('savefile') f = file(saveas, 'w') f.write(self.buffer.get_text(self.buffer.get_start_iter(), self.buffer.get_end_iter())) save_message = self.buffer.log_text('log saved', None) f.write(save_message) f.close() def clear_log(self, *args): self.buffer.clear_log() def close(self, widget): self.win.destroy()class LogBuffer(gtk.TextBuffer): h = { CRITICAL:'critical', ERROR :'error' , WARNING :'warning' , INFO :'info' , } def __init__(self): gtk.TextBuffer.__init__(self) tt = self.get_tag_table() size_tag = gtk.TextTag('small') size_tag.set_property('size-points', 10) tt.add(size_tag) info_tag = gtk.TextTag('info') info_tag.set_property('foreground', '#00a040') tt.add(info_tag) warning_tag = gtk.TextTag('warning') warning_tag.set_property('foreground', '#a09000') tt.add(warning_tag) error_tag = gtk.TextTag('error') error_tag.set_property('foreground', '#b00000') tt.add(error_tag) critical_tag = gtk.TextTag('critical') critical_tag.set_property('foreground', '#b00000') critical_tag.set_property('weight', pango.WEIGHT_BOLD) tt.add(critical_tag) def log_text(self, text, severity=CRITICAL): now_str = datetime.datetime.strftime(datetime.datetime.now(), '[%Y-%m-%d %H:%M:%S] ') self.insert_with_tags_by_name(self.get_end_iter(), now_str, 'small') if severity is not None: self.insert_with_tags_by_name(self.get_end_iter(), '%s\n'%text, 'small', self.h[severity]) else: self.insert_with_tags_by_name(self.get_end_iter(), ' -- %s -- \n'%text, 'small') return now_str+text+'\n' def clear_log(self): self.set_text('') self.log_text('log cleared', None)class SettingsWindow(object): def __init__(self, main, config, setfunc): self.main = main self.setfunc = setfunc self.config = config self.win = Window() self.win.connect("destroy", lambda w: main.window_closed('settings')) self.win.set_title('%s Settings'%app_name) self.win.set_border_width(SPACING) self.notebook = gtk.Notebook() self.vbox = gtk.VBox(spacing=SPACING) self.vbox.pack_start(self.notebook, expand=False, fill=False) # Saving tab self.saving_box = gtk.VBox(spacing=SPACING) self.saving_box.set_border_width(SPACING) self.notebook.append_page(self.saving_box, gtk.Label("Saving")) self.dl_frame = gtk.Frame("Download folder:") self.saving_box.pack_start(self.dl_frame, expand=False, fill=False) self.dl_box = gtk.VBox(spacing=SPACING) self.dl_box.set_border_width(SPACING) self.dl_frame.add(self.dl_box) self.save_in_box = gtk.HBox(spacing=SPACING) self.save_in_box.pack_start(gtk.Label("Default:"), expand=False, fill=False) self.dl_save_in = gtk.Entry() self.dl_save_in.set_editable(False) self.set_save_in(self.config['save_in']) self.save_in_box.pack_start(self.dl_save_in, expand=True, fill=True) self.dl_save_in_button = gtk.Button('Change...') self.dl_save_in_button.connect('clicked', self.get_save_in) self.save_in_box.pack_start(self.dl_save_in_button, expand=False, fill=False) self.dl_box.pack_start(self.save_in_box, expand=False, fill=False) self.dl_ask_checkbutton = gtk.CheckButton("Ask where to save each download") self.dl_ask_checkbutton.set_active( bool(self.config['ask_for_save']) ) def toggle_save(w): self.config['ask_for_save'] = int(not self.config['ask_for_save']) self.setfunc('ask_for_save', self.config['ask_for_save']) self.dl_ask_checkbutton.connect('toggled', toggle_save) self.dl_box.pack_start(self.dl_ask_checkbutton, expand=False, fill=False) # end Saving tab # Downloading tab self.downloading_box = gtk.VBox(spacing=SPACING) self.downloading_box.set_border_width(SPACING) self.notebook.append_page(self.downloading_box, gtk.Label("Downloading")) self.dnd_frame = gtk.Frame('Starting additional torrents manually:') self.dnd_box = gtk.VBox(spacing=SPACING, homogeneous=True) self.dnd_box.set_border_width(SPACING) self.dnd_states = ['replace','add','ask'] self.dnd_original_state = self.config['start_torrent_behavior'] self.always_replace_radio = gtk.RadioButton( group=None, label="Always stops the _last running torrent") self.dnd_box.pack_start(self.always_replace_radio) self.always_replace_radio.state_name = self.dnd_states[0] self.always_add_radio = gtk.RadioButton( group=self.always_replace_radio, label="Always starts the torrent in _parallel") self.dnd_box.pack_start(self.always_add_radio) self.always_add_radio.state_name = self.dnd_states[1] self.always_ask_radio = gtk.RadioButton( group=self.always_replace_radio, label="_Asks each time" ) self.dnd_box.pack_start(self.always_ask_radio) self.always_ask_radio.state_name = self.dnd_states[2] self.dnd_group = self.always_replace_radio.get_group() for r in self.dnd_group: r.connect('toggled', self.start_torrent_behavior_changed) self.set_start_torrent_behavior(self.config['start_torrent_behavior']) self.dnd_frame.add(self.dnd_box) self.downloading_box.pack_start(self.dnd_frame, expand=False, fill=False) self.next_torrent_frame = gtk.Frame('Seed completed torrents:') self.next_torrent_box = gtk.VBox(spacing=SPACING, homogeneous=True) self.next_torrent_box.set_border_width(SPACING) self.next_torrent_frame.add(self.next_torrent_box) self.next_torrent_ratio_box = gtk.HBox() self.next_torrent_ratio_box.pack_start(gtk.Label('until share ratio reaches '), fill=False, expand=False) self.next_torrent_ratio_field = PercentValidator('next_torrent_ratio', self.config, self.setfunc) self.next_torrent_ratio_box.pack_start(self.next_torrent_ratio_field, fill=False, expand=False) self.next_torrent_ratio_box.pack_start(gtk.Label(' percent, or'), fill=False, expand=False) self.next_torrent_box.pack_start(self.next_torrent_ratio_box) self.next_torrent_time_box = gtk.HBox() self.next_torrent_time_box.pack_start(gtk.Label('for '), fill=False, expand=False) self.next_torrent_time_field = MinutesValidator('next_torrent_time', self.config, self.setfunc) self.next_torrent_time_box.pack_start(self.next_torrent_time_field, fill=False, expand=False) self.next_torrent_time_box.pack_start(gtk.Label(' minutes, whichever comes first.'), fill=False, expand=False) self.next_torrent_box.pack_start(self.next_torrent_time_box) self.downloading_box.pack_start(self.next_torrent_frame, expand=False, fill=False) self.last_torrent_frame = gtk.Frame('Seed last completed torrent:') self.last_torrent_box = gtk.HBox() self.last_torrent_box.set_border_width(SPACING) self.last_torrent_box.pack_start(gtk.Label('until share ratio reaches '), expand=False, fill=False) self.last_torrent_ratio_field = PercentValidator('last_torrent_ratio',
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -