Source code for Cells
# CellTracking.py
# By MW, Jun 2013
# GPLv3+
#
# Class the display of the cells. Should be called by a player instance for example.
import gtk, imp, logging
MenuCells = imp.load_source("MenuCells", './bin/Movies/Cells/Cells_menu_gtk.py')
NewCells = imp.load_source("NewCells", './bin/Movies/Cells/Cells_newcell_gtk.py')
[docs]class CellsPanel :
"""A class displaying a cell panel with lot of options to edit them"""
def __init__(self, state) :
self.new_cell_panel = NewCells.Panel(state, self)
self.state = state
self.hidden = False
self.initiated = False
self.cells_dict = {}
self.cells_list_dict = {}
self.panel_rb_none = gtk.RadioButton(None)
self.panel_rb = self.panel_rb_none # The radiobutton for the left panel
self.r_panel = None # The right panel
self.selected_cell = None # Reference to the gtk selected cell
[docs] def hide_show_panel(self, hide=None) :
"""hide=None means 'switch state'"""
if ((hide or (not self.hidden and hide==None)) and self.initiated) : # Hide a displayed panel
self.window.hide()
self.hidden = True
elif ((not hide or (self.hidden and hide==None)) and self.initiated) :
self.window.show()
self.hidden = False
elif ((self.hidden or not hide) and not self.initiated) : # Create a new display
# Window
self.window = gtk.Window()
self.window.set_title("Cells")
self.window.connect("delete-event", self.hide_show_change)
panel = gtk.VBox()
self.window.add(panel)
self.window.set_default_size(500, 300) # Specify size
# Menu
self.menu = MenuCells.Menu(self)
self.menu_w = self.menu.get_menu()
panel.pack_start(self.menu_w, fill=False, expand=False)
# -
# Left panel
l_scrollbar = gtk.ScrolledWindow()
l_scrollbar.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
self.cells_list = gtk.VBox()
self.cells_list.pack_start(gtk.Label("Cells"), fill=False, expand=False)
self.cells_list.pack_start(gtk.HSeparator(), fill=False, expand=False)
l_scrollbar.add_with_viewport(self.cells_list)
# Right panel
self.r_panel = gtk.ScrolledWindow()
self.r_panel.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
self.r_panel.show_all()
# split window
self.b_panel = gtk.HPaned() # Bottom panel
self.b_panel.add1(l_scrollbar)
self.b_panel.add2(self.r_panel)
self.b_panel.set_position(200) # Size of the left panel
panel.pack_start(self.b_panel, expand=True, fill=True)
# scrollbar on the left
# Have a cells instance...
self.window.show_all()
self.initiated = True
self.hidden = False
else :
logging.error("This case in hide_show_panel had never been considered. Fatal.")
return True
[docs] def draw(self, im) :
"""Function that return an image with the cells that have to be displayed"""
if (self.cells_dict != {}) or (self.new_cell_panel.is_polygon_open()):
im = self.new_cell_panel.draw(im)
sth_selected = False
for c in self.cells_dict.values() :
im = c.draw_polygon(im)
if c.get_selected() :
self.selected_cell = c
sth_selected = True
if not sth_selected :
self.selected_cell = None
return im
[docs] def hide_show_change(self, q, qq=None) :
self.hide_show_panel(hide=True)
return True
[docs] def hide_show_new_cell_panel(self, celltype=None) :
self.new_cell_panel.set_visible(celltype)
[docs] def click(self, tup) :
r = self.new_cell_panel.click(tup) # Returns True if click intercepted
sth_selected = False
if not r :
for c in self.cells_list_dict.values() :
res = c.click(tup)
if res :
sth_selected = True
self.selected_cell = c
if not sth_selected :
logging.debug("everything is unselected")
self.panel_rb_none.set_active(True)
self.selected_cell = None
[docs] def set_image_move(self, tup) :
"""Function called when the users keeps the left button pressed on
the viewer panel"""
# directly send to selected cell
if self.selected_cell != None :
self.selected_cell.move(tup)
[docs] def unclick(self) :
"""Function that forward the signal that the user has released the
click to all cells"""
for c in self.cells_list_dict.values() :
c.unclick()
[docs] def del_cell(self, name) :
"""Function that delete a cell"""
logging.error("Function remove cell to be fully implemented")
# Change cell state to deleted
# Remove cell from the self.cells_list and from the self.cells_list_dict
[docs] def add_cell(self, name, cell) :
if name not in self.cells_dict.keys() :
self.cells_dict[name] = cell
n = cell.get_name()
# Record it to the base so that we can esily remove it
self.cells_list_dict[n] = cell
# Add cell to the panel
cell.set_r_panel(self.r_panel)
self.panel_rb = gtk.RadioButton(self.panel_rb)
p = cell.get_panel(self.panel_rb, self.panel_rb_none)
p.show_all()
box = gtk.HBox()
self.panel_rb.connect('toggled', self.rb_toggled, cell)
#cell.set_selected(True)
self.panel_rb.set_active(True)
box.pack_start(self.panel_rb, fill=False, expand=False)
box.pack_start(p, fill=False, expand=False)
box.show_all()
self.cells_list.pack_start(box, fill=False, expand=False)
# The newly created cell is automatically selected
self.selected_cell = cell
[docs] def rb_toggled(self, w, cell) :
"""Function called when the user clicks on a radiobutton
to select another cell"""
cell.rb_toggled(w.get_active())