Browse Source

Fix PEP 8 errors

Piotr Orzechowski 1 year 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
24 24
 import argparse
25 25
 import ctypes
26 26
 import gettext
27
+import gi
27 28
 import locale
28 29
 import os
29 30
 import platform
30 31
 import sys
31 32
 
32
-from os import path
33
-from os.path import abspath
34
-from os.path import dirname
35
-from os.path import join
36
-
37 33
 from abc import ABCMeta
38 34
 from abc import abstractmethod
39
-
35
+from gi.repository import GObject
36
+from gi.repository import Gtk
40 37
 from hashlib import md5
41 38
 from hashlib import sha1
42 39
 from hashlib import sha224
43 40
 from hashlib import sha256
44 41
 from hashlib import sha384
45 42
 from hashlib import sha512
46
-
43
+from os import path
44
+from os.path import abspath
45
+from os.path import dirname
46
+from os.path import join
47 47
 from threading import Thread
48 48
 
49
-import gi
50
-
51 49
 gi.require_version('Gtk', '3.0')
52 50
 
53
-from gi.repository import GObject
54
-from gi.repository import Gtk
55
-
56 51
 APP = 'gsummer'
57 52
 ROOT_DIR = abspath(dirname(__file__))
58 53
 LOCALE_DIR = join(ROOT_DIR, 'locale')
@@ -79,23 +74,21 @@ except (OSError, AttributeError) as e:
79 74
 else:
80 75
     gettext.install(APP, LOCALE_DIR)
81 76
 
77
+
82 78
 class CheckSumThreadListener(metaclass=ABCMeta):
83 79
 
84 80
     @abstractmethod
85 81
     def on_fraction_calculated(self, fraction):
86 82
         pass
87 83
 
88
-
89 84
     @abstractmethod
90 85
     def on_calculation_finished(self, checksum):
91 86
         pass
92 87
 
93
-
94 88
     @abstractmethod
95 89
     def on_calculation_cancelled(self):
96 90
         pass
97 91
 
98
-
99 92
     @abstractmethod
100 93
     def on_calculation_exception(self, exception):
101 94
         pass
@@ -110,11 +103,9 @@ class CheckSumThread(Thread):
110 103
         self._method = method
111 104
         self._listener = listener
112 105
 
113
-
114 106
     def stop(self):
115 107
         self._stopped = True
116 108
 
117
-
118 109
     def run(self):
119 110
         try:
120 111
             with open(self._file_name, 'rb') as file:
@@ -154,7 +145,6 @@ class MainController(CheckSumThreadListener):
154 145
         self.setup_ui()
155 146
         self.setup_connections(builder)
156 147
 
157
-
158 148
     def load_ui(self, builder):
159 149
         self._window = builder.get_object('main_window')
160 150
         self._file_chooser = builder.get_object('file_chooser')
@@ -170,13 +160,11 @@ class MainController(CheckSumThreadListener):
170 160
         self._verify_icon = builder.get_object('verify_icon')
171 161
         self._cancel_icon = builder.get_object('cancel_icon')
172 162
 
173
-
174 163
     def setup_ui(self):
175 164
         self._file_chooser.set_local_only(True)
176 165
         self._combo_box.set_active(3)
177 166
         self._about_dialog.set_transient_for(self._window)
178 167
 
179
-
180 168
     def setup_connections(self, builder):
181 169
         handlers = {
182 170
             'on_main_window_delete_event': self.quit,
@@ -187,9 +175,7 @@ class MainController(CheckSumThreadListener):
187 175
         }
188 176
         builder.connect_signals(handlers)
189 177
 
190
-        self._verify_cancel_handler = self._verify_cancel_button.connect('clicked',
191
-                                                                  self.start_verification)
192
-
178
+        self._verify_cancel_handler = self._verify_cancel_button.connect('clicked', self.start_verification)
193 179
 
194 180
     def show(self, args):
195 181
         if len(args.file):
@@ -197,7 +183,6 @@ class MainController(CheckSumThreadListener):
197 183
             self._verify_cancel_button.set_sensitive(True)
198 184
         self._window.show_all()
199 185
 
200
-
201 186
     def reset(self, widget):
202 187
         self._verify_cancel_button.set_sensitive(False)
203 188
         self._file_chooser.unselect_all()
@@ -205,12 +190,10 @@ class MainController(CheckSumThreadListener):
205 190
         self._progress_bar.set_fraction(0.0)
