Skip to content

Commit 6b4bfab

Browse files
committed
Aply consistent source formatting (autopep8)
1 parent 120aa12 commit 6b4bfab

File tree

3 files changed

+86
-51
lines changed

3 files changed

+86
-51
lines changed

Form/UK1841.py

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1919
#
2020

21-
#------------------------------------------------------------------------
21+
# ------------------------------------------------------------------------
2222
#
2323
# Gramps modules
2424
#
25-
#------------------------------------------------------------------------
25+
# ------------------------------------------------------------------------
2626
from gramps.gen.datehandler import displayer as date_displayer
2727
from gramps.gen.db import DbTxn
2828
from gramps.gen.display.name import displayer as name_displayer
@@ -31,18 +31,18 @@
3131
Name, Person)
3232
from gramps.gen.utils.db import get_participant_from_event
3333

34-
#------------------------------------------------------------------------
34+
# ------------------------------------------------------------------------
3535
#
3636
# Gramplet modules
3737
#
38-
#------------------------------------------------------------------------
38+
# ------------------------------------------------------------------------
3939
import actionutils
4040

41-
#------------------------------------------------------------------------
41+
# ------------------------------------------------------------------------
4242
#
4343
# Internationalisation
4444
#
45-
#------------------------------------------------------------------------
45+
# ------------------------------------------------------------------------
4646
from gramps.gen.const import GRAMPS_LOCALE as glocale
4747
try:
4848
_trans = glocale.get_addon_translator(__file__)
@@ -51,27 +51,30 @@
5151

5252
_ = _trans.gettext
5353

54+
5455
def get_actions(dbstate, citation, form_event):
5556
"""
5657
return a list of all actions that this module can provide for the given citation and form
5758
each list entry is a string, describing the action category, and a list of actions that can be performed.
5859
"""
5960
actions = []
60-
actions.append(PrimaryNameCitation.get_actions(dbstate, citation, form_event))
61+
actions.append(PrimaryNameCitation.get_actions(
62+
dbstate, citation, form_event))
6163
actions.append(AlternateName.get_actions(dbstate, citation, form_event))
6264
actions.append(BirthEvent.get_actions(dbstate, citation, form_event))
6365
actions.append(OccupationEvent.get_actions(dbstate, citation, form_event))
6466
actions.append(ResidenceEvent.get_actions(dbstate, citation, form_event))
6567
return actions
6668

69+
6770
class PrimaryNameCitation:
6871
@staticmethod
6972
def get_actions(dbstate, citation, form_event):
7073
db = dbstate.db
7174
actions = []
7275
for (person, attr) in actionutils.get_form_person_attr(db, form_event.get_handle(), 'Name'):
7376
actions.append((name_displayer.display(person), attr.get_value(),
74-
lambda dbstate, uistate, track, citation_handle = citation.handle, person_handle = person.handle: PrimaryNameCitation.command(dbstate, uistate, track, citation_handle, person_handle)))
77+
lambda dbstate, uistate, track, citation_handle=citation.handle, person_handle=person.handle: PrimaryNameCitation.command(dbstate, uistate, track, citation_handle, person_handle)))
7578
return (_("Add Primary Name citation"), actions)
7679

7780
@staticmethod
@@ -82,6 +85,7 @@ def command(dbstate, uistate, track, citation_handle, person_handle):
8285
with DbTxn(_("Add Person ({name})").format(name=name_displayer.display(person)), db) as trans:
8386
db.commit_person(person, trans)
8487

88+
8589
class AlternateName:
8690
@staticmethod
8791
def get_actions(dbstate, citation, form_event):
@@ -93,7 +97,7 @@ def get_actions(dbstate, citation, form_event):
9397
alternate.add_citation(citation.handle)
9498
detail = _('Given Name: {name}').format(name=attr.get_value())
9599
actions.append((name_displayer.display(person), detail,
96-
lambda dbstate, uistate, track, person_handle = person.handle, alternate_ = alternate: AlternateName.command(dbstate, uistate, track, person_handle, alternate_)))
100+
lambda dbstate, uistate, track, person_handle=person.handle, alternate_=alternate: AlternateName.command(dbstate, uistate, track, person_handle, alternate_)))
97101
return (_("Add alternate name"), actions)
98102

