Exemplo n.º 1
0
    def check_input(self):
        """Checks if all input fields have valid flag, and changes program
        state if needed. Should be called after an input field updates.

        :return: None
        """
        if self.ldraw_name_isvalid and self.stl_path_isvalid:
            if UIDriver.application_state != ApplicationState.WAITING_GO:
                UIDriver.fire_event(UserEvent(
                    UserEventType.INPUT_VALID,
                    LogMessage(LogType.IGNORE, "")))
        else:
            if UIDriver.application_state != ApplicationState.WAITING_INPUT:
                UIDriver.fire_event(UserEvent(
                    UserEventType.INPUT_INVALID,
                    LogMessage(LogType.IGNORE, "")))

        # Set colors
        if self.ldraw_name_isvalid:
            self.ldraw_name_input.SetBackgroundColour(UIStyle.metadata_input_valid_background)
        else:
            self.ldraw_name_input.SetBackgroundColour(UIStyle.metadata_input_invalid_background)
        if self.stl_path_isvalid:
            self.stl_path_input.SetBackgroundColour(UIStyle.metadata_input_valid_background)
        else:
            self.stl_path_input.SetBackgroundColour(wx.Colour(UIStyle.metadata_input_invalid_background))
Exemplo n.º 2
0
    def __init__(self, message_type: LogType, message: str, value: bool):
        """Constructor for the FloatMessage class.

        :param message_type: The LogType for the message.
        :param message: The str message contained in the LogMessage.
        :param value: The bool value that is contained.
        """
        LogMessage.__init__(self, message_type, message)
        self.value = value
Exemplo n.º 3
0
    def text_ctrl_input_on_kill_focus(self, event):
        """Get the path for STL input file from user typing into TextCtrl element.
        :param event:
        :return:
        """
        prev_text = self.stl_path_text
        self.stl_path_text = self.stl_path_input.GetValue()
        self.stl_path_input.SetValue(MetadataPanel.reduce_text_path(self.stl_path_input.GetValue()))

        if prev_text != self.stl_path_text:

            # Check file path validity
            if Util.is_file(self.stl_path_text):
                if self.stl_path_text.endswith('.stl'):

                    # Check if this .stl is valid

                    mesh = ModelShipper.load_stl_model(self.stl_path_text)

                    if mesh:
                        # Load in LDraw object to input model
                        ModelShipper.input_model = LDrawModel(mesh)
                        self.stl_dir = Util.get_parent(self.stl_path_text)  # Only the dir
                        SettingsManager.save_settings("stl_dir", self.stl_dir)
                        self.stl_path_isvalid = True
                        UIDriver.fire_event(
                            UserEvent(UserEventType.INPUT_MODEL_READY,
                                      LogMessage(LogType.INFORMATION,
                                                 "Input file loaded from: '" +
                                                 self.stl_path_text + "'.")))
                    else:
                        self.stl_path_isvalid = False
                        UIDriver.fire_event(
                            UserEvent(UserEventType.LOG_INFO,
                                      LogMessage(LogType.ERROR,
                                                 "The input file '" +
                                                 self.stl_path_text +
                                                 "' is not a valid STL file.")))
                else:
                    self.stl_path_isvalid = False
                    UIDriver.fire_event(
                        UserEvent(UserEventType.LOG_INFO,
                                  LogMessage(LogType.ERROR,
                                             "Input file must have .stl extension.")))
            else:
                self.stl_path_isvalid = False
                if len(self.stl_path_text) <=0:
                    log_msg = "Input filepath cannot be blank."
                else:
                    log_msg = "The path '" + self.stl_path_text + "' could not be found."
                UIDriver.fire_event(
                    UserEvent(UserEventType.LOG_INFO,
                              LogMessage(LogType.ERROR, log_msg)))
            self.check_input()
        event.Skip()
