Esempio n. 1
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()
Esempio n. 2
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()
Esempio n. 3
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
Esempio n. 4
0
    def load_settings(self):
        """Load settings values into memory on startup.
        """
        # If settings file doesnt exist
        if not Util.is_file(SettingsManager.file_path):
            # If directory doesnt exist
            if not Util.is_dir(SettingsManager.settings_path):
                Util.mkdir(SettingsManager.settings_path)
            # Create user settings with default
            SettingsManager.create_settings(SettingsManager.filename)

        with open(SettingsManager.file_path, "r") as file:
            file_settings = json.load(file)
            self.stl_dir = file_settings["stl_dir"]
            self.part_name = file_settings["part_name"]
            self.part_dir = file_settings["part_dir"]
            self.author_default = file_settings["author"]
            self.license_default = file_settings["license"]
Esempio n. 5
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()
Esempio n. 6
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()
Esempio n. 7
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()
from src.project_manager import ProjectManager

# TODO: Add test cases

# Get Project Manager's home directory
PM_HOME = str(os.path.dirname(os.path.abspath(__file__)))

__version__ = "v0.2 Beta"

# Check if the pm-settings.json not exists in the project's home folder
if not os.path.exists(f"{PM_HOME}/pm-settings.json"):
    print(colored(f"Welcome to Project Manager {__version__}", "green"))
    print("Looks like this is first time you are running Project Manager.")
    print("Entering setup mode...")

    settings_manager = SettingsManager(PM_HOME)
    settings_manager.setup()
    exit()
else:
    try:
        with open(f"{PM_HOME}/pm-settings.json", "r") as file:
            settings = load(file)
    except:
        print(
            colored(
                """The settings cannot be read. Please check pm-settings.json file.""",
                "red"))
        exit(1)

parser = ArgumentParser(
    "pm",