Skip to content

Commit

Permalink
Merge pull request #186 from cmutel/location-strings
Browse files Browse the repository at this point in the history
Compatibility with regionalization
  • Loading branch information
bsteubing committed Sep 14, 2018
2 parents 2852af5 + d8a03ee commit 3980a85
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions activity_browser/app/bwutils/commontasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def format_activity_label(act, style='pnl', max_length=40):
if style == 'pnl':
label = wrap_text(
'\n'.join([a.get('reference product', ''), a.get('name', ''),
a.get('location', '')]), max_length=max_length)
str(a.get('location', ''))]), max_length=max_length)
elif style == 'pl':
label = wrap_text(', '.join([a.get('reference product', '') or a.get('name', ''),
a.get('location', ''),
str(a.get('location', '')),
]), max_length=40)
elif style == 'key':
label = wrap_text(str(a.key)) # safer to use key, code does not always exist
Expand All @@ -39,7 +39,7 @@ def format_activity_label(act, style='pnl', max_length=40):
else:
label = wrap_text(
'\n'.join([a.get('reference product', ''), a.get('name', ''),
a.get('location', '')]))
str(a.get('location', ''))]))
except:
if isinstance(act, tuple):
return wrap_text(str(''.join(act)))
Expand Down
2 changes: 1 addition & 1 deletion activity_browser/app/ui/tables/LCA_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def append_row(self, key, amount='1.0'):
self.setItem(new_row, 2, ABTableItem(act.get('reference product'),
key=key, color="product"))
self.setItem(new_row, 3, ABTableItem(act.get('name'), key=key, color="name"))
self.setItem(new_row, 4, ABTableItem(act.get('location'), key=key, color="location"))
self.setItem(new_row, 4, ABTableItem(str(act.get('location')), key=key, color="location"))
self.setItem(new_row, 5, ABTableItem(act.get('database'), key=key, color="database"))
except:
print("Could not load key in Calculation Setup: ", key)
Expand Down
2 changes: 1 addition & 1 deletion activity_browser/app/ui/tables/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def sync(self, limit=100):
self.setItem(row, 3, ABTableItem(
obj.get('name'), exchange=exc, direction=direction, color="name")
)
self.setItem(row, 4, ABTableItem(obj.get('location', 'Unknown'), color="location"))
self.setItem(row, 4, ABTableItem(str(obj.get('location', 'Unknown')), color="location"))
self.setItem(row, 5, ABTableItem(obj.get('database'), color="database"))
self.setItem(row, 6, ABTableItem(
"True" if exc.get("uncertainty type", 0) > 1 else "False")
Expand Down
5 changes: 4 additions & 1 deletion activity_browser/app/ui/tables/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ def add_activity(self, key):
ds = bw.get_activity(key)
self.insertRow(0)
for col, value in self.COLUMNS.items():
self.setItem(0, col, ABTableItem(ds.get(value, ''), key=key, color=value))
if value == 'location':
self.setItem(0, col, ABTableItem(str(ds.get(value, '')), key=key, color=value))
else:
self.setItem(0, col, ABTableItem(ds.get(value, ''), key=key, color=value))

self.resizeColumnsToContents()
self.resizeRowsToContents()
Expand Down
5 changes: 4 additions & 1 deletion activity_browser/app/ui/tables/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,12 @@ def sync(self, name, data=None):
self.setHorizontalHeaderLabels(self.HEADERS)
for row, ds in enumerate(data):
for col, value in self.COLUMNS.items():
self.setItem(row, col, ABTableItem(ds.get(value, ''), key=ds.key, color=value))
if value == "key":
self.setItem(row, col, ABTableItem(str(ds.key), key=ds.key, color=value))
elif value == "location":
self.setItem(row, col, ABTableItem(str(ds.get(value, '')), key=ds.key, color=value))
else:
self.setItem(row, col, ABTableItem(ds.get(value, ''), key=ds.key, color=value))

def filter_database_changed(self, database_name):
if not hasattr(self, "database") or self.database.name != database_name:
Expand Down
2 changes: 1 addition & 1 deletion activity_browser/app/ui/widgets/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def populate(self, activity=None):
self.database.setText(self.activity['database'])
self.name_box.setText(self.activity['name'])
self.name_box._key = self.activity.key
self.location_box.setText(self.activity.get('location', ''))
self.location_box.setText(str(self.activity.get('location', '')))
self.location_box._key = self.activity.key
self.comment_box.setPlainText(self.activity.get('comment', ''))
# the <font> html-tag has no effect besides making the tooltip rich text
Expand Down

0 comments on commit 3980a85

Please sign in to comment.