Пример #1
0
 def SaveSettings(self):
     settingsPath = QDir.temp().absoluteFilePath("polygonize.ini")
     settings = QSettings(settingsPath, QSettings.IniFormat)
     settings.beginGroup("export")
     settings.setValue("path", self.ui.le_Path.text())
     settings.setValue("name", self.ui.le_Name.text())
     settings.endGroup()
     settings.sync()
Пример #2
0
    def LoadSettings(self):
        settingsPath = QDir.temp().absoluteFilePath("polygonize.ini")
        settings = QSettings(settingsPath, QSettings.IniFormat)

        settings.beginGroup("export")
        if settings.contains("path"):
            self.ui.le_Path.setText(settings.value("path"))
        if settings.contains("name"):
            self.ui.le_Name.setText(settings.value("name"))
        settings.endGroup()
 def SaveSettings(self):
     LogDebug("Saving main window")
     settingsPath = QDir.temp().absoluteFilePath("polygonize.ini")
     settings = QSettings(settingsPath, QSettings.IniFormat)
     settings.beginGroup("main")
     settings.setValue("arc_length", self.ui.dsb_ArcLength.value())
     settings.setValue("width", self.ui.dsb_Width.value())
     settings.setValue("layer", self.ui.cb_Layer.currentText())
     settings.setValue("delete_after", self.ui.chb_DeleteAfter.checkState())
     settings.endGroup()
     settings.sync()
     LogDebug("done saving main window")
Пример #4
0
    def run(self):
        try:
            picBytes = self.wallhaven_random(search=self.settings.interests,
                                             people=self.settings.people,
                                             anime=self.settings.anime,
                                             general=self.settings.general,
                                             nsfw=self.settings.nsfw)

            if picBytes is None:
                print("Pic fetch failed...")
                return

            print("Writing pic to {}/wp.jpg".format(QDir.temp().path()))
            tempfile = open(QDir.temp().path() + "/wp.jpg", "wb+")
            tempfile.write(picBytes)
            tempfile.close()
            self.change_wallpaper()
            print("Wallpaper changed")

        except Exception as ex:
            print("Exception occured: " + str(ex))
            self.error.emit(str(ex))
Пример #5
0
    def change_wallpaper(self):

        if platform.system() == "Linux":
            if subprocess.check_call([
                    "gsettings", "set", "org.gnome.desktop.background",
                    "picture-uri", "file:///tmp/wp.jpg"
            ]) != 0:
                raise Exception("Wallpaper setting failed!")
            return

        if platform.system() == "Windows":
            import ctypes
            ctypes.windll.user32.SystemParametersInfoW(
                20, 0,
                QDir.temp().path() + "/wp.jpg", 0)
Пример #6
0
    def SaveClicked(self):
        LogInfo("Temp path: {} {}".format(QDir.temp(), QDir.tempPath()))
        if (self.ValidateSave()):
            self.done(QtWidgets.QDialog.Accepted)
            self.close()
        else:
            msgBox = QtWidgets.QMessageBox()
            if self.ui.le_Name == "":
                msgBox.setText("Name must not be empty")
            else:
                msgBox.setText(
                    "Selected folder does not exist or is write-protected")
            msgBox.exec()

        polygons = GetSelectedDrawings()
        WriteToFootprint(self.ui.le_Name.text(), self.ui.le_Path.text(),
                         polygons, True)
    def LoadSettings(self):
        LogDebug("Loading main window")
        settingsPath = QDir.temp().absoluteFilePath("polygonize.ini")
        settings = QSettings(settingsPath, QSettings.IniFormat)
        settings.beginGroup("main")
        if settings.contains("arc_length"):
            self.ui.dsb_ArcLength.setValue(float(settings.value("arc_length")))

        if settings.contains("width"):
            self.ui.dsb_Width.setValue(float(settings.value("width")))

        if settings.contains("layer"):
            layer = settings.value("layer")
            layerIndex = self.ui.cb_Layer.findText(layer)
            if (layerIndex >= 0):
                #it is in the ini and it is a valid layer on this board
                self.ui.cb_Layer.setCurrentIndex(layerIndex)

        if settings.contains("delete_after"):
            self.ui.chb_DeleteAfter.setCheckState(
                int(settings.value("delete_after")))

        LogDebug("done loading main window")
Пример #8
0
def launch_mia():
    global imageViewer

    def my_excepthook(type, value, tback):
        # log the exception here

        print("excepthook")

        clean_up()

        # then call the default handler
        sys.__excepthook__(type, value, tback)

        sys.exit(1)

    sys.excepthook = my_excepthook

    # Working from the scripts directory
    os.chdir(os.path.dirname(os.path.realpath(__file__)))

    lock_file = QLockFile(
        QDir.temp().absoluteFilePath('lock_file_populse_mia.lock'))

    if not lock_file.tryLock(100):
        # Software already opened in another instance
        pass

    else:
        # No instances of the software is opened, the list of opened projects can be cleared
        config = Config()
        config.set_opened_projects([])

    app = QApplication(sys.argv)
    project = Project(None, True)
    imageViewer = Main_Window(project)
    imageViewer.show()
    app.exec()
