cq: Format with black and isort
This commit is contained in:
@@ -20,41 +20,31 @@ import time
|
||||
from gi.repository import Gtk
|
||||
|
||||
from gajim.common import app
|
||||
|
||||
from gajim.gtk.dialogs import ConfirmationDialog
|
||||
from gajim.gtk.dialogs import DialogButton
|
||||
from gajim.plugins.plugins_i18n import _
|
||||
|
||||
from openpgp.modules.util import Trust
|
||||
|
||||
log = logging.getLogger('gajim.p.openpgp.keydialog')
|
||||
log = logging.getLogger("gajim.p.openpgp.keydialog")
|
||||
|
||||
TRUST_DATA = {
|
||||
Trust.NOT_TRUSTED: ('dialog-error-symbolic',
|
||||
_('Not Trusted'),
|
||||
'error-color'),
|
||||
Trust.UNKNOWN: ('security-low-symbolic',
|
||||
_('Not Decided'),
|
||||
'warning-color'),
|
||||
Trust.BLIND: ('security-medium-symbolic',
|
||||
_('Blind Trust'),
|
||||
'encrypted-color'),
|
||||
Trust.VERIFIED: ('security-high-symbolic',
|
||||
_('Verified'),
|
||||
'encrypted-color')
|
||||
Trust.NOT_TRUSTED: ("dialog-error-symbolic", _("Not Trusted"), "error-color"),
|
||||
Trust.UNKNOWN: ("security-low-symbolic", _("Not Decided"), "warning-color"),
|
||||
Trust.BLIND: ("security-medium-symbolic", _("Blind Trust"), "encrypted-color"),
|
||||
Trust.VERIFIED: ("security-high-symbolic", _("Verified"), "encrypted-color"),
|
||||
}
|
||||
|
||||
|
||||
class KeyDialog(Gtk.Dialog):
|
||||
def __init__(self, account, jid, transient):
|
||||
super().__init__(title=_('Public Keys for %s') % jid,
|
||||
destroy_with_parent=True)
|
||||
super().__init__(title=_("Public Keys for %s") % jid, destroy_with_parent=True)
|
||||
|
||||
self.set_transient_for(transient)
|
||||
self.set_resizable(True)
|
||||
self.set_default_size(500, 300)
|
||||
|
||||
self.get_style_context().add_class('openpgp-key-dialog')
|
||||
self.get_style_context().add_class("openpgp-key-dialog")
|
||||
|
||||
self._client = app.get_client(account)
|
||||
|
||||
@@ -62,17 +52,15 @@ class KeyDialog(Gtk.Dialog):
|
||||
self._listbox.set_selection_mode(Gtk.SelectionMode.NONE)
|
||||
|
||||
self._scrolled = Gtk.ScrolledWindow()
|
||||
self._scrolled.set_policy(Gtk.PolicyType.NEVER,
|
||||
Gtk.PolicyType.AUTOMATIC)
|
||||
self._scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
|
||||
self._scrolled.add(self._listbox)
|
||||
|
||||
box = self.get_content_area()
|
||||
box.pack_start(self._scrolled, True, True, 0)
|
||||
|
||||
keys = self._client.get_module('OpenPGP').get_keys(
|
||||
jid, only_trusted=False)
|
||||
keys = self._client.get_module("OpenPGP").get_keys(jid, only_trusted=False)
|
||||
for key in keys:
|
||||
log.info('Load: %s', key.fingerprint)
|
||||
log.info("Load: %s", key.fingerprint)
|
||||
self._listbox.add(KeyRow(key))
|
||||
self.show_all()
|
||||
|
||||
@@ -92,11 +80,10 @@ class KeyRow(Gtk.ListBoxRow):
|
||||
box.add(self._trust_button)
|
||||
|
||||
label_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
|
||||
fingerprint = Gtk.Label(
|
||||
label=self._format_fingerprint(key.fingerprint))
|
||||
fingerprint.get_style_context().add_class('openpgp-mono')
|
||||
fingerprint = Gtk.Label(label=self._format_fingerprint(key.fingerprint))
|
||||
fingerprint.get_style_context().add_class("openpgp-mono")
|
||||
if not key.active:
|
||||
fingerprint.get_style_context().add_class('openpgp-inactive-color')
|
||||
fingerprint.get_style_context().add_class("openpgp-inactive-color")
|
||||
fingerprint.set_selectable(True)
|
||||
fingerprint.set_halign(Gtk.Align.START)
|
||||
fingerprint.set_valign(Gtk.Align.START)
|
||||
@@ -105,9 +92,9 @@ class KeyRow(Gtk.ListBoxRow):
|
||||
|
||||
date = Gtk.Label(label=self._format_timestamp(key.timestamp))
|
||||
date.set_halign(Gtk.Align.START)
|
||||
date.get_style_context().add_class('openpgp-mono')
|
||||
date.get_style_context().add_class("openpgp-mono")
|
||||
if not key.active:
|
||||
date.get_style_context().add_class('openpgp-inactive-color')
|
||||
date.get_style_context().add_class("openpgp-inactive-color")
|
||||
label_box.add(date)
|
||||
|
||||
box.add(label_box)
|
||||
@@ -122,12 +109,12 @@ class KeyRow(Gtk.ListBoxRow):
|
||||
self.destroy()
|
||||
|
||||
ConfirmationDialog(
|
||||
_('Delete Public Key?'),
|
||||
_('This will permanently delete this public key'),
|
||||
[DialogButton.make('Cancel'),
|
||||
DialogButton.make('Remove',
|
||||
text=_('Delete'),
|
||||
callback=_remove)],
|
||||
_("Delete Public Key?"),
|
||||
_("This will permanently delete this public key"),
|
||||
[
|
||||
DialogButton.make("Cancel"),
|
||||
DialogButton.make("Remove", text=_("Delete"), callback=_remove),
|
||||
],
|
||||
).show()
|
||||
|
||||
def set_trust(self, trust):
|
||||
@@ -140,22 +127,21 @@ class KeyRow(Gtk.ListBoxRow):
|
||||
def _format_fingerprint(fingerprint):
|
||||
fplen = len(fingerprint)
|
||||
wordsize = fplen // 8
|
||||
buf = ''
|
||||
buf = ""
|
||||
for w in range(0, fplen, wordsize):
|
||||
buf += '{0} '.format(fingerprint[w:w + wordsize])
|
||||
buf += "{0} ".format(fingerprint[w : w + wordsize])
|
||||
return buf.rstrip()
|
||||
|
||||
@staticmethod
|
||||
def _format_timestamp(timestamp):
|
||||
return time.strftime('%Y-%m-%d %H:%M:%S',
|
||||
time.localtime(timestamp))
|
||||
return time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(timestamp))
|
||||
|
||||
|
||||
class TrustButton(Gtk.MenuButton):
|
||||
def __init__(self, row):
|
||||
Gtk.MenuButton.__init__(self)
|
||||
self._row = row
|
||||
self._css_class = ''
|
||||
self._css_class = ""
|
||||
self.set_popover(TrustPopver(row))
|
||||
self.update()
|
||||
|
||||
@@ -167,8 +153,8 @@ class TrustButton(Gtk.MenuButton):
|
||||
image.get_style_context().remove_class(self._css_class)
|
||||
|
||||
if not self._row.key.active:
|
||||
css_class = 'openpgp-inactive-color'
|
||||
tooltip = '%s - %s' % (_('Inactive'), tooltip)
|
||||
css_class = "openpgp-inactive-color"
|
||||
tooltip = "%s - %s" % (_("Inactive"), tooltip)
|
||||
|
||||
image.get_style_context().add_class(css_class)
|
||||
self._css_class = css_class
|
||||
@@ -188,8 +174,8 @@ class TrustPopver(Gtk.Popover):
|
||||
self._listbox.add(DeleteOption())
|
||||
self.add(self._listbox)
|
||||
self._listbox.show_all()
|
||||
self._listbox.connect('row-activated', self._activated)
|
||||
self.get_style_context().add_class('openpgp-trust-popover')
|
||||
self._listbox.connect("row-activated", self._activated)
|
||||
self.get_style_context().add_class("openpgp-trust-popover")
|
||||
|
||||
def _activated(self, listbox, row):
|
||||
self.popdown()
|
||||
@@ -215,8 +201,7 @@ class MenuOption(Gtk.ListBoxRow):
|
||||
box = Gtk.Box()
|
||||
box.set_spacing(6)
|
||||
|
||||
image = Gtk.Image.new_from_icon_name(self.icon,
|
||||
Gtk.IconSize.MENU)
|
||||
image = Gtk.Image.new_from_icon_name(self.icon, Gtk.IconSize.MENU)
|
||||
label = Gtk.Label(label=self.label)
|
||||
image.get_style_context().add_class(self.color)
|
||||
|
||||
@@ -229,9 +214,9 @@ class MenuOption(Gtk.ListBoxRow):
|
||||
class VerifiedOption(MenuOption):
|
||||
|
||||
type_ = Trust.VERIFIED
|
||||
icon = 'security-high-symbolic'
|
||||
label = _('Verified')
|
||||
color = 'encrypted-color'
|
||||
icon = "security-high-symbolic"
|
||||
label = _("Verified")
|
||||
color = "encrypted-color"
|
||||
|
||||
def __init__(self):
|
||||
MenuOption.__init__(self)
|
||||
@@ -240,9 +225,9 @@ class VerifiedOption(MenuOption):
|
||||
class NotTrustedOption(MenuOption):
|
||||
|
||||
type_ = Trust.NOT_TRUSTED
|
||||
icon = 'dialog-error-symbolic'
|
||||
label = _('Not Trusted')
|
||||
color = 'error-color'
|
||||
icon = "dialog-error-symbolic"
|
||||
label = _("Not Trusted")
|
||||
color = "error-color"
|
||||
|
||||
def __init__(self):
|
||||
MenuOption.__init__(self)
|
||||
@@ -251,9 +236,9 @@ class NotTrustedOption(MenuOption):
|
||||
class DeleteOption(MenuOption):
|
||||
|
||||
type_ = None
|
||||
icon = 'user-trash-symbolic'
|
||||
label = _('Delete')
|
||||
color = ''
|
||||
icon = "user-trash-symbolic"
|
||||
label = _("Delete")
|
||||
color = ""
|
||||
|
||||
def __init__(self):
|
||||
MenuOption.__init__(self)
|
||||
|
||||
Reference in New Issue
Block a user