99103
@staticmethod
@@ -104,6 +108,7 @@ def command(dbstate, uistate, track, person_handle, alternate):
104108
with DbTxn(_("Add Person ({name})").format(name=name_displayer.display(person)), db) as trans:
105109
db.commit_person(person, trans)
106110

111+
107112
class BirthEvent:
108113
@staticmethod
109114
def get_actions(dbstate, citation, form_event):
@@ -126,26 +131,31 @@ def get_actions(dbstate, citation, form_event):
126131
elif not birth_date.is_compound():
127132
# in theory, birth_date will never be compound since 1841 census date was 1841-06-06. Let's handle it anyway.
128133
# create a compound range spanning the possible birth years
129-
birth_range = (birth_date - 5).get_dmy() + (False,) + birth_date.get_dmy() + (False,)
130-
birth_date.set(Date.QUAL_NONE, Date.MOD_RANGE, birth_date.get_calendar(), birth_range, newyear=birth_date.get_new_year())
134+
birth_range = (birth_date - 5).get_dmy() + \
135+
(False,) + birth_date.get_dmy() + (False,)
136+
birth_date.set(Date.QUAL_NONE, Date.MOD_RANGE, birth_date.get_calendar(
137+
), birth_range, newyear=birth_date.get_new_year())
131138
birth_date.set_quality(Date.QUAL_CALCULATED)
132-
detail = _('Age: {age}\nDate: {date}').format(age=age_string, date=date_displayer.display(birth_date))
139+
detail = _('Age: {age}\nDate: {date}').format(
140+
age=age_string, date=date_displayer.display(birth_date))
133141
actions.append((name_displayer.display(person), detail,
134-
lambda dbstate, uistate, track, citation_handle = citation.handle, person_handle = person.handle, birth_date_ = birth_date: actionutils.add_event_to_person(dbstate, uistate, track, person_handle, EventType.BIRTH, birth_date_, None, citation_handle, EventRoleType.PRIMARY)))
142+
lambda dbstate, uistate, track, citation_handle=citation.handle, person_handle=person.handle, birth_date_=birth_date: actionutils.add_event_to_person(dbstate, uistate, track, person_handle, EventType.BIRTH, birth_date_, None, citation_handle, EventRoleType.PRIMARY)))
135143
return (_("Add Birth event"), actions)
136144

145+
137146
class OccupationEvent:
138147
@staticmethod
139148
def get_actions(dbstate, citation, form_event):
140149
db = dbstate.db
141150
actions = []
142151
for (person, attr) in actionutils.get_form_person_attr(db, form_event.get_handle(), 'Occupation'):
143152
occupation = attr.get_value()
144-
if (occupation) :
153+
if (occupation):
145154
actions.append((name_displayer.display(person), _('Description: {occupation}').format(occupation=occupation),
146-
lambda dbstate, uistate, track, citation_handle = citation.handle, person_handle = person.handle, occupation_ = occupation: actionutils.add_event_to_person(dbstate, uistate, track, person_handle, EventType.OCCUPATION, form_event.get_date_object(), occupation_, citation_handle, EventRoleType.PRIMARY)))
155+
lambda dbstate, uistate, track, citation_handle=citation.handle, person_handle=person.handle, occupation_=occupation: actionutils.add_event_to_person(dbstate, uistate, track, person_handle, EventType.OCCUPATION, form_event.get_date_object(), occupation_, citation_handle, EventRoleType.PRIMARY)))
147156
return (_("Add Occupation event"), actions)
148157

