# CellTracking.py
# By MW, Jun 2013
# GPLv3+
#
# Class managing the display of the features
import sys, gtk
sys.path.append('./bin/Features/')
import Slider_multi, Feature_gtk
[docs]class Features_gtk :
def __init__(self, f, state) :
self.state = state
self.features = f
self.features_dict = {} # To store features_gtk objects
self.features_typ ={'point' : Feature_gtk.Point_gtk,
'multipoint' : Feature_gtk.Multipoint_gtk,
'segment' : Feature_gtk.Segment_gtk,
'multisegment' : Feature_gtk.Multisegment_gtk,
'cell' : Feature_gtk.Cell_gtk
}
self.slider = None
self.cell = None
[docs] def update(self) :
# Update cell
self.features.get_features_dict()['cell'].update()
self.slider.update()
[docs] def set_cell(self, cell) :
"""Register the cell polygon and bind everything so that it
can be updated"""
if self.cell == None :
self.cell = self.features.new_feature('cell', 'cell', 'C', (1.0, 1.0, 0.72), 'the cell polygon')
if self.cell == False :
self.cell = self.features.get_features_dict()['cell']
self.cell.set_cell(cell)
[docs] def get_panel(self, bounds) :
"""Returns the full panel to manage features (panel+controls)
bounds: (min_frame, max_frame)
"""
# Create gtk features associated with features
# (move to other function?)
for f in self.features.get_features_dict().values() :
n = f.get_name()
t = f.get_type()
feat = self.features_typ[t](f, self.state)
feat.connect('slider-changed', self.slider_changed_evt)
feat.set_bounds(bounds)
self.features_dict[n] = feat
mainbox = gtk.VBox()
bottombox = gtk.HBox()
# Slider
self.slider = Slider_multi.Slider_multi(bounds)
s_panel = self.slider.get_panel() # call before setting features
self.slider.set_features(self.features_dict.values())
# Right panel
r_panel = gtk.Label('Select a feature to edit it.')
# Left panel
table = gtk.Table(len(self.features_dict)+1, 2)
show_l = gtk.Label()
show_l.set_markup('<b>Show</b>')
edit_l = gtk.Label()
edit_l.set_markup('<b>Edit</b>')
table.attach(show_l, 0,1,0,1)
table.attach(edit_l, 1,2,0,1)
edit_b_ref = gtk.RadioButton(None)
for (i, n) in enumerate(self.features_dict.keys()) :
f = self.features_dict[n]
show_b = gtk.CheckButton()
show_b.set_active(True)
edit_b = gtk.RadioButton(edit_b_ref, n)
table.attach(show_b, 0,1,i+1, i+2)
#table.attach(edit_b, 1,2,i+1, i+2)
bg = gtk.EventBox()
bg.add(edit_b)
(r,g,b) = f.feature.get_color()
r=int(r*65535)
g=int(g*65535)
b=int(b*65535)
bg.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(red=r,green=g,blue=b))
table.attach(bg,1,2,i+1,i+2)
edit_b.connect('toggled', self.edit_feature_evt, f, bottombox)
show_b.connect('toggled', self.show_feature_evt, f, self.slider)
bottombox.pack_start(table, fill=False, expand=False)
bottombox.pack_start(gtk.Label(' '), fill=False, expand=False)
bottombox.pack_start(r_panel, fill=True, expand=True)
bottombox.show_all()
mainbox.pack_start(s_panel, fill=False, expand=False)
mainbox.pack_start(bottombox, fill=False, expand=False)
mainbox.pack_start(gtk.Label(''), fill=True, expand=True)
mainbox.show_all()
return mainbox
[docs] def edit_feature_evt(self, rb, f, bottombox) :
if rb.get_active() :
toremove = bottombox.get_children()[-1]
bottombox.remove(toremove)
bottombox.pack_start(f.get_panel())
[docs] def show_feature_evt(self, rb, f, slider) :
f.set_visible(rb.get_active())
slider.update()
[docs] def slider_changed_evt(self, evt) :
self.slider.update()
if __name__ == '__main__' :
import Features
features = Features.Features()
f1 = features.new_feature('point', 'telophase', 'T', (0,0,1), '')
f2 = features.new_feature('segment', 'anaphase', 'A', (0,2,0), '')
f3 = features.new_feature('point', 'telophase2', 'TT', (0,0,0.5), '')
w = gtk.Window()
w.set_title("Slider")
w.set_size_request(350, 130)
w.set_position(gtk.WIN_POS_CENTER)
w.connect("destroy", gtk.main_quit)
f = Features_gtk(features, None)
w.add(f.get_panel((0,101)))
w.show()
gtk.main()