Skip to content

Commit

Permalink
Merge branch 'master' of github.com:NaturalHistoryMuseum/inselect
Browse files Browse the repository at this point in the history
  • Loading branch information
quicklizard99 committed Dec 12, 2016
2 parents ada0788 + 7047bb1 commit 30df8da
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ This is an overview of major changes. Refer to the git repository for a full log

Version 0.1.35
-------------
- #407 Performance impact of 2to3
- #406 Show Boxes view on creating new document
- #405 Remove qtpy
- #401 Support new pyzbar and pylibdmtx
Expand Down
4 changes: 2 additions & 2 deletions inselect/gui/views/boxes/boxes_scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def pixmap_item(self):
"""The single QGraphicsPixmapItem within this scene, or None if there is
no open document
"""
items = list(self.items())
items = self.items()
if not items:
return None
else:
Expand Down Expand Up @@ -80,7 +80,7 @@ def set_pixmap(self, pixmap):

def box_items(self):
"Iterable containin just BoxItems"
return filter(lambda i: isinstance(i, BoxItem), list(self.items()))
return filter(lambda i: isinstance(i, BoxItem), self.items())

def add_box(self, rect, isvalid):
"""Notification from source that a box has been added.
Expand Down
2 changes: 1 addition & 1 deletion inselect/lib/cookie_cutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def save(self, path):
'boxes': self._boxes,
}
with Path(path).open('w', encoding='utf8') as outfile:
outfile.write(str(json.dumps(doc, indent=4)))
outfile.write(json.dumps(doc, indent=4))

@property
def document_items(self):
Expand Down
10 changes: 5 additions & 5 deletions inselect/lib/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ def load(cls, path):
properties = doc.get('properties', {})

# Parse datetimes
for dt in {'Saved on', 'Created on'}.intersection(list(properties.keys())):
for dt in {'Saved on', 'Created on'}.intersection(properties.keys()):
properties[dt] = cls._parse_datetime(properties[dt])

msg = 'Loaded [{0}] items from [{1}]'
Expand All @@ -274,7 +274,7 @@ def save(self):
properties = deepcopy(self.properties)

# Format datetimes
for dt in {'Saved on', 'Created on'}.intersection(list(properties.keys())):
for dt in {'Saved on', 'Created on'}.intersection(properties.keys()):
properties[dt] = self._format_datetime(properties[dt])

doc = {
Expand All @@ -290,8 +290,8 @@ def save(self):
# http://stackoverflow.com/a/20776329/1773758
# Specify separators to prevent trailing whitespace
with path.open("w", newline='\n', encoding='utf8') as f:
f.write(str(json.dumps(doc, ensure_ascii=False, indent=4,
separators=(',', ': '), sort_keys=True)))
f.write(json.dumps(doc, ensure_ascii=False, indent=4,
separators=(',', ': '), sort_keys=True))

debug_print('Saved [{0}] items to [{1}]'.format(len(items), path))

Expand Down Expand Up @@ -336,4 +336,4 @@ def metadata_fields(self):
"""An iterable of metadata field names
"""
# The union of fields among all items
return set(chain(*(list(i['fields'].keys()) for i in self._items)))
return set(chain(*(i['fields'].keys() for i in self._items)))
5 changes: 0 additions & 5 deletions inselect/lib/segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,6 @@ def swallow(*args, **kwargs):
new_rects.append(new_rect)
rects = new_rects

# Reverse order so that boxes at the top left are towards the start
# and boxes at the bottom right are towards the end
# TODO LH This is crummy - need a way to order rects
rects = list(reversed(rects))

return rects, display


Expand Down
2 changes: 1 addition & 1 deletion inselect/lib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def duplicated(v):
"""Returns a generator expression of values within v that appear more than
once
"""
return (x for x, y in list(Counter(v).items()) if y > 1)
return (x for x, y in Counter(v).items() if y > 1)


class FormatDefault(string.Formatter):
Expand Down
5 changes: 4 additions & 1 deletion inselect/tests/gui/test_export_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ def _test_csv(self):
'ItemNumber': '{0}'.format(1 + index),
'Cropped_image_name': '{0:04}.jpg'.format(1 + index),
})
actual = {k: v for k, v in list(row.items()) if v and k not in BOUNDING_BOX_FIELD_NAMES}
actual = {
k: v for k, v in row.items()
if v and k not in BOUNDING_BOX_FIELD_NAMES
}
self.assertEqual(expected, actual)

# Expect 4 rows
Expand Down
5 changes: 4 additions & 1 deletion inselect/tests/scripts/test_export_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ def test_export_csv(self):
'ItemNumber': str(1+index),
'Cropped_image_name': '{0:04}.jpg'.format(1+index)
})
actual = {k: v for k, v in list(row.items()) if v and k not in BOUNDING_BOX_FIELD_NAMES}
actual = {
k: v for k, v in row.items()
if v and k not in BOUNDING_BOX_FIELD_NAMES
}
self.assertEqual(expected, actual)

def test_export_csv_with_template(self):
Expand Down

0 comments on commit 30df8da

Please sign in to comment.