Skip to content

Commit 780177c

Browse files
cdhornNick-Hall
authored andcommitted
Some pylint cleanups for gramps/gen/plug/*.py
1 parent 0e626b6 commit 780177c

File tree

6 files changed

+271
-260
lines changed

6 files changed

+271
-260
lines changed

gramps/gen/plug/_gramplet.py

+49-37
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
2020
#
2121

22+
"""
23+
Base class for Gramplet plugins
24+
"""
25+
2226
# -------------------------------------------------------------------------
2327
#
2428
# Python modules
@@ -27,8 +31,6 @@
2731
import types
2832
import logging
2933

30-
LOG = logging.getLogger(".Gramplets")
31-
3234
# ------------------------------------------------------------------------
3335
#
3436
# Gramps modules
@@ -37,9 +39,16 @@
3739
from ...gui.dbguielement import DbGUIElement
3840
from ..const import GRAMPS_LOCALE as glocale
3941

42+
LOG = logging.getLogger(".Gramplets")
43+
4044
_ = glocale.translation.gettext
4145

4246

47+
# ------------------------------------------------------------------------
48+
#
49+
# Gramplet class
50+
#
51+
# ------------------------------------------------------------------------
4352
class Gramplet:
4453
"""
4554
Base class for non-graphical gramplet code.
@@ -94,17 +103,17 @@ def init(self): # once, constructor
94103
External constructor for developers to put their initialization
95104
code. Designed to be overridden.
96105
"""
97-
pass
98106

99107
def post_init(self):
100-
pass
108+
"""
109+
Another for developers to hook into post initialization phase.
110+
"""
101111

102112
def build_options(self):
103113
"""
104114
External constructor for developers to put code for building
105115
options.
106116
"""
107-
pass
108117

109118
def main(self): # return false finishes
110119
"""
@@ -118,14 +127,12 @@ def on_load(self):
118127
Gramplets should override this to take care of loading previously
119128
their special data.
120129
"""
121-
pass
122130

123131
def on_save(self):
124132
"""
125133
Gramplets should override this to take care of saving their
126134
special data.
127135
"""
128-
return
129136

130137
def get_active(self, nav_type):
131138
"""
@@ -138,7 +145,7 @@ def get_active_object(self, nav_type):
138145
Return the object of the active handle for the given navigation type.
139146
"""
140147
handle = self.uistate.get_active(nav_type, self.nav_group)
141-
handle_func = getattr(self.dbstate.db, "get_%s_from_handle" % nav_type.lower())
148+
handle_func = getattr(self.dbstate.db, f"get_{nav_type.lower()}_from_handle")
142149
if handle:
143150
return handle_func(handle)
144151
return None
@@ -154,7 +161,6 @@ def active_changed(self, handle):
154161
Developers should put their code that occurs when the active
155162
person is changed.
156163
"""
157-
pass
158164

159165
def _active_changed(self, handle):
160166
"""
@@ -166,7 +172,6 @@ def db_changed(self):
166172
"""
167173
Method executed when the database is changed.
168174
"""
169-
pass
170175

171176
def link(self, text, link_type, data, size=None, tooltip=None):
172177
"""
@@ -260,7 +265,7 @@ def set_wrap(self, value):
260265
textview.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)
261266
else:
262267
raise ValueError(
263-
"Unknown wrap mode: '%s': use 0,1,'char' or 'word char')" % value
268+
f"Unknown wrap mode: '{value}': use 0,1,'char' or 'word char')"
264269
)
265270

266271
def no_wrap(self):
@@ -290,7 +295,7 @@ def save_text_to_data(self):
290295
text = text.replace(chr(10), "\\n")
291296
self.gui.data.append(text)
292297

293-
def update(self, *args):
298+
def update(self, *_):
294299
"""
295300
The main interface for running the :meth:`main` method.
296301
"""
@@ -306,7 +311,7 @@ def update(self, *args):
306311
return
307312
# print " %s is UPDATING" % self.gui.gname
308313
self.dirty = False
309-
LOG.debug("gramplet updater: %s: running" % self.gui.title)
314+
LOG.debug("gramplet updater: %s: running", self.gui.title)
310315
if self._idle_id != 0:
311316
self.interrupt()
312317
self._generator = self.main()
@@ -317,29 +322,29 @@ def _updater(self):
317322
"""
318323
Runs the generator.
319324
"""
320-
LOG.debug("gramplet updater: %s" % self.gui.title)
325+
LOG.debug("gramplet updater: %s", self.gui.title)
321326
if not isinstance(self._generator, types.GeneratorType):
322327
self._idle_id = 0
323-
LOG.debug("gramplet updater: %s : One time, done!" % self.gui.title)
328+
LOG.debug("gramplet updater: %s : One time, done!", self.gui.title)
324329
return False
325330
try:
326331
retval = next(self._generator)
327332
if not retval:
328333
self._idle_id = 0
329334
if self._pause:
330-
LOG.debug("gramplet updater: %s: return False" % self.gui.title)
335+
LOG.debug("gramplet updater: %s: return False", self.gui.title)
331336
return False
332-
LOG.debug("gramplet updater: %s: return %s" % (self.gui.title, retval))
337+
LOG.debug("gramplet updater: %s: return %s", self.gui.title, retval)
333338
return retval
334339
except StopIteration:
335340
self._idle_id = 0
336341
self._generator.close()
337-
LOG.debug("gramplet updater: %s: Done!" % self.gui.title)
342+
LOG.debug("gramplet updater: %s: Done!", self.gui.title)
338343
return False
339-
except Exception as e:
344+
except Exception:
340345
import traceback
341346

342-
LOG.warning("Gramplet gave an error: %s" % self.gui.title)
347+
LOG.warning("Gramplet gave an error: %s", self.gui.title)
343348
traceback.print_exc()
344349
print("Continuing after gramplet error...")
345350
self._idle_id = 0
@@ -348,13 +353,13 @@ def _updater(self):
348353
)
349354
return False
350355

351-
def pause(self, *args):
356+
def pause(self, *_):
352357
"""
353358
Pause the :meth:`main` method.
354359
"""
355360
self._pause = True
356361

357-
def resume(self, *args):
362+
def resume(self, *_):
358363
"""
359364
Resume the :meth:`main` method that has previously paused.
360365
"""
@@ -363,17 +368,17 @@ def resume(self, *args):
363368
self._pause = False
364369
self._idle_id = GLib.idle_add(self._updater, priority=GLib.PRIORITY_LOW - 10)
365370

366-
def update_all(self, *args):
371+
def update_all(self, *_):
367372
"""
368373
Force the main loop to run right now (as opposed to running in
369374
background).
370375
"""
371376
self._generator = self.main()
372377
if isinstance(self._generator, types.GeneratorType):
373-
for step in self._generator:
378+
for _ in self._generator:
374379
pass
375380

376-
def interrupt(self, *args):
381+
def interrupt(self, *_):
377382
"""
378383
Force the generator to stop running.
379384
"""
@@ -421,15 +426,15 @@ def get_option_widget(self, label):
421426

422427
def get_option(self, label):
423428
"""
424-
Retireve an option by its label text.
429+
Retrieve an option by its label text.
425430
"""
426431
return self.option_dict[label][1]
427432

428433
def add_option(self, option):
429434
"""
430435
Add an option to the GUI gramplet.
431436
"""
432-
widget, label = self.gui.add_gui_option(option)
437+
widget, _ = self.gui.add_gui_option(option)
433438
self.option_dict.update({option.get_label(): [widget, option]})
434439
self.option_order.append(option.get_label())
435440

@@ -441,29 +446,37 @@ def save_update_options(self, obj):
441446
self.update()
442447

443448
def save_options(self):
444-
pass
449+
"""
450+
Save a gramplet's options.
451+
"""
445452

446453
def connect(self, signal_obj, signal, method):
447-
id = signal_obj.connect(signal, method)
454+
"""
455+
Connect signals.
456+
"""
457+
signal_id = signal_obj.connect(signal, method)
448458
signal_list = self._signal.get(signal, [])
449-
signal_list.append((id, signal_obj))
459+
signal_list.append((signal_id, signal_obj))
450460
self._signal[signal] = signal_list
451461

452462
def disconnect(self, signal):
463+
"""
464+
Disconnect signals.
465+
"""
453466
if signal in self._signal:
454-
for id, signal_obj in self._signal[signal]:
455-
signal_obj.disconnect(id)
467+
for signal_id, signal_obj in self._signal[signal]:
468+
signal_obj.disconnect(signal_id)
456469
self._signal[signal] = []
457470
else:
458-
raise AttributeError("unknown signal: '%s'" % signal)
471+
raise AttributeError(f"unknown signal: '{signal}'")
459472

460473
def disconnect_all(self):
461474
"""
462475
Used to disconnect all the signals for this specific gramplet
463476
"""
464-
for signal in self._signal:
465-
for sig_id, signal_obj in self._signal[signal]:
466-
signal_obj.disconnect(sig_id)
477+
for signal, signal_data in self._signal.items():
478+
for signal_id, signal_obj in signal_data:
479+
signal_obj.disconnect(signal_id)
467480
self._signal[signal] = []
468481

469482
def hidden_widgets(self):
@@ -495,4 +508,3 @@ def set_orientation(self, orientation):
495508
:param orientation: A Gtk.Orientation (VERTCIAL or HORIZONTAL)
496509
:type orientation: int
497510
"""
498-
pass

0 commit comments

Comments
 (0)