示例#1
0
class ConfigManager(QtGui.QMainWindow, Ui_ConfigManager):
    def __init__(self, *args, **kwargs):
        super(ConfigManager, self).__init__(*args, **kwargs)
        self.setupUi()
        self.bindUi()
        self.windows = {}

    def setupUi(self):
        super(ConfigManager, self).setupUi(self)

    def bindUi(self):
        self.model = QFileSystemModel()
        self.model.setRootPath("/")
        self.model.setFilter(QDir.AllDirs | QDir.NoDotAndDotDot)
        self.treeView.setModel(self.model)
        if app_config.get_last_dir():
            self.treeView.setCurrentIndex(
                self.model.index(app_config.get_last_dir()))
        self.treeView.setAnimated(True)
        self.treeView.setIndentation(20)
        self.treeView.setSortingEnabled(True)
        self.treeView.setWindowTitle("Branded App Configurations")
        self.treeView.doubleClicked.connect(self.config_selected)
        self.set_recent_config_actions()

    def set_recent_config_actions(self):
        history = app_config.get_config_history()
        self.historyActions = []
        for k in history:
            a = QtGui.QAction(self)
            a.triggered.connect(lambda: self.open_config(k))
            a.setText(k)
            self.historyActions.append(a)
            self.menuRecent.addAction(a)

    @QtCore.Slot()
    def publish_clicked(self):
        #    index = self.treeView.currentIndex()
        pass

    def open_config(self, config_path):
        if os.path.exists(config_path):
            app_config.set_last_dir(os.path.dirname(config_path))
            if not config_path in self.windows:
                c = ConfigWindow(self)
                c.set_configuration(config_path, None)
                app_config.add_config_to_history(config_path)
                c.closeEvent = lambda x: self.windows.pop(config_path)
                self.windows[config_path] = c
            self.windows[config_path].show()

    @QtCore.Slot()
    def config_selected(self):
        print "Config is selected"
        p = self.model.filePath(self.treeView.currentIndex())
        config_path = os.path.join(p, "bc.json")
        config_path = config_path.replace('\\', '/')
        self.open_config(config_path)
示例#2
0
class ConfigManager(QtGui.QMainWindow, Ui_ConfigManager):
  def __init__(self, *args, **kwargs):
    super(ConfigManager, self).__init__(*args, **kwargs)
    self.setupUi()
    self.bindUi()
    self.windows = {}

  def setupUi(self):
    super(ConfigManager, self).setupUi(self)

  def bindUi(self):
    self.model = QFileSystemModel()
    self.model.setRootPath("/")
    self.model.setFilter(QDir.AllDirs | QDir.NoDotAndDotDot)
    self.treeView.setModel(self.model)
    if app_config.get_last_dir():
      self.treeView.setCurrentIndex(self.model.index(app_config.get_last_dir()))
    self.treeView.setAnimated(True)
    self.treeView.setIndentation(20)
    self.treeView.setSortingEnabled(True)
    self.treeView.setWindowTitle("Branded App Configurations")
    self.treeView.doubleClicked.connect(self.config_selected)
    self.set_recent_config_actions()

  def set_recent_config_actions(self):
    history = app_config.get_config_history()
    self.historyActions = []
    for k in history:
      a = QtGui.QAction(self)
      a.triggered.connect(lambda: self.open_config(k))
      a.setText(k)
      self.historyActions.append(a)
      self.menuRecent.addAction(a)

  @QtCore.Slot()
  def publish_clicked(self):
#    index = self.treeView.currentIndex()
    pass

  def open_config(self, config_path):
    if os.path.exists(config_path):
      app_config.set_last_dir(os.path.dirname(config_path))
      if not config_path in self.windows:
        c = ConfigWindow(self)
        c.set_configuration(config_path, None)
        app_config.add_config_to_history(config_path)
        c.closeEvent = lambda x: self.windows.pop(config_path)
        self.windows[config_path] = c
      self.windows[config_path].show()

  @QtCore.Slot()
  def config_selected(self):
    print "Config is selected"
    p = self.model.filePath(self.treeView.currentIndex())
    config_path = os.path.join(p, "bc.json")
    config_path = config_path.replace('\\', '/')
    self.open_config(config_path)
