Beispiel #1
0
    def __createWorkspaceSegment(self):
        """
        This private method creates the Workspace Segment in the application.

        PARAMETERS
        ----------
        NONE

        RETURNS
        -------
        NOTHING
        """
        self.workspace_segment = tk.LabelFrame(self.root, text="Workspace")
        self.workspace_segment.pack(expand=1, fill=tk.X, padx=5)

        self.workspace_label = tk.Label(self.workspace_segment,
                                        text=os_utility.getActiveWorkspace(),
                                        width=60,
                                        anchor='w')
        self.workspace_label.pack(expand=1,
                                  fill=tk.X,
                                  side=tk.LEFT,
                                  padx=5,
                                  pady=5)

        self.explorer_button = tk.Button(self.workspace_segment,
                                         text=" browse ",
                                         command=self.__browseButtonHandler)
        self.explorer_button.configure(width=appconst.explorer_button_width)
        self.explorer_button.pack(expand=1, padx=5, pady=5)
Beispiel #2
0
    def serial1StartedClbk(self):
        """
        This method is called by serial thread 1 when it has started successfully.

        PARAMETERS
        ----------
        NONE

        RETURNS
        -------
        NOTHING
        """
        # clear the recorded data upon a new connection
        self.recorded_data.flush()
        self.recorded_csv_list = []
        self.csv_data_var = b''
        self.csv_index = 0

        # if there exits a record file when a connection is made then, delete it
        if not self.record_file_name == "":
            os.remove(self.record_file_name)
            self.record_file_name = ""

        # if there exits a record file when a connection is made then, delete it
        if not self.csv_record_file_name == "":
            os.remove(self.csv_record_file_name)
            self.csv_record_file_name = ""

        # Create a record file only when a workspace has been selected. This mechanism is fail proof because, recording
        # can be enabled only when there is valid workspace selected and similarly record file can be created only
        # when a valid workspace is selected. Moreover, there is data in the record buffer only when record option is enabled.
        # So, indirectly, there is data in the record buffer only when there is a valid workspace and hence a valid record file.
        wrksp = os_utility.getActiveWorkspace()
        if not wrksp == "none":
            flnm = os.path.join(wrksp, self.createFileName() + '.bin')
            with open(flnm, 'ab') as fl:
                fl.write(b'')
            self.record_file_name = flnm

            flnm = os.path.join(wrksp, self.createFileName() + '.csv')
            with open(flnm, 'w') as fl:
                fl.write('')
            self.csv_record_file_name = flnm

        self.play_button['state'] = 'normal'
        self.play_button['text'] = 'stop'
Beispiel #3
0
    def __toggleRecordOption(self):
        """
        This method is invoked whenever the record option is toggled.

        PARMETERS
        ---------
        NONE

        RETURNS
        -------
        NOTHING
        """
        if self.doRecord():
            # if the record option is enabled then, make sure that a workspace has been selected
            if os_utility.getActiveWorkspace() == "none":
                self.information(
                    "Please select a workspace before enabling the record option"
                )
                self.record_option.deselect()
                self.record_csv_option.deselect()
        else:
            #if the record option has been deselected then deselect the record as csv option as well
            self.record_csv_option.deselect()
Beispiel #4
0
    def __browseButtonHandler(self):
        """
        EVENT HANDLER
        This method is invoked when the browse button is clicked on.

        PARAMETERS
        ----------
        NONE

        RETURNS
        -------
        NOTHING
        """
        if self.connect_button['text'] == 'disconnect':
            self.information("Disconnect port before changing workspace")
            return

        dir_name = filedialog.askdirectory()
        if not dir_name == '':
            os_utility.updateWorkspace(dir_name)
            self.workspace_label.configure(
                text=os_utility.getActiveWorkspace())
            self.updatePlayFileMenu()
Beispiel #5
0
    def playButtonHandler(self):
        """
        EVENT HANDLER
        This method is invoked whenever the play button is clicked on.

        PARAMETERS
        ----------
        NONE

        RETURNS
        -------
        NOTHING
        """
        def disableButtons(app):
            app.connect_button['state'] = "disabled"
            app.play_button['state'] = "disabled"
            app.send_button['state'] = "disabled"

        def enableButtons(app):
            app.connect_button['state'] = "normal"
            app.play_button['state'] = "normal"
            app.send_button['state'] = "normal"

        disableButtons(self)

        if self.play_button['text'] == 'play':

            # if a port is already connected then, cancel any further operations
            if self.connect_button['text'] == 'disconnect':
                self.information("Disconnect before playing !!")
                enableButtons(self)
                return

            # if no valid play file is selected then, cancel any futher operations
            if self.getPlayFile() == '-':
                self.error("No play file selected")
                enableButtons(self)
                return

            delay = self.getDelay()
            if delay < 0:
                self.information("Invalid delay")
                enableButtons(self)
                return

            try:
                with open(
                        os.path.join(os_utility.getActiveWorkspace(),
                                     self.getPlayFile()), 'rb') as fl:
                    byts = fl.read()

                self.send_buff.enqueue(byts)

            except:
                self.error("Could not read file")
                enableButtons(self)
                return

            serial_utility.run_serial_thread1 = 1
            self.serial_thread1 = threading.Thread(
                target=serial_utility.SERIAL_THREAD1,
                args=(self, delay),
                daemon=True)
            self.serial_thread1.start()
        else:
            serial_utility.run_serial_thread1 = 0