示例#1
0
 def _run_clock(self):
     # Updates the status bar time once every second.
     self.clock_running = True
     self.start_time = time()
     while self.clock_running:
         self.td = time() - self.start_time
         self.clock = secs_to_time(self.td)
         sleep(1.0)
示例#2
0
 def load(self, input_ports):
     self.logger.debug("Load recorded values [Recorder]")
     with open(join(recorder_dir, recorder_file), 'r') as f:
         data = jload(f)
     self.images = data["images"]
     values = load(join(recorder_dir, recording_file))
     self.reset(input_ports)
     nv = len(values)
     nip = len(input_ports)
     self.plotview.update_subplots(input_ports)
     self.plotview.update_values(values)
     for i in range(nv):
         t = secs_to_time(values[i, 0])
         for j in range(nip):
             self.container[j].append((t, values[i, j + 1]))
     self.result_viewer.show_images=False
     self._update_record_information(0)
     self.show_images=True
示例#3
0
class DialogPhaseTime(DialogPhase):
    """
    Dialog to create a instance of the class
    PhaseTime. The dialog checks all attributes and make sure
    that a invalid phase can not created.
    """

    position = Instance(Combobox, ())

    name = Str

    interval = Str(secs_to_time(0))

    ticks = Str(secs_to_time(0))

    def _get_attributes(self):
        # Return all attributes of the view.
        idays, ihours, imins, isecs = map(int, self.interval.split(":"))
        interval = idays * 24 * 60**2 + ihours * 60**2 + imins * 60 + isecs
        tdays, thours, tmins, tsecs = map(int, self.ticks.split(":"))
        ticks = tdays * 24 * 60**2 + thours * 60**2 + tmins * 60 + tsecs
        return interval, ticks, self.name, self.reset, self.reset_time,\
            self.interval, self.ticks

    def _update_attributes(self, args):
        # update the attributes of the view with the given arguments
        self.name, self.reset, self.reset_time,\
            self.interval, self.ticks = args

    #=========================================================================
    # Methods to handle the dialog with other classes
    #=========================================================================

    def open_dialog(self, phase_num, phases=None):
        if not phases == None:
            self.cur_phases = phases
        self.position.reset()
        for i in range(1, phase_num + 1):
            self.position.add_item("Position " + str(i), i)
        self._check_attributes()
        return self.configure_traits(kind="livemodal")

    def load(self):
        """Create a instance of the class PhaseTime with the attributes\
            of the view.

        :returns: Time based phase
        :rtype: PhaseTime
        """
        phase = PhaseTime(self.model, self, *self._get_attributes())
        self.name = ""
        return phase

    #=========================================================================
    # Traitsview + Traitsevent
    #=========================================================================

    ConfirmButton = Action(name="OK", enabled_when="not error")

    @on_trait_change("name,interval,ticks")
    def _check_attributes(self):
        # Checks whether the given attributes are correctly.
        try:
            for phase in self.cur_phases:
                if phase.name == self.name:
                    raise ValueError("The name does already exists")
            interval, ticks = self._get_attributes()[:2]
            if interval < 1:
                raise ValueError("The interval must be positive")
            elif ticks < 1:
                raise ValueError("The ticks must be positive")
            elif ticks > interval:
                raise ValueError("The interval must be greater than the ticks")
            elif self.position.get_selected_value() < 1:
                raise ValueError("The position is invalid")
            PhaseTime(self.model, None, *self._get_attributes())
            self.error = False
        except Exception, e:
            self.error = True
            self.error_msg = str(e)
示例#4
0
 def start_clock(self):
     """Run the clock in the status bar."""
     self.logger.info("Start the time-thread [SMRCWindow]")
     self.clock = secs_to_time(0)
     RunThread(target=self._run_clock)
示例#5
0
class SMRCWindow(HasTraits):
    """
    SMRCWindow is the Mainwindow of the application SmartRecord. The window 
    shows the time and the current phase of the experiment when it's running. 
    Furthermore the window interacts with the SMRCModel and 
    make it possible that the user can start and 
    cancel the experiment by clicking a icon.
    """

    model = Instance(SMRCModel)

    smrc_handler = SMRCHandler()

    current_phase = Str("Current Phase - Not Started")

    clock = Str(secs_to_time(0))

    record_mode = Bool(True)

    def __init__(self, model):
        self.logger = getLogger("application")
        self.logger.debug("Initializes SMRCWindow")
        self.record_mode = model.record_mode
        self.model = model
        self.model.experiment.window = self

    def start_clock(self):
        """Run the clock in the status bar."""
        self.logger.info("Start the time-thread [SMRCWindow]")
        self.clock = secs_to_time(0)
        RunThread(target=self._run_clock)

    def _run_clock(self):
        # Updates the status bar time once every second.
        self.clock_running = True
        self.start_time = time()
        while self.clock_running:
            self.td = time() - self.start_time
            self.clock = secs_to_time(self.td)
            sleep(1.0)

    #=========================================================================
    # Traitsview
    #=========================================================================

    # Switch to stop the running thread
    clock_running = Bool(False)

    view = View(UItem("model", style="custom"),
                menubar=MenuBar(Menu(*file_actions, name="File"),
                                Menu(*configure_actions, name="Configuration"),
                                Menu(*import_action, name="Import"),
                                Menu(help_docs, name="Help")),
                toolbar=ToolBar(*toolbar_actions,
                                show_tool_names=False,
                                image_size=(30, 30)),
                statusbar=[
                    StatusItem(name="current_phase", width=0.5),
                    StatusItem(name="clock", width=85)
                ],
                handler=smrc_handler,
                resizable=True,
                height=680,
                width=1300,
                title="SmartRecord",
                icon=ImageResource("../../icons/smrc_icon.png"))