diff options
Diffstat (limited to 'deluge/ui/gtk3')
52 files changed, 436 insertions, 562 deletions
diff --git a/deluge/ui/gtk3/__init__.py b/deluge/ui/gtk3/__init__.py index 8e8b19613..8db2773e4 100644 --- a/deluge/ui/gtk3/__init__.py +++ b/deluge/ui/gtk3/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com> # @@ -7,8 +6,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging from os import environ @@ -25,7 +22,7 @@ class Gtk(UI): cmd_description = """GTK-based graphical user interface""" def __init__(self, *args, **kwargs): - super(Gtk, self).__init__( + super().__init__( 'gtk', *args, description='Starts the Deluge GTK+ interface', **kwargs ) @@ -42,7 +39,7 @@ class Gtk(UI): ) def start(self): - super(Gtk, self).start() + super().start() import deluge.common from .gtkui import GtkUI diff --git a/deluge/ui/gtk3/aboutdialog.py b/deluge/ui/gtk3/aboutdialog.py index 9974a13de..fe3452b82 100644 --- a/deluge/ui/gtk3/aboutdialog.py +++ b/deluge/ui/gtk3/aboutdialog.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007 Marcos Mobley ('markybob') <markybob@gmail.com> # @@ -7,7 +6,7 @@ # See LICENSE for more details. # -from __future__ import unicode_literals +from datetime import date from gi.repository import Gtk @@ -18,7 +17,7 @@ from deluge.ui.client import client from .common import get_deluge_icon, get_pixbuf -class AboutDialog(object): +class AboutDialog: def __init__(self): self.about = Gtk.AboutDialog() self.about.set_transient_for(component.get('MainWindow').window) @@ -38,7 +37,7 @@ class AboutDialog(object): self.about.set_copyright( _('Copyright %(year_start)s-%(year_end)s Deluge Team') - % {'year_start': 2007, 'year_end': 2019} + % {'year_start': 2007, 'year_end': date.today().year} ) self.about.set_comments( _('A peer-to-peer file sharing program\nutilizing the BitTorrent protocol.') diff --git a/deluge/ui/gtk3/addtorrentdialog.py b/deluge/ui/gtk3/addtorrentdialog.py index 81b8dbaf3..cf3851d6c 100644 --- a/deluge/ui/gtk3/addtorrentdialog.py +++ b/deluge/ui/gtk3/addtorrentdialog.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com> # @@ -7,11 +6,9 @@ # See LICENSE for more details. # -from __future__ import division, unicode_literals - import logging import os -from base64 import b64encode +from base64 import b64decode, b64encode from xml.sax.saxutils import escape as xml_escape from xml.sax.saxutils import unescape as xml_unescape @@ -19,6 +16,7 @@ from gi.repository import Gtk from gi.repository.GObject import TYPE_INT64, TYPE_UINT64 import deluge.component as component +from deluge.bencode import bdecode from deluge.common import ( create_magnet_uri, decode_bytes, @@ -271,6 +269,7 @@ class AddTorrentDialog(component.Component): return if metadata: + metadata = bdecode(b64decode(metadata)) info = TorrentInfo.from_metadata(metadata, [[t] for t in trackers]) self.files[info_hash] = info.files self.infos[info_hash] = info.filedata @@ -775,7 +774,7 @@ class AddTorrentDialog(component.Component): else: ErrorDialog( _('Invalid URL'), - '%s %s' % (url, _('is not a valid URL.')), + '{} {}'.format(url, _('is not a valid URL.')), self.dialog, ).run() @@ -817,7 +816,7 @@ class AddTorrentDialog(component.Component): dialog.destroy() ErrorDialog( _('Download Failed'), - '%s %s' % (_('Failed to download:'), url), + '{} {}'.format(_('Failed to download:'), url), details=result.getErrorMessage(), parent=self.dialog, ).run() diff --git a/deluge/ui/gtk3/common.py b/deluge/ui/gtk3/common.py index e7b46c8d5..42a14b407 100644 --- a/deluge/ui/gtk3/common.py +++ b/deluge/ui/gtk3/common.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2008 Marcos Mobley ('markybob') <markybob@gmail.com> # @@ -7,15 +6,13 @@ # See LICENSE for more details. # """Common functions for various parts of gtkui to use.""" -from __future__ import unicode_literals - import contextlib import logging import os +import pickle import shutil import sys -import six.moves.cPickle as pickle # noqa: N813 from gi.repository.Gdk import SELECTION_CLIPBOARD, SELECTION_PRIMARY, Display from gi.repository.GdkPixbuf import Colorspace, Pixbuf from gi.repository.GLib import GError @@ -29,7 +26,7 @@ from gi.repository.Gtk import ( SortType, ) -from deluge.common import PY2, get_pixmap, is_ip, osx_check, windows_check +from deluge.common import get_pixmap, is_ip, osx_check, windows_check log = logging.getLogger(__name__) @@ -62,12 +59,36 @@ def create_blank_pixbuf(size=16): return pix -def get_pixbuf(filename): +def get_pixbuf(filename: str, size: int = 0) -> Pixbuf: + """Creates a new pixbuf by loading an image from file + + Args: + filename: An image file to load + size: Specify a size constraint (equal aspect ratio) + + Returns: + A newly created pixbuf + + """ + # Skip ico and gif that cause Pixbuf crash on Windows + # https://dev.deluge-torrent.org/ticket/3501 + if windows_check() and filename.endswith(('.ico', '.gif')): + return create_blank_pixbuf(size) + + if not os.path.isabs(filename): + filename = get_pixmap(filename) + + pixbuf = None try: - return Pixbuf.new_from_file(get_pixmap(filename)) + if size: + pixbuf = Pixbuf.new_from_file_at_size(filename, size, size) + else: + pixbuf = Pixbuf.new_from_file(filename) except GError as ex: + # Failed to load the pixbuf (Bad image file), so return a blank pixbuf. log.warning(ex) - return create_blank_pixbuf() + + return pixbuf or create_blank_pixbuf(size or 16) # Status icons.. Create them from file only once to avoid constantly re-creating them. @@ -79,17 +100,6 @@ icon_queued = get_pixbuf('queued16.png') icon_checking = get_pixbuf('checking16.png') -def get_pixbuf_at_size(filename, size): - if not os.path.isabs(filename): - filename = get_pixmap(filename) - try: - return Pixbuf.new_from_file_at_size(filename, size, size) - except GError as ex: - # Failed to load the pixbuf (Bad image file), so return a blank pixbuf. - log.warning(ex) - return create_blank_pixbuf(size) - - def get_logo(size): """A Deluge logo. @@ -102,7 +112,7 @@ def get_logo(size): filename = 'deluge.svg' if windows_check(): filename = 'deluge.png' - return get_pixbuf_at_size(filename, size) + return get_pixbuf(filename, size) def build_menu_radio_list( @@ -232,14 +242,11 @@ def associate_magnet_links(overwrite=False): """ if windows_check(): - try: - import winreg - except ImportError: - import _winreg as winreg # For Python 2. + import winreg try: hkey = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, 'Magnet') - except WindowsError: + except OSError: overwrite = True else: winreg.CloseKey(hkey) @@ -248,7 +255,7 @@ def associate_magnet_links(overwrite=False): deluge_exe = os.path.join(os.path.dirname(sys.executable), 'deluge.exe') try: magnet_key = winreg.CreateKey(winreg.HKEY_CLASSES_ROOT, 'Magnet') - except WindowsError: + except OSError: # Could not create for all users, falling back to current user magnet_key = winreg.CreateKey( winreg.HKEY_CURRENT_USER, 'Software\\Classes\\Magnet' @@ -257,14 +264,12 @@ def associate_magnet_links(overwrite=False): winreg.SetValue(magnet_key, '', winreg.REG_SZ, 'URL:Magnet Protocol') winreg.SetValueEx(magnet_key, 'URL Protocol', 0, winreg.REG_SZ, '') winreg.SetValueEx(magnet_key, 'BrowserFlags', 0, winreg.REG_DWORD, 0x8) - winreg.SetValue( - magnet_key, 'DefaultIcon', winreg.REG_SZ, '{},0'.format(deluge_exe) - ) + winreg.SetValue(magnet_key, 'DefaultIcon', winreg.REG_SZ, f'{deluge_exe},0') winreg.SetValue( magnet_key, r'shell\open\command', winreg.REG_SZ, - '"{}" "%1"'.format(deluge_exe), + f'"{deluge_exe}" "%1"', ) winreg.CloseKey(magnet_key) @@ -320,7 +325,7 @@ def save_pickled_state_file(filename, state): if os.path.isfile(filepath): log.debug('Creating backup of %s at: %s', filename, filepath_bak) shutil.copy2(filepath, filepath_bak) - except IOError as ex: + except OSError as ex: log.error('Unable to backup %s to %s: %s', filepath, filepath_bak, ex) else: log.info('Saving the %s at: %s', filename, filepath) @@ -331,7 +336,7 @@ def save_pickled_state_file(filename, state): _file.flush() os.fsync(_file.fileno()) shutil.move(filepath_tmp, filepath) - except (IOError, EOFError, pickle.PicklingError) as ex: + except (OSError, EOFError, pickle.PicklingError) as ex: log.error('Unable to save %s: %s', filename, ex) if os.path.isfile(filepath_bak): log.info('Restoring backup of %s from: %s', filename, filepath_bak) @@ -356,11 +361,8 @@ def load_pickled_state_file(filename): log.info('Opening %s for load: %s', filename, _filepath) try: with open(_filepath, 'rb') as _file: - if PY2: - state = pickle.load(_file) - else: - state = pickle.load(_file, encoding='utf8') - except (IOError, pickle.UnpicklingError) as ex: + state = pickle.load(_file, encoding='utf8') + except (OSError, pickle.UnpicklingError) as ex: log.warning('Unable to load %s: %s', _filepath, ex) else: log.info('Successfully loaded %s: %s', filename, _filepath) diff --git a/deluge/ui/gtk3/connectionmanager.py b/deluge/ui/gtk3/connectionmanager.py index d5883c4b3..b53dd8e04 100644 --- a/deluge/ui/gtk3/connectionmanager.py +++ b/deluge/ui/gtk3/connectionmanager.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com> # @@ -7,11 +6,10 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging import os -from socket import gaierror, gethostbyname +from socket import gaierror, getaddrinfo +from urllib.parse import urlparse from gi.repository import Gtk from twisted.internet import defer, reactor @@ -26,12 +24,6 @@ from deluge.ui.hostlist import DEFAULT_PORT, LOCALHOST, HostList from .common import get_clipboard_text from .dialogs import AuthenticationDialog, ErrorDialog -try: - from urllib.parse import urlparse -except ImportError: - # PY2 fallback - from urlparse import urlparse # pylint: disable=ungrouped-imports - log = logging.getLogger(__name__) HOSTLIST_COL_ID = 0 @@ -230,7 +222,7 @@ class ConnectionManager(component.Component): __, host, port, __, __, status, __, __ = model[row] try: - gethostbyname(host) + getaddrinfo(host, None) except gaierror as ex: log.error( 'Error resolving host %s to ip: %s', row[HOSTLIST_COL_HOST], ex.args[1] diff --git a/deluge/ui/gtk3/createtorrentdialog.py b/deluge/ui/gtk3/createtorrentdialog.py index 1e5e73cb6..e9f16906c 100644 --- a/deluge/ui/gtk3/createtorrentdialog.py +++ b/deluge/ui/gtk3/createtorrentdialog.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com> # @@ -7,8 +6,6 @@ # See LICENSE for more details. # -from __future__ import division, unicode_literals - import logging import os.path from base64 import b64encode @@ -31,7 +28,7 @@ from .torrentview_data_funcs import cell_data_size log = logging.getLogger(__name__) -class CreateTorrentDialog(object): +class CreateTorrentDialog: def __init__(self): pass diff --git a/deluge/ui/gtk3/details_tab.py b/deluge/ui/gtk3/details_tab.py index 2431e0836..04a5eabfe 100644 --- a/deluge/ui/gtk3/details_tab.py +++ b/deluge/ui/gtk3/details_tab.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com> # @@ -7,8 +6,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging from xml.sax.saxutils import escape as xml_escape @@ -23,7 +20,7 @@ log = logging.getLogger(__name__) class DetailsTab(Tab): def __init__(self): - super(DetailsTab, self).__init__('Details', 'details_tab', 'details_tab_label') + super().__init__('Details', 'details_tab', 'details_tab_label') self.add_tab_widget('summary_name', None, ('name',)) self.add_tab_widget('summary_total_size', fsize, ('total_size',)) @@ -65,7 +62,7 @@ class DetailsTab(Tab): txt = xml_escape(self.widget_status_as_fstr(widget, status)) if decode_bytes(widget.obj.get_text()) != txt: if 'comment' in widget.status_keys and is_url(txt): - widget.obj.set_markup('<a href="%s">%s</a>' % (txt, txt)) + widget.obj.set_markup(f'<a href="{txt}">{txt}</a>') else: widget.obj.set_markup(txt) diff --git a/deluge/ui/gtk3/dialogs.py b/deluge/ui/gtk3/dialogs.py index 4a2a60a7e..db337d3d5 100644 --- a/deluge/ui/gtk3/dialogs.py +++ b/deluge/ui/gtk3/dialogs.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2009 Andrew Resch <andrewresch@gmail.com> # @@ -9,7 +8,7 @@ # pylint: disable=super-on-old-class -from __future__ import unicode_literals +from collections import namedtuple from gi.repository import Gtk from twisted.internet import defer @@ -17,7 +16,9 @@ from twisted.internet import defer import deluge.component as component from deluge.common import windows_check -from .common import get_deluge_icon, get_pixbuf_at_size +from .common import get_deluge_icon, get_pixbuf + +Account = namedtuple('Account', 'username password authlevel') class BaseDialog(Gtk.Dialog): @@ -34,7 +35,7 @@ class BaseDialog(Gtk.Dialog): :param parent: gtkWindow, the parent window, if None it will default to the MainWindow """ - super(BaseDialog, self).__init__( + super().__init__( title=header, parent=parent if parent else component.get('MainWindow').window, flags=Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, @@ -55,7 +56,7 @@ class BaseDialog(Gtk.Dialog): # Hack for Windows since it doesn't support svg if icon.endswith('.svg') and windows_check(): icon = icon.rpartition('.svg')[0] + '16.png' - image.set_from_pixbuf(get_pixbuf_at_size(icon, 24)) + image.set_from_pixbuf(get_pixbuf(icon, 24)) else: image.set_from_icon_name(icon, Gtk.IconSize.LARGE_TOOLBAR) image.set_alignment(0.5, 0.0) @@ -103,7 +104,7 @@ class YesNoDialog(BaseDialog): :param text: see `:class:BaseDialog` :param parent: see `:class:BaseDialog` """ - super(YesNoDialog, self).__init__( + super().__init__( header, text, 'dialog-question', @@ -127,7 +128,7 @@ class InformationDialog(BaseDialog): :param text: see `:class:BaseDialog` :param parent: see `:class:BaseDialog` """ - super(InformationDialog, self).__init__( + super().__init__( header, text, 'dialog-information', @@ -154,7 +155,7 @@ class ErrorDialog(BaseDialog): :param traceback: show the traceback information in the details area :type traceback: bool """ - super(ErrorDialog, self).__init__( + super().__init__( header, text, 'dialog-error', (_('_Close'), Gtk.ResponseType.CLOSE), parent ) @@ -198,7 +199,7 @@ class AuthenticationDialog(BaseDialog): :param err_msg: the error message we got back from the server :type err_msg: string """ - super(AuthenticationDialog, self).__init__( + super().__init__( _('Authenticate'), err_msg, 'dialog-password', @@ -255,7 +256,7 @@ class AccountDialog(BaseDialog): parent=None, ): if username: - super(AccountDialog, self).__init__( + super().__init__( _('Edit Account'), _('Edit existing account'), 'dialog-information', @@ -268,7 +269,7 @@ class AccountDialog(BaseDialog): parent, ) else: - super(AccountDialog, self).__init__( + super().__init__( _('New Account'), _('Create a new account'), 'dialog-information', @@ -276,21 +277,21 @@ class AccountDialog(BaseDialog): parent, ) - self.levels_mapping = levels_mapping + self.account = None table = Gtk.Table(2, 3, False) - self.username_label = Gtk.Label() - self.username_label.set_markup('<b>' + _('Username:') + '</b>') - self.username_label.set_alignment(1.0, 0.5) - self.username_label.set_padding(5, 5) + username_label = Gtk.Label() + username_label.set_markup('<b>' + _('Username:') + '</b>') + username_label.set_alignment(1.0, 0.5) + username_label.set_padding(5, 5) self.username_entry = Gtk.Entry() - table.attach(self.username_label, 0, 1, 0, 1) + table.attach(username_label, 0, 1, 0, 1) table.attach(self.username_entry, 1, 2, 0, 1) - self.authlevel_label = Gtk.Label() - self.authlevel_label.set_markup('<b>' + _('Authentication Level:') + '</b>') - self.authlevel_label.set_alignment(1.0, 0.5) - self.authlevel_label.set_padding(5, 5) + authlevel_label = Gtk.Label() + authlevel_label.set_markup('<b>' + _('Authentication Level:') + '</b>') + authlevel_label.set_alignment(1.0, 0.5) + authlevel_label.set_padding(5, 5) # combo_box_new_text is deprecated but no other pygtk alternative. self.authlevel_combo = Gtk.ComboBoxText() @@ -305,16 +306,16 @@ class AccountDialog(BaseDialog): if active_idx is not None: self.authlevel_combo.set_active(active_idx) - table.attach(self.authlevel_label, 0, 1, 1, 2) + table.attach(authlevel_label, 0, 1, 1, 2) table.attach(self.authlevel_combo, 1, 2, 1, 2) - self.password_label = Gtk.Label() - self.password_label.set_markup('<b>' + _('Password:') + '</b>') - self.password_label.set_alignment(1.0, 0.5) - self.password_label.set_padding(5, 5) + password_label = Gtk.Label() + password_label.set_markup('<b>' + _('Password:') + '</b>') + password_label.set_alignment(1.0, 0.5) + password_label.set_padding(5, 5) self.password_entry = Gtk.Entry() self.password_entry.set_visibility(False) - table.attach(self.password_label, 0, 1, 2, 3) + table.attach(password_label, 0, 1, 2, 3) table.attach(self.password_entry, 1, 2, 2, 3) self.vbox.pack_start(table, False, False, padding=5) @@ -327,18 +328,17 @@ class AccountDialog(BaseDialog): if password: self.password_entry.set_text(username) - self.show_all() - - def get_username(self): - return self.username_entry.get_text() - - def get_password(self): - return self.password_entry.get_text() + self.vbox.show_all() - def get_authlevel(self): - combobox = self.authlevel_combo - level = combobox.get_model()[combobox.get_active()][0] - return level + def _on_response(self, widget, response): + if response == Gtk.ResponseType.OK: + self.account = Account( + self.username_entry.get_text(), + self.password_entry.get_text(), + self.authlevel_combo.get_active_text(), + ) + self.destroy() + self.deferred.callback(response) class OtherDialog(BaseDialog): @@ -359,7 +359,7 @@ class OtherDialog(BaseDialog): if not icon: icon = 'dialog-information' - super(OtherDialog, self).__init__( + super().__init__( header, text, icon, @@ -421,7 +421,7 @@ class PasswordDialog(BaseDialog): :param password_msg: the error message we got back from the server :type password_msg: string """ - super(PasswordDialog, self).__init__( + super().__init__( header=_('Password Protected'), text=password_msg, icon='dialog-password', @@ -455,3 +455,44 @@ class PasswordDialog(BaseDialog): def on_password_activate(self, widget): self.response(Gtk.ResponseType.OK) + + +class CopyMagnetDialog(BaseDialog): + """ + Displays a dialog with a magnet URI + """ + + def __init__(self, torrent_magnet='', parent=None): + super().__init__( + header=_('Copy Magnet URI'), + text='', + icon='magnet_copy.svg', + buttons=(_('_Close'), Gtk.ResponseType.CLOSE), + parent=parent, + ) + self.copied = False + + table = Gtk.Table(1, 2, False) + self.magnet_entry = Gtk.Entry() + self.magnet_entry.set_text(torrent_magnet) + self.magnet_entry.set_editable(False) + self.magnet_entry.connect('copy-clipboard', self.on_copy_emitted) + table.attach(self.magnet_entry, 0, 1, 0, 1) + + copy_button = Gtk.Button.new_with_label(_('Copy')) + copy_button.connect('clicked', self.on_copy_clicked) + table.attach(copy_button, 1, 2, 0, 1) + + self.vbox.pack_start(table, False, False, padding=5) + self.set_focus(self.magnet_entry) + + self.show_all() + + def on_copy_clicked(self, widget): + self.magnet_entry.select_region(0, -1) + self.magnet_entry.copy_clipboard() + self.magnet_entry.set_position(0) + self.copied = True + + def on_copy_emitted(self, widget): + self.copied = True diff --git a/deluge/ui/gtk3/edittrackersdialog.py b/deluge/ui/gtk3/edittrackersdialog.py index a21a7d71f..861e3924b 100644 --- a/deluge/ui/gtk3/edittrackersdialog.py +++ b/deluge/ui/gtk3/edittrackersdialog.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007, 2008 Andrew Resch <andrewresch@gmail.com> # @@ -7,8 +6,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging import os.path @@ -77,7 +74,7 @@ def trackers_tiers_from_text(text_str=''): return trackers -class EditTrackersDialog(object): +class EditTrackersDialog: def __init__(self, torrent_id, parent=None): self.torrent_id = torrent_id self.builder = Gtk.Builder() @@ -134,6 +131,11 @@ class EditTrackersDialog(object): self.dialog.connect('response', self._on_response) self.treeview.connect('button_press_event', self.on_button_press_event) + self.add_tracker_dialog.connect('key-press-event', self.on_key_add_press_event) + self.add_tracker_dialog.connect('delete-event', self.on_delete_event_add) + self.edit_tracker_entry.connect('key-press-event', self.on_key_edit_press_event) + self.edit_tracker_entry.connect('delete-event', self.on_delete_event_edit) + def run(self): # Make sure we have a torrent_id.. if not just return if self.torrent_id is None: @@ -192,7 +194,7 @@ class EditTrackersDialog(object): self.old_trackers = list(status['trackers']) for tracker in self.old_trackers: self.add_tracker(tracker['tier'], tracker['url']) - self.treeview.set_cursor((0)) + self.treeview.set_cursor(0) self.dialog.show() def add_tracker(self, tier, url): @@ -208,6 +210,7 @@ class EditTrackersDialog(object): # Show the add tracker dialog self.add_tracker_dialog.show() self.builder.get_object('textview_trackers').grab_focus() + self.dialog.set_sensitive(False) def on_button_remove_clicked(self, widget): log.debug('on_button_remove_clicked') @@ -236,11 +239,27 @@ class EditTrackersDialog(object): self.edit_tracker_entry.grab_focus() self.dialog.set_sensitive(False) - def on_button_edit_cancel_clicked(self, widget): - log.debug('on_button_edit_cancel_clicked') + def _close_edit_dialog(self): self.dialog.set_sensitive(True) self.edit_tracker_entry.hide() + def on_button_edit_cancel_clicked(self, widget): + """handles the cancel button""" + log.debug('on_button_edit_cancel_clicked') + self._close_edit_dialog() + + def on_key_edit_press_event(self, widget, event): + """handles Escape key press""" + if event.keyval == Gdk.KEY_Escape: + log.debug('on_key_edit_press_event') + self._close_edit_dialog() + + def on_delete_event_edit(self, widget, event): + """handles the Top-Right X button""" + log.debug('on_delete_event_edit') + self._close_edit_dialog() + return True + def on_button_edit_ok_clicked(self, widget): log.debug('on_button_edit_ok_clicked') selected = self.get_selected() @@ -301,11 +320,29 @@ class EditTrackersDialog(object): # Clear the entry widget and hide the dialog textview_buf.set_text('') + self.dialog.set_sensitive(True) self.add_tracker_dialog.hide() - def on_button_add_cancel_clicked(self, widget): - log.debug('on_button_add_cancel_clicked') + def _discard_and_close_add_dialog(self): # Clear the entry widget and hide the dialog b = Gtk.TextBuffer() self.builder.get_object('textview_trackers').set_buffer(b) + self.dialog.set_sensitive(True) self.add_tracker_dialog.hide() + + def on_button_add_cancel_clicked(self, widget): + """handles the cancel button""" + log.debug('on_button_add_cancel_clicked') + self._discard_and_close_add_dialog() + + def on_key_add_press_event(self, widget, event): + """handles Escape key press""" + if event.keyval == Gdk.KEY_Escape: + log.debug('on_key_add_press_event') + self._discard_and_close_add_dialog() + + def on_delete_event_add(self, widget, event): + """handles the Top-Right X button""" + log.debug('on_delete_event_add') + self._discard_and_close_add_dialog() + return True diff --git a/deluge/ui/gtk3/files_tab.py b/deluge/ui/gtk3/files_tab.py index 50f8a4587..24c169727 100644 --- a/deluge/ui/gtk3/files_tab.py +++ b/deluge/ui/gtk3/files_tab.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com> # @@ -7,15 +6,13 @@ # See LICENSE for more details. # -from __future__ import division, unicode_literals - import json import logging import os.path import gi # isort:skip (Required before Gtk import). -gi.require_version('Gtk', '3.0') # NOQA: E402 +gi.require_version('Gtk', '3.0') # isort:imports-thirdparty from gi.repository import Gio, Gtk @@ -84,7 +81,7 @@ def cell_progress(column, cell, model, row, data): class FilesTab(Tab): def __init__(self): - super(FilesTab, self).__init__('Files', 'files_tab', 'files_tab_label') + super().__init__('Files', 'files_tab', 'files_tab_label') self.listview = self.main_builder.get_object('files_listview') # filename, size, progress string, progress value, priority, file index, icon id diff --git a/deluge/ui/gtk3/filtertreeview.py b/deluge/ui/gtk3/filtertreeview.py index 4272ef018..40752d78c 100644 --- a/deluge/ui/gtk3/filtertreeview.py +++ b/deluge/ui/gtk3/filtertreeview.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com> # 2008 Andrew Resch <andrewresch@gmail.com> @@ -9,8 +8,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging import os import warnings @@ -24,7 +21,7 @@ from deluge.common import TORRENT_STATE, decode_bytes, resource_filename from deluge.configmanager import ConfigManager from deluge.ui.client import client -from .common import get_pixbuf, get_pixbuf_at_size +from .common import get_pixbuf log = logging.getLogger(__name__) @@ -90,7 +87,7 @@ class FilterTreeView(component.Component): self.treeview.set_level_indentation(-21) # Force theme to use expander-size so we don't cut out entries due to indentation hack. provider = Gtk.CssProvider() - provider.load_from_data('* {-GtkTreeView-expander-size: 9;}'.encode()) + provider.load_from_data(b'* {-GtkTreeView-expander-size: 9;}') context = self.treeview.get_style_context() context.add_provider(provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) @@ -256,7 +253,7 @@ class FilterTreeView(component.Component): return get_pixbuf('%s16.png' % pix) def set_row_image(self, cat, value, filename): - pix = get_pixbuf_at_size(filename, 16) + pix = get_pixbuf(filename, size=16) row = self.filters[(cat, value)] self.treestore.set_value(row, 4, pix) return False diff --git a/deluge/ui/gtk3/glade/add_torrent_dialog.infohash.ui b/deluge/ui/gtk3/glade/add_torrent_dialog.infohash.ui index a7a8caeaa..8adbad329 100644 --- a/deluge/ui/gtk3/glade/add_torrent_dialog.infohash.ui +++ b/deluge/ui/gtk3/glade/add_torrent_dialog.infohash.ui @@ -144,8 +144,6 @@ <property name="invisible_char">•</property> <property name="activates_default">True</property> <property name="truncate_multiline">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> </object> <packing> <property name="expand">True</property> diff --git a/deluge/ui/gtk3/glade/add_torrent_dialog.ui b/deluge/ui/gtk3/glade/add_torrent_dialog.ui index 4d3680344..7183272e1 100644 --- a/deluge/ui/gtk3/glade/add_torrent_dialog.ui +++ b/deluge/ui/gtk3/glade/add_torrent_dialog.ui @@ -727,8 +727,6 @@ used sparingly.</property> <object class="GtkSpinButton" id="spin_maxup"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment2</property> <property name="update_policy">if-valid</property> </object> @@ -741,8 +739,6 @@ used sparingly.</property> <object class="GtkSpinButton" id="spin_maxconnections"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment3</property> </object> <packing> @@ -754,8 +750,6 @@ used sparingly.</property> <object class="GtkSpinButton" id="spin_maxupslots"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment4</property> </object> <packing> @@ -767,8 +761,6 @@ used sparingly.</property> <object class="GtkSpinButton" id="spin_maxdown"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment1</property> </object> <packing> diff --git a/deluge/ui/gtk3/glade/add_torrent_dialog.url.ui b/deluge/ui/gtk3/glade/add_torrent_dialog.url.ui index ecbd0f7cf..6b75b235f 100644 --- a/deluge/ui/gtk3/glade/add_torrent_dialog.url.ui +++ b/deluge/ui/gtk3/glade/add_torrent_dialog.url.ui @@ -143,8 +143,6 @@ <property name="invisible_char">•</property> <property name="activates_default">True</property> <property name="truncate_multiline">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> </object> <packing> <property name="expand">True</property> diff --git a/deluge/ui/gtk3/glade/connect_peer_dialog.ui b/deluge/ui/gtk3/glade/connect_peer_dialog.ui index f5e9337ea..4a60751d0 100644 --- a/deluge/ui/gtk3/glade/connect_peer_dialog.ui +++ b/deluge/ui/gtk3/glade/connect_peer_dialog.ui @@ -128,8 +128,6 @@ <property name="width_chars">39</property> <property name="text" translatable="yes">hostname:port</property> <property name="truncate_multiline">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> </object> <packing> <property name="expand">True</property> diff --git a/deluge/ui/gtk3/glade/connection_manager.addhost.ui b/deluge/ui/gtk3/glade/connection_manager.addhost.ui index 641a71cc1..ea5376e45 100644 --- a/deluge/ui/gtk3/glade/connection_manager.addhost.ui +++ b/deluge/ui/gtk3/glade/connection_manager.addhost.ui @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- Generated with glade 3.22.1 --> +<!-- Generated with glade 3.22.2 --> <interface> <requires lib="gtk+" version="3.0"/> <object class="GtkAdjustment" id="adjustment_port"> @@ -16,7 +16,7 @@ <property name="window_position">center-on-parent</property> <property name="destroy_with_parent">True</property> <property name="type_hint">dialog</property> - <child> + <child type="titlebar"> <placeholder/> </child> <child internal-child="vbox"> @@ -24,11 +24,12 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="orientation">vertical</property> - <property name="spacing">2</property> + <property name="spacing">5</property> <child internal-child="action_area"> <object class="GtkButtonBox" id="dialog-action_area5"> <property name="visible">True</property> <property name="can_focus">False</property> + <property name="margin_top">15</property> <property name="layout_style">end</property> <child> <object class="GtkButton" id="button_addhost_cancel"> @@ -65,49 +66,41 @@ <property name="expand">False</property> <property name="fill">True</property> <property name="pack_type">end</property> - <property name="position">0</property> + <property name="position">1</property> </packing> </child> <child> - <object class="GtkBox" id="hbox2"> + <object class="GtkGrid"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="spacing">5</property> + <property name="row_spacing">5</property> + <property name="column_spacing">5</property> <child> <object class="GtkLabel" id="label3"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="halign">start</property> <property name="label" translatable="yes">Hostname:</property> + <property name="xalign">0</property> </object> <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">0</property> + <property name="left_attach">0</property> + <property name="top_attach">0</property> </packing> </child> <child> - <object class="GtkAlignment" id="alignment4"> + <object class="GtkEntry" id="entry_hostname"> <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="left_padding">1</property> - <child> - <object class="GtkEntry" id="entry_hostname"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="invisible_char">•</property> - <property name="activates_default">True</property> - <property name="truncate_multiline">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> - <signal name="paste-clipboard" handler="on_entry_host_paste_clipboard" swapped="no"/> - </object> - </child> + <property name="can_focus">True</property> + <property name="hexpand">True</property> + <property name="invisible_char">•</property> + <property name="activates_default">True</property> + <property name="truncate_multiline">True</property> + <signal name="paste-clipboard" handler="on_entry_host_paste_clipboard" swapped="no"/> </object> <packing> - <property name="expand">True</property> - <property name="fill">True</property> - <property name="position">1</property> + <property name="left_attach">1</property> + <property name="top_attach">0</property> </packing> </child> <child> @@ -115,116 +108,90 @@ <property name="visible">True</property> <property name="can_focus">False</property> <property name="label" translatable="yes">Port:</property> + <property name="xalign">0</property> </object> <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">2</property> + <property name="left_attach">0</property> + <property name="top_attach">1</property> </packing> </child> <child> <object class="GtkSpinButton" id="spinbutton_port"> <property name="visible">True</property> <property name="can_focus">True</property> + <property name="halign">start</property> <property name="max_length">5</property> <property name="invisible_char">•</property> <property name="width_chars">5</property> + <property name="max_width_chars">5</property> <property name="progress_pulse_step">1</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_port</property> <property name="climb_rate">1</property> <property name="numeric">True</property> </object> <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">3</property> + <property name="left_attach">1</property> + <property name="top_attach">1</property> </packing> </child> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> - <child> - <object class="GtkGrid" id="table1"> - <property name="visible">True</property> - <property name="can_focus">False</property> <child> - <object class="GtkAlignment" id="alignment3"> + <object class="GtkLabel" id="label5"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="left_padding">5</property> - <child> - <object class="GtkEntry" id="entry_password"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="visibility">False</property> - <property name="invisible_char">•</property> - <property name="truncate_multiline">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> - </object> - </child> + <property name="halign">start</property> + <property name="label" translatable="yes">Username:</property> + <property name="xalign">0</property> </object> <packing> - <property name="left_attach">1</property> - <property name="top_attach">1</property> + <property name="left_attach">0</property> + <property name="top_attach">2</property> </packing> </child> <child> - <object class="GtkAlignment" id="alignment2"> + <object class="GtkEntry" id="entry_username"> <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="left_padding">5</property> - <child> - <object class="GtkEntry" id="entry_username"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="invisible_char">•</property> - <property name="truncate_multiline">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> - </object> - </child> + <property name="can_focus">True</property> + <property name="hexpand">True</property> + <property name="invisible_char">•</property> + <property name="truncate_multiline">True</property> </object> <packing> <property name="left_attach">1</property> - <property name="top_attach">0</property> + <property name="top_attach">2</property> </packing> </child> <child> - <object class="GtkLabel" id="label5"> + <object class="GtkLabel" id="label6"> <property name="visible">True</property> <property name="can_focus">False</property> <property name="halign">start</property> - <property name="label" translatable="yes">Username:</property> + <property name="label" translatable="yes">Password:</property> + <property name="xalign">0</property> </object> <packing> <property name="left_attach">0</property> - <property name="top_attach">0</property> + <property name="top_attach">3</property> </packing> </child> <child> - <object class="GtkLabel" id="label6"> + <object class="GtkEntry" id="entry_password"> <property name="visible">True</property> - <property name="can_focus">False</property> - <property name="halign">start</property> - <property name="label" translatable="yes">Password:</property> + <property name="can_focus">True</property> + <property name="hexpand">True</property> + <property name="visibility">False</property> + <property name="invisible_char">•</property> + <property name="truncate_multiline">True</property> </object> <packing> - <property name="left_attach">0</property> - <property name="top_attach">1</property> + <property name="left_attach">1</property> + <property name="top_attach">3</property> </packing> </child> </object> <packing> <property name="expand">False</property> <property name="fill">True</property> - <property name="position">2</property> + <property name="position">0</property> </packing> </child> </object> diff --git a/deluge/ui/gtk3/glade/connection_manager.ui b/deluge/ui/gtk3/glade/connection_manager.ui index 11516aa76..44f4b34e3 100644 --- a/deluge/ui/gtk3/glade/connection_manager.ui +++ b/deluge/ui/gtk3/glade/connection_manager.ui @@ -30,7 +30,7 @@ <property name="modal">True</property> <property name="window_position">center-on-parent</property> <property name="default_width">300</property> - <property name="default_height">250</property> + <property name="default_height">285</property> <property name="destroy_with_parent">True</property> <property name="type_hint">dialog</property> <child> diff --git a/deluge/ui/gtk3/glade/create_torrent_dialog.remote_path.ui b/deluge/ui/gtk3/glade/create_torrent_dialog.remote_path.ui index dc7b7e93e..43283305a 100644 --- a/deluge/ui/gtk3/glade/create_torrent_dialog.remote_path.ui +++ b/deluge/ui/gtk3/glade/create_torrent_dialog.remote_path.ui @@ -143,8 +143,6 @@ <property name="invisible_char">•</property> <property name="activates_default">True</property> <property name="truncate_multiline">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> </object> <packing> <property name="expand">True</property> diff --git a/deluge/ui/gtk3/glade/create_torrent_dialog.remote_save.ui b/deluge/ui/gtk3/glade/create_torrent_dialog.remote_save.ui index a380718e4..712305489 100644 --- a/deluge/ui/gtk3/glade/create_torrent_dialog.remote_save.ui +++ b/deluge/ui/gtk3/glade/create_torrent_dialog.remote_save.ui @@ -143,8 +143,6 @@ <property name="invisible_char">•</property> <property name="activates_default">True</property> <property name="truncate_multiline">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> </object> <packing> <property name="expand">True</property> diff --git a/deluge/ui/gtk3/glade/create_torrent_dialog.ui b/deluge/ui/gtk3/glade/create_torrent_dialog.ui index 0166e2d0b..0d1594014 100644 --- a/deluge/ui/gtk3/glade/create_torrent_dialog.ui +++ b/deluge/ui/gtk3/glade/create_torrent_dialog.ui @@ -356,8 +356,6 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="truncate_multiline">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> </object> <packing> <property name="expand">True</property> @@ -393,8 +391,6 @@ <object class="GtkEntry" id="entry_comments"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> </object> <packing> <property name="expand">True</property> diff --git a/deluge/ui/gtk3/glade/edit_trackers.edit.ui b/deluge/ui/gtk3/glade/edit_trackers.edit.ui index 2521e8ff8..fc3e51b83 100644 --- a/deluge/ui/gtk3/glade/edit_trackers.edit.ui +++ b/deluge/ui/gtk3/glade/edit_trackers.edit.ui @@ -144,8 +144,6 @@ <property name="invisible_char">•</property> <property name="activates_default">True</property> <property name="truncate_multiline">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> </object> <packing> <property name="expand">True</property> diff --git a/deluge/ui/gtk3/glade/main_window.tabs.ui b/deluge/ui/gtk3/glade/main_window.tabs.ui index d4984dd9d..7ecf61821 100644 --- a/deluge/ui/gtk3/glade/main_window.tabs.ui +++ b/deluge/ui/gtk3/glade/main_window.tabs.ui @@ -1166,8 +1166,6 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="invisible_char">•</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">spin_stop_ratio_adjustment</property> <property name="digits">1</property> <property name="numeric">True</property> @@ -1267,8 +1265,6 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="invisible_char">•</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">spin_max_connections_adjustment</property> <property name="numeric">True</property> </object> @@ -1282,8 +1278,6 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="invisible_char">•</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">spin_max_upload_adjustment</property> <property name="digits">1</property> <property name="numeric">True</property> @@ -1298,8 +1292,6 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="invisible_char">•</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">spin_max_download_adjustment</property> <property name="climb_rate">1</property> <property name="digits">1</property> @@ -1356,8 +1348,6 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="invisible_char">•</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">spin_max_upload_slots_adjustment</property> <property name="numeric">True</property> </object> diff --git a/deluge/ui/gtk3/glade/other_dialog.ui b/deluge/ui/gtk3/glade/other_dialog.ui index 26d3d08bf..01a5597f2 100644 --- a/deluge/ui/gtk3/glade/other_dialog.ui +++ b/deluge/ui/gtk3/glade/other_dialog.ui @@ -148,8 +148,6 @@ <property name="max_length">6</property> <property name="activates_default">True</property> <property name="width_chars">6</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment1</property> </object> </child> diff --git a/deluge/ui/gtk3/glade/path_combo_chooser.ui b/deluge/ui/gtk3/glade/path_combo_chooser.ui index f79685d26..871bac01e 100644 --- a/deluge/ui/gtk3/glade/path_combo_chooser.ui +++ b/deluge/ui/gtk3/glade/path_combo_chooser.ui @@ -98,8 +98,6 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="max_length">2</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment3</property> <property name="climb_rate">1</property> <property name="numeric">True</property> @@ -571,6 +569,7 @@ <object class="GtkEntry" id="entry_text"> <property name="visible">True</property> <property name="can_focus">True</property> + <property name="hexpand">True</property> <property name="invisible_char">•</property> <signal name="changed" handler="on_entry_text_changed" swapped="no"/> <signal name="delete-text" handler="on_entry_text_delete_text" swapped="no"/> diff --git a/deluge/ui/gtk3/glade/preferences_dialog.ui b/deluge/ui/gtk3/glade/preferences_dialog.ui index 4b223cb44..aa1531d75 100644 --- a/deluge/ui/gtk3/glade/preferences_dialog.ui +++ b/deluge/ui/gtk3/glade/preferences_dialog.ui @@ -929,8 +929,6 @@ and daemon (does not apply in Standalone mode).</property> <property name="width_chars">16</property> <property name="text">********</property> <property name="truncate_multiline">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> </object> <packing> <property name="expand">False</property> @@ -1150,6 +1148,7 @@ and daemon (does not apply in Standalone mode).</property> <property name="top_padding">2</property> <property name="bottom_padding">2</property> <property name="left_padding">12</property> + <property name="right_padding">12</property> <child> <object class="GtkGrid" id="table9"> <property name="visible">True</property> @@ -1545,8 +1544,6 @@ used sparingly.</property> <object class="GtkSpinButton" id="spin_max_connections_per_second"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_spin_max_conn_per_sec</property> <property name="numeric">True</property> </object> @@ -1559,8 +1556,6 @@ used sparingly.</property> <object class="GtkSpinButton" id="spin_max_half_open_connections"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_spin_max_half_open_conn</property> <property name="numeric">True</property> </object> @@ -1624,8 +1619,6 @@ used sparingly.</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="tooltip_text" translatable="yes">The maximum number of connections allowed. Set -1 for unlimited.</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_spin_max_conn_global</property> <property name="climb_rate">1</property> <property name="snap_to_ticks">True</property> @@ -1655,8 +1648,6 @@ used sparingly.</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="tooltip_text" translatable="yes">The maximum download speed for all torrents. Set -1 for unlimited.</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_spin_max_download</property> <property name="climb_rate">1</property> <property name="digits">1</property> @@ -1672,8 +1663,6 @@ used sparingly.</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="tooltip_text" translatable="yes">The maximum upload speed for all torrents. Set -1 for unlimited.</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_spin_max_upload</property> <property name="climb_rate">1</property> <property name="digits">1</property> @@ -1689,8 +1678,6 @@ used sparingly.</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="tooltip_text" translatable="yes">The maximum upload slots for all torrents. Set -1 for unlimited.</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_spin_max_upload_slots_global</property> <property name="climb_rate">1</property> <property name="snap_to_ticks">True</property> @@ -1849,8 +1836,6 @@ used sparingly.</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="tooltip_text" translatable="yes">The maximum upload slots per torrent. Set -1 for unlimited.</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_spin_max_upload_slots_per_torrent</property> <property name="climb_rate">1</property> <property name="snap_to_ticks">True</property> @@ -1866,8 +1851,6 @@ used sparingly.</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="tooltip_text" translatable="yes">The maximum number of connections per torrent. Set -1 for unlimited.</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_spin_max_conn_per_torrent</property> <property name="snap_to_ticks">True</property> <property name="numeric">True</property> @@ -1930,8 +1913,6 @@ used sparingly.</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="tooltip_text" translatable="yes">The maximum number download speed per torrent. Set -1 for unlimited.</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_spin_max_download_per_torrent</property> <property name="digits">1</property> <property name="numeric">True</property> @@ -1946,8 +1927,6 @@ used sparingly.</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="tooltip_text" translatable="yes">The maximum upload speed per torrent. Set -1 for unlimited.</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_spin_max_upload_per_torrent</property> <property name="digits">1</property> <property name="numeric">True</property> @@ -2131,8 +2110,6 @@ used sparingly.</property> <object class="GtkSpinButton" id="spin_active"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_spin_active</property> <property name="snap_to_ticks">True</property> <property name="numeric">True</property> @@ -2146,8 +2123,6 @@ used sparingly.</property> <object class="GtkSpinButton" id="spin_seeding"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_spin_seeding</property> <property name="snap_to_ticks">True</property> <property name="numeric">True</property> @@ -2185,8 +2160,6 @@ used sparingly.</property> <object class="GtkSpinButton" id="spin_downloading"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_spin_downloading</property> <property name="snap_to_ticks">True</property> <property name="numeric">True</property> @@ -2323,8 +2296,6 @@ used sparingly.</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="invisible_char">•</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_spin_seed_time_limit</property> </object> <packing> @@ -2337,8 +2308,6 @@ used sparingly.</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="invisible_char">•</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_time_ratio_limit</property> <property name="digits">2</property> </object> @@ -2352,8 +2321,6 @@ used sparingly.</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="invisible_char">•</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_share_ratio_limit</property> <property name="digits">2</property> </object> @@ -2425,8 +2392,6 @@ used sparingly.</property> <property name="sensitive">False</property> <property name="can_focus">True</property> <property name="invisible_char">•</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_share_ratio</property> <property name="digits">2</property> <property name="numeric">True</property> @@ -2572,12 +2537,10 @@ used sparingly.</property> <object class="GtkEntry" id="entry_interface"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="tooltip_text" translatable="yes">The IP address of the interface to listen for incoming bittorrent connections on. Leave this empty if you want to use the default.</property> - <property name="max_length">15</property> + <property name="tooltip_text" translatable="yes">IP address or network interface name to listen for incoming BitTorrent connections. Leave empty to use system default.</property> + <property name="max_length">40</property> <property name="width_chars">15</property> <property name="truncate_multiline">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> </object> </child> </object> @@ -2586,7 +2549,7 @@ used sparingly.</property> <object class="GtkLabel" id="label110"> <property name="visible">True</property> <property name="can_focus">False</property> - <property name="label" translatable="yes">Incoming Address</property> + <property name="label" translatable="yes">Incoming Interface</property> <attributes> <attribute name="weight" value="bold"/> </attributes> @@ -2628,8 +2591,6 @@ used sparingly.</property> <property name="can_focus">True</property> <property name="max_length">5</property> <property name="max_width_chars">6</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_spin_incoming_port</property> <property name="climb_rate">1</property> <property name="snap_to_ticks">True</property> @@ -2728,6 +2689,24 @@ used sparingly.</property> </packing> </child> <child> + <object class="GtkAlignment" id="alignment31"> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="left_padding">10</property> + <child> + <object class="GtkSpinner" id="port_spinner"> + <property name="visible">False</property> + <property name="can_focus">False</property> + </object> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">True</property> + <property name="position">2</property> + </packing> + </child> + <child> <object class="GtkAlignment" id="alignment48"> <property name="visible">True</property> <property name="can_focus">False</property> @@ -2742,7 +2721,7 @@ used sparingly.</property> <packing> <property name="expand">False</property> <property name="fill">True</property> - <property name="position">2</property> + <property name="position">3</property> </packing> </child> </object> @@ -2793,14 +2772,12 @@ used sparingly.</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="tooltip_text" translatable="yes"> -The network interface name or IP address for outgoing BitTorrent connections. (Leave empty for default.) + IP address or network interface name for outgoing BitTorrent connections. Leave empty to use system default. </property> - <property name="max_length">15</property> + <property name="max_length">40</property> <property name="invisible_char">●</property> <property name="width_chars">15</property> <property name="truncate_multiline">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> </object> </child> </object> @@ -2880,8 +2857,6 @@ The network interface name or IP address for outgoing BitTorrent connections. (L <property name="can_focus">True</property> <property name="max_length">5</property> <property name="width_chars">7</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_spin_outgoing_port_min</property> <property name="climb_rate">1</property> <property name="snap_to_ticks">True</property> @@ -2913,8 +2888,6 @@ The network interface name or IP address for outgoing BitTorrent connections. (L <property name="can_focus">True</property> <property name="max_length">5</property> <property name="width_chars">7</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_spin_outgoing_port_max</property> <property name="climb_rate">1</property> <property name="snap_to_ticks">True</property> @@ -3236,8 +3209,6 @@ The network interface name or IP address for outgoing BitTorrent connections. (L <property name="width_chars">1</property> <property name="text">0x00</property> <property name="truncate_multiline">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> </object> <packing> <property name="expand">False</property> @@ -3345,8 +3316,6 @@ The network interface name or IP address for outgoing BitTorrent connections. (L <property name="can_focus">True</property> <property name="visibility">False</property> <property name="truncate_multiline">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> </object> <packing> <property name="left_attach">1</property> @@ -3370,8 +3339,6 @@ The network interface name or IP address for outgoing BitTorrent connections. (L <property name="visible">True</property> <property name="can_focus">True</property> <property name="truncate_multiline">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <signal name="paste-clipboard" handler="on_entry_proxy_host_paste_clipboard" swapped="no"/> </object> <packing> @@ -3399,8 +3366,6 @@ The network interface name or IP address for outgoing BitTorrent connections. (L <object class="GtkSpinButton" id="spin_proxy_port"> <property name="visible">True</property> <property name="can_focus">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_spin_proxy_port</property> <property name="numeric">True</property> </object> @@ -3416,8 +3381,6 @@ The network interface name or IP address for outgoing BitTorrent connections. (L <property name="visible">True</property> <property name="can_focus">True</property> <property name="truncate_multiline">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> </object> <packing> <property name="left_attach">1</property> @@ -3696,8 +3659,6 @@ the proxy instead of using the local DNS service</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="invisible_char">●</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_cache_size</property> <property name="numeric">True</property> <property name="update_policy">if-valid</property> @@ -3713,8 +3674,6 @@ the proxy instead of using the local DNS service</property> <property name="can_focus">True</property> <property name="max_length">5</property> <property name="invisible_char">●</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_cache_expiry</property> </object> <packing> @@ -4248,8 +4207,6 @@ the proxy instead of using the local DNS service</property> <property name="tooltip_text" translatable="yes">If Deluge cannot find the database file at this location it will fallback to using DNS to resolve the peer's country.</property> <property name="invisible_char">●</property> <property name="truncate_multiline">True</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> </object> <packing> <property name="expand">False</property> @@ -4427,8 +4384,6 @@ the proxy instead of using the local DNS service</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="max_width_chars">6</property> - <property name="primary_icon_activatable">False</property> - <property name="secondary_icon_activatable">False</property> <property name="adjustment">adjustment_spin_daemon_port</property> </object> <packing> diff --git a/deluge/ui/gtk3/glade/torrent_menu.ui b/deluge/ui/gtk3/glade/torrent_menu.ui index c1b77b4ad..c9ee289c1 100644 --- a/deluge/ui/gtk3/glade/torrent_menu.ui +++ b/deluge/ui/gtk3/glade/torrent_menu.ui @@ -31,6 +31,11 @@ <property name="icon_name">media-playback-pause-symbolic</property> <property name="icon_size">1</property> </object> + <object class="GtkImage" id="menu-item-image15"> + <property name="can_focus">False</property> + <property name="icon_name">edit-copy-symbolic</property> + <property name="icon_size">1</property> + </object> <object class="GtkImage" id="menu-item-image19"> <property name="visible">True</property> <property name="can_focus">False</property> @@ -155,6 +160,17 @@ </object> </child> <child> + <object class="GtkImageMenuItem" id="menuitem_copymagnet"> + <property name="label" translatable="yes">_Copy Magnet URI</property> + <property name="visible">True</property> + <property name="can_focus">False</property> + <property name="use_underline">True</property> + <property name="image">menu-item-image15</property> + <property name="use_stock">False</property> + <signal name="activate" handler="on_menuitem_copymagnet_activate" swapped="no"/> + </object> + </child> + <child> <object class="GtkImageMenuItem" id="menuitem_updatetracker"> <property name="label" translatable="yes">_Update Tracker</property> <property name="visible">True</property> diff --git a/deluge/ui/gtk3/gtkui.py b/deluge/ui/gtk3/gtkui.py index 02b309078..ddb2eb529 100644 --- a/deluge/ui/gtk3/gtkui.py +++ b/deluge/ui/gtk3/gtkui.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com> # @@ -8,8 +7,6 @@ # # pylint: disable=wrong-import-position -from __future__ import division, unicode_literals - import logging import os import signal @@ -18,8 +15,8 @@ import time import gi # isort:skip (Required before Gtk import). -gi.require_version('Gtk', '3.0') # NOQA: E402 -gi.require_version('Gdk', '3.0') # NOQA: E402 +gi.require_version('Gtk', '3.0') +gi.require_version('Gdk', '3.0') # isort:imports-thirdparty from gi.repository.GLib import set_prgname @@ -32,7 +29,7 @@ try: # Install twisted reactor, before any other modules import reactor. reactor = gtk3reactor.install() except ReactorAlreadyInstalledError: - # Running unit tests so trial already installed a rector + # Running unit tests so already installed a rector from twisted.internet import reactor # isort:imports-firstparty @@ -140,7 +137,7 @@ DEFAULT_PREFS = { } -class GtkUI(object): +class GtkUI: def __init__(self, args): # Setup gtkbuilder/glade translation setup_translation() diff --git a/deluge/ui/gtk3/ipcinterface.py b/deluge/ui/gtk3/ipcinterface.py index 78858c443..0ef28d8c0 100644 --- a/deluge/ui/gtk3/ipcinterface.py +++ b/deluge/ui/gtk3/ipcinterface.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2008-2009 Andrew Resch <andrewresch@gmail.com> # @@ -7,14 +6,14 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging import os import sys from base64 import b64encode from glob import glob from tempfile import mkstemp +from urllib.parse import urlparse +from urllib.request import url2pathname import rencode import twisted.internet.error @@ -26,14 +25,6 @@ from deluge.common import decode_bytes, is_magnet, is_url, windows_check from deluge.configmanager import ConfigManager, get_config_dir from deluge.ui.client import client -try: - from urllib.parse import urlparse - from urllib.request import url2pathname -except ImportError: - # PY2 fallback - from urllib import url2pathname # pylint: disable=ungrouped-imports - from urlparse import urlparse # pylint: disable=ungrouped-imports - log = logging.getLogger(__name__) diff --git a/deluge/ui/gtk3/listview.py b/deluge/ui/gtk3/listview.py index 4e9fe5db8..e9f6b1084 100644 --- a/deluge/ui/gtk3/listview.py +++ b/deluge/ui/gtk3/listview.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007, 2008 Andrew Resch <andrewresch@gmail.com> # @@ -7,20 +6,18 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging from gi.repository import GObject, Gtk -from deluge.common import PY2, decode_bytes +from deluge.common import decode_bytes from .common import cmp, load_pickled_state_file, save_pickled_state_file log = logging.getLogger(__name__) -class ListViewColumnState(object): +class ListViewColumnState: """Class used for saving/loading column state.""" def __init__(self, name, position, width, visible, sort, sort_order): @@ -32,13 +29,13 @@ class ListViewColumnState(object): self.sort_order = sort_order -class ListView(object): +class ListView: """ListView is used to make custom GtkTreeViews. It supports the adding and removing of columns, creating a menu for a column toggle list and support for 'status_field's which are used while updating the columns data. """ - class ListViewColumn(object): + class ListViewColumn: """Holds information regarding a column in the ListView""" def __init__(self, name, column_indices): @@ -66,7 +63,7 @@ class ListView(object): self.pixbuf_index = 0 self.data_func = None - class TreeviewColumn(Gtk.TreeViewColumn, object): + class TreeviewColumn(Gtk.TreeViewColumn): """ TreeViewColumn does not signal right-click events, and we need them This subclass is equivalent to TreeViewColumn, but it signals these events @@ -75,13 +72,11 @@ class ListView(object): """ __gsignals__ = { - 'button-press-event' - if not PY2 - else b'button-press-event': (GObject.SIGNAL_RUN_LAST, None, (object,)) + 'button-press-event': (GObject.SIGNAL_RUN_LAST, None, (object,)) } def __init__(self, title=None, cell_renderer=None, **args): - """ Constructor, see Gtk.TreeViewColumn """ + """Constructor, see Gtk.TreeViewColumn""" Gtk.TreeViewColumn.__init__(self, title, cell_renderer, **args) label = Gtk.Label(label=title) self.set_widget(label) diff --git a/deluge/ui/gtk3/mainwindow.py b/deluge/ui/gtk3/mainwindow.py index b7d751410..d11ff317a 100644 --- a/deluge/ui/gtk3/mainwindow.py +++ b/deluge/ui/gtk3/mainwindow.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com> # @@ -7,8 +6,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging import os.path from hashlib import sha1 as sha @@ -45,7 +42,7 @@ if windowing('X11'): log = logging.getLogger(__name__) -class _GtkBuilderSignalsHolder(object): +class _GtkBuilderSignalsHolder: def connect_signals(self, mapping_or_class): if isinstance(mapping_or_class, dict): @@ -341,7 +338,9 @@ class MainWindow(component.Component): return self.previous_clipboard_text = text if text and ( - (is_url(text) and text.endswith('.torrent')) or is_magnet(text) + (is_url(text) and text.endswith('.torrent')) + or is_magnet(text) + and not component.get('MenuBar').magnet_copied() ): component.get('AddTorrentDialog').show() component.get('AddTorrentDialog').on_button_url_clicked(window) diff --git a/deluge/ui/gtk3/menubar.py b/deluge/ui/gtk3/menubar.py index e09f394fc..a812a8cac 100644 --- a/deluge/ui/gtk3/menubar.py +++ b/deluge/ui/gtk3/menubar.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007, 2008 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2011 Pedro Algarvio <pedro@algarvio.me> @@ -9,8 +8,6 @@ # -from __future__ import unicode_literals - import logging import os.path @@ -21,7 +18,7 @@ import deluge.component as component from deluge.configmanager import ConfigManager from deluge.ui.client import client -from .dialogs import ErrorDialog, OtherDialog +from .dialogs import CopyMagnetDialog, ErrorDialog, OtherDialog from .path_chooser import PathChooser log = logging.getLogger(__name__) @@ -34,6 +31,7 @@ class MenuBar(component.Component): self.mainwindow = component.get('MainWindow') self.main_builder = self.mainwindow.get_builder() self.config = ConfigManager('gtk3ui.conf') + self._magnet_copied = False self.builder = Gtk.Builder() # Get the torrent menu from the gtk builder file @@ -142,6 +140,19 @@ class MenuBar(component.Component): self.change_sensitivity = ['menuitem_addtorrent'] + def magnet_copied(self): + """ + lets the caller know whether a magnet was copied internally + + the `mainwindow` checks every time the data in the clipboard, + so it will automatically open the AddTorrentURL dialog in case it + contains a valid link (URL to a torrent or a magnet URI). + + """ + val = self._magnet_copied + self._magnet_copied = False + return val + def start(self): for widget in self.change_sensitivity: self.main_builder.get_object(widget).set_sensitive(True) @@ -282,6 +293,21 @@ class MenuBar(component.Component): component.get('TorrentView').get_selected_torrents() ) + def on_menuitem_copymagnet_activate(self, data=None): + log.debug('on_menuitem_copymagnet_activate') + torrent_ids = component.get('TorrentView').get_selected_torrents() + if torrent_ids: + + def _on_magnet_uri(magnet_uri): + def update_copied(response_id): + if dialog.copied: + self._magnet_copied = True + + dialog = CopyMagnetDialog(magnet_uri) + dialog.run().addCallback(update_copied) + + client.core.get_magnet_uri(torrent_ids[0]).addCallback(_on_magnet_uri) + def on_menuitem_updatetracker_activate(self, data=None): log.debug('on_menuitem_updatetracker_activate') client.core.force_reannounce( @@ -541,7 +567,7 @@ class MenuBar(component.Component): account_to_log = {} for key, value in account.copy().items(): if key == 'password': - value = '*' * len(value) + value = '*' * 10 account_to_log[key] = value known_accounts_to_log.append(account_to_log) log.debug('_on_known_accounts: %s', known_accounts_to_log) diff --git a/deluge/ui/gtk3/menubar_osx.py b/deluge/ui/gtk3/menubar_osx.py index 1df6fab08..53150fbf3 100644 --- a/deluge/ui/gtk3/menubar_osx.py +++ b/deluge/ui/gtk3/menubar_osx.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com> # @@ -7,8 +6,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - from gi.repository.Gdk import ModifierType from gi.repository.Gtk import SeparatorMenuItem, accel_groups_from_object from gi.repository.Gtk.AccelFlags import VISIBLE diff --git a/deluge/ui/gtk3/new_release_dialog.py b/deluge/ui/gtk3/new_release_dialog.py index 6aa328260..a635bd2cd 100644 --- a/deluge/ui/gtk3/new_release_dialog.py +++ b/deluge/ui/gtk3/new_release_dialog.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com> # @@ -7,8 +6,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - from gi.repository.Gtk import IconSize import deluge.common @@ -17,7 +14,7 @@ from deluge.configmanager import ConfigManager from deluge.ui.client import client -class NewReleaseDialog(object): +class NewReleaseDialog: def __init__(self): pass diff --git a/deluge/ui/gtk3/options_tab.py b/deluge/ui/gtk3/options_tab.py index 6a25fd1e8..b0411a8b6 100644 --- a/deluge/ui/gtk3/options_tab.py +++ b/deluge/ui/gtk3/options_tab.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com> # 2017 Calum Lind <calumlind+deluge@gmail.com> @@ -8,8 +7,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - from gi.repository.Gdk import keyval_name import deluge.component as component @@ -21,7 +18,7 @@ from .torrentdetails import Tab class OptionsTab(Tab): def __init__(self): - super(OptionsTab, self).__init__('Options', 'options_tab', 'options_tab_label') + super().__init__('Options', 'options_tab', 'options_tab_label') self.prev_torrent_ids = None self.prev_status = None @@ -191,8 +188,9 @@ class OptionsTab(Tab): ): options[status_key] = widget_value - if options.get('move_completed', False): - options['move_completed_path'] = self.move_completed_path_chooser.get_text() + move_completed_path = self.move_completed_path_chooser.get_text() + if move_completed_path != self.prev_status['move_completed_path']: + options['move_completed_path'] = move_completed_path client.core.set_torrent_options(self.prev_torrent_ids, options) self.button_apply.set_sensitive(False) diff --git a/deluge/ui/gtk3/path_chooser.py b/deluge/ui/gtk3/path_chooser.py index b7228415e..805819660 100644 --- a/deluge/ui/gtk3/path_chooser.py +++ b/deluge/ui/gtk3/path_chooser.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2013 Bro <bro.development@gmail.com> # @@ -7,8 +6,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging import deluge.component as component @@ -125,7 +122,7 @@ class PathChoosersHandler(component.Component): class PathChooser(PathChooserComboBox): def __init__(self, paths_config_key=None, parent=None): self.paths_config_key = paths_config_key - super(PathChooser, self).__init__(parent=parent) + super().__init__(parent=parent) self.chooser_handler = PathChoosersHandler() self.chooser_handler.register_chooser(self) self.set_auto_completer_func(self.on_completion) diff --git a/deluge/ui/gtk3/path_combo_chooser.py b/deluge/ui/gtk3/path_combo_chooser.py index 72e98e497..74d9055b7 100755 --- a/deluge/ui/gtk3/path_combo_chooser.py +++ b/deluge/ui/gtk3/path_combo_chooser.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -# -*- coding: utf-8 -*- # # Copyright (C) 2013 Bro <bro.development@gmail.com> # @@ -8,15 +7,13 @@ # See LICENSE for more details. # -from __future__ import division, print_function, unicode_literals - import os import warnings from gi.repository import Gdk, GObject, Gtk from gi.repository.GObject import SignalFlags -from deluge.common import PY2, resource_filename +from deluge.common import resource_filename from deluge.path_chooser_common import get_completion_paths # Filter the pygobject signal warning: @@ -64,7 +61,7 @@ def path_without_trailing_path_sep(path): return path -class ValueList(object): +class ValueList: paths_without_trailing_path_sep = False @@ -176,7 +173,7 @@ class ValueList(object): """ for i, row in enumerate(self.tree_store): if row[0] == value: - self.treeview.set_cursor((i)) + self.treeview.set_cursor(i) return # The value was not found if select_first: @@ -374,7 +371,7 @@ class StoredValuesList(ValueList): """ # This is left click if event.button != 3: - super(StoredValuesList, self).on_treeview_mouse_button_press_event( + super().on_treeview_mouse_button_press_event( treeview, event, double_click=True ) return False @@ -412,9 +409,7 @@ class StoredValuesList(ValueList): PathChooserPopup.popup(self) def on_stored_values_treeview_key_press_event(self, widget, event): - super(StoredValuesList, self).on_value_list_treeview_key_press_event( - widget, event - ) + super().on_value_list_treeview_key_press_event(widget, event) # Prevent the default event handler to move the cursor in the list if key_is_up_or_down(event.keyval): return True @@ -479,9 +474,9 @@ class CompletionList(ValueList): ] = self.on_completion_treeview_motion_notify_event # Add super class signal handler - self.signal_handlers['on_completion_treeview_mouse_button_press_event'] = super( - CompletionList, self - ).on_treeview_mouse_button_press_event + self.signal_handlers[ + 'on_completion_treeview_mouse_button_press_event' + ] = super().on_treeview_mouse_button_press_event def reduce_values(self, prefix): """ @@ -499,9 +494,7 @@ class CompletionList(ValueList): self.add_values(matching_values, clear=True) def on_completion_treeview_key_press_event(self, widget, event): - ret = super(CompletionList, self).on_value_list_treeview_key_press_event( - widget, event - ) + ret = super().on_value_list_treeview_key_press_event(widget, event) if ret: return ret keyval = event.keyval @@ -529,7 +522,7 @@ class CompletionList(ValueList): self.handle_list_scroll(path=path[0], _next=None) -class PathChooserPopup(object): +class PathChooserPopup: """This creates the popop window for the ComboEntry.""" def __init__(self, min_visible_rows, max_visible_rows, popup_alignment_widget): @@ -983,7 +976,7 @@ class PathCompletionPopup(CompletionList, PathChooserPopup): return True -class PathAutoCompleter(object): +class PathAutoCompleter: def __init__(self, builder, path_entry, max_visible_rows): self.completion_popup = PathCompletionPopup( builder, path_entry, max_visible_rows @@ -1106,9 +1099,7 @@ class PathAutoCompleter(object): class PathChooserComboBox(Gtk.Box, StoredValuesPopup, GObject.GObject): __gsignals__ = { - signal - if not PY2 - else signal.encode(): (SignalFlags.RUN_FIRST, GObject.TYPE_NONE, (object,)) + signal: (SignalFlags.RUN_FIRST, GObject.TYPE_NONE, (object,)) for signal in [ 'text-changed', 'accelerator-set', @@ -1414,7 +1405,7 @@ class PathChooserComboBox(Gtk.Box, StoredValuesPopup, GObject.GObject): self.set_text(self.get_text()) def _on_entry_combobox_hbox_realize(self, widget): - """ Must do this when the widget is realized """ + """Must do this when the widget is realized""" self.set_filechooser_button_visible(self.filechooser_visible) self.set_path_entry_visible(self.path_entry_visible) @@ -1466,7 +1457,7 @@ class PathChooserComboBox(Gtk.Box, StoredValuesPopup, GObject.GObject): ) return True elif is_ascii_value(keyval, 's'): - super(PathChooserComboBox, self).add_current_value_to_saved_list() + super().add_current_value_to_saved_list() return True elif is_ascii_value(keyval, 'd'): # Set the default value in the text entry @@ -1696,7 +1687,7 @@ if __name__ == '__main__': box1 = Gtk.Box.new(Gtk.Orientation.VERTICAL, spacing=0) def get_resource2(filename): - return '%s/glade/%s' % (os.path.abspath(os.path.dirname(sys.argv[0])), filename) + return f'{os.path.abspath(os.path.dirname(sys.argv[0]))}/glade/{filename}' # Override get_resource which fetches from deluge install # get_resource = get_resource2 diff --git a/deluge/ui/gtk3/peers_tab.py b/deluge/ui/gtk3/peers_tab.py index e0282becf..b458f7a7d 100644 --- a/deluge/ui/gtk3/peers_tab.py +++ b/deluge/ui/gtk3/peers_tab.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com> # @@ -7,8 +6,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging import os.path @@ -42,18 +39,12 @@ from .torrentview_data_funcs import ( cell_data_speed_up, ) -try: - from future_builtins import zip -except ImportError: - # Ignore on Py3. - pass - log = logging.getLogger(__name__) class PeersTab(Tab): def __init__(self): - super(PeersTab, self).__init__('Peers', 'peers_tab', 'peers_tab_label') + super().__init__('Peers', 'peers_tab', 'peers_tab_label') self.peer_menu = self.main_builder.get_object('menu_peer_tab') component.get('MainWindow').connect_signals(self) @@ -313,7 +304,7 @@ class PeersTab(Tab): ip_int = int( binascii.hexlify(socket.inet_pton(socket.AF_INET6, ip)), 16 ) - peer_ip = '[%s]:%s' % (ip, peer['ip'].split(':')[-1]) + peer_ip = '[{}]:{}'.format(ip, peer['ip'].split(':')[-1]) if peer['seed']: icon = self.seed_pixbuf diff --git a/deluge/ui/gtk3/piecesbar.py b/deluge/ui/gtk3/piecesbar.py index 549f9c048..8665328c0 100644 --- a/deluge/ui/gtk3/piecesbar.py +++ b/deluge/ui/gtk3/piecesbar.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2011 Pedro Algarvio <pedro@algarvio.me> # @@ -7,15 +6,13 @@ # See LICENSE for more details. # -from __future__ import division, unicode_literals - from math import pi import gi # isort:skip (Version check required before import). -gi.require_version('PangoCairo', '1.0') # NOQA: E402 -gi.require_foreign('cairo') # NOQA: E402 -gi.require_version('cairo', '1.0') # NOQA: E402 +gi.require_version('PangoCairo', '1.0') +gi.require_foreign('cairo') +gi.require_version('cairo', '1.0') # isort:imports-thirdparty import cairo # Backward compat cairo <= 1.15 @@ -24,7 +21,6 @@ from gi.repository.Gtk import DrawingArea, ProgressBar, StateFlags from gi.repository.Pango import SCALE, Weight # isort:imports-firstparty -from deluge.common import PY2 from deluge.configmanager import ConfigManager COLOR_STATES = ['missing', 'waiting', 'downloading', 'completed'] @@ -32,10 +28,10 @@ COLOR_STATES = ['missing', 'waiting', 'downloading', 'completed'] class PiecesBar(DrawingArea): # Draw in response to an draw - __gsignals__ = {'draw': 'override'} if not PY2 else {b'draw': b'override'} + __gsignals__ = {'draw': 'override'} def __init__(self): - super(PiecesBar, self).__init__() + super().__init__() # Get progress bar styles, in order to keep font consistency pb = ProgressBar() pb_style = pb.get_style_context() diff --git a/deluge/ui/gtk3/pluginmanager.py b/deluge/ui/gtk3/pluginmanager.py index d60f8d390..63353c0df 100644 --- a/deluge/ui/gtk3/pluginmanager.py +++ b/deluge/ui/gtk3/pluginmanager.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007, 2008 Andrew Resch <andrewresch@gmail.com> # @@ -7,8 +6,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging import deluge.component as component diff --git a/deluge/ui/gtk3/preferences.py b/deluge/ui/gtk3/preferences.py index 13930fc55..a008a9562 100644 --- a/deluge/ui/gtk3/preferences.py +++ b/deluge/ui/gtk3/preferences.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007, 2008 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2011 Pedro Algarvio <pedro@algarvio.me> @@ -8,11 +7,10 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging import os from hashlib import sha1 as sha +from urllib.parse import urlparse from gi import require_version from gi.repository import Gtk @@ -21,6 +19,7 @@ from gi.repository.Gdk import Color import deluge.common import deluge.component as component from deluge.configmanager import ConfigManager, get_config_dir +from deluge.decorators import maybe_coroutine from deluge.error import AuthManagerError, NotAuthorizedError from deluge.i18n import get_languages from deluge.ui.client import client @@ -31,12 +30,6 @@ from .dialogs import AccountDialog, ErrorDialog, InformationDialog, YesNoDialog from .path_chooser import PathChooser try: - from urllib.parse import urlparse -except ImportError: - # PY2 fallback - from urlparse import urlparse # pylint: disable=ungrouped-imports - -try: require_version('AppIndicator3', '0.1') from gi.repository import AppIndicator3 # noqa: F401 except (ImportError, ValueError): @@ -679,11 +672,15 @@ class Preferences(component.Component): 'chk_random_outgoing_ports' ).get_active() incoming_address = self.builder.get_object('entry_interface').get_text().strip() - if deluge.common.is_ip(incoming_address) or not incoming_address: + if deluge.common.is_interface(incoming_address) or not incoming_address: new_core_config['listen_interface'] = incoming_address - new_core_config['outgoing_interface'] = ( + outgoing_address = ( self.builder.get_object('entry_outgoing_interface').get_text().strip() ) + if deluge.common.is_interface(outgoing_address) or not outgoing_address: + new_core_config['outgoing_interface'] = ( + self.builder.get_object('entry_outgoing_interface').get_text().strip() + ) new_core_config['peer_tos'] = self.builder.get_object( 'entry_peer_tos' ).get_text() @@ -948,6 +945,7 @@ class Preferences(component.Component): def hide(self): self.window_open = False + self.builder.get_object('port_spinner').stop() self.builder.get_object('port_img').hide() self.pref_dialog.hide() @@ -1092,6 +1090,8 @@ class Preferences(component.Component): log.debug('on_test_port_clicked') def on_get_test(status): + self.builder.get_object('port_spinner').stop() + self.builder.get_object('port_spinner').hide() if status: self.builder.get_object('port_img').set_from_icon_name( 'emblem-ok-symbolic', Gtk.IconSize.MENU @@ -1104,12 +1104,9 @@ class Preferences(component.Component): self.builder.get_object('port_img').show() client.core.test_listen_port().addCallback(on_get_test) - # XXX: Consider using gtk.Spinner() instead of the loading gif - # It requires gtk.ver > 2.12 - self.builder.get_object('port_img').set_from_file( - deluge.common.get_pixmap('loading.gif') - ) - self.builder.get_object('port_img').show() + self.builder.get_object('port_spinner').start() + self.builder.get_object('port_spinner').show() + self.builder.get_object('port_img').hide() client.force_call() def on_plugin_toggled(self, renderer, path): @@ -1333,58 +1330,46 @@ class Preferences(component.Component): (model, itr) = treeselection.get_selected() if not itr: return - username = model[itr][0] - if username: + level = model[itr][1] + if level: self.builder.get_object('accounts_edit').set_sensitive(True) self.builder.get_object('accounts_delete').set_sensitive(True) else: self.builder.get_object('accounts_edit').set_sensitive(False) self.builder.get_object('accounts_delete').set_sensitive(False) - def on_accounts_add_clicked(self, widget): + @maybe_coroutine + async def on_accounts_add_clicked(self, widget): dialog = AccountDialog( levels_mapping=client.auth_levels_mapping, parent=self.pref_dialog ) + response = await dialog.run() + if response != Gtk.ResponseType.OK: + return - def dialog_finished(response_id): - username = dialog.get_username() - password = dialog.get_password() - authlevel = dialog.get_authlevel() - - def add_ok(rv): - accounts_iter = self.accounts_liststore.append() - self.accounts_liststore.set_value( - accounts_iter, ACCOUNTS_USERNAME, username - ) - self.accounts_liststore.set_value( - accounts_iter, ACCOUNTS_LEVEL, authlevel - ) - self.accounts_liststore.set_value( - accounts_iter, ACCOUNTS_PASSWORD, password - ) - - def add_fail(failure): - if failure.type == AuthManagerError: - ErrorDialog( - _('Error Adding Account'), - _('Authentication failed'), - parent=self.pref_dialog, - details=failure.getErrorMessage(), - ).run() - else: - ErrorDialog( - _('Error Adding Account'), - _('An error occurred while adding account'), - parent=self.pref_dialog, - details=failure.getErrorMessage(), - ).run() - - if response_id == Gtk.ResponseType.OK: - client.core.create_account(username, password, authlevel).addCallback( - add_ok - ).addErrback(add_fail) - - dialog.run().addCallback(dialog_finished) + account = dialog.account + try: + await client.core.create_account(*account) + except AuthManagerError as ex: + return ErrorDialog( + _('Error Adding Account'), + _('Authentication failed'), + parent=self.pref_dialog, + details=ex, + ).run() + except Exception as ex: + return ErrorDialog( + _('Error Adding Account'), + _(f'An error occurred while adding account: {account}'), + parent=self.pref_dialog, + details=ex, + ).run() + + self.accounts_liststore.set( + self.accounts_liststore.append(), + [ACCOUNTS_USERNAME, ACCOUNTS_LEVEL, ACCOUNTS_PASSWORD], + [account.username, account.authlevel, account.password], + ) def on_accounts_edit_clicked(self, widget): (model, itr) = self.accounts_listview.get_selection().get_selected() diff --git a/deluge/ui/gtk3/queuedtorrents.py b/deluge/ui/gtk3/queuedtorrents.py index 0f08c24c6..6fdecec76 100644 --- a/deluge/ui/gtk3/queuedtorrents.py +++ b/deluge/ui/gtk3/queuedtorrents.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com> # @@ -7,8 +6,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging import os.path diff --git a/deluge/ui/gtk3/removetorrentdialog.py b/deluge/ui/gtk3/removetorrentdialog.py index 48806a5d5..06fca7704 100644 --- a/deluge/ui/gtk3/removetorrentdialog.py +++ b/deluge/ui/gtk3/removetorrentdialog.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007-2008 Andrew Resch <andrewresch@gmail.com> # @@ -7,8 +6,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging import os @@ -21,7 +18,7 @@ from deluge.ui.client import client log = logging.getLogger(__name__) -class RemoveTorrentDialog(object): +class RemoveTorrentDialog: """ This class is used to create and show a Remove Torrent Dialog. diff --git a/deluge/ui/gtk3/sidebar.py b/deluge/ui/gtk3/sidebar.py index 1d751918f..5a2b15466 100644 --- a/deluge/ui/gtk3/sidebar.py +++ b/deluge/ui/gtk3/sidebar.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com> # Copyright (C) 2008 Martijn Voncken <mvoncken@gmail.com> @@ -8,8 +7,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging from gi.repository.Gtk import Label, PolicyType, ScrolledWindow diff --git a/deluge/ui/gtk3/status_tab.py b/deluge/ui/gtk3/status_tab.py index 938c2dd7d..6a9010b6f 100644 --- a/deluge/ui/gtk3/status_tab.py +++ b/deluge/ui/gtk3/status_tab.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com> # @@ -7,8 +6,6 @@ # See LICENSE for more details. # -from __future__ import division, unicode_literals - import logging import deluge.component as component @@ -32,7 +29,7 @@ log = logging.getLogger(__name__) class StatusTab(Tab): def __init__(self): - super(StatusTab, self).__init__('Status', 'status_tab', 'status_tab_label') + super().__init__('Status', 'status_tab', 'status_tab_label') self.config = ConfigManager('gtk3ui.conf') diff --git a/deluge/ui/gtk3/statusbar.py b/deluge/ui/gtk3/statusbar.py index 18db753fa..0a2e80095 100644 --- a/deluge/ui/gtk3/statusbar.py +++ b/deluge/ui/gtk3/statusbar.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007-2008 Andrew Resch <andrewresch@gmail.com> # @@ -7,8 +6,6 @@ # See LICENSE for more details. # -from __future__ import division, unicode_literals - import logging from gi.repository import Gtk @@ -25,7 +22,7 @@ from .dialogs import OtherDialog log = logging.getLogger(__name__) -class StatusBarItem(object): +class StatusBarItem: def __init__( self, image=None, @@ -320,18 +317,22 @@ class StatusBar(component.Component): def send_status_request(self): # Sends an async request for data from the core keys = [ - 'num_peers', + 'peer.num_peers_connected', 'upload_rate', 'download_rate', 'payload_upload_rate', 'payload_download_rate', + 'net.sent_bytes', + 'net.recv_bytes', + 'net.sent_payload_bytes', + 'net.recv_payload_bytes', ] if self.dht_status: - keys.append('dht_nodes') + keys.append('dht.dht_nodes') if not self.health: - keys.append('has_incoming_connections') + keys.append('net.has_incoming_connections') client.core.get_session_status(keys).addCallback(self._on_get_session_status) client.core.get_free_space().addCallback(self._on_get_free_space) @@ -370,18 +371,18 @@ class StatusBar(component.Component): self.upload_protocol_rate = ( status['upload_rate'] - status['payload_upload_rate'] ) // 1024 - self.num_connections = status['num_peers'] + self.num_connections = status['peer.num_peers_connected'] self.update_download_label() self.update_upload_label() self.update_traffic_label() self.update_connections_label() - if 'dht_nodes' in status: - self.dht_nodes = status['dht_nodes'] + if 'dht.dht_nodes' in status: + self.dht_nodes = status['dht.dht_nodes'] self.update_dht_label() - if 'has_incoming_connections' in status: - self.health = status['has_incoming_connections'] + if 'net.has_incoming_connections' in status: + self.health = status['net.has_incoming_connections'] if self.health: self.remove_item(self.health_item) @@ -412,7 +413,7 @@ class StatusBar(component.Component): if self.max_connections_global < 0: label_string = '%s' % self.num_connections else: - label_string = '%s <small>(%s)</small>' % ( + label_string = '{} <small>({})</small>'.format( self.num_connections, self.max_connections_global, ) diff --git a/deluge/ui/gtk3/systemtray.py b/deluge/ui/gtk3/systemtray.py index a2435223b..f65fde590 100644 --- a/deluge/ui/gtk3/systemtray.py +++ b/deluge/ui/gtk3/systemtray.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007, 2008 Andrew Resch <andrewresch@gmail.com> # @@ -7,8 +6,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging import os @@ -238,13 +235,13 @@ class SystemTray(component.Component): if max_download_speed == -1: max_download_speed = _('Unlimited') else: - max_download_speed = '%s %s' % (max_download_speed, _('K/s')) + max_download_speed = '{} {}'.format(max_download_speed, _('K/s')) if max_upload_speed == -1: max_upload_speed = _('Unlimited') else: - max_upload_speed = '%s %s' % (max_upload_speed, _('K/s')) + max_upload_speed = '{} {}'.format(max_upload_speed, _('K/s')) - msg = '%s\n%s: %s (%s)\n%s: %s (%s)' % ( + msg = '{}\n{}: {} ({})\n{}: {} ({})'.format( _('Deluge'), _('Down'), self.download_rate, diff --git a/deluge/ui/gtk3/tab_data_funcs.py b/deluge/ui/gtk3/tab_data_funcs.py index 6fa0ba59c..a78994f69 100644 --- a/deluge/ui/gtk3/tab_data_funcs.py +++ b/deluge/ui/gtk3/tab_data_funcs.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007, 2008 Andrew Resch <andrewresch@gmail.com> # @@ -7,14 +6,12 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - from deluge.common import fdate, fsize, fspeed, ftime from deluge.ui.common import TRACKER_STATUS_TRANSLATION def ftotal_sized(first, second): - return '%s (%s)' % (fsize(first, shortform=True), fsize(second, shortform=True)) + return f'{fsize(first, shortform=True)} ({fsize(second, shortform=True)})' def fratio(value): @@ -24,7 +21,7 @@ def fratio(value): def fpcnt(value, state, message): state_i18n = _(state) if state not in ('Error', 'Seeding') and value < 100: - percent = '{:.2f}'.format(value).rstrip('0').rstrip('.') + percent = f'{value:.2f}'.rstrip('0').rstrip('.') return _('{state} {percent}%').format(state=state_i18n, percent=percent) elif state == 'Error': return _('{state}: {err_msg}').format(state=state_i18n, err_msg=message) @@ -34,7 +31,7 @@ def fpcnt(value, state, message): def fspeed_max(value, max_value=-1): value = fspeed(value, shortform=True) - return '%s (%s %s)' % (value, max_value, _('K/s')) if max_value > -1 else value + return '{} ({} {})'.format(value, max_value, _('K/s')) if max_value > -1 else value def fdate_or_never(value): @@ -73,7 +70,7 @@ def fseed_rank_or_dash(seed_rank, seeding_time): def fpieces_num_size(num_pieces, piece_size): - return '%s (%s)' % (num_pieces, fsize(piece_size, precision=0)) + return f'{num_pieces} ({fsize(piece_size, precision=0)})' def fcount(value): diff --git a/deluge/ui/gtk3/toolbar.py b/deluge/ui/gtk3/toolbar.py index 7bc029e4b..1b6952e74 100644 --- a/deluge/ui/gtk3/toolbar.py +++ b/deluge/ui/gtk3/toolbar.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007-2009 Andrew Resch <andrewresch@gmail.com> # @@ -7,8 +6,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging from gi.repository.Gtk import SeparatorToolItem, ToolButton diff --git a/deluge/ui/gtk3/torrentdetails.py b/deluge/ui/gtk3/torrentdetails.py index a586c2997..08c37a1de 100644 --- a/deluge/ui/gtk3/torrentdetails.py +++ b/deluge/ui/gtk3/torrentdetails.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007 Andrew Resch <andrewresch@gmail.com> # @@ -9,8 +8,6 @@ """The torrent details component shows info about the selected torrent.""" -from __future__ import unicode_literals - import logging from collections import namedtuple @@ -33,7 +30,7 @@ log = logging.getLogger(__name__) TabWidget = namedtuple('TabWidget', ('obj', 'func', 'status_keys')) -class Tab(object): +class Tab: def __init__(self, name=None, child_widget=None, tab_label=None): self._name = name self.is_visible = True diff --git a/deluge/ui/gtk3/torrentview.py b/deluge/ui/gtk3/torrentview.py index 3aee11e5c..16de16ea7 100644 --- a/deluge/ui/gtk3/torrentview.py +++ b/deluge/ui/gtk3/torrentview.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007, 2008 Andrew Resch <andrewresch@gmail.com> # @@ -8,8 +7,6 @@ # """The torrent view component that lists all torrents in the session.""" -from __future__ import unicode_literals - import logging from locale import strcoll @@ -77,13 +74,13 @@ def eta_column_sort(model, iter1, iter2, data): if v1 == v2: return 0 if v1 == 0: - return 1 - if v2 == 0: return -1 - if v1 > v2: + if v2 == 0: return 1 - if v2 > v1: + if v1 > v2: return -1 + if v2 > v1: + return 1 def seed_peer_column_sort(model, iter1, iter2, data): @@ -107,7 +104,7 @@ def progress_sort(model, iter1, iter2, sort_column_id): return cmp(progress1, progress2) -class SearchBox(object): +class SearchBox: def __init__(self, torrentview): self.torrentview = torrentview mainwindow = component.get('MainWindow') diff --git a/deluge/ui/gtk3/torrentview_data_funcs.py b/deluge/ui/gtk3/torrentview_data_funcs.py index 8bd1f9c51..0b2545d8c 100644 --- a/deluge/ui/gtk3/torrentview_data_funcs.py +++ b/deluge/ui/gtk3/torrentview_data_funcs.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2007, 2008 Andrew Resch <andrewresch@gmail.com> # @@ -7,8 +6,6 @@ # See LICENSE for more details. # -from __future__ import print_function, unicode_literals - import warnings from functools import partial @@ -17,7 +14,7 @@ import deluge.component as component from .common import ( create_blank_pixbuf, - get_pixbuf_at_size, + get_pixbuf, icon_alert, icon_checking, icon_downloading, @@ -42,7 +39,6 @@ ICON_STATE = { # renderer. This is much cheaper than fetch the current value and test if # it's equal. func_last_value = { - 'cell_data_time': None, 'cell_data_ratio_seeds_peers': None, 'cell_data_ratio_ratio': None, 'cell_data_ratio_avail': None, @@ -86,7 +82,7 @@ def set_tracker_icon(tracker_icon, cell): if tracker_icon: pixbuf = tracker_icon.get_cached_icon() if pixbuf is None: - pixbuf = get_pixbuf_at_size(tracker_icon.get_filename(), 16) + pixbuf = get_pixbuf(tracker_icon.get_filename(), 16) tracker_icon.set_cached_icon(pixbuf) else: pixbuf = create_blank_pixbuf() @@ -162,7 +158,7 @@ def cell_data_speed(cell, model, row, data): if speed > 0: speed_str = common.fspeed(speed, shortform=True) cell.set_property( - 'markup', '{0} <small>{1}</small>'.format(*tuple(speed_str.split())) + 'markup', '{} <small>{}</small>'.format(*tuple(speed_str.split())) ) else: cell.set_property('text', '') @@ -189,7 +185,7 @@ def cell_data_speed_limit(cell, model, row, data, cache_key): if speed > 0: speed_str = common.fspeed(speed * 1024, shortform=True) cell.set_property( - 'markup', '{0} <small>{1}</small>'.format(*tuple(speed_str.split())) + 'markup', '{} <small>{}</small>'.format(*tuple(speed_str.split())) ) else: cell.set_property('text', '') @@ -222,10 +218,6 @@ def cell_data_peer(column, cell, model, row, data): def cell_data_time(column, cell, model, row, data): """Display value as time, eg 1m10s""" time = model.get_value(row, data) - if func_last_value['cell_data_time'] == time: - return - func_last_value['cell_data_time'] = time - if time <= 0: time_str = '' else: diff --git a/deluge/ui/gtk3/trackers_tab.py b/deluge/ui/gtk3/trackers_tab.py index d83b9956c..d671471b0 100644 --- a/deluge/ui/gtk3/trackers_tab.py +++ b/deluge/ui/gtk3/trackers_tab.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # Copyright (C) 2008 Andrew Resch <andrewresch@gmail.com> # @@ -7,8 +6,6 @@ # See LICENSE for more details. # -from __future__ import unicode_literals - import logging import deluge.component as component @@ -22,9 +19,7 @@ log = logging.getLogger(__name__) class TrackersTab(Tab): def __init__(self): - super(TrackersTab, self).__init__( - 'Trackers', 'trackers_tab', 'trackers_tab_label' - ) + super().__init__('Trackers', 'trackers_tab', 'trackers_tab_label') self.add_tab_widget('summary_next_announce', ftime, ('next_announce',)) self.add_tab_widget('summary_tracker', None, ('tracker_host',)) |