Exemplo n.º 4
0
    def browse_input(self, event):
        """Browse for a valid STL input file.
        :param event:
        :return:
        """
        UIDriver.fire_event(UserEvent(
            UserEventType.RENDERING_CANVAS_DISABLE,
            LogMessage(LogType.IGNORE, "")))
        stl_wildcard = "*.stl"
        dialog = wx.FileDialog(self, "Choose a STL file",
                               defaultDir=self.stl_dir, wildcard=stl_wildcard,
                               style=wx.FD_OPEN
                               | wx.FD_FILE_MUST_EXIST)

        if dialog.ShowModal() == wx.ID_OK:
            filename = dialog.GetPath()
            # Check for file existing
            # If valid, pass to worker thread who will check data
            if self.stl_path_text != filename:
                self.stl_path_input.SetValue(filename)
                self.stl_path_input.SetValue(MetadataPanel.reduce_text_path(self.stl_path_input.GetValue()))

                # Only update stuff if selection changed
                # Check if this .stl is valid
                mesh = ModelShipper.load_stl_model(filename)
                if mesh:
                    # Load in LDraw object to input model
                    ModelShipper.input_model = LDrawModel(mesh)
                    self.stl_dir = Util.get_parent(filename)  # Only the dir
                    self.stl_path_text = filename  # The whole path to file
                    self.stl_path_isvalid = True
                    SettingsManager.save_settings("stl_dir", self.stl_dir)

                    UIDriver.fire_event(
                        UserEvent(UserEventType.INPUT_MODEL_READY,
                                  LogMessage(LogType.INFORMATION,
                                             "Input file loaded from: '" +
                                             self.stl_path_text + "'.")))
                else:
                    self.stl_path_isvalid = False
                    UIDriver.fire_event(
                        UserEvent(UserEventType.LOG_INFO,
                                  LogMessage(LogType.ERROR,
                                             "The input file '" +
                                             filename +
                                             "' is not a valid STL file.")))
                self.check_input()

            UIDriver.fire_event(UserEvent(
                UserEventType.RENDERING_CANVAS_ENABLE,
                LogMessage(LogType.IGNORE, "")))

        dialog.Destroy()
Exemplo n.º 5
0
 def put_feedback(self, msg, log_type):
     """Puts a LogMessage into the feedback queue
     :param msg: message text
     :param log_type: type of log
     :return: None
     """
     log_msg = LogMessage(log_type, msg)
     self.feedback_log.put(log_msg)
Exemplo n.º 6
0
    def save_log(self, event):
        """
        Save the feedback log to a file
        :param event:
        :return:
        """
        try:
            UIDriver.fire_event(
                UserEvent(UserEventType.RENDERING_CANVAS_DISABLE,
                          LogMessage(LogType.IGNORE, "")))

            with open(SettingsManager.file_path, "r") as file:
                file_settings = json.load(file)
                part_name = file_settings["part_name"]
                log_dir = file_settings["log_dir"]

            log_name = part_name.split(".")[0] + ".txt"
            dialog = wx.FileDialog(self,
                                   "Choose a log save location",
                                   defaultFile=log_name,
                                   defaultDir=log_dir,
                                   style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT,
                                   wildcard="*.txt")

            if dialog.ShowModal() == wx.ID_OK:
                pathname = dialog.GetPath()
                directory = dialog.GetDirectory()

                # Check if the new directory is different the old one. If so update the settings file.
                if log_dir != directory:
                    SettingsManager.save_settings("log_dir", directory)

                try:
                    log_file = open(pathname, mode="w")
                    log_file.write(self.log_text_ctrl.GetValue())
                    log_file.close()
                except IOError:
                    pass
                finally:
                    pass
            UIDriver.fire_event(
                UserEvent(UserEventType.RENDERING_CANVAS_ENABLE,
                          LogMessage(LogType.IGNORE, "")))
            dialog.Destroy()
        except IOError:
            pass
Exemplo n.º 7
0
class TestLogMessage(unittest.TestCase):
    def setUp(self):
        self.log_type = LogType.ERROR
        self.log_color = [255, 0, 0]
        self.message = 'This is a test error'
        self.log = LogMessage(self.log_type, self.message)

    def test_get_message(self):
        self.assertEqual(self.log.get_message(), self.message)

    def test_get_message_type(self):
        self.assertEqual(self.log.get_message_type(), self.log_type)

    def test_get_timestamp(self):
        self.assertIsInstance(self.log.get_timestamp(), str)

    def test_get_log_message_color(self):
        self.assertEqual(self.log.get_log_message_color(), self.log_color)
