Ejemplo n.º 1
0
    def before_render(self):
        self.data(CustomDataRole.ITEMDATA).set_value(
            "albumDuration", str(self.get_duration_ms() / 1000))
        self.data(CustomDataRole.ITEMDATA).set_value(
            "fileOutput",
            posixpath.join(self.get("fileOutputDirAlbum"),
                           self.get("fileOutputNameAlbum")),
        )
        command_path = resource_path(
            posixpath.join("commands", "concat",
                           self.get("concatCommandName") + ".command"))
        if not os.path.exists(command_path):
            appdata_path = QStandardPaths.writableLocation(
                QStandardPaths.AppDataLocation)
            command_path = posixpath.join(
                appdata_path,
                "commands",
                "concat",
                self.get("concatCommandName") + ".command",
            )
        try:
            with open(command_path, "r") as f:
                command = f.read().strip()
                self.set("concatCommandString", command)
        except:
            raise Exception(f"Could not read command from {command_path}")

        if self.get("albumPlaylist") == SETTINGS_VALUES.AlbumPlaylist.SINGLE:
            # override song audio codec output to 24 bit FLAC
            # so they can be concatenated
            for song in self.getChildren():
                song.set("audioCodec", "flac -sample_fmt s32")
Ejemplo n.º 2
0
 def nextImageFileName(self):
     picturesLocation = QStandardPaths.writableLocation(
         QStandardPaths.PicturesLocation)
     dateString = QDate.currentDate().toString("yyyyMMdd")
     pattern = picturesLocation + "/pyside6_camera_" + dateString + "_{:03d}.jpg"
     n = 1
     while True:
         result = pattern.format(n)
         if not os.path.exists(result):
             return result
         n = n + 1
     return None
Ejemplo n.º 3
0
 def open(self):
     fileDialog = QFileDialog(self)
     supportedMimeTypes = QMediaPlayer.supportedMimeTypes()
     if not supportedMimeTypes:
         supportedMimeTypes.append("video/x-msvideo")  # AVI
     fileDialog.setMimeTypeFilters(supportedMimeTypes)
     moviesLocation = QStandardPaths.writableLocation(
         QStandardPaths.MoviesLocation)
     fileDialog.setDirectory(moviesLocation)
     if fileDialog.exec_() == QDialog.Accepted:
         self.playlist.addMedia(fileDialog.selectedUrls()[0])
         self.player.play()
Ejemplo n.º 4
0
 def load(self):
     conf_dir = QStandardPaths.writableLocation(QStandardPaths.AppConfigLocation)
     if not os.path.exists(conf_dir):
         os.makedirs(conf_dir)
     self.conf = os.path.join(conf_dir, 'config.json')
     if os.path.exists(self.conf):
         with open(self.conf) as cf:
             try:
                 self.config = json.load(cf)
             except:
                 print('error to load config, use {}')
                 pass
     return self.config
 def _select_models_path(self):
     print('Selecting models path... ', end='', flush=True)
     settings = QSettings()
     models_path = QFileDialog.getExistingDirectory(
         parent=self,
         caption='Select models directory',
         dir=QStandardPaths.standardLocations(
             QStandardPaths.AppDataLocation).pop(),
     )
     if models_path != '':
         settings.setValue(self._models_path_key, str(models_path))
         self._models_path = Path(models_path)
         print(models_path)
     else:
         print('canceled')
 def on_select_image_clicked(self):
     print('Selecting image... ', end='', flush=True)
     filename, _ = QFileDialog.getOpenFileName(
         parent=self,
         caption='Select chest X-ray image',
         dir=QStandardPaths.standardLocations(
             QStandardPaths.PicturesLocation).pop(),
         filter='Images (*.png *.jpg *.jpeg)')
     if filename != '':
         self._input = cv2.imread(filename)
         self.ui.input.setPixmap(
             numpy_to_pixmap(self._input, self._input_size))
         self.ui.prediction.clear()
         self.ui.confidence.clear()
         self.ui.explanation.setPixmap(':/images/default.png')
         self._input_predicted = False
         self.ui.input_state.setPixmap(':/images/ok.png')
         print(filename)
     else:
         print('canceled')
Ejemplo n.º 7
0
 def before_render(self):
     self.set(
         "fileOutput",
         posixpath.join(self.get("fileOutputDir"),
                        self.get("fileOutputName")),
     )
     self.set("songDuration", str(self.get_duration_ms() / 1000))
     command_path = resource_path(
         posixpath.join("commands", "render",
                        self.get("commandName") + ".command"))
     if not os.path.exists(command_path):
         appdata_path = QStandardPaths.writableLocation(
             QStandardPaths.AppDataLocation)
         command_path = posixpath.join(appdata_path, "commands", "render",
                                       self.get("commandName") + ".command")
     try:
         with open(command_path, "r") as f:
             command = f.read().strip()
             self.set("commandString", command)
     except:
         raise Exception(f"Could not read command from {command_path}")
Ejemplo n.º 8
0
def _config_dir():
    return '{}/QtForPythonBrowser'.format(
        QStandardPaths.writableLocation(QStandardPaths.ConfigLocation))