158+
149159
class ResidenceEvent:
150160
@staticmethod
151161
def get_actions(dbstate, citation, form_event):
@@ -162,10 +172,11 @@ def get_actions(dbstate, citation, form_event):
162172
if people:
163173
detail = None
164174
if form_event.get_place_handle():
165-
place = place_displayer.display(db, db.get_place_from_handle(form_event.get_place_handle()))
175+
place = place_displayer.display(
176+
db, db.get_place_from_handle(form_event.get_place_handle()))
166177
detail = _('Place: {place}').format(place=place)
167178
actions.append((get_participant_from_event(db, form_event.get_handle()), detail,
168-
lambda dbstate, uistate, track, citation_handle = citation.handle, people_handles = people: ResidenceEvent.command(dbstate, uistate, track, citation_handle, form_event.get_date_object(), form_event.get_place_handle(), people_handles)))
179+
lambda dbstate, uistate, track, citation_handle=citation.handle, people_handles=people: ResidenceEvent.command(dbstate, uistate, track, citation_handle, form_event.get_date_object(), form_event.get_place_handle(), people_handles)))
169180
return (_("Add Residence event"), actions)
170181

171182
@staticmethod

Form/actionutils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@
1818
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1919
#
2020

21-
#------------------------------------------------------------------------
21+
# ------------------------------------------------------------------------
2222
#
2323
# Gramps modules
2424
#
25-
#------------------------------------------------------------------------
25+
# ------------------------------------------------------------------------
2626
from gramps.gen.db import DbTxn
2727
from gramps.gen.display.name import displayer as name_displayer
2828
from gramps.gen.lib import (Event, EventType, EventRef, EventRoleType,
2929
Person)
3030

31-
#------------------------------------------------------------------------
31+
# ------------------------------------------------------------------------
3232
#
3333
# Internationalisation
3434
#
35-
#------------------------------------------------------------------------
35+
# ------------------------------------------------------------------------
3636
from gramps.gen.const import GRAMPS_LOCALE as glocale
3737
try:
3838
_trans = glocale.get_addon_translator(__file__)
@@ -41,6 +41,7 @@
4141

4242
_ = _trans.gettext
4343

44+
4445
def add_event_to_person(dbstate, uistate, track, person_handle, event_type, event_date_object, event_description, citation_handle, event_role_type):
4546
db = dbstate.db
4647
"""
@@ -64,6 +65,7 @@ def add_event_to_person(dbstate, uistate, track, person_handle, event_type, even
6465
with DbTxn(_("Add Event ({name})").format(name=name_displayer.display(person)), db) as trans:
6566
db.commit_person(person, trans)
6667

68+
6769
def get_form_person_attr(db, form_event_handle, attr_type):
6870
"""
6971
Find all persons referencing the form_event and which have an attribute of type attr_type
@@ -80,6 +82,7 @@ def get_form_person_attr(db, form_event_handle, attr_type):
8082
result.append((person, attr))
8183
return result
8284