Exemplo n.º 8
0
    def browse_output(self, event):
        """Browse for a valid output file path
        :param event:
        :return:
        """
        UIDriver.fire_event(UserEvent(
            UserEventType.RENDERING_CANVAS_DISABLE,
            LogMessage(LogType.IGNORE, "")))

        dat_wildcard = "*.dat"
        dialog = wx.FileDialog(self, "Choose a location for the LDraw file",
                               defaultDir=self.part_dir,
                               style=wx.FD_SAVE | wx.FD_OVERWRITE_PROMPT,
                               wildcard=dat_wildcard)

        dialog.SetFilename(self.part_name)

        if dialog.ShowModal() == wx.ID_OK:
            pathname = dialog.GetPath()

            if self.out_file != pathname:
                # Check if part name ends with .dat, if not append that
                if not pathname.endswith('.dat'):
                    pathname = pathname + '.dat'

                self.out_file = pathname  # Full path
                self.part_dir = Util.get_parent(pathname)  # Only the dir
                self.part_name = Util.get_filename(pathname)  # Only filename
                self.ldraw_name_isvalid = True
                SettingsManager.save_settings("part_dir", self.part_dir)
                SettingsManager.save_settings("part_name", self.part_name)
                self.ldraw_name_input.SetValue(self.out_file)
                self.ldraw_name_input.SetValue(MetadataPanel.reduce_text_path(self.ldraw_name_input.GetValue()))
                self.check_input()
                UIDriver.fire_event(
                    UserEvent(UserEventType.LOG_INFO,
                              LogMessage(LogType.INFORMATION,
                                         "Output file will be saved as: '" +
                                         self.out_file + "'.")))

        UIDriver.fire_event(UserEvent(
            UserEventType.RENDERING_CANVAS_ENABLE,
            LogMessage(LogType.IGNORE, "")))
        dialog.Destroy()
Exemplo n.º 9
0
    def convert(self, event):
        """Convert the selected STL file into an LDraw file.

        :param event: The wx event that was recorded.
        :return: None
        """
        UIDriver.fire_event(
            UserEvent(
                UserEventType.CONVERSION_STARTED,
                LogMessage(LogType.INFORMATION,
                           "Conversion process started..")))
Exemplo n.º 10
0
    def cancel(self, event):
        """Cancel the conversion operation.

        :param event: The wx event that was recorded.
        :return: None
        """
        UIDriver.fire_event(
            UserEvent(
                UserEventType.CONVERSION_CANCELED,
                LogMessage(LogType.INFORMATION,
                           "Conversion process canceled.")))
Exemplo n.º 11
0
    def pause_resume(self, event):
        """Pause/resume the conversion process.

        :param event: The wx event that was recorded.
        :return: None
        """
        self.is_paused = not self.is_paused
        if self.is_paused:
            self.pause_button.SetLabelText('Resume')
            UIDriver.fire_event(
                UserEvent(
                    UserEventType.CONVERSION_PAUSED,
                    LogMessage(LogType.INFORMATION,
                               "Conversion process paused.")))
        else:
            self.pause_button.SetLabelText('Pause')
            UIDriver.fire_event(
                UserEvent(
                    UserEventType.CONVERSION_RESUMED,
                    LogMessage(LogType.INFORMATION,
                               "Conversion process resumed.")))
Exemplo n.º 12
0
    def on_state_changed(self, new_state: ApplicationState):
        """A state change was passed to the LogPanel.

        :param new_state: The recorded ApplicationState.
        :return: None
        """
        if new_state == ApplicationState.STARTUP:
            self.save_log_button.Enable()

        self.handle_log_message_event(
            UserEvent(
                UserEventType.APPLICATION_STATE_CHANGE,
                LogMessage(LogType.DEBUG,
                           "State changed to: " + str(new_state))))