206 191
         self._status_bar.set_markup('')
207 192
 
208
-
209 193
     def show_about_dialog(self, widget):
210 194
         self._about_dialog.run()
211 195
         self._about_dialog.hide()
212 196
 
213
-
214 197
     def start_verification(self, widget):
215 198
         self.set_cancel_action()
216 199
         self._status_bar.set_markup('')
@@ -223,7 +206,6 @@ class MainController(CheckSumThreadListener):
223 206
         self._thread = CheckSumThread(self._file_chooser.get_filename(), self.get_algorithm(), self)
224 207
         self._thread.start()
225 208
 
226
-
227 209
     def cancel_verification(self, widget):
228 210
         self._thread.stop()
229 211
         self._thread.join()
@@ -235,7 +217,6 @@ class MainController(CheckSumThreadListener):
235 217
         self._new_main_menu_item.set_sensitive(True)
236 218
         self.set_verify_action()
237 219
 
238
-
239 220
     def get_algorithm(self):
240 221
         options = {
241 222
             0: md5(),
@@ -247,33 +228,27 @@ class MainController(CheckSumThreadListener):
247 228
         }
248 229
         return options[self._combo_box.get_active()]
249 230
 
250
-
251 231
     def on_fraction_calculated(self, fraction):
252 232
         GObject.idle_add(self._progress_bar.set_fraction, fraction)
253 233
 
254
-
255 234
     def on_calculation_finished(self, checksum):
256 235
         GObject.idle_add(self.show_results, checksum)
257 236
 
258
-
259 237
     def on_calculation_cancelled(self):
260 238
         GObject.idle_add(self._progress_bar.set_fraction, 0.0)
261 239
 
262
-
263 240
     def on_calculation_exception(self, exception):
264 241
         GObject.idle_add(self.show_exception, exception)
265 242
 
266
-
267 243
     def on_file_set(self, file):
268 244
         self._verify_cancel_button.set_sensitive(True)
269 245
 
270
-
271 246
     def show_results(self, checksum):
272 247
         if (checksum == self._entry.get_text()):
273
-            self._status_bar.set_markup('<span foreground=\"darkgreen\">' + \
248
+            self._status_bar.set_markup('<span foreground=\"darkgreen\">' +
274 249
                                         _('Checksums are equal') + '</span>')
275 250
         else:
276
-            self._status_bar.set_markup('<span foreground=\"red\">' + \
251
+            self._status_bar.set_markup('<span foreground=\"red\">' +
277 252
                                         _('Checksums ARE NOT equal') + '</span>')
278 253
 
279 254
         self._progress_bar.set_fraction(1)
@@ -283,7 +258,6 @@ class MainController(CheckSumThreadListener):
283 258
         self._new_main_menu_item.set_sensitive(True)
284 259
         self.set_verify_action()
285 260
 
286
-
287 261
     def show_exception(self, exception):
288 262
         self._status_bar.set_markup('<span foreground=\"red\">' + str(exception) + '</span>')
289 263
         self._progress_bar.set_fraction(1)
@@ -293,7 +267,6 @@ class MainController(CheckSumThreadListener):
293 267
         self._new_main_menu_item.set_sensitive(True)
294 268
         self.set_verify_action()
295 269
 
296
-
297 270
     def set_verify_action(self):
298 271
         self._verify_cancel_button.disconnect(self._verify_cancel_handler)
299 272
         self._verify_cancel_button.set_label(_('_Verify'))
@@ -302,7 +275,6 @@ class MainController(CheckSumThreadListener):
302 275
         self._verify_cancel_handler = self._verify_cancel_button.connect('clicked',
303 276
                                                                          self.start_verification)
304 277
 
305
-
306 278
     def set_cancel_action(self):
307 279
         self._verify_cancel_button.disconnect(self._verify_cancel_handler)
308 280
         self._verify_cancel_button.set_label(_('_Cancel'))
@@ -311,9 +283,8 @@ class MainController(CheckSumThreadListener):
311 283
         self._verify_cancel_handler = self._verify_cancel_button.connect('clicked',
312 284
                                                                          self.cancel_verification)
313 285
 
314
-
315 286
     def quit(self, *args):
316
-        if (self._thread != None):
287
+        if (self._thread is not None):
317 288
             self._thread.stop()
318 289
             self._thread.join()
319 290
             self._thread = None

Loading…
Cancel
Save