Browse Source

Fix PEP 8 errors

master
Piotr Orzechowski 2 years ago
parent
commit
7785b28f45
1 changed files with 12 additions and 41 deletions
  1. 12
    41
      src/gsummer.py

+ 12
- 41
src/gsummer.py View File

@@ -24,35 +24,30 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import argparse
import ctypes
import gettext
import gi
import locale
import os
import platform
import sys

from os import path
from os.path import abspath
from os.path import dirname
from os.path import join

from abc import ABCMeta
from abc import abstractmethod

from gi.repository import GObject
from gi.repository import Gtk
from hashlib import md5
from hashlib import sha1
from hashlib import sha224
from hashlib import sha256
from hashlib import sha384
from hashlib import sha512

from os import path
from os.path import abspath
from os.path import dirname
from os.path import join
from threading import Thread

import gi

gi.require_version('Gtk', '3.0')

from gi.repository import GObject
from gi.repository import Gtk

APP = 'gsummer'
ROOT_DIR = abspath(dirname(__file__))
LOCALE_DIR = join(ROOT_DIR, 'locale')
@@ -79,23 +74,21 @@ except (OSError, AttributeError) as e:
else:
gettext.install(APP, LOCALE_DIR)


class CheckSumThreadListener(metaclass=ABCMeta):

@abstractmethod
def on_fraction_calculated(self, fraction):
pass


@abstractmethod
def on_calculation_finished(self, checksum):
pass


@abstractmethod
def on_calculation_cancelled(self):
pass


@abstractmethod
def on_calculation_exception(self, exception):
pass
@@ -110,11 +103,9 @@ class CheckSumThread(Thread):
self._method = method
self._listener = listener


def stop(self):
self._stopped = True


def run(self):
try:
with open(self._file_name, 'rb') as file:
@@ -154,7 +145,6 @@ class MainController(CheckSumThreadListener):
self.setup_ui()
self.setup_connections(builder)


def load_ui(self, builder):
self._window = builder.get_object('main_window')
self._file_chooser = builder.get_object('file_chooser')
@@ -170,13 +160,11 @@ class MainController(CheckSumThreadListener):
self._verify_icon = builder.get_object('verify_icon')
self._cancel_icon = builder.get_object('cancel_icon')


def setup_ui(self):
self._file_chooser.set_local_only(True)
self._combo_box.set_active(3)
self._about_dialog.set_transient_for(self._window)


def setup_connections(self, builder):
handlers = {
'on_main_window_delete_event': self.quit,
@@ -187,9 +175,7 @@ class MainController(CheckSumThreadListener):
}
builder.connect_signals(handlers)

self._verify_cancel_handler = self._verify_cancel_button.connect('clicked',
self.start_verification)

self._verify_cancel_handler = self._verify_cancel_button.connect('clicked', self.start_verification)

def show(self, args):
if len(args.file):
@@ -197,7 +183,6 @@ class MainController(CheckSumThreadListener):
self._verify_cancel_button.set_sensitive(True)
self._window.show_all()


def reset(self, widget):
self._verify_cancel_button.set_sensitive(False)
self._file_chooser.unselect_all()
@@ -205,12 +190,10 @@ class MainController(CheckSumThreadListener):
self._progress_bar.set_fraction(0.0)
self._status_bar.set_markup('')


def show_about_dialog(self, widget):
self._about_dialog.run()
self._about_dialog.hide()


def start_verification(self, widget):
self.set_cancel_action()
self._status_bar.set_markup('')
@@ -223,7 +206,6 @@ class MainController(CheckSumThreadListener):
self._thread = CheckSumThread(self._file_chooser.get_filename(), self.get_algorithm(), self)
self._thread.start()


def cancel_verification(self, widget):
self._thread.stop()
self._thread.join()
@@ -235,7 +217,6 @@ class MainController(CheckSumThreadListener):
self._new_main_menu_item.set_sensitive(True)
self.set_verify_action()


def get_algorithm(self):
options = {
0: md5(),
@@ -247,33 +228,27 @@ class MainController(CheckSumThreadListener):
}
return options[self._combo_box.get_active()]


def on_fraction_calculated(self, fraction):
GObject.idle_add(self._progress_bar.set_fraction, fraction)


def on_calculation_finished(self, checksum):
GObject.idle_add(self.show_results, checksum)


def on_calculation_cancelled(self):
GObject.idle_add(self._progress_bar.set_fraction, 0.0)


def on_calculation_exception(self, exception):
GObject.idle_add(self.show_exception, exception)


def on_file_set(self, file):
self._verify_cancel_button.set_sensitive(True)


def show_results(self, checksum):
if (checksum == self._entry.get_text()):
self._status_bar.set_markup('<span foreground=\"darkgreen\">' + \
self._status_bar.set_markup('<span foreground=\"darkgreen\">' +
_('Checksums are equal') + '</span>')
else:
self._status_bar.set_markup('<span foreground=\"red\">' + \
self._status_bar.set_markup('<span foreground=\"red\">' +
_('Checksums ARE NOT equal') + '</span>')

self._progress_bar.set_fraction(1)
@@ -283,7 +258,6 @@ class MainController(CheckSumThreadListener):
self._new_main_menu_item.set_sensitive(True)
self.set_verify_action()


def show_exception(self, exception):
self._status_bar.set_markup('<span foreground=\"red\">' + str(exception) + '</span>')
self._progress_bar.set_fraction(1)
@@ -293,7 +267,6 @@ class MainController(CheckSumThreadListener):
self._new_main_menu_item.set_sensitive(True)
self.set_verify_action()


def set_verify_action(self):
self._verify_cancel_button.disconnect(self._verify_cancel_handler)
self._verify_cancel_button.set_label(_('_Verify'))
@@ -302,7 +275,6 @@ class MainController(CheckSumThreadListener):
self._verify_cancel_handler = self._verify_cancel_button.connect('clicked',
self.start_verification)


def set_cancel_action(self):
self._verify_cancel_button.disconnect(self._verify_cancel_handler)
self._verify_cancel_button.set_label(_('_Cancel'))
@@ -311,9 +283,8 @@ class MainController(CheckSumThreadListener):
self._verify_cancel_handler = self._verify_cancel_button.connect('clicked',
self.cancel_verification)


def quit(self, *args):
if (self._thread != None):
if (self._thread is not None):
self._thread.stop()
self._thread.join()
self._thread = None

Loading…
Cancel
Save