def create(self):
     self.setSortingEnabled(True)
     QtCompat.setSectionResizeMode(
         self.header(),
         QtWidgets.QHeaderView.ResizeToContents
     )
     self.model = QtWidgets.QFileSystemModel(self)
     self.model.setFilter(QtCore.QDir.Files)
     self.setModel(self.model)
Esempio n. 2
0
 def __init__(self, parent=None):
     super(SearchLineEdit, self).__init__(parent)
     completer = QtWidgets.QCompleter(parent=self)
     model = QtWidgets.QFileSystemModel(completer)
     model.setNameFilters(['*.nxt', '*.nxtb'])
     model.setNameFilterDisables(False)
     completer.setModel(model)
     completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
     completer.setCompletionMode(completer.UnfilteredPopupCompletion)
     completer.popup().setStyleSheet(parent.parent().stylesheet)
     self.returnPressed.connect(self.file_chosen.emit)
     self.setCompleter(completer)
     self.setFocusPolicy(QtCore.Qt.FocusPolicy.StrongFocus)
Esempio n. 3
0
    def __init__(self, file_filter=("*.nxt", "*.nxtb"), caption=''):
        super(NxtFileDialog, self).__init__()
        self.filter = file_filter
        self.filter_string = " ".join(self.filter)
        self.dir = ''
        self._file_path = ''
        self.mode = 'open'
        self.caption = caption
        self.setWindowTitle("{} nxt layer".format(self.mode))
        self.modes = {'open': self._open,
                      'save': self._save}
        self.vb_main_layout = QtWidgets.QVBoxLayout()
        self.setLayout(self.vb_main_layout)

        self.hb_file_browse = QtWidgets.QHBoxLayout()
        self.vb_main_layout.addLayout(self.hb_file_browse)
        # File path line edit
        self.l_file_path = QtWidgets.QLineEdit()
        self.l_file_path.setText(self.get_base_path(with_file_name=False))
        self.hb_file_browse.addWidget(self.l_file_path)
        # TODO: Get the completer to complete relative paths based on the
        #  self.dir path. Right now it starts completions from the file
        #  system root.
        self.fsm_file = QtWidgets.QFileSystemModel()
        self.fsm_file.setFilter(QtCore.QDir.AllDirs |
                                QtCore.QDir.NoDotAndDotDot |
                                QtCore.QDir.Files)
        self.fsm_file.setNameFilters(self.filter)
        self.fsm_file.setNameFilterDisables(False)
        self.fsm_file.setRootPath(self.dir)
        self.completer = QtWidgets.QCompleter()
        self.completer.setModel(self.fsm_file)
        self.idx = QtCore.QModelIndex(self.fsm_file.index(self.dir))
        self.l_file_path.setCompleter(self.completer)
        # Default file browser
        self.btn_browse = QtWidgets.QPushButton('Browse')
        self.btn_browse.clicked.connect(self.browse)
        self.hb_file_browse.addWidget(self.btn_browse)

        self.hb_options = QtWidgets.QHBoxLayout()
        self.vb_main_layout.addLayout(self.hb_options)
        self.pb_rel_path = QtWidgets.QPushButton('Convert to relative path')
        self.pb_rel_path.clicked.connect(self.convert_path)
        self.hb_options.addWidget(self.pb_rel_path)
        self.btn_accept = QtWidgets.QPushButton(self.mode.capitalize())
        self.btn_accept.setDefault(True)
        self.btn_accept.clicked.connect(self.accept)
        self.hb_options.addWidget(self.btn_accept)
Esempio n. 4
0
    def __init__(self, parent=None):
        super(ScriptTree, self).__init__(parent)

        self._settings = ScriptEditorSettings()

        main_layout = QtWidgets.QVBoxLayout()
        main_layout.setContentsMargins(4, 4, 4, 4)
        main_layout.setSpacing(2)

        self.file_model = QtWidgets.QFileSystemModel()

        folder_path_layout = QtWidgets.QHBoxLayout()
        self.folder_path_line_edit = QtWidgets.QLineEdit()
        folder_path_layout.addWidget(self.folder_path_line_edit)

        self.folder_path_browse_button = QtWidgets.QPushButton("...")
        self.folder_path_browse_button.clicked.connect(self.browse_folder_path)
        folder_path_layout.addWidget(self.folder_path_browse_button)
        main_layout.addLayout(folder_path_layout)

        self.tree_view = QtWidgets.QTreeView()
        self.tree_view.setModel(self.file_model)
        self.tree_view.setHeaderHidden(True)
        for i in range(1, self.tree_view.model().columnCount()):
            self.tree_view.header().hideSection(i)
        main_layout.addWidget(self.tree_view)

        folder_path = self._settings.value(ScriptEditorSettings.k_folder_path)
        if folder_path is None:
            folder_path = os.path.dirname(__file__)
        self.set_folder_path(folder_path)

        self.tree_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.tree_view.customContextMenuRequested.connect(self.context_menu)
        self.tree_view.doubleClicked.connect(self._path_double_clicked)

        self.setLayout(main_layout)
