示例#1
0
def _add_file_item(stage, unit, stage_item, indir_item, outdir_item):
    """Add file item to the view model."""

    filename = stage.handle2file(unit)

    file_item = HandleItem(File(stage, unit))
    stage_item.appendChild(file_item)

    ref_item = None
    for dir_item in indir_item, outdir_item:
        directory = dir_item.dir
        if is_subpath(filename, directory):
            if behavior().join_similar_files:
                for i in range(dir_item.childCount()):
                    item = dir_item.child(i)
                    if item.filename == filename and item.unit == unit:
                        ref_item = item
                        break
            if ref_item is not None:
                ref_item.itemData().add_entry(stage, unit)
            else:
                file_unit = File(stage, unit)
                file_unit.forced_attr = FileAttr.In \
                    if dir_item is indir_item else FileAttr.Out
                ref_item = HandleItem(file_unit)
                dir_item.appendChild(ref_item)
            break

    return file_item, ref_item
示例#2
0
    def _setup(self, case):
        """Build initial tree of items."""
        self.rootItem = ModelItem(self)

        # top-level 'Case' item
        case_item = CaseItem(case)
        self.rootItem.appendChild(case_item)

        # 'InDir' and 'OutDir' items - children of 'Case' item
        indir_item = DirItem(Directory(case, Directory.InDir))
        case_item.appendChild(indir_item)
        outdir_item = DirItem(Directory(case, Directory.OutDir))
        case_item.appendChild(outdir_item)

        # top-level 'Stage' items
        for stage in case:
            stage_item = StageItem(stage, self.rootItem)

            for handle in stage.handle2info:
                file_item, ref_item = _add_file_item(stage, handle, stage_item,
                                                     indir_item, outdir_item)
                if behavior().show_related_concepts:
                    for command in stage.handle2info[handle].commands:
                        file_item.appendChild(CommandItem(command))
                        if ref_item is not None:
                            ref_item.appendChild(CommandItem(command))
示例#3
0
    def sort_stages():
        """
        Get 'sort stages' option.

        Returns:
            bool: *True* if stages should be sorted.
        """
        return Model.FORCE_RESORT or behavior().sort_stages
示例#4
0
    def setMeshList(self, meshlist):
        """
        Sets the mesh commands list

        Arguments:
            meshlist: List of commands with meshes.
        """
        self._mesh.clear()
        show_title = behavior().show_catalogue_name_in_selectors
        title_mask = '{n} ({t})' if show_title else '{n}'
        for meshcmd in meshlist:
            title = title_mask.format(n=meshcmd.name, t=meshcmd.title)
            self._mesh.addItem(title, meshcmd)
示例#5
0
    def preferenceChanged(self, section, name):
        """
        Called when preferences item is changed in Preferences dialog.

        Arguments:
            section (str): Resource section's name.
            name (str): Resource parameter's name.
        """
        has_changes = False

        if section == AsterSalomeGui.NAME:
            has_changes = True
            self.from_preferences()  # re-initialize behavior from preferences
            if name == "workspace_tab_position":
                if self.work_space is not None:
                    tbposition = behavior().workspace_tab_position
                    self.work_space.setTabPosition(tab_position(tbposition))
            elif name in ("use_business_translations", "content_mode"):
                self.updateTranslations()
            elif name == "sort_stages":
                self.workSpace().view(Context.DataFiles).resort()
            elif name in ("show_related_concepts", "join_similar_files"):
                self.workSpace().view(Context.DataFiles).update()
            elif name in ("show_catalogue_name", "show_comments"):
                self.workSpace().view(Context.DataSettings).update()
            elif name == "auto_hide_search":
                view = self.workSpace().view(Context.DataSettings)
                view.setAutoHideSearch(behavior().auto_hide_search)
            elif name == "show_readonly_banner":
                self._updateWindows()

        elif section == "PyEditor":
            has_changes = True

        if has_changes:
            self.preferencesChanged.emit(self.preferencesMgr())