Ejemplo n.º 9
0
 def get_all_usernames():
     appdata_path = QStandardPaths.writableLocation(
         QStandardPaths.AppDataLocation)
     general_cookies_folder_path = os.path.join(appdata_path, 'cookies')
     os.makedirs(general_cookies_folder_path, exist_ok=True)
     return next(os.walk(general_cookies_folder_path))[1]
Ejemplo n.º 10
0
 def get_cookie_path_from_username(username):
     appdata_path = QStandardPaths.writableLocation(
         QStandardPaths.AppDataLocation)
     general_cookies_folder_path = os.path.join(appdata_path, 'cookies')
     os.makedirs(general_cookies_folder_path, exist_ok=True)
     return os.path.join(general_cookies_folder_path, username)
Ejemplo n.º 11
0
 def open_download_directory():
     path = QStandardPaths.writableLocation(QStandardPaths.DownloadLocation)
     DownloadWidget.open_file(path)
Ejemplo n.º 12
0
Archivo: tfm.py Proyecto: tmahlburg/tfm
    def __init__(self, args: List[str]):
        """
        At the moment the very, very long initialization of the main window,
        setting up everything.

        :param default_path: Use a user defined path as entrypoint. If it's
                             empty, the home directory of the current user will
                             be used.
        :type default_path: str
        """
        super(tfm, self).__init__()
        self.setupUi(self)
        self.setWindowIcon(QIcon.fromTheme('system-file-manager'))

        self.clipboard = QApplication.clipboard()
        self.marked_to_cut = []

        self.back_stack = stack()
        self.forward_stack = stack()

        self.config_dir = os.path.join(
            QStandardPaths.writableLocation(
                QStandardPaths().ConfigLocation),
            type(self).__name__)

        self.current_path = utility.handle_args(args)
        self.default_path = self.current_path

        self.threadpool = QThreadPool()

        # MAIN VIEW #
        # set up QFileSystemModel
        self.filesystem = QFileSystemModel()
        self.filesystem.setRootPath(self.current_path)
        self.filesystem.setReadOnly(False)

        # connect QFileSystemModel to View
        self.table_view.setModel(self.filesystem)
        self.table_view.setRootIndex(
            self.filesystem.index(self.current_path))

        # set up header
        self.horizontal_header = self.table_view.horizontalHeader()
        self.horizontal_header.setSectionsMovable(True)
        # name
        self.horizontal_header.resizeSection(0, 200)
        # size
        self.horizontal_header.resizeSection(1, 100)
        # type
        self.horizontal_header.resizeSection(2, 100)

        # FS TREE #
        # create seperate FileSystemModel for the fs tree
        self.fs_tree_model = QFileSystemModel()
        self.fs_tree_model.setFilter(QDir.AllDirs | QDir.NoDotAndDotDot)
        self.fs_tree_model.setRootPath(QDir.rootPath())

        # connect model to view
        self.fs_tree.setModel(self.fs_tree_model)
        # hide unneeded columns
        for column in range(1, self.fs_tree.header().count()):
            self.fs_tree.hideColumn(column)
        # expand root item
        self.fs_tree.expand(self.fs_tree_model.index(0, 0))

        # BOOKMARKS #
        self.bookmarks = bm(path_to_bookmark_file=os.path.join(self.config_dir,
                                                               'bookmarks'))
        self.bookmark_view.setModel(self.bookmarks)

        # MOUNTS #
        self.udev_context = Context()
        self.mounts = mounts_model(context=self.udev_context)
        self.mounts_view.setModel(self.mounts)
        udev_monitor = Monitor.from_netlink(self.udev_context)
        udev_monitor.filter_by(subsystem='block', device_type='partition')
        udev_observer = MonitorObserver(udev_monitor,
                                        self.devices_changed)
        udev_observer.start()

        # STATUSBAR #
        # TODO: dir info
        self.item_info = QLabel()
        # self.dir_info = QLabel()
        self.part_info = QLabel()
        self.statusbar.addPermanentWidget(self.item_info)
        # self.statusbar.addPermanentWidget(self.dir_info)
        self.statusbar.addPermanentWidget(self.part_info)

        self.part_info.setText(utility.part_info(self.current_path))

        # TOOLBAR #
        # initially disable back/forward navigation
        self.action_back.setEnabled(False)
        self.action_forward.setEnabled(False)

        # main menu
        self.main_menu = QMenu()
        self.main_menu.addAction(self.action_show_hidden)

        self.menu_button = QToolButton()
        self.menu_button.setMenu(self.main_menu)
        self.menu_button.setPopupMode(QToolButton().InstantPopup)
        self.menu_button.setDefaultAction(self.action_menu)

        self.toolbar.insertWidget(self.action_back, self.menu_button)

        # adress bar
        self.adressbar = QLineEdit()
        self.adressbar.setText(self.current_path)
        self.toolbar.insertWidget(self.action_go, self.adressbar)

        # menu for new file or directory
        self.new_menu = QMenu()
        self.new_menu.addAction(self.action_new_dir)
        self.new_menu.addAction(self.action_new_file)

        self.new_button = QToolButton()
        self.new_button.setMenu(self.new_menu)
        self.new_button.setPopupMode(QToolButton().MenuButtonPopup)
        self.new_button.setDefaultAction(self.action_new_dir)

        self.toolbar.insertWidget(self.action_back, self.new_button)

        self.connect_actions_to_events()
        self.set_shortcuts()
        self.set_icons()
        self.set_context_menus()