Commit a31500d5 authored by Franziska Koehn's avatar Franziska Koehn
Browse files

Comparison-View remodeled and fed with data

parent 1daa8e7e
......@@ -9,7 +9,7 @@ This module houses classes relating to the GUI-representation of the additional
import gtk
class AdddataView(gtk.HPaned):
class AdddataView(gtk.VBox):
"""Container with all widgets for working with some additional data."""
def __init__(self):
......@@ -17,25 +17,8 @@ class AdddataView(gtk.HPaned):
super(AdddataView, self).__init__()
self.set_position(300)
# experiments
sw_expt = gtk.ScrolledWindow()
sw_expt.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw_expt.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.add1(sw_expt)
self.treeview_projects = TreeViewTypes()
sw_expt.add(self.treeview_projects)
# results-table
vbox = gtk.VBox()
self.add2(vbox)
hbox_formula = gtk.HBox()
vbox.pack_start(hbox_formula, False, True, 0)
self.pack_start(hbox_formula, False, True, 0)
label_user = gtk.Label()
label_user.set_text("Filter: ")
......@@ -48,148 +31,56 @@ class AdddataView(gtk.HPaned):
sw_results = gtk.ScrolledWindow()
sw_results.set_shadow_type(gtk.SHADOW_ETCHED_IN)
sw_results.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
vbox.pack_start(sw_results, True, True, 0)
self.pack_start(sw_results, True, True, 0)
self.treeview_results = TreeViewResults()
sw_results.add(self.treeview_results)
def show_comparison(self, root_type, table):
pass
#self.treeview_projects.show_data(root_type, table)
#self.treeview_results.show_data(table.headers())
def show_comparison(self, root_type, table):
self.treeview_results.show_data(root_type, table)
class TreeViewTypes(gtk.TreeView):
class TreeViewResults(gtk.TreeView):
def __init__(self):
super(TreeViewResults, self).__init__()
super(TreeViewTypes, self).__init__()
TARGETS = [
('Target', gtk.TARGET_SAME_APP, 0),
('text/plain', 0, 1),
('TEXT', 0, 2),
('STRING', 0, 3),
]
self.enable_model_drag_source(gtk.gdk.BUTTON1_MASK, TARGETS, gtk.gdk.ACTION_COPY)
def drag_data_get_data(treeview, context, selection, info, *_):
treeselection = treeview.get_selection()
model, iter = treeselection.get_selected()
data = model.get_value(iter, 0)
print selection
selection.set(selection.target, 8, data)
def show_data(self, root_type, table):
if table == []:
return
self.create_columns(root_type, table.headers())
self.create_model(table)
self.connect('drag_data_get', drag_data_get_data)
self.set_rules_hint(gtk.TRUE)
def show_data(self, root_type, results):
def create_columns(self, root_type, column_names):
import xsa.datatypereader
keys = xsa.datatypereader.get_comparison_identifier(root_type)
labels = []
for k in keys:
labels.append(xsa.datatypereader.get_field_label_by_key(root_type, k))
create_columns(labels)
create_model(keys, results)
def create_columns(self, labels):
def cell_data_func(tree_column, cell, model, tree_iter):
if model.get_value(tree_iter, 2):
stock_id = gtk.STOCK_APPLY
else:
stock_id = gtk.STOCK_CLOSE
cell.set_property('stock-id', stock_id)
self.insert_column_with_data_func(0, 'added', gtk.CellRendererPixbuf(), cell_data_func)
for c in self.get_columns():
self.remove_column(c)
for i,label in enumerate(labels, start=2):
column = gtk.TreeViewColumn(label, gtk.CellRendererText(), text=i)
for i,key in enumerate(column_names, start=1):
cname = xsa.datatypereader.get_field_label_by_key(root_type, key)
column = gtk.TreeViewColumn(cname, gtk.CellRendererText(), text=i)
column.set_sort_column_id(i)
column.set_resizable(True)
self.append_column(column)
def create_model(self, keys, results):
def create_model(self, table):
import gobject
model_columns = []
model_columns.append(gobject.TYPE_PYOBJECT) # 1 result
for k in keys:
model_columns.append(str) # 2..* identifiers
self.store = gtk.ListStore(*model_columns)
for result in results:
new_set = []
new_set.append(result)
for k in keys:
new_set.append(result[k])
self.store.append(new_set)
self.set_model(self.store)
class TreeViewResults(gtk.TreeView):
def __init__(self):
super(TreeViewResults, self).__init__()
self.create_model()
self.create_columns()
TARGETS = [
('Target', gtk.TARGET_SAME_APP, 0),
('text/plain', 0, 1),
('TEXT', 0, 2),
('STRING', 0, 3),
]
self.enable_model_drag_source(gtk.gdk.BUTTON1_MASK, TARGETS, gtk.gdk.ACTION_DEFAULT|gtk.gdk.ACTION_MOVE)
self.enable_model_drag_dest(TARGETS, gtk.gdk.ACTION_DEFAULT)
def drag_data_get_data(treeview, context, selection, info, *_):
treeselection = treeview.get_selection()
model, iter = treeselection.get_selected()
data = model.get_value(iter, 0)
selection.set(selection.target, 8, data)
def drag_data_received_data(treeview, context, x, y, selection, info, etime, *_):
model = treeview.get_model()
data = selection.data
drop_info = treeview.get_dest_row_at_pos(x, y)
print drop_info
if str(data) == "field0":
self.append_column(gtk.TreeViewColumn("field0", gtk.CellRendererText(), text=1))
else:
if drop_info:
path, position = drop_info
iter = model.get_iter(path)
if (position == gtk.TREE_VIEW_DROP_BEFORE
or position == gtk.TREE_VIEW_DROP_INTO_OR_BEFORE):
model.insert_before(iter, [data])
else:
model.insert_after(iter, [data])
else:
model.append([data])
if context.action == gtk.gdk.ACTION_MOVE:
context.finish(True, True, etime)
return
self.connect('drag_data_get', drag_data_get_data)
self.connect('drag_data_received', drag_data_received_data)
def create_columns(self):
column = gtk.TreeViewColumn("Project", gtk.CellRendererText(), text=0)
column.set_sort_column_id(0)
self.append_column(column)
def create_model(self):
self.store = gtk.ListStore(str)
for i in range(0,4):
self.store.append(["example%i"%i])
self.set_model(self.store)
model_columns.append(gobject.TYPE_PYOBJECT) # 0 data-set
for column in table.headers():
model_columns.append(str) # 1..* values for chosen columns
store = gtk.ListStore(*model_columns)
for row in table:
row_data=[]
row_data.append(row)
for h in table.headers():
row_data.append(row[h])
store.append(row_data)
self.set_model(store)
......@@ -27,7 +27,8 @@ class ComparisonDialogView(gtk.HBox):
def callback_get_add_data(*_):
print "Downloading data..."
data = self.treev_identifier.get_additional_data(host, user, passw)
self.treev_identifier.get_additional_data(host, user, passw)
data = self.treev_identifier.data
print "Importing data..."
self.treev_fields.add_new_fields(data)
print "finished."
......@@ -114,8 +115,8 @@ class ComparisonDialogView(gtk.HBox):
def create_comparison_table(self):
column_store = self.treev_columns.store
data = self.treev_identifier.get_data()
data = self.treev_identifier.data
print data
result=[]
for d in data:
dic = {}
......@@ -132,14 +133,13 @@ class ComparisonDialogView(gtk.HBox):
except:
pass
if values == []:
dic[field] = "no value"
dic[field] = "N/A"
else:
dic[field] = values
result.append(dic)
from pyxnat.core.jsonutil import JsonTable
print "JsonTable:"
print JsonTable(result)
return JsonTable(result)
class TreeViewIdentifier(gtk.TreeView):
......@@ -163,9 +163,9 @@ class TreeViewIdentifier(gtk.TreeView):
self.source = None
self.root_type = root_type
self.data = results
self.create_columns(labels)
self.create_model(keys, results, (self.source is not None))
self.create_model(keys, (self.source is not None))
def get_additional_data(self, host, user, passw):
import xsa.queries
......@@ -173,18 +173,13 @@ class TreeViewIdentifier(gtk.TreeView):
rest = xsa.datatypereader.get_comparison_extra_source(self.root_type)
self.data = []
result = []
for row in self.store:
new_result = xsa.queries.query_for_additional_data(rest, row[1], host, user, passw)
self.data.append(new_result)
result.append(xsa.queries.query_for_additional_data(rest, row[1], host, user, passw))
row[0] = False
return self.data
#TODO get_additional_data vs get_data
def get_data(self):
return self.data
if result is not []:
self.data = result
def create_columns(self, labels):
......@@ -203,7 +198,7 @@ class TreeViewIdentifier(gtk.TreeView):
self.append_column(column)
def create_model(self, keys, results, has_source):
def create_model(self, keys, has_source):
import gobject
......@@ -214,7 +209,7 @@ class TreeViewIdentifier(gtk.TreeView):
model_columns.append(str) # 2..* identifiers
self.store = gtk.ListStore(*model_columns)
for result in results:
for result in self.data:
new_set = []
new_set.append(has_source)
new_set.append(result)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment