def open_save_UI(self, plot_id='plot'): save_controller = SaveFileController(plot=self.get_plot(plot_id), parent=self) save_dialog = simple_session('save', 'Save dialog', SavePlotDialog, controller=save_controller) Application.instance().add_factories([save_dialog]) session_id = Application.instance().start_session('save') save_controller._session_id = session_id
def open_MDA_UI(self): mda_controller = MDAExecutionController(parent=self, treasure_chest=self.chest) mda_dialog = simple_session('mda', 'MDA dialog', MDAInterface, controller=mda_controller) Application.instance().add_factories([mda_dialog]) session_id = Application.instance().start_session('mda') mda_controller._session_id = session_id
def open_crop_UI(self): crop_controller = CellCropController(parent=self, treasure_chest=self.chest) cell_cropper = simple_session('cropper', 'Cell cropper', CellCropperInterface, controller=crop_controller) Application.instance().add_factories([cell_cropper]) session_id = Application.instance().start_session('cropper') crop_controller._session_id = session_id
def parse_and_create(self, source, **kwargs): """ Parses and compiles the source. The source should have a component defined with the name 'MainView'. Arguments --------- source : str The enaml source file kwargs : dict The default attribute values to pass to the component. Returns ------- The component tree for the 'MainView' component. """ enaml_ast = parse(source) enaml_module = types.ModuleType('__tests__') ns = enaml_module.__dict__ code = EnamlCompiler.compile(enaml_ast, '__enaml_tests__') exec code in ns View = ns['MainView'] # Start the app instance first. session_name = get_unique_session_identifier() view_factory = simple_session(session_name, 'test', View) self.app = TestingQtApplication.instance() if self.app is None: self.app = TestingQtApplication([]) self.app.add_factories([view_factory]) session_id = self.app.start_session(session_name) self.app.start() session = self.app._sessions[session_id] # retrieve the enaml server side root widget self.view = session.windows[0] # retrieve the enaml client side root widget self.client_view = self.app._qt_sessions[session_id]._windows[0]
def main(): import enaml from enaml.stdlib.sessions import simple_session from enaml.qt.qt_application import QtApplication with enaml.imports(): from analyzarr.ui.main_view import Main from controllers.HighSeasAdventure import HighSeasAdventure controller = HighSeasAdventure() # For enaml 0.7 #qtapp = QtApplication() #view=Main("Ahoy!") # for enaml 0.6 qtapp = QtApplication([]) main_ui = simple_session('main', 'The main UI window', Main, controller=controller) qtapp.add_factories([main_ui]) qtapp.start_session('main') # version agnostic qtapp.start()
debug = Bool(False) @on_trait_change('age') def debug_print(self): """ Prints out a debug message whenever the person's age changes. """ if self.debug: templ = "{first} {last} is {age} years old." s = templ.format( first=self.first_name, last=self.last_name, age=self.age, ) print s if __name__ == '__main__': with enaml.imports(): from person_view import PersonView john = Person(first_name='John', last_name='Doe', age=42) john.debug = True session = simple_session( 'john', 'A view of the Person john', PersonView, person=john ) app = QtApplication([session]) app.start_session('john') app.start()
@on_trait_change('age') def debug_print(self): """ Prints out a debug message whenever the person's age changes. """ if self.debug: templ = "{first} {last} is {age} years old." s = templ.format( first=self.first_name, last=self.last_name, age=self.age, ) print s if __name__ == '__main__': with enaml.imports(): from person_view import PersonView john = Person(first_name='John', last_name='Doe', age=42) john.debug = True session = simple_session('john', 'A view of the Person john', PersonView, person=john) app = QtApplication([session]) app.start_session('john') app.start()
#------------------------------------------------------------------------------ # Copyright (c) 2011, Enthought, Inc. # All rights reserved. #------------------------------------------------------------------------------ import enaml from enaml.stdlib.sessions import simple_session if __name__ == '__main__': with enaml.imports(): from hello_world_view import Main sess_one = simple_session('hello-world', 'A hello world example', Main) sess_two = simple_session( 'hello-world-python', 'A customized hello world example', Main, message="Hello, world, from Python!" ) from enaml.qt.qt_application import QtApplication app = QtApplication([sess_one, sess_two]) app.start_session('hello-world') app.start_session('hello-world-python') app.start()
def age_at_date(self, date): """Return age rounded to the nearest 1/2 year. """ age = int((date - self.DOB).days / 365.25 * 2) / 2. return age def _get_age(self): time_since_birth = date.today() - self.DOB return int(time_since_birth.days / 365.25 * 2.) / 2. if __name__ == '__main__': import enaml from enaml.stdlib.sessions import show_simple_view, simple_session from enaml.qt.qt_application import QtApplication eld = Person(first_name="Eliza", last_name="Diller", DOB=date(2003,6,9)) print "{} {} is {} years old.".format(eld.first_name, eld.last_name, eld.age) with enaml.imports(): from bod_person_view import PersonView eld_view = PersonView(person=eld) session = simple_session( eld.first_name, 'A view of the Person {} {}'.format(eld.first_name, eld.last_name), PersonView, person=eld ) app = QtApplication([session]) app.start_session(eld.first_name) app.start() # show_simple_view(eld_view)
from enaml.stdlib.sessions import simple_session from enaml.qt.qt_application import QtApplication from enaml.qt.qt.QtCore import QTimer, SIGNAL import serial_connection import robot_interface robot = robot_interface.RobotInterface() def update(): conn = serial_connection.SerialConnection(); if conn.is_connected(): commandstr = conn.poll() if commandstr: robot.log(commandstr) from PySide.QtCore import * from PySide.QtGui import * if __name__ == '__main__': with enaml.imports(): from control_panel import Main session = simple_session('main','main window',Main) app = QtApplication([session]) timer = QTimer() timer.connect(timer, SIGNAL("timeout()"), update) timer.start(10) app.start_session('main') app.start()
#------------------------------------------------------------------------------ # Copyright (c) 2011, Enthought, Inc. # All rights reserved. #------------------------------------------------------------------------------ import enaml from enaml.stdlib.sessions import simple_session if __name__ == '__main__': with enaml.imports(): from hello_world_view import Main sess_one = simple_session('hello-world', 'A hello world example', Main) sess_two = simple_session('hello-world-python', 'A customized hello world example', Main, message="Hello, world, from Python!") from enaml.qt.qt_application import QtApplication app = QtApplication([sess_one, sess_two]) app.start_session('hello-world') app.start_session('hello-world-python') app.start()
""" age = int((date - self.DOB).days / 365.25 * 2) / 2. return age def _get_age(self): time_since_birth = date.today() - self.DOB return int(time_since_birth.days / 365.25 * 2.) / 2. if __name__ == '__main__': import enaml from enaml.stdlib.sessions import show_simple_view, simple_session from enaml.qt.qt_application import QtApplication eld = Person(first_name="Eliza", last_name="Diller", DOB=date(2003, 6, 9)) print "{} {} is {} years old.".format(eld.first_name, eld.last_name, eld.age) with enaml.imports(): from bod_person_view import PersonView eld_view = PersonView(person=eld) session = simple_session(eld.first_name, 'A view of the Person {} {}'.format( eld.first_name, eld.last_name), PersonView, person=eld) app = QtApplication([session]) app.start_session(eld.first_name) app.start() # show_simple_view(eld_view)