示例#6
0
    def update(self):
        """
        Update tree view contents.
        """
        super(DataSettings, self).update()

        self._view.setColumnHidden(1, not behavior().show_catalogue_name)

        view = self._view
        study = self._astergui.study()
        if study is not None:
            block = view.signalsBlocked()
            view.blockSignals(True)
            category_model = study.categoryModel()
            if category_model is not None:
                category_model.update_all(view.invisibleRootItem())
            else:
                view.clear()
            view.blockSignals(block)
示例#7
0
    def grid(self):
        """
        Create and return top-level grid layout to arrange child items.

        Returns:
            QGridLayout: Layout for widgets.
        """
        if self.layout() is None:
            grid = self.GridLayout()
            grid.setSpacing(10)
            extlist = behavior().external_list
            if self.isItemList() and not extlist:
                grid.setColumnStretch(self.ColumnId.Label, 0)
                grid.setColumnStretch(self.ColumnId.Editor, 1)
            else:
                grid.setColumnStretch(self.ColumnId.Label, 1)
                grid.setColumnStretch(self.ColumnId.Editor, 0)
            self.setLayout(grid)
            self._updateGrid()
        return self.layout()
示例#8
0
 def update(self):
     """Update model."""
     stages = []
     if self.case is None:
         if get_node_type(self.root) == NodeType.Stage:
             stages.append(self.root)
     else:
         self._stage_children = {}
         self._categories = []
         stages = self.case.stages
     for stage in stages:
         if stage.is_graphical_mode():
             # not be necessary if command.check was called before update
             stage.reorder()
             commands = stage.sorted_commands
             categories = []
             withnext = []
             for command in commands:
                 if command.title == "_CONVERT_COMMENT":
                     if behavior().show_comments:
                         withnext.append(command)
                     continue
                 category = CATA.get_command_category(command.title)
                 category = translate_category(category)
                 if not categories or categories[-1].name != category:
                     uid = len(self._categories) + 1
                     new_category = Category(-uid, category, stage.uid,
                                             self._history_proxy)
                     self._categories.append(new_category)
                     categories.append(new_category)
                 for i in withnext:
                     categories[-1].add_child(i)
                 categories[-1].add_child(command)
                 withnext = []
             # purge the buffer
             if categories:  # only comments => ignored!
                 for i in withnext:
                     categories[-1].add_child(i)
             self._stage_children[stage] = categories
         else:
             self._stage_children[stage] = []
示例#9
0
    def __init__(self, astergui, parent=None):
        """
        Create view.

        Arguments:
            astergui (AsterGui): *AsterGui* instance.
            parent (Optional[QWidget]): Parent widget. Defaults to
                *None*.
        """
        super(DataSettings, self).__init__(parent)
        self._astergui = astergui

        base = Q.QVBoxLayout(self)
        base.setContentsMargins(0, 0, 0, 0)

        self._view = TreeWidget(self)
        self._view.itemDelegate().setEditColumns(0)
        self._view.setColumnCount(2)
        if debug_mode():
            self._view.setColumnCount(3)
        self._view.setSelectionMode(Q.QTreeWidget.ExtendedSelection)
        header = self._view.header()
        header.hide()
        header.setSectionResizeMode(Q.QHeaderView.ResizeToContents)
        header.setMaximumSectionSize(250)
        header.setStretchLastSection(True)
        root = self._view.invisibleRootItem()
        root.setData(0, Role.IdRole, root_node_type())
        base.addWidget(self._view)

        self._finder = Searcher(astergui, self)
        self._finder.setAutoHide(behavior().auto_hide_search)
        base.addWidget(self._finder)

        connect(self._view.itemSelectionChanged, self.itemSelectionChanged)
        connect(self._view.itemDoubleClicked, self._itemDoubleClicked)
        connect(self._view.itemChanged, self._itemChanged)

        self.update()
示例#10
0
def get_object_name(obj):
    """
    Get object name to be displayed in data view.

    Arguments:
        obj (Node): Data model node.

    Returns:
        str: Object's name.
    """
    node_type = get_node_type(obj)
    if node_type == NodeType.History:
        return translate("AsterStudy", "History")
    elif node_type == NodeType.Command:
        if obj.gettype(ConversionLevel.NoFail) is not None:
            return obj.name
        if behavior().show_catalogue_name:
            return translate("AsterStudy", "[noname]")
        else:
            return translate_command(obj.title)
    elif node_type == NodeType.Comment:
        return obj.content.split("\n")[0]

    return obj.name
