Source code for Contrast
# This is a simple brightness/contrast manager for CellTracking
# MW Aug 2012 - GPLv3+
# Ported from CellTracking O.x to CellTracking 1.x
# MW Jun 2013 - GPLv3+
import gtk, logging
#import cv
#from numpy import *
[docs]class State_contrast :
def __init__(self) :
self.hidden = False
self.initiated = False
self.auto_contrast = False
self.current_contrast = 1.0
[docs]class Contrast :
def __init__(self, state) :
# Create a state for the contrast
self.state = state
self.state_contrast = State_contrast()
self.state_contrast = self.state.add_subclass('contrast', self.state_contrast)
[docs] def hide_show_panel_evt(self, w) :
self.hide_show_panel()
return True
[docs] def hide_show_panel(self, hide=None) :
"""hide=None means 'switch state'"""
if ((hide or (not self.state_contrast.hidden and hide==None)) and self.state_contrast.initiated) : # Hide a displayed panel
self.window.hide()
self.state_contrast.hidden = True
elif ((not hide or (self.state_contrast.hidden and hide==None)) and self.state_contrast.initiated) :
self.window.show()
self.state_contrast.hidden = False
elif ((self.state_contrast.hidden or not hide) and not self.state_contrast.initiated) : # Create a new display
# Window
self.window = gtk.Window()
self.window.set_title("B&C")
self.window.connect("delete-event", self.hide_show_change)
self.panel = gtk.HBox()
# Buttons
self.panel.pack_start(gtk.Label('Contrast:'))
b_minus = gtk.Button('-')
b_minus.connect('clicked', self.change_contrast_evt, -1)
self.panel.pack_start(b_minus, fill=False, expand=False)
b_plus = gtk.Button('+')
b_plus.connect('clicked', self.change_contrast_evt, +1)
self.panel.pack_start(b_plus, fill=False, expand=False)
b_auto = gtk.Button('Auto')
b_auto.connect('clicked', self.auto_contrast_evt)
self.panel.pack_start(b_auto, fill=False, expand=False)
b_reset = gtk.Button('Reset')
b_reset.connect('clicked', self.reset_contrast_evt)
self.panel.pack_start(b_reset, fill=False, expand=False)
self.window.add(self.panel)
self.window.show_all()
self.state_contrast.initiated = True
self.state_contrast.hidden = False
else :
logging.error("This case in hide_show_panel had never been considered. Fatal.")
[docs] def change_contrast_evt(self, w, incr) :
self.state_contrast.current_contrast += incr
#print self.state_contrast.current_contrast
[docs] def reset_contrast_evt(self, w) :
"""Function called to reset contrast to 1
also unselects the auto contrast"""
self.state_contrast.current_contrast = 1
self.state_contrast.auto_contrast = False
[docs] def auto_contrast_evt(self, w) :
self.state_contrast.auto_contrast = not self.state_contrast.auto_contrast
[docs] def hide_show_change(self, q, qq=None) :
self.hide_show_panel(hide=True)
return True