Skip to content
This repository has been archived by the owner on Mar 22, 2018. It is now read-only.

Commit

Permalink
most of the interaction with the tick-off window
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrasca committed Dec 26, 2015
1 parent bcda4e2 commit b875372
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 26 deletions.
83 changes: 76 additions & 7 deletions bauble/plugins/plants/taxonomy_check.glade
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkEntry" id="entry1">
<object class="GtkEntry" id="file_path_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="invisible_char">•</property>
Expand All @@ -61,6 +61,7 @@
<property name="secondary_icon_activatable">False</property>
<property name="primary_icon_sensitive">True</property>
<property name="secondary_icon_sensitive">True</property>
<signal name="changed" handler="on_text_entry_changed" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
Expand All @@ -79,6 +80,8 @@
<object class="GtkImage" id="image9">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="xpad">3</property>
<property name="ypad">3</property>
<property name="stock">gtk-open</property>
</object>
</child>
Expand Down Expand Up @@ -132,7 +135,7 @@
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">start TNRS lookup</property>
<property name="use_action_appearance">False</property>
<signal name="activate" handler="on_tnrs_browse_button_activate" swapped="no"/>
<signal name="clicked" handler="on_tnrs_browse_button_clicked" swapped="no"/>
<child>
<object class="GtkImage" id="image8">
<property name="visible">True</property>
Expand All @@ -152,7 +155,8 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">continue to next screen</property>
<property name="tooltip_text" translatable="yes">use this data and
continue to next screen</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="on_frame1_next" swapped="no"/>
<child>
Expand Down Expand Up @@ -220,8 +224,65 @@
<object class="GtkTreeView" id="treeview2">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="model">liststore1</property>
<property name="model">liststore2</property>
<property name="search_column">0</property>
<property name="level_indentation">11</property>
<signal name="row-activated" handler="on_tick_off_view_row_activated" swapped="no"/>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn1">
<property name="title" translatable="yes">use</property>
<child>
<object class="GtkCellRendererPixbuf" id="tvc1_use_cell"/>
<attributes>
<attribute name="stock-id">0</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn2">
<property name="title" translatable="yes">Query binomial</property>
<child>
<object class="GtkCellRendererText" id="tvc1_query_cell"/>
<attributes>
<attribute name="text">1</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn3">
<property name="title" translatable="yes">Matched binomial</property>
<child>
<object class="GtkCellRendererText" id="tvc1_matched_cell"/>
<attributes>
<attribute name="text">2</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn4">
<property name="title" translatable="yes">Authorship</property>
<child>
<object class="GtkCellRendererText" id="tvc1_matched_author_cell"/>
<attributes>
<attribute name="text">3</attribute>
</attributes>
</child>
</object>
</child>
<child>
<object class="GtkTreeViewColumn" id="treeviewcolumn5">
<property name="title" translatable="yes">Status</property>
<child>
<object class="GtkCellRendererText" id="tvc1_status_cell"/>
<attributes>
<attribute name="text">4</attribute>
</attributes>
</child>
</object>
</child>
</object>
</child>
</object>
Expand Down Expand Up @@ -268,6 +329,8 @@
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">use this data and
continue to next screen</property>
<property name="use_action_appearance">False</property>
<signal name="clicked" handler="on_frame2_next" swapped="no"/>
<child>
Expand Down Expand Up @@ -476,11 +539,17 @@
<action-widget response="0">button12</action-widget>
</action-widgets>
</object>
<object class="GtkListStore" id="liststore1">
<object class="GtkListStore" id="liststore2">
<columns>
<!-- column-name active -->
<column type="gboolean"/>
<!-- column-name text -->
<column type="gchararray"/>
<!-- column-name query -->
<column type="gchararray"/>
<!-- column-name Name_Binomial -->
<column type="gchararray"/>
<!-- column-name Name_Authorship -->
<column type="gchararray"/>
<!-- column-name Taxonomic_status -->
<column type="gchararray"/>
</columns>
</object>
Expand Down
71 changes: 52 additions & 19 deletions bauble/plugins/plants/taxonomy_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ def start_taxonomy_check():
'taxonomy_check.glade'),
parent=None,
root_widget_name='dialog1')
env = {'page': 1,
'selection': view.get_selection(),
'tick_off': None,
'report': None,
}
if env['selection'] is None:
model = type('BTCStatus', (object,), {})()
model.page = 1
model.selection = view.get_selection()
model.tick_off = None
model.report = None
model.file_path = '/home/mario/Downloads/tnrs_results.txt'