Esempio n. 5
0
    def __init__(self, path="", filter="", selectedFilter="", parent=None):
        """ Initialize the panel.
        
        :Parameters:
            path : `str`
                default path to look in when creating or choosing the file.
            filter : `list`
                A list of strings denoting filename match filters. These strings
                are displayed in a user-selectable combobox. When selected,
                the file list is filtered by the pattern
                The format must follow:
                ["Descriptive text (pattern1  pattern2  ...)", ...]
                The glob matching pattern is in parens, and the entire string is
                displayed for the user.
            selectedFilter : `str`
                Set the current filename filter. Needs to be one of the entries
                specified in the "filter" parameter.
            parent : `QObject`
                Parent for this widget.
        """
        super(IncludePanel, self).__init__(parent)

        # Setup UI.
        self.lookInCombo = QtWidgets.QComboBox(self)
        self.toParentButton = QtWidgets.QToolButton(self)
        self.buttonHome = QtWidgets.QToolButton(self)
        self.buttonOriginal = QtWidgets.QPushButton("Original", self)
        self.fileNameEdit = QtWidgets.QLineEdit(self)
        self.fileNameLabel = QtWidgets.QLabel("File:", self)
        self.fileTypeCombo = QtWidgets.QComboBox(self)
        self.fileTypeLabel = QtWidgets.QLabel("Type:", self)
        self.stackedWidget = QtWidgets.QStackedWidget(self)
        self.listView = QtWidgets.QListView(self)
        self.fileTypeLabelFiller = QtWidgets.QLabel(self)
        self.fileTypeComboFiller = QtWidgets.QLabel(self)
        self.buttonOpen = QtWidgets.QPushButton(
            QIcon.fromTheme("document-open"), "Open", self)

        # Item settings.
        self.buttonHome.setIcon(self.style().standardIcon(
            QtWidgets.QStyle.SP_DirHomeIcon))
        self.buttonHome.setToolTip("User's home directory")
        self.buttonHome.setAutoRaise(True)
        self.buttonOriginal.setToolTip("Original directory")
        self.lookInCombo.setMinimumSize(50, 0)
        self.toParentButton.setIcon(self.style().standardIcon(
            QtWidgets.QStyle.SP_FileDialogToParent))
        self.toParentButton.setAutoRaise(True)
        self.toParentButton.setToolTip("Parent directory")
        self.listView.setDragEnabled(True)
        self.fileNameLabel.setToolTip("Selected file or directory")
        self.fileTypeLabel.setBuddy(self.fileTypeCombo)
        self.fileTypeLabel.setToolTip("File type filter")
        self.buttonOpen.setToolTip("Open selected file")

        # Focus policies.
        self.lookInCombo.setFocusPolicy(QtCore.Qt.NoFocus)
        self.toParentButton.setFocusPolicy(QtCore.Qt.NoFocus)
        self.buttonHome.setFocusPolicy(QtCore.Qt.NoFocus)
        self.buttonOriginal.setFocusPolicy(QtCore.Qt.NoFocus)
        self.buttonOpen.setFocusPolicy(QtCore.Qt.NoFocus)

        # Item size policies.
        self.lookInCombo.setSizePolicy(QtWidgets.QSizePolicy.Ignored,
                                       QtWidgets.QSizePolicy.Fixed)
        self.toParentButton.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                          QtWidgets.QSizePolicy.Fixed)
        self.buttonHome.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                      QtWidgets.QSizePolicy.Fixed)
        self.buttonOriginal.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                          QtWidgets.QSizePolicy.Fixed)
        self.fileNameLabel.setSizePolicy(QtWidgets.QSizePolicy.Minimum,
                                         QtWidgets.QSizePolicy.Fixed)
        self.fileTypeCombo.setSizePolicy(QtWidgets.QSizePolicy.Ignored,
                                         QtWidgets.QSizePolicy.Fixed)
        self.fileTypeLabel.setSizePolicy(QtWidgets.QSizePolicy.Minimum,
                                         QtWidgets.QSizePolicy.Fixed)
        self.buttonOpen.setSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                      QtWidgets.QSizePolicy.Fixed)

        # Layouts.
        self.include1Layout = QtWidgets.QHBoxLayout()
        self.include1Layout.setContentsMargins(0, 0, 0, 0)
        self.include1Layout.setSpacing(5)
        self.include1Layout.addWidget(self.buttonHome)
        self.include1Layout.addWidget(self.lookInCombo)
        self.include1Layout.addWidget(self.toParentButton)

        self.include2Layout = QtWidgets.QHBoxLayout()
        self.include2Layout.setContentsMargins(0, 0, 0, 0)
        self.include2Layout.setSpacing(5)
        self.include2Layout.addWidget(self.stackedWidget)

        self.include4Layout = QtWidgets.QGridLayout()
        self.include4Layout.setContentsMargins(0, 0, 0, 0)
        self.include4Layout.setSpacing(5)
        self.include4Layout.addWidget(
            self.fileNameLabel, 0, 0,
            QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
        self.include4Layout.addWidget(self.fileNameEdit, 0, 1)
        self.include4Layout.addWidget(
            self.fileTypeLabel, 1, 0,
            QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
        self.include4Layout.addWidget(self.fileTypeCombo, 1, 1)
        self.include4Layout.addWidget(self.fileTypeLabelFiller, 2, 0)
        self.include4Layout.addWidget(self.fileTypeComboFiller, 2, 1)

        self.include5Layout = QtWidgets.QHBoxLayout()
        self.include5Layout.setAlignment(QtCore.Qt.AlignLeft
                                         | QtCore.Qt.AlignVCenter)
        self.include5Layout.setContentsMargins(0, 0, 0, 0)
        self.include5Layout.setSpacing(5)
        self.include5Layout.addWidget(self.buttonOriginal)
        spacer = QtWidgets.QSpacerItem(5, 0,
                                       QtWidgets.QSizePolicy.MinimumExpanding)
        self.include5Layout.addSpacerItem(spacer)
        self.include5Layout.addWidget(self.buttonOpen)

        self.includeLayout = QtWidgets.QVBoxLayout()
        self.includeLayout.setContentsMargins(0, 0, 0, 0)
        self.includeLayout.setSpacing(5)
        self.includeLayout.addLayout(self.include1Layout)
        self.includeLayout.addLayout(self.include2Layout)
        self.includeLayout.addLayout(self.include4Layout)
        line1 = QtWidgets.QFrame()
        line1.setFrameStyle(QtWidgets.QFrame.HLine | QtWidgets.QFrame.Sunken)
        self.includeLayout.addWidget(line1)
        self.includeLayout.addLayout(self.include5Layout)

        self.setLayout(self.includeLayout)
        self.setSizePolicy(QtWidgets.QSizePolicy.Minimum,
                           QtWidgets.QSizePolicy.Expanding)

        self.buttonHome.clicked.connect(self.onHome)
        self.buttonOriginal.clicked.connect(self.onOriginal)
        self.lookInCombo.activated[int].connect(self.onPathComboChanged)
        self.fileTypeCombo.activated[int].connect(self._useNameFilter)

        self.fileModel = QtWidgets.QFileSystemModel(parent)
        self.fileModel.setReadOnly(True)
        self.fileModel.setNameFilterDisables(False)
        self.fileModel.setResolveSymlinks(True)
        self.fileModel.rootPathChanged.connect(self.pathChanged)

        self.listView.setModel(self.fileModel)

        self.listView.activated[QtCore.QModelIndex].connect(
            self.enterDirectory)

        # Set selection mode and behavior.
        self.listView.setSelectionBehavior(
            QtWidgets.QAbstractItemView.SelectRows)
        self.listView.setWrapping(False)
        self.listView.setResizeMode(QtWidgets.QListView.Adjust)

        selectionMode = QtWidgets.QAbstractItemView.SingleSelection
        self.listView.setSelectionMode(selectionMode)

        # Setup the completer.
        completer = QtWidgets.QCompleter(self.fileModel, self.fileNameEdit)
        completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
        self.fileNameEdit.setCompleter(completer)
        self.fileNameEdit.textChanged.connect(self.autoCompleteFileName)
        self.fileNameEdit.returnPressed.connect(self.accept)

        pathFile = None
        if not path:
            self.__path = os.getcwd()
        elif os.path.isfile(path):
            self.__path, pathFile = os.path.split(path)
        else:
            self.__path = path

        self.setPath(self.__path)

        if filter:
            self.setNameFilters(filter)

        if selectedFilter:
            self.selectNameFilter(selectedFilter)

        self.listPage = QtWidgets.QWidget(self.stackedWidget)
        self.stackedWidget.addWidget(self.listPage)
        listLayout = QtWidgets.QGridLayout(self.listPage)
        #listLayout.setMargin(0)
        listLayout.setContentsMargins(0, 0, 0, 0)
        listLayout.addWidget(self.listView, 0, 0, 1, 1)

        self.fileTypeLabelFiller.hide()
        self.fileTypeComboFiller.hide()

        # Selections
        selections = self.listView.selectionModel()
        selections.selectionChanged.connect(self.fileSelectionChanged)

        if pathFile is not None:
            idx = self.fileModel.index(self.fileModel.rootPath() +
                                       QtCore.QDir.separator() + pathFile)
            self.select(idx)
            self.fileNameEdit.setText(pathFile)

        # Connect signals.
        self.toParentButton.clicked.connect(self.onUp)
        self.buttonOpen.clicked.connect(self.accept)

        self.listView.scheduleDelayedItemsLayout()
        self.stackedWidget.setCurrentWidget(self.listPage)
        self.fileNameEdit.setFocus()
Esempio n. 6
0
    def __init__(self, parent, tab=0):
        """Constructor for the OpenDialog."""
        super().__init__(parent)
        self.setWindowTitle(self.tr("Open Simulation"))
        self.setMinimumWidth(800)
        self.setMinimumHeight(800)

        m = 5
        containerLayout = QtWidgets.QHBoxLayout()
        containerLayout.setContentsMargins(m, m, m, m)
        self.setLayout(containerLayout)

        # ========================================
        # Left Bar + navigation
        self.leftBar = QtWidgets.QVBoxLayout()
        self.leftBar.setContentsMargins(0, 0, 0, 0)
        containerLayout.addLayout(self.leftBar)

        self.buttGroup = QtWidgets.QButtonGroup()
        self.buttGroup.setExclusive(True)

        self.leftBar.addWidget(self._make_nav_button(self.tr("Sims"),
                                                     NAV.sims))
        self.leftBar.addWidget(
            self._make_nav_button(self.tr("Recent"), NAV.recent))
        self.leftBar.addWidget(
            self._make_nav_button(self.tr("Browse"), NAV.filesystem))
        self.leftBar.addStretch(20)

        # ==================================================================================
        # Stack widget for main
        mainLayout = QtWidgets.QVBoxLayout()
        mainLayout.setContentsMargins(0, 0, 0, 0)
        containerLayout.addLayout(mainLayout)

        self.stackWidget = QtWidgets.QStackedWidget()
        mainLayout.addWidget(self.stackWidget, 200)

        # =================
        # Downloaded Sims
        self.downloadWidget = QtWidgets.QWidget()
        self.downloadLayout = QtWidgets.QVBoxLayout()
        self.downloadLayout.setContentsMargins(0, 0, 0, 0)
        self.downloadWidget.setLayout(self.downloadLayout)
        self.stackWidget.addWidget(self.downloadWidget)

        tbBrowse = QtWidgets.QToolBar()
        self.downloadLayout.addWidget(tbBrowse)

        self.txtUrl = QtWidgets.QLineEdit(self)
        self.txtUrl.setText(ts2.get_info().get('simulations_repo'))
        tbBrowse.addWidget(self.txtUrl)

        self.buttDownload = tbBrowse.addAction("Download", self.onDownload)

        self.treeSims = QtWidgets.QTreeWidget()
        self.downloadLayout.addWidget(self.treeSims)
        hitem = self.treeSims.headerItem()
        hitem.setText(C.name, "Name")
        hitem.setText(C.description, "Description")
        hitem.setText(C.file_name, "File")
        hitem.setText(C.file_path, "Path")
        self.treeSims.setColumnHidden(C.file_path, True)
        self.treeSims.header().setStretchLastSection(True)
        self.treeSims.itemDoubleClicked.connect(self.onTreeSimsItemDblClicked)

        # =====================================
        # Recent

        self.treeRecent = QtWidgets.QTreeWidget()
        self.stackWidget.addWidget(self.treeRecent)

        hitem = self.treeRecent.headerItem()
        hitem.setText(0, "Path")

        self.treeRecent.itemDoubleClicked.connect(
            self.onTreeRecentItemDblClicked)

        # =====================================
        # Browse
        self.filesModel = QtWidgets.QFileSystemModel()
        self.filesModel.setRootPath(QtCore.QDir.homePath())
        self.filesModel.setNameFilters(["*.ts2", "*.json"])

        self.treeFiles = QtWidgets.QTreeView()
        self.treeFiles.setModel(self.filesModel)

        self.stackWidget.addWidget(self.treeFiles)

        self.treeFiles.doubleClicked.connect(self.onTreeBrowseItemDblClicked)

        # =================================
        # Bottom status
        self.statusBar = widgets.StatusBar()
        mainLayout.addWidget(self.statusBar, 0)
        if settings.debug:
            self.statusBar.showMessage(settings.simulationsDir)

        self.buttGroup.buttonToggled.connect(self.onNavButtClicked)
        self.buttGroup.button(tab).setChecked(True)
Esempio n. 7
0
    def __init__(self, parent, tab=0):
        """Constructor for the OpenDialog."""
        super().__init__(parent)
        self.setWindowTitle(self.tr("Open Simulation"))
        self.setMinimumWidth(800)
        self.setMinimumHeight(800)

        m = 5
        containerLayout = QtWidgets.QHBoxLayout()
        containerLayout.setContentsMargins(m, m, m, m)
        self.setLayout(containerLayout)

        # ========================================
        # Left Bar + navigation
        self.leftBar = QtWidgets.QVBoxLayout()
        self.leftBar.setContentsMargins(0, 0, 0, 0)
        containerLayout.addLayout(self.leftBar)

        self.buttGroup = QtWidgets.QButtonGroup()
        self.buttGroup.setExclusive(True)

        self.leftBar.addWidget(self._make_nav_button(self.tr("Sims"),
                                                     NAV.sims))
        self.leftBar.addWidget(
            self._make_nav_button(self.tr("Recent"), NAV.recent))
        self.leftBar.addWidget(
            self._make_nav_button(self.tr("Browse"), NAV.filesystem))
        self.leftBar.addWidget(
            self._make_nav_button(self.tr("Network"), NAV.network))
        self.leftBar.addStretch(20)

        # ==================================================================================
        # Stack widget for main
        mainLayout = QtWidgets.QVBoxLayout()
        mainLayout.setContentsMargins(0, 0, 0, 0)
        containerLayout.addLayout(mainLayout)

        self.stackWidget = QtWidgets.QStackedWidget()
        mainLayout.addWidget(self.stackWidget, 200)

        # =================
        # Downloaded Sims
        self.downloadWidget = QtWidgets.QWidget()
        self.downloadLayout = QtWidgets.QVBoxLayout()
        self.downloadLayout.setContentsMargins(0, 0, 0, 0)
        self.downloadWidget.setLayout(self.downloadLayout)
        self.stackWidget.addWidget(self.downloadWidget)

        tbBrowse = QtWidgets.QToolBar()
        self.downloadLayout.addWidget(tbBrowse)

        self.txtUrl = QtWidgets.QLineEdit(self)
        self.txtUrl.setText(ts2.get_info().get('simulations_repo'))
        tbBrowse.addWidget(self.txtUrl)

        self.buttDownload = tbBrowse.addAction(self.tr("Download"),
                                               self.onDownload)

        self.treeSims = QtWidgets.QTreeWidget()
        self.downloadLayout.addWidget(self.treeSims)
        hitem = self.treeSims.headerItem()
        hitem.setText(C.name, "Name")
        hitem.setText(C.description, "Description")
        hitem.setText(C.file_name, "File")
        hitem.setText(C.file_path, "Path")
        self.treeSims.setColumnHidden(C.file_path, True)
        self.treeSims.header().setStretchLastSection(True)
        self.treeSims.itemDoubleClicked.connect(self.onTreeSimsItemDblClicked)

        # =====================================
        # Recent

        self.treeRecent = QtWidgets.QTreeWidget()
        self.stackWidget.addWidget(self.treeRecent)

        hitem = self.treeRecent.headerItem()
        hitem.setText(0, "Path")

        self.treeRecent.itemDoubleClicked.connect(
            self.onTreeRecentItemDblClicked)

        # =====================================
        # Browse
        self.filesModel = QtWidgets.QFileSystemModel()
        self.filesModel.setRootPath(QtCore.QDir.homePath())
        self.filesModel.setNameFilters(["*.ts2", "*.json"])
        self.filesModel.setNameFilterDisables(False)

        self.treeFiles = QtWidgets.QTreeView()
        self.treeFiles.setModel(self.filesModel)
        self.treeFiles.setColumnWidth(0, 300)
        self.treeFiles.setExpanded(
            self.filesModel.index(QtCore.QDir.homePath()), True)
        path = QtCore.QDir.home()
        while path.cdUp():
            self.treeFiles.setExpanded(self.filesModel.index(path.path()),
                                       True)

        self.stackWidget.addWidget(self.treeFiles)

        self.treeFiles.doubleClicked.connect(self.onTreeBrowseItemDblClicked)

        # =================================
        # Network
        self.networkWidget = QtWidgets.QWidget()
        self.networkLayout = QtWidgets.QVBoxLayout()
        self.networkLayout.setContentsMargins(0, 0, 0, 0)
        self.networkWidget.setLayout(self.networkLayout)
        self.stackWidget.addWidget(self.networkWidget)

        networkLabel = QtWidgets.QLabel(
            self.tr("Connect to simulation server"))
        networkLabel.setStyleSheet("font-size: 15px; font-weight: bold;")
        labelLayout = QtWidgets.QHBoxLayout()
        labelLayout.addStretch(1)
        labelLayout.addWidget(networkLabel)
        labelLayout.addStretch(1)
        self.networkLayout.addLayout(labelLayout)

        tbNetworkBarLayout = QtWidgets.QHBoxLayout()
        self.networkLayout.addLayout(tbNetworkBarLayout)

        tbNetworkBarLayout.addWidget(QtWidgets.QLabel(self.tr("Host:")))
        self.networkServer = QtWidgets.QLineEdit(self)
        self.networkServer.setText("localhost")
        tbNetworkBarLayout.addWidget(self.networkServer, 2)
        tbNetworkBarLayout.addWidget(QtWidgets.QLabel(self.tr("Port:")))
        self.networkPort = QtWidgets.QLineEdit(self)
        self.networkPort.setInputMask("00000")
        self.networkPort.setText("22222")
        tbNetworkBarLayout.addWidget(self.networkPort, 1)

        self.connectAction = QtWidgets.QAction(self.tr("Connect"))
        self.connectAction.triggered.connect(self.onConnect)
        btn = QtWidgets.QToolButton()
        btn.setDefaultAction(self.connectAction)
        self.buttConnect = tbNetworkBarLayout.addWidget(btn)
        self.networkLayout.addStretch(1)

        # =================================
        # Bottom status
        self.statusBar = widgets.StatusBar()
        mainLayout.addWidget(self.statusBar, 0)
        if settings.debug:
            self.statusBar.showMessage(settings.simulationsDir)

        self.buttGroup.buttonToggled.connect(self.onNavButtClicked)
        self.buttGroup.button(tab).setChecked(True)
Esempio n. 8
0
    def __init__(self, parent=None):
        super(PresetShareUI, self).__init__(parent=parent)
        # window prep ---------------------------------------------------------
        self.parent = parent
        self.setWindowTitle(WINDOW_TITLE)
        self.setObjectName(self.__class__.__name__)
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
        minflag = QtCore.Qt.WindowMinimizeButtonHint
        self.setWindowFlags(self.windowFlags() | minflag)
        self.setMinimumWidth(350)
        self.preset_share_dir = preset_share_utils.get_base_dir()
        self.mainLayout = QtWidgets.QVBoxLayout()
        self.setLayout(self.mainLayout)

        # logic variables -----------------------------------------------------
        self._remember_dir_var = "{}lastpath".format(self.__class__.__name__)
        self.skip_other_users = True
        self.collected_dir_info = {}
        self.view_expanded_state_info = {}
        self._state_gathered = False

        # file system crawl and display ---------------------------------------
        self.search_widget = QtWidgets.QLineEdit()
        self.search_widget.setPlaceholderText("Search")

        self.file_manager = QtWidgets.QFileSystemModel()
        ext_filters = ["*.{}".format(preset_share_utils.PRESET_EXT)]
        self.file_manager.setNameFilters(ext_filters)
        self.file_manager.rowsInserted.connect(self.manual_tracking)
        self.file_manager.columnsInserted.connect(self.manual_tracking)
        self.file_manager.directoryLoaded.connect(self.loadedPath)
        self.root_model_index = self.file_manager.setRootPath(
            self.preset_share_dir)

        self.file_view = QtWidgets.QTreeView()
        self.file_view.setModel(self.file_manager)
        self.file_view.setRootIndex(self.root_model_index)
        self.file_view.hideColumn(1)
        self.file_view.hideColumn(2)
        self.file_view.clicked.connect(self.preset_selected)
        self.file_view.header().setSectionResizeMode(
            QtWidgets.QHeaderView.Stretch)
        # self.file_view.header().setStretchLastSection(True)
        self.file_view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.file_view.customContextMenuRequested.connect(
            self.create_context_menu)

        # Arbitrarily setting this now, as it gets set again with signals -----
        self.set_search_completer()

        self.text_view = QtWidgets.QTextEdit()
        self.text_view.setReadOnly(True)
        self.text_view.setMaximumHeight(100)

        self.apply_preset_btn = QtWidgets.QPushButton("Apply Preset")
        self.apply_preset_btn.setToolTip("Select Node of same type.")
        self.apply_preset_btn.setEnabled(False)
        self.apply_preset_btn.clicked.connect(self.apply_preset)

        self.create_preset_btn = QtWidgets.QPushButton("Create Preset")
        self.create_preset_btn.setToolTip("Select Node in Maya")
        self.create_preset_btn.clicked.connect(self.create_preset)

        self.mainLayout.addWidget(self.search_widget)
        self.mainLayout.addWidget(self.file_view)
        self.mainLayout.addWidget(self.text_view)
        self.mainLayout.addWidget(self.apply_preset_btn)
        self.mainLayout.addWidget(self.create_preset_btn)