Source code for Cells_newcell_gtk
# CellTracking.py
# By MW, Jun 2013
# GPLv3+
#
# Module containing all the required functions to manage the creation of cells
import gtk, imp
Cell = imp.load_source("Cell", "./bin/Movies/Cells/Cell_gtk.py")
[docs]class Panel :
"""Class managing the panel to create new cells"""
def __init__(self, state, cells) :
self.cells = cells
self.state = state
self.state_player = self.state.get_subclass('player')
self.visible = False
self.initiated = False
self.names = {'pol' : 'Polygon', 'rect_ct' : 'bla', 'rect_tp' : 'blasquare'}
self.tmp_cell = None
self.type = None
[docs] def click(self, tup) :
rr = True
if self.tmp_cell != None :
r=self.tmp_cell.add_point(tup)
if r==False :
n = self.tmp_cell.cell.get_name()
self.cells.add_cell(n, self.tmp_cell)
self.tmp_cell = None
elif self.visible : # Create a new cell if the window is visible
self.tmp_cell = self.new_cell(self.type)
#cells = self.state.movie.Cells
#if self.type == 'pol' :
# self.tmp_cell = Cell.GtkCell(cells, self.state)
#elif self.type == 'rect_ct' :
# self.tmp_cell = Cell.GtkRect_ct(cells, self.state)
#elif self.type == 'rect_tp' :
# self.tmp_cell = Cell.GtkRect_tp(cells, self.state)
self.tmp_cell.add_point(tup)
else :
rr = False
return rr
[docs] def new_cell(self, typ) :
cells = self.state.movie.Cells
if typ == 'pol' :
tmp_cell = Cell.GtkCell(cells, self.cells.delete_cell, self.cells.export_progress_bar, self.state)
elif typ == 'rect_ct' :
tmp_cell = Cell.GtkRect_ct(cells, self.cells.delete_cell, self.cells.export_progress_bar, self.state)
elif typ == 'rect_tp' :
tmp_cell = Cell.GtkRect_tp(cells, self.cells.delete_cell, self.cells.export_progress_bar, self.state)
return tmp_cell
[docs] def draw(self, im) :
if self.tmp_cell != None :
im = self.tmp_cell.draw_polygon(im)
return im
[docs] def get_visible(self) :
return self.visible
[docs] def is_polygon_open(self) :
if self.tmp_cell != None :
return True
else :
return False
[docs] def set_visible(self, celltype=None, set_visible=None) :
if set_visible==False or (set_visible==None and self.visible) : # Hide panel
self.visible = False
self.window.hide()
#self.window.destroy()
self.state_player.set_lock(False)
self.type = None
else :
self.get_panel(celltype)
self.visible = True
self.type = celltype
[docs] def get_panel(self, celltype) :
if self.initiated :
self.window.show()
else :
self.window = gtk.Window()
self.window.set_title("Create new cells")
self.window.connect('delete-event', self.hide_show_panel_evt)
panel = gtk.HBox()
reset_b = gtk.Button('Delete current cell')
reset_b.connect('clicked', self.reset_polygon_evt)
panel.pack_start(reset_b, fill=False, expand=False)
refsize_l = gtk.Label('Reference polygon size:')
refsize = self.state_player.reference_size
adj = gtk.Adjustment(refsize, 2, 100, 1, 5, 0)
refsize_sb = gtk.SpinButton(adj)
refsize_sb.connect('value-changed', self.refsize_changed_evt)
panel.pack_start(refsize_l, fill=False, expand=False)
panel.pack_start(refsize_sb, fill=False, expand=False)
# ref_size_cb
self.window.add(panel)
panel.show_all()
self.initiated = True
self.state_player.set_lock(True)
self.window.show()
[docs] def refsize_changed_evt(self, evt) :
self.state_player.reference_size = evt.get_value()
[docs] def hide_show_panel_evt(self, q, qq) :
self.set_visible(set_visible=False) #Switch the visibility state of the panel
return True
[docs] def reset_polygon_evt(self, w) :
if self.tmp_cell != None :
self.tmp_cell.reset_polygon()