if model.selection is None:
return
presenter = BatchTaxonomicCheckPresenter(env, view, refresh_view=True)
presenter = BatchTaxonomicCheckPresenter(model, view, refresh_view=True)
error_state = presenter.start()
if error_state:
presenter.session.rollback()
Expand All @@ -70,46 +72,77 @@ class BatchTaxonomicCheckPresenter(GenericEditorPresenter):
'''

widget_to_field_map = {'file_path_entry': 'file_path'}

def __init__(self, *args, **kwargs):
super(BatchTaxonomicCheckPresenter, self).__init__(*args, **kwargs)
self.refresh_visible_frame()
self.tick_off_list = self.view.widgets.liststore2
self.tick_off_view = self.view.widgets.treeview2
from bauble.plugins.plants import Species
self.binomials = [item.str(item, remove_zws=True)
for item in self.model.selection
if isinstance(item, Species) and item.sp != '']

def refresh_visible_frame(self):
for i in range(1, 4):
frame_id = 'frame%d' % i
self.view.widget_set_visible(frame_id, i == self.model['page'])
self.view.widget_set_visible(frame_id, i == self.model.page)

def on_frame1_next(self, *args):
'parse the results into the liststore1 and move to frame 2'
'parse the results into the liststore2 and move to frame 2'
responses = []
self.tick_off_list.clear()
import codecs
with codecs.open(self.model.file_path, 'r', 'utf16') as f:
keys = f.readline().strip().split('\t')
for l in f.readlines():
l = l.strip()
values = [i.strip() for i in l.split("\t")]
responses.append(dict(zip(keys, values)))
for binomial, response in zip(self.binomials, responses):
row = [response['Name_matched_rank'] == u'species'
and 'gtk-yes' or 'gtk-no',
binomial]
for key in ['Name_matched', 'Name_matched_author',
'Taxonomic_status']:
row.append(response[key])
self.tick_off_list.append(row)
if response['Taxonomic_status'] == 'Synonym':
row = ['gtk-yes', '', response['Accepted_name'],
response['Accepted_name_author'], 'Accepted']
self.tick_off_list.append(row)
self.on_frame_next(*args)

def on_frame2_next(self, *args):
'execute all that is selected in liststore1 and move to frame 3'
'execute all that is selected in liststore2 and move to frame 3'
self.on_frame_next(*args)

def on_frame_next(self, *args):
self.model['page'] += 1
self.model.page += 1
self.refresh_visible_frame()

def on_frame_previous(self, *args):
self.model['page'] -= 1
self.model.page -= 1
self.refresh_visible_frame()

def on_copy_to_clipboard_button_clicked(self, *args):
from bauble.plugins.plants import Species
binomials = [item.str(item, remove_zws=True)
for item in self.model['selection']
if isinstance(item, Species) and item.sp != '']
text = '\n'.join(binomials)
text = '\n'.join(self.binomials)
import gtk
clipboard = gtk.Clipboard()
clipboard.set_text(text)

def on_tnrs_browse_button_clicked(self, *args):
from bauble.utils import desktop
desktop.open('http://tnrs.iplantcollaborative.org/TNRSapp.html')

def on_tick_off_view_row_activated(self, view, path, column, data=None):
iter = self.tick_off_list.get_iter(path)
value = self.tick_off_list[path][0]
value = (value == 'gtk-yes') and 'gtk-no' or 'gtk-yes'
self.tick_off_list.set_value(iter, 0, value)
pass

pass


class TaxonomyCheckTool(pluginmgr.Tool):
label = _('Taxonomy check')
Expand Down

0 comments on commit b875372

Please sign in to comment.