85+
8386
def represents_int(s):
8487
"""
8588
return True iff s is convertable to an int, False otherwise

Form/formactions.py

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -21,62 +21,69 @@
2121
"""
2222
Form action chooser
2323
"""
24-
#-------------------------------------------------------------------------
24+
# -------------------------------------------------------------------------
2525
#
2626
# Standard Python modules
2727
#
28-
#-------------------------------------------------------------------------
28+
# -------------------------------------------------------------------------
2929
import logging
3030
import importlib.util
3131
import inspect
3232
import os
3333
import sys
3434

35-
LOG = logging.getLogger('.form')
36-
37-
#------------------------------------------------------------------------
35+
# ------------------------------------------------------------------------
3836
#
3937
# GTK modules
4038
#
41-
#------------------------------------------------------------------------
39+
# ------------------------------------------------------------------------
4240
from gi.repository import Gtk, GObject
4341

44-
#------------------------------------------------------------------------
42+
# ------------------------------------------------------------------------
4543
#
4644
# Gramps modules
4745
#
48-
#------------------------------------------------------------------------
49-
from gramps.gui.managedwindow import ManagedWindow
46+
# ------------------------------------------------------------------------
5047
from gramps.gen.config import config
48+
from gramps.gen.const import GRAMPS_LOCALE as glocale
5149
from gramps.gen.datehandler import get_date
5250
from gramps.gen.db import DbTxn
5351
from gramps.gui.display import display_help
52+
from gramps.gui.managedwindow import ManagedWindow
5453

55-
#------------------------------------------------------------------------
54+
# ------------------------------------------------------------------------
5655
#
5756
# Gramplet modules
5857
#
59-
#------------------------------------------------------------------------
58+
# ------------------------------------------------------------------------
6059
from editform import find_form_event
6160
from form import (get_form_id, get_form_type)
6261

63-
#------------------------------------------------------------------------
62+
# ------------------------------------------------------------------------
63+
#
64+
# Logging
65+
#
66+
# ------------------------------------------------------------------------
67+
LOG = logging.getLogger('.form')
68+
69+
# ------------------------------------------------------------------------
6470
#
6571
# Internationalisation
6672
#
67-
#------------------------------------------------------------------------
68-
from gramps.gen.const import GRAMPS_LOCALE as glocale
73+
# ------------------------------------------------------------------------
6974
try:
7075
_trans = glocale.get_addon_translator(__file__)
7176
except ValueError:
7277
_trans = glocale.translation
7378
_ = _trans.gettext
7479

75-
#------------------------------------------------------------------------
80+
# ------------------------------------------------------------------------
7681
#
7782
# FormActions class
7883
#
79-
#------------------------------------------------------------------------
84+
# ------------------------------------------------------------------------
85+
86+
8087
class FormActions(object):
8188
"""
8289
Form Action selector.
@@ -99,17 +106,20 @@ def __init__(self, dbstate, uistate, track, citation):
99106

100107
self.actions_module = None
101108
# for security reasons provide the full path to the actions_module .py file
102-
full_path = os.path.join(os.path.dirname(__file__), '{form_id}.py'.format(form_id=self.form_id))
109+
full_path = os.path.join(os.path.dirname(
110+
__file__), '{form_id}.py'.format(form_id=self.form_id))
103111
if os.path.exists(full_path):
104112
# temporarily modify sys.path so that any import statements in the module get processed correctly
105113
sys.path.insert(0, os.path.dirname(__file__))
106114
try:
107-
spec = importlib.util.spec_from_file_location('form.actions.{form_id}'.format(form_id=self.form_id), full_path)
115+
spec = importlib.util.spec_from_file_location(
116+
'form.actions.{form_id}'.format(form_id=self.form_id), full_path)
108117
self.actions_module = importlib.util.module_from_spec(spec)
109118
spec.loader.exec_module(self.actions_module)
110119
except (ValueError, ImportError, SyntaxError) as err:
111120
self.actions_module = None
112-
LOG.warning(_("Form plugin error (from '{path}'): {error}").format(path=full_path, error=err))
121+
LOG.warning(_("Form plugin error (from '{path}'): {error}").format(
122+
path=full_path, error=err))
113123
finally:
114124
# must make sure we restore sys.path
115125
sys.path.pop(0)
@@ -122,8 +132,10 @@ def __init__(self, dbstate, uistate, track, citation):
122132
width = self._config.get('interface.form-actions-width')
123133
height = self._config.get('interface.form-actions-height')
124134
self.top.resize(width, height)
125-
horiz_position = self._config.get('interface.form-actions-horiz-position')
126-
vert_position = self._config.get('interface.form-actions-vert-position')
135+
horiz_position = self._config.get(
136+
'interface.form-actions-horiz-position')
137+
vert_position = self._config.get(
138+
'interface.form-actions-vert-position')
127139
if horiz_position != -1:
128140
self.top.move(horiz_position, vert_position)
129141