Пример #9
0
    def onButtonPlay(self):
        settings = QSettings()
        programPath = settings.value('options/VideoPlayerPath', '')
        parameters = settings.value('options/VideoPlayerParameters', '')
        if programPath == '':
            QMessageBox.about(
                self, _('Error'),
                _('No default video player has been defined in Settings.'))
            return

        selected_subtitle = self.get_current_selected_item_videomodel()
        if isinstance(selected_subtitle, SubtitleFileNetwork):
            selected_subtitle = selected_subtitle.get_subtitles()[0]

        if isinstance(selected_subtitle, LocalSubtitleFile):
            subtitle_file_path = selected_subtitle.get_filepath()
        elif isinstance(selected_subtitle, RemoteSubtitleFile):
            subtitle_file_path = QDir.temp().absoluteFilePath(
                'subdownloader.tmp.srt')
            log.debug(
                'Temporary subtitle will be downloaded into: {temp_path}'.
                format(temp_path=subtitle_file_path))
            # FIXME: must pass mainwindow as argument to ProgressCallbackWidget
            callback = ProgressCallbackWidget(self)
            callback.set_title_text(_('Playing video + sub'))
            callback.set_label_text(_('Downloading files...'))
            callback.set_finished_text(_('Downloading finished'))
            callback.set_block(True)
            callback.set_range(0, 100)
            callback.show()
            try:
                subtitle_stream = selected_subtitle.download(
                    self.get_state().get_OSDBServer(), callback=callback)
            except ProviderConnectionError:
                log.debug('Unable to download subtitle "{}"'.format(
                    selected_subtitle.get_filename()),
                          exc_info=True)
                QMessageBox.about(
                    self, _('Error'),
                    _('Unable to download subtitle "{subtitle}"').format(
                        subtitle=selected_subtitle.get_filename()))
                callback.finish()
                return
            callback.finish()
            write_stream(subtitle_stream, subtitle_file_path)

        video = selected_subtitle.get_parent().get_parent().get_parent()

        def windows_escape(text):
            return '"{text}"'.format(text=text.replace('"', '\\"'))

        params = [windows_escape(programPath)]

        for param in parameters.split(' '):
            param = param.format(video.get_filepath(), subtitle_file_path)
            if platform.system() in ('Windows', 'Microsoft'):
                param = windows_escape(param)
            params.append(param)

        pid = None
        log.info('Running this command: {params}'.format(params=params))
        try:
            log.debug('Trying os.spawnvpe ...')
            pid = os.spawnvpe(os.P_NOWAIT, programPath, params, os.environ)
            log.debug('... SUCCESS. pid={pid}'.format(pid=pid))
        except AttributeError:
            log.debug('... FAILED', exc_info=True)
        except Exception as e:
            log.debug('... FAILED', exc_info=True)
        if pid is None:
            try:
                log.debug('Trying os.fork ...')
                pid = os.fork()
                if not pid:
                    log.debug('... SUCCESS. pid={pid}'.format(pid=pid))
                    os.execvpe(os.P_NOWAIT, programPath, params, os.environ)
            except:
                log.debug('... FAIL', exc_info=True)
        if pid is None:
            QMessageBox.about(self, _('Error'),
                              _('Unable to launch videoplayer'))
Пример #10
0
def launch_mia():
    """Actual launch of the mia software.

    Overload the sys.excepthook handler with the _my_excepthook private
    function. Check if the software is already opened in another instance.
    If not, the list of opened projects is cleared. Checks if saved projects
    known in the mia software still exist, and updates if necessary.
    Instantiates a 'project' object that handles projects and their
    associated database anf finally launch of the mia's GUI.


    **Contains: Private function:**
        - *_my_excepthook(etype, evalue, tback)*
           Log all uncaught exceptions in non-interactive mode.

           All python exceptions are handled by function, stored in
           sys.excepthook. By overloading the sys.excepthook handler with
           _my_excepthook function, this last function is called whenever
           there is a unhandled exception (so one that exits the interpreter).
           We take advantage of it to clean up mia software before closing.

            :Parameters:
                - :etype: exception class
                - :evalue: exception instance
                - :tback: traceback object

            **Contains: Private function:**
              - *_clean_up()*
                 Cleans up the mia software during "normal" closing.

                 Make a clean up of the opened projects just before exiting
                 mia.
        - *_verify_saved_projects()*
               Verify if the projects saved in saved_projects.yml are still
               on the disk.

               :Returns: the list of the deleted projects


    """
    def _my_excepthook(etype, evalue, tback):
        def _clean_up():

            global main_window
            config = Config()
            opened_projects = config.get_opened_projects()

            try:
                opened_projects.remove(main_window.project.folder)
                config.set_opened_projects(opened_projects)
                main_window.remove_raw_files_useless()

            except AttributeError as e:
                opened_projects = []
                config.set_opened_projects(opened_projects)

            print("\nClean up before closing mia done ...\n")

        # log the exception here
        print("\nException hooking in progress ...")
        _clean_up()
        # then call the default handler
        sys.__excepthook__(etype, evalue, tback)
        # there was some issue/error/problem, so exiting
        sys.exit(1)

    def _verify_saved_projects():

        saved_projects_object = SavedProjects()
        saved_projects_list = copy.deepcopy(saved_projects_object.pathsList)
        deleted_projects = []
        for saved_project in saved_projects_list:
            if not os.path.isdir(saved_project):
                deleted_projects.append(saved_project)
                saved_projects_object.removeSavedProject(saved_project)

        return deleted_projects

    global main_window
    app = QApplication(sys.argv)
    QApplication.setOverrideCursor(Qt.WaitCursor)
    sys.excepthook = _my_excepthook

    # working from the scripts directory
    os.chdir(os.path.dirname(os.path.realpath(__file__)))
    lock_file = QLockFile(
        QDir.temp().absoluteFilePath('lock_file_populse_mia.lock'))

    if not lock_file.tryLock(100):
        # software already opened in another instance
        pass

    else:
        # no instances of the software is opened, the list of opened projects
        # can be cleared
        config = Config()
        config.set_opened_projects([])

    deleted_projects = _verify_saved_projects()
    project = Project(None, True)
    main_window = MainWindow(project, deleted_projects=deleted_projects)
    main_window.show()
    app.exec()