Esempio n. 1
0
    def __init__(self, controller, title="Seamless Typewriter"):
        # Create a Tk.App(), which handles the windowing system event loop
        self.root = self.tk_get_root()
        self.root.protocol("WM_DELETE_WINDOW", self._quit)
        self.root.winfo_toplevel().title(title)

        MainFrame(self.root, controller)

        # show the player window centred and run the application
        self.root.mainloop()
Esempio n. 2
0
    def __init__(self):
        self.__dict__ = self.__shared_state

        if not self.__shared_state:
            """
            Borg Design Pattern: inicia o estado apenas uma vez
            """
            self.__wx_app = wx.App(False)
            self.main_frame = MainFrame(self)
            self.main_frame.wx_app = self.__wx_app

            self.comp_pkgs = ctrl.Packages()
            self.__guictrl = GuiController(self.main_frame, self.comp_pkgs)

            ctrl_serial.load(self.__guictrl)
Esempio n. 3
0
class View:
    ''' 
        Component of the library in charge of what the user can see. Every action of the user are communicated to the controller. 
    No direct interaction with the Model part. 
    Essentially composed of two frames:
    - the main_frame with which the user can start a new game, and play as well
    - the config_frame to change the parameters of the game.
    '''
    def __init__(self, root, controller):
        self.root = init_root(root)
        self.controller = controller
        self.main_frame = MainFrame(self.controller, self, self.root)
        self.config_frame = ConfigFrame(self.controller, self, self.root)
        self.main_frame.grid(row=0)  # display the main_frame at the beginning

    def go_to_config(self):
        ''' To go to the config_frame. '''
        change_page(self.main_frame, self.config_frame)

    def go_to_main(self):
        ''' To go to the main_frame. '''
        change_page(self.config_frame, self.main_frame)

    def display_message(self, text, delay=0):
        ''' To display a message on the main_frame; delay is the time, in seconds, before the change occurs. '''
        self.main_frame.display_message(text, delay)

    def collect_parameters(self):
        ''' To pick up the parameters chosen by the user on the configuration frame. '''
        return self.config_frame.LabelledSpinb_nbr_games.get(
        ), self.config_frame.LabelledSpinb_born_sup.get(
        ), self.config_frame.LabelledSpinb_nbr_dec.get(
        ), self.config_frame.tablecheckb.get()

    def restart(self):
        ''' Restart the game. '''
        self.main_frame.restart()

    def get_time(self):
        ''' To pick up the time displayed by the chronometer. '''
        return self.main_frame.chrono.get()

    def get_record(self):
        ''' To pick up the current record. '''
        return self.main_frame.record_screen.get()

    def update_record(self, new_record):
        ''' Update the record on the main_frame '''
        self.main_frame.record_screen.update(new_record)
Esempio n. 4
0
    def __init__(self, app, cfg):
        self.frame = MainFrame(app)
        self.cfg = cfg
        self.session_id2page = {}
        self.page2session_id = {}
        
        #Event Bindings
        self.frame.Bind(wx.EVT_TOOL, self.on_btn_save_session, 
                  id=self.frame.save_session_btn.GetId())
        self.frame.Bind(wx.EVT_TOOL, self.on_btn_new_session, 
                  id=self.frame.new_session_btn.GetId()) 
        self.frame.Bind(wx.EVT_TOOL, self.on_btn_switch_session, 
                  id=self.frame.switch_session_btn.GetId()) 
        self.frame.Bind(wx.EVT_TOOL, self.on_btn_clone_session,
                  id=self.frame.clone_session_btn.GetId())
        self.frame.Bind(wx.EVT_TOOL, self.on_btn_clear_session, 
                  id=self.frame.clear_session_btn.GetId()) 
        self.frame.Bind(wx.EVT_TOOL, self.on_btn_start_server, 
                  id=self.frame.start_server_btn.GetId())
        self.frame.Bind(wx.EVT_TOOL, self.on_btn_stop_server, 
                  id=self.frame.stop_server_btn.GetId())
        
        self.frame.Bind(wx.EVT_CLOSE, self.on_quit)
        
        #Service that handles HTTP requests
        dl = DataListener()
    
        self.session_manager = SessionManager(cfg, dl)
        self.session_manager.session_new.connect(self.on_session_new)
        self.session_manager.session_switch.connect(self.on_session_switch)
        self.session_manager.switch_new_session()
        
        #Start the HTTP server
        self.ls = ListeningService(cfg.get('cherrypy',{}), dl)
        self.ls.server_started.connect(self.on_server_started)
        self.ls.server_stopped.connect(self.on_server_stopped)
        self.ls.start()
        

        self.frame.Show()
        self.frame.Maximize()
Esempio n. 5
0
def main():

    # here is a logging configuration with three handlers (two handlers configured on one file and one stream)
    logger = logging.getLogger()
    logger.setLevel(logging.NOTSET)

    debug_logger = logging.FileHandler('log_file.log')
    debug_logger.setLevel(logging.DEBUG)

    error_logger = logging.FileHandler('log_file.log')
    error_logger.setLevel(logging.ERROR)

    console_logger = logging.StreamHandler()
    console_logger.setLevel(logging.ERROR)

    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    debug_logger.setFormatter(formatter)
    error_logger.setFormatter(formatter)
    console_logger.setFormatter(formatter)

    logger.addHandler(debug_logger)
    logger.addHandler(error_logger)
    logger.addHandler(console_logger)

    #Running app
    logging.debug("Running Gym'Administration app")

    #Init database
    logging.debug("Init database")
    database_engine = DatabaseEngine(url='sqlite:///database.db')
    database_engine.create_database()

    #Controller
    gym_controller = GymController(database_engine)
    admin_controller = AdminController(database_engine)
    coach_controller = CoachController(database_engine)
    machine_controller = MachineController(database_engine)

    #Vue
    root = MainFrame(gym_controller, admin_controller, coach_controller,
                     machine_controller)
    root.master.title("Gym'Administration - Desktop App")
    root.show_menu()

    #Start
    root.mainloop()