@@ -146,12 +158,15 @@ def _create_dialog(self, title):
146158
renderer_action_toggle = Gtk.CellRendererToggle()
147159
renderer_action_toggle.connect('toggled', self.on_action_toggled)
148160
column1.pack_start(renderer_action_toggle, False)
149-
column1.add_attribute(renderer_action_toggle, 'active', self.RUN_ACTION_COL)
150-
column1.add_attribute(renderer_action_toggle, 'inconsistent', self.RUN_INCONSISTENT_COL)
161+
column1.add_attribute(renderer_action_toggle,
162+
'active', self.RUN_ACTION_COL)
163+
column1.add_attribute(renderer_action_toggle,
164+
'inconsistent', self.RUN_INCONSISTENT_COL)
151165
column1.pack_start(renderer_text, True)
152166
column1.add_attribute(renderer_text, 'text', self.ACTION_COL)
153167

154-
column2 = Gtk.TreeViewColumn(_("Detail"), renderer_text, text=self.DETAIL_COL)
168+
column2 = Gtk.TreeViewColumn(
169+
_("Detail"), renderer_text, text=self.DETAIL_COL)
155170
self.tree.append_column(column1)
156171
self.tree.append_column(column2)
157172

@@ -187,7 +202,8 @@ def on_action_toggled(self, widget, path):
187202
self.model[row_iter][self.RUN_ACTION_COL] = not self.model[row_iter][self.RUN_ACTION_COL]
188203
if parent:
189204
# update the status of the parent
190-
(consistent, value) = FormActions.all_children_consistent(self.model, parent, FormActions.RUN_ACTION_COL)
205+
(consistent, value) = FormActions.all_children_consistent(
206+
self.model, parent, FormActions.RUN_ACTION_COL)
191207
self.model[parent][self.RUN_INCONSISTENT_COL] = not consistent
192208
self.model[parent][self.RUN_ACTION_COL] = consistent and value
193209

@@ -211,14 +227,17 @@ def _populate_model(self):
211227
if self.actions_module:
212228
# get the all actions that the actions module can provide for the form
213229
# because the module is dynamically loaded, use getattr to retrieve the actual function to call
214-
all_actions = getattr(self.actions_module, 'get_actions')(self.dbstate, self.citation, self.event)
230+
all_actions = getattr(self.actions_module, 'get_actions')(
231+
self.dbstate, self.citation, self.event)
215232
for (title, actions) in all_actions:
216233
if actions:
217234
# add the action category
218-
parent = self.model.append(None, (False, False, title, None, None))
235+
parent = self.model.append(
236+
None, (False, False, title, None, None))
219237
for action_detail in actions:
220238
# add available actions within this category
221-
self.model.append(parent, (False, False) + action_detail)
239+
self.model.append(
240+
parent, (False, False) + action_detail)
222241

223242
def run(self):
224243
"""
@@ -252,11 +271,13 @@ def run(self):
252271
for action_type_row in self.model:
253272
for action_row in action_type_row.iterchildren():
254273
if action_row.model.get_value(action_row.iter, self.RUN_ACTION_COL):
255-
actions.append(action_row.model.get_value(action_row.iter, self.ACTION_COMMAND_COL))
274+
actions.append(action_row.model.get_value(
275+
action_row.iter, self.ACTION_COMMAND_COL))
256276
# run the actions
257277
for index, action in enumerate(actions):
258278
(action)(self.dbstate, self.uistate, self.track)
259-
self.uistate.pulse_progressbar((index + 1) / len(actions) * 100)
279+
self.uistate.pulse_progressbar(
280+
(index + 1) / len(actions) * 100)
260281
self.uistate.progress.hide()
261282
self.uistate.set_busy_cursor(False)
262283

0 commit comments

Comments
 (0)