示例#3
0
class FileBrowser(QMainWindow):
    """Example file browsing widget. Based of the C++ example."""
    def __init__(self, parent=None, flags=Qt.Widget):
        super(FileBrowser, self).__init__(parent, flags)

        self.gallery = QDocumentGallery(self)
        self.fileSystemModel = QFileSystemModel(self)

        self.rootPath = QDesktopServices.storageLocation(QDesktopServices.HomeLocation)
        self.fileSystemModel.setRootPath(self.rootPath)

        self.view = QListView()
        self.view.setModel(self.fileSystemModel)
        self.view.activated.connect(self.activated)

        self.setCentralWidget(self.view)

        self.menuBar().addAction(self.tr("Documents"), self.browseDocuments)
        self.menuBar().addAction(self.tr("Audio"), self.browseAudio)
        self.menuBar().addAction(self.tr("Images"), self.browseImages)
        self.menuBar().addAction(self.tr("Videos"), self.browseVideos)

        self.browseDocuments()

    def activated(self, index):
        fileInfo = self.fileSystemModel.fileInfo(index)

        if fileInfo.isDir() and fileInfo.fileName() != '.':
            if fileInfo.fileName() == '..':
                parent = self.view.rootIndex().parent()

                fileInfo = self.fileSystemModel.fileInfo(parent)

                if fileInfo.absoluteFilePath() == self.rootPath:
                    self.fileSystemModel.setFilter(QDir.AllEntries | QDir.NoDotAndDotDot | QDir.AllDirs)

                self.view.setRootIndex(parent)

            else:
                self.fileSystemModel.setFilter(QDir.AllEntries | QDir.AllDirs)
                self.view.setRootIndex(index)

            self.setWindowTitle(fileInfo.fileName())
        else:
            if fileInfo.fileName() == '.':
                fileInfo = self.fileSystemModel.fileInfo(self.view.rootIndex())

            widget = DocumentPropertiesWidget(fileInfo, self.gallery, self)
            widget.setWindowFlags(self.window().windowFlags() | Qt.Dialog)
            widget.setAttribute(Qt.WA_DeleteOnClose)
            widget.setWindowModality(Qt.WindowModal)
            widget.show()

    def browseAudio(self):
        self.rootPath = QDesktopServices.storageLocation(QDesktopServices.MusicLocation)
        self.fileSystemModel.setFilter(QDir.AllEntries | QDir.NoDotAndDotDot | QDir.AllDirs)
        self.view.setRootIndex(self.fileSystemModel.index(self.rootPath))
        self.setWindowTitle(self.tr("Audio"))

    def browseDocuments(self):
        self.rootPath = QDesktopServices.storageLocation(QDesktopServices.DocumentsLocation)
        self.fileSystemModel.setFilter(QDir.AllEntries | QDir.NoDotAndDotDot | QDir.AllDirs)
        self.view.setRootIndex(self.fileSystemModel.index(self.rootPath))
        self.setWindowTitle(self.tr("Documents"))

    def browseImages(self):
        self.rootPath = QDesktopServices.storageLocation(QDesktopServices.PicturesLocation)
        self.fileSystemModel.setFilter(QDir.AllEntries | QDir.NoDotAndDotDot | QDir.AllDirs)
        self.view.setRootIndex(self.fileSystemModel.index(self.rootPath))
        self.setWindowTitle(self.tr("Images"))

    def browseVideos(self):
        self.rootPath = QDesktopServices.storageLocation(QDesktopServices.MoviesLocation)
        self.fileSystemModel.setFilter(QDir.AllEntries | QDir.NoDotAndDotDot | QDir.AllDirs)
        self.view.setRootIndex(self.fileSystemModel.index(self.rootPath))
        self.setWindowTitle(self.tr("Videos"))