Esempio n. 6
0
class GUIController(object):
    def __init__(self, app, cfg):
        self.frame = MainFrame(app)
        self.cfg = cfg
        self.session_id2page = {}
        self.page2session_id = {}
        
        #Event Bindings
        self.frame.Bind(wx.EVT_TOOL, self.on_btn_save_session, 
                  id=self.frame.save_session_btn.GetId())
        self.frame.Bind(wx.EVT_TOOL, self.on_btn_new_session, 
                  id=self.frame.new_session_btn.GetId()) 
        self.frame.Bind(wx.EVT_TOOL, self.on_btn_switch_session, 
                  id=self.frame.switch_session_btn.GetId()) 
        self.frame.Bind(wx.EVT_TOOL, self.on_btn_clone_session,
                  id=self.frame.clone_session_btn.GetId())
        self.frame.Bind(wx.EVT_TOOL, self.on_btn_clear_session, 
                  id=self.frame.clear_session_btn.GetId()) 
        self.frame.Bind(wx.EVT_TOOL, self.on_btn_start_server, 
                  id=self.frame.start_server_btn.GetId())
        self.frame.Bind(wx.EVT_TOOL, self.on_btn_stop_server, 
                  id=self.frame.stop_server_btn.GetId())
        
        self.frame.Bind(wx.EVT_CLOSE, self.on_quit)
        
        #Service that handles HTTP requests
        dl = DataListener()
    
        self.session_manager = SessionManager(cfg, dl)
        self.session_manager.session_new.connect(self.on_session_new)
        self.session_manager.session_switch.connect(self.on_session_switch)
        self.session_manager.switch_new_session()
        
        #Start the HTTP server
        self.ls = ListeningService(cfg.get('cherrypy',{}), dl)
        self.ls.server_started.connect(self.on_server_started)
        self.ls.server_stopped.connect(self.on_server_stopped)
        self.ls.start()
        

        self.frame.Show()
        self.frame.Maximize()
        
    def on_quit(self, event):
        self.ls.stop()
        self.ls.exit()
        event.Skip()
        
    def on_server_started(self, **kwargs):
        self.frame.toolbar.EnableTool(self.frame.start_server_btn.GetId(), False)
        self.frame.toolbar.EnableTool(self.frame.stop_server_btn.GetId(), True)
    
    def on_server_stopped(self, **kwargs):
        self.frame.toolbar.EnableTool(self.frame.start_server_btn.GetId(), True)
        self.frame.toolbar.EnableTool(self.frame.stop_server_btn.GetId(), False)
        
    def on_btn_clear_session(self, event):
        self.session_manager.clear()
        event.Skip()    
        
    def on_btn_save_session(self, event):
        dir_dialog = wx.DirDialog(self.frame, "Select the output directory")
        if dir_dialog.ShowModal() == wx.ID_OK:
            self.save(dir_dialog.GetPath())
        event.Skip()
    
    def on_btn_new_session(self, event):
        self.session_manager.new_session()
        event.Skip()
        
    def on_btn_switch_session(self, event):
        page_id = self.frame.get_selection()
        session_id = self.page2session_id[page_id]
        self.session_manager.switch_session(session_id)
        event.Skip()
        
    def on_btn_clone_session(self, event):
        page_id = self.frame.get_selection()
        session_id = self.page2session_id[page_id]
        self.session_manager.clone_session(session_id)
        event.Skip()
            
    def on_btn_start_server(self, event):
        self.ls.start()
        event.Skip()
        
    def on_btn_stop_server(self, event):
        self.ls.stop()
        event.Skip()
        
    def save(self, outdir):
        self.session_manager.save(outdir)
    
    def on_session_switch(self, session_id, **kwargs):
        page_id = self.session_id2page[session_id]
        self.frame.select_active_session(page_id)
    
        
    def on_session_new(self, session_id, session_monitors, **kwargs):
        session_panel, page_id = self.frame.new_session_panel(session_id)
        self.session_id2page[session_id] = page_id
        self.page2session_id[page_id] = session_id
        for tab_name, tab_monitors in sorted(session_monitors.iteritems()):
            tab_panel = session_panel.new_tab(tab_name)
            for monitor_name, monitor in sorted(tab_monitors.iteritems()):
                try:
                    monitor_cfg = self.cfg['elements']['tabs'][tab_name][monitor_name]
                except KeyError:
                    monitor_cfg = self.cfg['elements'][monitor_name]
                monitor_figure = monitor.get_figure()
                tab_panel.add_monitor(monitor_cfg, 
                                   monitor_figure, monitor_name)
Esempio n. 7
0
 def __init__(self, root, controller):
     self.root = init_root(root)
     self.controller = controller
     self.main_frame = MainFrame(self.controller, self, self.root)
     self.config_frame = ConfigFrame(self.controller, self, self.root)
     self.main_frame.grid(row=0)  # display the main_frame at the beginning
Esempio n. 8
0
from view.main_frame import MainFrame

main_frame = MainFrame()