From d8a03eef02a31ad51fe63822bed4eea19b2bc7f9 Mon Sep 17 00:00:00 2001 From: Chris Mutel Date: Wed, 12 Sep 2018 23:09:10 +0200 Subject: [PATCH] Cast locations to strings --- activity_browser/app/bwutils/commontasks.py | 6 +++--- activity_browser/app/ui/tables/LCA_setup.py | 2 +- activity_browser/app/ui/tables/activity.py | 2 +- activity_browser/app/ui/tables/history.py | 5 ++++- activity_browser/app/ui/tables/inventory.py | 5 ++++- activity_browser/app/ui/widgets/activity.py | 2 +- 6 files changed, 14 insertions(+), 8 deletions(-) diff --git a/activity_browser/app/bwutils/commontasks.py b/activity_browser/app/bwutils/commontasks.py index 934c7233f..381ab7a94 100644 --- a/activity_browser/app/bwutils/commontasks.py +++ b/activity_browser/app/bwutils/commontasks.py @@ -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 @@ -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))) diff --git a/activity_browser/app/ui/tables/LCA_setup.py b/activity_browser/app/ui/tables/LCA_setup.py index f6d608ee4..90e92f037 100644 --- a/activity_browser/app/ui/tables/LCA_setup.py +++ b/activity_browser/app/ui/tables/LCA_setup.py @@ -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) diff --git a/activity_browser/app/ui/tables/activity.py b/activity_browser/app/ui/tables/activity.py index 669597919..717038ec5 100644 --- a/activity_browser/app/ui/tables/activity.py +++ b/activity_browser/app/ui/tables/activity.py @@ -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") diff --git a/activity_browser/app/ui/tables/history.py b/activity_browser/app/ui/tables/history.py index 1c1909dbe..e4796c9f6 100644 --- a/activity_browser/app/ui/tables/history.py +++ b/activity_browser/app/ui/tables/history.py @@ -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() diff --git a/activity_browser/app/ui/tables/inventory.py b/activity_browser/app/ui/tables/inventory.py index 2a7b9edac..4b90b131d 100644 --- a/activity_browser/app/ui/tables/inventory.py +++ b/activity_browser/app/ui/tables/inventory.py @@ -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: diff --git a/activity_browser/app/ui/widgets/activity.py b/activity_browser/app/ui/widgets/activity.py index 525d45ed4..d17123edc 100644 --- a/activity_browser/app/ui/widgets/activity.py +++ b/activity_browser/app/ui/widgets/activity.py @@ -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 html-tag has no effect besides making the tooltip rich text