示例#4
0
class FileBrowser(QMainWindow):
    """Example file browsing widget. Based of the C++ example."""
    def __init__(self, parent=None, flags=Qt.Widget):
        super(FileBrowser, self).__init__(parent, flags)

        self.gallery = QDocumentGallery(self)
        self.fileSystemModel = QFileSystemModel(self)

        self.rootPath = QDesktopServices.storageLocation(
            QDesktopServices.HomeLocation)
        self.fileSystemModel.setRootPath(self.rootPath)

        self.view = QListView()
        self.view.setModel(self.fileSystemModel)
        self.view.activated.connect(self.activated)

        self.setCentralWidget(self.view)

        self.menuBar().addAction(self.tr("Documents"), self.browseDocuments)
        self.menuBar().addAction(self.tr("Audio"), self.browseAudio)
        self.menuBar().addAction(self.tr("Images"), self.browseImages)
        self.menuBar().addAction(self.tr("Videos"), self.browseVideos)

        self.browseDocuments()

    def activated(self, index):
        fileInfo = self.fileSystemModel.fileInfo(index)

        if fileInfo.isDir() and fileInfo.fileName() != '.':
            if fileInfo.fileName() == '..':
                parent = self.view.rootIndex().parent()

                fileInfo = self.fileSystemModel.fileInfo(parent)

                if fileInfo.absoluteFilePath() == self.rootPath:
                    self.fileSystemModel.setFilter(QDir.AllEntries
                                                   | QDir.NoDotAndDotDot
                                                   | QDir.AllDirs)

                self.view.setRootIndex(parent)

            else:
                self.fileSystemModel.setFilter(QDir.AllEntries | QDir.AllDirs)
                self.view.setRootIndex(index)

            self.setWindowTitle(fileInfo.fileName())
        else:
            if fileInfo.fileName() == '.':
                fileInfo = self.fileSystemModel.fileInfo(self.view.rootIndex())

            widget = DocumentPropertiesWidget(fileInfo, self.gallery, self)
            widget.setWindowFlags(self.window().windowFlags() | Qt.Dialog)
            widget.setAttribute(Qt.WA_DeleteOnClose)
            widget.setWindowModality(Qt.WindowModal)
            widget.show()

    def browseAudio(self):
        self.rootPath = QDesktopServices.storageLocation(
            QDesktopServices.MusicLocation)
        self.fileSystemModel.setFilter(QDir.AllEntries | QDir.NoDotAndDotDot
                                       | QDir.AllDirs)
        self.view.setRootIndex(self.fileSystemModel.index(self.rootPath))
        self.setWindowTitle(self.tr("Audio"))

    def browseDocuments(self):
        self.rootPath = QDesktopServices.storageLocation(
            QDesktopServices.DocumentsLocation)
        self.fileSystemModel.setFilter(QDir.AllEntries | QDir.NoDotAndDotDot
                                       | QDir.AllDirs)
        self.view.setRootIndex(self.fileSystemModel.index(self.rootPath))
        self.setWindowTitle(self.tr("Documents"))

    def browseImages(self):
        self.rootPath = QDesktopServices.storageLocation(
            QDesktopServices.PicturesLocation)
        self.fileSystemModel.setFilter(QDir.AllEntries | QDir.NoDotAndDotDot
                                       | QDir.AllDirs)
        self.view.setRootIndex(self.fileSystemModel.index(self.rootPath))
        self.setWindowTitle(self.tr("Images"))

    def browseVideos(self):
        self.rootPath = QDesktopServices.storageLocation(
            QDesktopServices.MoviesLocation)
        self.fileSystemModel.setFilter(QDir.AllEntries | QDir.NoDotAndDotDot
                                       | QDir.AllDirs)
        self.view.setRootIndex(self.fileSystemModel.index(self.rootPath))
        self.setWindowTitle(self.tr("Videos"))