示例#11
0
    def __init__(self, astergui, parent=None):
        """
        Create panel.

        Arguments:
            astergui (AsterGui): AsterGui instance.
            parent (Optional[QWidget]): Parent widget.
        """
        super(ParameterPanel,
              self).__init__(parent=parent,
                             name=translate("ParameterPanel", "Edit command"),
                             astergui=astergui)
        self.setPixmap(load_pixmap("as_pic_edit_command.png"))

        self._files_model = astergui.study().dataFilesModel()
        self._unit_model = None

        self._command = None
        self.title = ParameterTitle(self)
        self.title.installEventFilter(self)
        self._name = QLineEdit(self)
        self.views = QStackedWidget(self)
        v_layout = QVBoxLayout(self)
        v_layout.setContentsMargins(0, 0, 0, 0)
        v_layout.setSpacing(5)
        v_layout.addWidget(self.title)
        v_layout.addWidget(HLine(self))

        n_layout = QHBoxLayout()
        v_layout.addLayout(n_layout)
        n_layout.addWidget(QLabel(translate("ParameterPanel", "Name"), self))
        n_layout.addWidget(self._name)
        # force to be a valid identifier + length <= 8
        self._name.setValidator(QRegExpValidator(QRegExp(r"[a-zA-Z]\w{1,7}")))

        # create toolbar
        tbar = QToolBar(self)
        tbar.setToolButtonStyle(Qt.ToolButtonIconOnly)
        # - Edit comment
        edit_comment = QAction(translate("AsterStudy", "Edit &Comment"), self)
        edit_comment.setToolTip(translate("AsterStudy", "Edit comment"))
        edit_comment.setStatusTip(
            translate("AsterStudy", "Edit comment for the "
                      "selected object"))
        edit_comment.setIcon(load_icon("as_pic_edit_comment.png"))
        connect(edit_comment.triggered, self._editComment)
        tbar.addAction(edit_comment)
        # - Switch on/off business-translations
        title = translate("AsterStudy", "Use Business-Oriented Translations")
        self.use_translations = QAction(title, self)
        title = translate("AsterStudy", "Use business-oriented translations")
        self.use_translations.setToolTip(title)
        self.use_translations.setStatusTip(title)
        self.use_translations.setIcon(load_icon("as_pic_use_translations.png"))
        self.use_translations.setCheckable(True)
        if behavior().forced_native_names:
            force = behavior().force_native_names
            self.use_translations.setDisabled(True)
            is_on = not force
        else:
            is_on = behavior().use_business_translations
        Options.use_translations = is_on
        self.use_translations.setChecked(is_on)
        connect(self.use_translations.toggled, self.updateTranslations)
        tbar.addAction(self.use_translations)
        # - Hide unused
        hide_unused = astergui.action(ActionType.HideUnused)
        connect(hide_unused.toggled, self._unusedVisibility)
        tbar.addAction(hide_unused)
        # - What's this
        whats_this = QWhatsThis.createAction(tbar)
        whats_this.setToolTip(translate("AsterStudy", "What's this?"))
        whats_this.setStatusTip(
            translate("AsterStudy", "Show element's description"))
        whats_this.setIcon(load_icon("as_pic_whats_this.png"))
        tbar.addAction(whats_this)
        # - Link to doc
        tbar.addAction(astergui.action(ActionType.LinkToDoc))

        n_layout.addWidget(tbar)

        v_layout.addWidget(self.views)
        self._updateState()
示例#12
0
 def createMeshView(self, parent=None):
     """Reimplemented from AsterGui."""
     no_mesh_view = behavior().no_mesh_view
     return MeshView(parent) if not no_mesh_view and \
         hasattr(get_salome_pyqt(), 'getViewWidget') \
         else MeshBaseView(parent)