Source code for State

# CellTracking.py
# By MW, Jun 2013
# GPLv3+
#
# Class representing a graphical player. It uses GTK so these functions can
#+hardly be used automatically in a script


import gtk, sys, gobject, imp

sys.path.append('./bin/Players/')
import State_player
import Menu, Viewer, Zoom, Controls
import Contrast

Cells_gtk = imp.load_source("Cells_gtk", './bin/Movies/Cells/Cells_gtk.py')

[docs]class Player : def __init__(self, state) : """Receives a state instance""" # State management self.state = state if not self.state.has_subclass("player") : p_state = State_player.Player_state(self.state) self.state.add_subclass("player", p_state) self.state_player = p_state # Channel ch = self.state.movie.Channels.get_channels_dict().keys()[0] self.state_player.set_current_channel(ch) # Instanciate classes (after the player_state) self.cells = Cells_gtk.CellsPanel(state) self.contrast = Contrast.Contrast(state) # Create window self.window = gtk.Window() self.window.set_title("CellTracking player") #self.window.set_default_size(500, 600) self.window.connect("delete_event", self.quit_cross) self.window.show() # Create organization of the window self.box = gtk.VBox() self.window.add(self.box) # Load subparts of the player #- Menu self.menu = Menu.Menu(self) # Takes a player instance in parameter self.menu_w = self.menu.get_menu() self.menu_w.show() self.box.pack_start(self.menu_w, expand=False, fill=False) self.menu.add_button(self.contrast) #- Viewer self.viewer = Viewer.Viewer(self) self.viewer_w = self.viewer.get_viewer() self.viewer_w.show_all() self.box.pack_start(self.viewer_w, expand=True, fill=True) # Bottom box self.bottom_box = gtk.HBox() self.box.pack_start(self.bottom_box, expand=False, fill=False) self.bottom_box.show() #- Zoom (w/ view?) self.zoom = Zoom.Zoom(self) self.zoom_w = self.zoom.get_zoom() self.zoom_w.show_all() self.bottom_box.pack_start(self.zoom_w, expand=False, fill=False) #- Controls self.controls = Controls.Controls(self) self.controls_w = self.controls.get_controls() self.controls_w.show_all() self.bottom_box.pack_start(self.controls_w, expand=True, fill=True) # Timer #gobject.timeout_add(50, self.update_player) gobject.timeout_add(200, self.update_player) # Show window # Detect resizing (requires Zoom to be instanciated) self.window.connect('check-resize', self.size_changed) self.window.show() self.box.show()
[docs] def update_player(self) : """Function calling everything needed to update the player""" # update the state newframe = False # if we have to read a frame from the file i = self.state_player.get_current_index() s = self.state_player.current_speed if self.state_player.play and not self.state_player.current_manual_mode : if s >= 1 : #n = self.state.get_frame_nb() #self.state_player.set_current_frame_index(max(0,min(n,i+s))) self.state_player.set_current_frame_index(i+s) newframe = True else : period = int(1./s) if self.state_player.slow_play_index >= period-1 : self.state_player.set_current_frame_index(i+1) self.state_player.slow_play_index = 0 newframe = True else : self.state_player.slow_play_index += 1 # Update the image if newframe : f = self.state_player.read_raw_frame() else : f = self.state_player.get_raw_frame() self.state_player.set_current_frame(f) # Update controls f = self.state_player.process_frame() # To call only once ! self.state_player.set_current_frame(self.cells.draw(f)) self.zoom.update_zoom() # Update the zoom display self.viewer.update_viewer()# Update the viewer panel self.controls.update_controls() # Manage clicks if self.state_player.current_click != None : self.cells.click(self.state_player.current_click) # Forward click to cells self.state_player.set_image_click(None) return True
[docs] def size_changed(self, w) : """Event called when the window is resized""" self.viewer.update_coord()
[docs] def quit_cross(self, q, qq) : self.quit(q)
[docs] def quit(self, q) : gtk.main_quit(q)
[docs] def start(self) : gtk.main()