Exemplo n.º 13
0
    def text_ctrl_output_on_kill_focus(self, event):
        """Called when the output text control loses focus.

        :param event: The event that occurred.
        :return: None.
        """
        output_text = self.ldraw_name_input.GetValue()
        if len(output_text) <= 0:
            self.ldraw_name_input.SetValue("Browse output -->")
            if len(self.ldraw_name_input.GetValue()) > 0:
                self.ldraw_name_input.SetBackgroundColour(UIStyle.metadata_input_valid_background)
            UIDriver.fire_event(
                UserEvent(UserEventType.LOG_INFO,
                          LogMessage(LogType.ERROR,
                                     "Output file path cannot be blank.")))
        event.Skip()
Exemplo n.º 14
0
    def test_constructor_user_event(self):
        """Test the constructor builds the correct user event.

        :return: None
        """
        event_type = UserEventType.INPUT_MODEL_READY
        log_type = LogType.ERROR
        log_message = "test user event"

        user_event = UserEvent(event_type, LogMessage(log_type, log_message))

        self.assertTrue(user_event.get_event_type(), event_type)
        self.assertTrue(user_event.log_message.get_message_type(), log_type)
        self.assertTrue(user_event.log_message.get_message(), log_message)

        # The log message color for ERROR should return full Red intensity. [255, 0, 0]
        self.assertTrue(user_event.get_log_message().get_log_message_color(), [255, 0, 0])
Exemplo n.º 15
0
    def text_ctrl_license_on_kill_focus(self, event):
        """Get the license value from the user and update the settings file
        as needed."""
        license_input_text = self.license_input.GetValue()

        # Update settings file license info
        if license_input_text != self.license_text and license_input_text != "":
            self.license_text = license_input_text
            UIDriver.fire_event(
                UserEvent(UserEventType.LOG_INFO,
                          LogMessage(LogType.INFORMATION,
                                     "License changed to: " +
                                     self.license_text)))
            SettingsManager.save_settings("license", self.license_text)

        elif len(license_input_text) == 0:
            self.reset_license()
        event.Skip()
Exemplo n.º 16
0
    def text_ctrl_author_on_kill_focus(self, event):
        """Get the author value from the user and update the settings file
        as needed.

        :param event: The event that occurred.
        :return: None
        """
        author = self.author_input.GetValue()

        # Update settings file author info
        if author != self.author_text and author != "":
            self.author_text = author
            UIDriver.fire_event(
                UserEvent(UserEventType.LOG_INFO,
                          LogMessage(LogType.INFORMATION,
                                     "Author changed to: " +
                                     self.author_text)))
            SettingsManager.save_settings("author", self.author_text)

        elif len(author) == 0:
            self.reset_author()
        event.Skip()
Exemplo n.º 17
0
    def save(self, event):
        """Save the finalized conversion of the input file. Hide main window options and replace them with metadata
        options. Once the user finalizes their metadata options (back or save), they return to the original options.

        :param event: The wx event that was recorded.
        :return: None
        """
        self.save_button.Disable()

        with open(SettingsManager.file_path, "r") as file:
            file_settings = json.load(file)
            part_dir = file_settings["part_dir"]
            part_name = file_settings["part_name"]

        file_path = Util.path_conversion(part_dir + "/" + part_name)
        with open(file_path, "w") as text_file:
            text_file.write(ModelShipper.get_metadata() +
                            ModelShipper.output_data_text)
        self.save_button.Enable()
        UIDriver.fire_event(
            UserEvent(
                UserEventType.LOG_INFO,
                LogMessage(LogType.INFORMATION,
                           "File was saved to '" + file_path + "'.")))
Exemplo n.º 18
0
 def __init__(self, message_type: LogType, message: str, model: Mesh):
     """Constructor for the InputModelMessage class.
     """
     LogMessage.__init__(self, message_type, message)
     self.model = model
Exemplo n.º 19
0
 def update_status(self, new_status):
     self.status = new_status
     self.put_feedback(LogMessage(LogType.INFORMATION, self.status))
Exemplo n.º 20
0
 def setUp(self):
     self.log_type = LogType.ERROR
     self.log_color = [255, 0, 0]
     self.message = 'This is a test error'
     self.log = LogMessage(self.log_type, self.message)