Exemple #1
0
    def node(self, node):
        """
        Set object to be edited.

        Arguments:
            node (Node): Object to be edited (*Command*, *Comment* or
                *Case* object).
        """
        if self._node is node:
            return

        self._node = node

        if node is not None:
            cname = ''
            pixmap = Q.QPixmap()
            node_type = get_node_type(node)
            if node_type in (NodeType.Command, NodeType.Variable):
                self._prev_state = node.comment.content \
                    if node.comment is not None else ''
                cname = translate("AsterStudy", "Edit comment")
                pixmap = load_pixmap("as_pic_edit_comment.png")
            elif node_type in (NodeType.Comment, ):
                self._prev_state = node.content
                cname = translate("AsterStudy", "Edit comment")
                pixmap = load_pixmap("as_pic_edit_comment.png")
            elif node_type in (NodeType.Case, ):
                self._prev_state = node.description
                cname = translate("AsterStudy", "Edit description")
                pixmap = load_pixmap("as_pic_edit_comment.png")
            if self._prev_state is not None:
                self.editor.setPlainText(self._prev_state)
            self._controllername = cname
            self.setWindowTitle(self.controllerName())
            self.setPixmap(pixmap)
Exemple #2
0
    def _updateState(self):
        """
        Update panel's state.
        """
        if self.variable is None:
            op_name = translate("VariablePanel", "Create variable")
            op_pixmap = load_pixmap("as_pic_new_variable.png")
        else:
            op_name = translate("VariablePanel", "Edit variable")
            op_pixmap = load_pixmap("as_pic_edit_variable.png")
        self._controllername = op_name
        self.setWindowTitle(op_name)
        self.setPixmap(op_pixmap)

        self._vins.menu().clear()

        vnames = sorted(self._variableNames())
        fnames = sorted([i + '()' for i in self._functionNames()])

        for i in vnames:
            self._vins.menu().addAction(i)

        if vnames and fnames:
            self._vins.menu().addSeparator()

        for f in fnames:
            a = self._vins.menu().addAction(f)
            f = a.font()
            f.setItalic(True)
            a.setFont(f)

        self._vins.menu().setEnabled(not self._vins.menu().isEmpty())
        self._vcomp.setModel(Q.QStringListModel(vnames + fnames, self._vcomp))

        self.updateButtonStatus()
Exemple #3
0
    def __init__(self, astergui, parent=None, **kwargs):
        """
        Create comment edition panel.

        Arguments:
            astergui (AsterGui): Parent *AsterGui* instance.
            parent (Optional[QWidget]): Parent widget. Defaults to
                *None*.
            **kwargs: Keyword arguments.
        """
        super(CommentPanel,
              self).__init__(parent=parent,
                             name=translate("AsterStudy", "Edit comment"),
                             astergui=astergui,
                             **kwargs)
        self._prev_state = None
        self._node = None

        self.setWindowTitle(self.controllerName())
        self.setPixmap(load_pixmap("as_pic_edit_comment.png"))

        self.editor = Q.QPlainTextEdit(self)
        self.editor.setObjectName("text_editor")
        v_layout = Q.QVBoxLayout(self)
        v_layout.addWidget(self.editor)
        self.editor.textChanged.connect(self.updateButtonStatus)
Exemple #4
0
    def __init__(self, file_name, astergui, parent=None, **kwargs):
        """
        Create editor.

        Arguments:
            file_name (str): File path.
            astergui (AsterGui): AsterGui instance.
            parent (Optional[QWidget]): Parent widget. Defaults to
                *None*.
            **kwargs: Keyword arguments.
        """
        super(TextFileEditor,
              self).__init__(parent=parent,
                             name=translate("AsterStudy", "Edit file"),
                             astergui=astergui,
                             **kwargs)
        self.file_name = file_name
        self.prev_state = _text2unicode(read_file(file_name))

        title = translate("AsterStudy", "Edit file") + " '{}'"
        self.setWindowTitle(title.format(get_base_name(file_name)))
        self.setPixmap(load_pixmap("as_pic_edit_file.png"))

        self.editor = Q.QTextEdit(self)
        self.editor.setLineWrapMode(Q.QTextEdit.NoWrap)
        self.setLayout(Q.QVBoxLayout())
        self.layout().setContentsMargins(0, 0, 0, 0)
        self.layout().addWidget(self.editor)

        self.editor.setPlainText(self.prev_state)
        self.editor.textChanged.connect(self.updateButtonStatus)
Exemple #5
0
    def __init__(self, stage, astergui, parent=None, **kwargs):
        """
        Create editor.

        Arguments:
            stage (Stage): Stage to edit.
            astergui (AsterGui): AsterGui instance.
            parent (Optional[QWidget]): Parent widget. Defaults to
                *None*.
            **kwargs: Keyword arguments.
        """
        super(StageTextEditor,
              self).__init__(parent=parent,
                             name=translate("StageTextEditor", "Edit stage"),
                             astergui=astergui,
                             **kwargs)

        self.stage = stage
        self.prev_state = stage.get_text()

        title = translate("StageTextEditor", "Edit stage '{}'")
        self.setWindowTitle(title.format(stage.name))
        self.setPixmap(load_pixmap("as_pic_edit_stage.png"))

        self.editor = TextEditor(self)
        v_layout = Q.QVBoxLayout(self)
        v_layout.addWidget(self.editor)
        commands = [j for i in [CATA.get_category(i) \
                                    for i in CATA.get_categories()] for j in i]
        self.editor.setKeywords(commands, 0, Q.QColor("#ff0000"))
        self.editor.setText(self.prev_state)
        self.editor.textChanged.connect(self.updateButtonStatus)
        self.setFocusProxy(self.editor)
        astergui.preferencesChanged.connect(self.editor.updateSettings)
        self.editor.updateSettings(self.astergui().preferencesMgr())
Exemple #6
0
    def __init__(self, astergui, parent=None):
        """
        Create `Show all` edition panel.

        Arguments:
            astergui (AsterGui): Parent AsterGui instance.
            parent (Optional[QWidget]): Parent widget. Defaults to
                *None*.
        """
        super(ShowAllPanel, self).__init__(parent=parent,
                                           name=translate("ShowAllPanel",
                                                          "Show all commands"),
                                           astergui=astergui)
        self.setWindowTitle(translate("ShowAllPanel", "Add command"))
        self.setPixmap(load_pixmap("as_pic_new_command.png"))
        v_layout = Q.QVBoxLayout(self)
        v_layout.setContentsMargins(0, 0, 0, 0)
        self.panel = Panel(self)
        description = Q.QGroupBox(self)
        description.setTitle(translate("ShowAllPanel", "Command description"))
        desc_layout = Q.QVBoxLayout(description)
        self.info = Q.QLabel(description)
        self.info.setWordWrap(True)
        self.info.setOpenExternalLinks(True)
        desc_layout.addWidget(self.info)
        for category in CATA.get_categories("showall"):
            # get commands from category
            items = CATA.get_category(category)
            if not items:
                continue
            # get translation for category's title
            view = CategoryView(translate_category(category),
                                parent=self.panel)
            view.category = category
            for item in items:
                # get translation for command
                title = translate_command(item)
                if title != item:
                    title = title + " ({})".format(item)
                view.addItem(title, item)
            self.panel.addWidget(view)
            connect(view.selected, self._selectionChanged)
            connect(view.doubleClicked, self._doubleClicked)
        v_layout.addWidget(self.panel)
        v_layout.addWidget(description)
        connect(self.astergui().selectionChanged, self.updateButtonStatus)
        self.panel.installEventFilter(self)
        self.setFocusProxy(self.panel)
Exemple #7
0
    def __init__(self, parent=None):
        """
        Create widget.

        Arguments:
            parent (Optional[QWidget]): Parent widget. Defaults to
                *None*.
        """
        super(SearchWidget, self).__init__(parent)
        h_layout = Q.QHBoxLayout(self)
        h_layout.setContentsMargins(0, 0, 0, 0)
        lab = Q.QLabel(self)
        lab.setPixmap(load_pixmap("as_pic_search.png", size=16))
        self._editor = LineEdit(self)
        self._editor.setObjectName("searcher")
        search_text = translate("SearchWidget",
                                "Search... (press Esc to clear search)")
        self._editor.setPlaceholderText(search_text)
        self._editor.setClearButtonEnabled(True)
        self._editor.textChanged.connect(self.filterChanged)
        self._editor.returnPressed.connect(self._returnPressed)
        h_layout.addWidget(lab)
        h_layout.addWidget(self._editor)
        self.setFocusProxy(self._editor)
Exemple #8
0
    def __init__(self, parent=None):
        """
        Create dialog.

        Arguments:
            parent (Optional[QWidget]): Parent widget. Defaults to
                *None*.
        """
        super(AboutDlg, self).__init__(parent)
        self.setModal(True)
        text = translate("AboutDlg", "About {}").format("AsterStudy")
        self.setWindowTitle(text)

        icon_lbl = Q.QLabel(self)
        title_lbl = Q.QLabel(self)
        version_lbl = Q.QLabel(self)
        description_lbl = Q.QLabel(self)
        license_lbl = Q.QLabel(self)
        credits_lbl = Q.QLabel(self)
        copyright_lbl = Q.QLabel(self)
        self.info_te = Q.QTextEdit(self)
        ok_btn = Q.QPushButton(self)

        main_wg = Q.QWidget(self)
        info_wg = Q.QWidget(self)

        hlayout = Q.QHBoxLayout()
        hlayout.addWidget(license_lbl)
        hlayout.addWidget(credits_lbl)

        glayout = Q.QGridLayout(main_wg)
        glayout.setContentsMargins(0, 0, 0, 0)
        glayout.addWidget(icon_lbl, 1, 1, 5, 1)
        glayout.addWidget(title_lbl, 1, 2)
        glayout.addWidget(version_lbl, 2, 2)
        glayout.addWidget(description_lbl, 4, 2)
        glayout.addLayout(hlayout, 6, 1, 1, 2)
        glayout.addWidget(copyright_lbl, 7, 0, 1, 4)
        glayout.setRowMinimumHeight(0, 10)
        glayout.setRowMinimumHeight(3, 10)
        glayout.setRowMinimumHeight(5, 20)
        glayout.setRowStretch(5, 10)
        glayout.setRowMinimumHeight(7, 40)
        glayout.setColumnMinimumWidth(0, 10)
        glayout.setColumnMinimumWidth(3, 10)

        hlayout = Q.QHBoxLayout()
        hlayout.addStretch()
        hlayout.addWidget(ok_btn)
        hlayout.addStretch()

        vlayout = Q.QVBoxLayout(info_wg)
        vlayout.addWidget(self.info_te)
        vlayout.addLayout(hlayout)

        slayout = Q.QStackedLayout()
        slayout.addWidget(main_wg)
        slayout.addWidget(info_wg)

        self.setLayout(slayout)

        pixmap = load_pixmap("asterstudy.png")
        icon_lbl.setPixmap(pixmap)
        icon_lbl.setFixedSize(pixmap.size() * 1.2)
        icon_lbl.setAlignment(Q.Qt.AlignCenter)
        title_lbl.setText(wrap_html("AsterStudy", "h1"))
        text = translate("AboutDlg", "Version: {}").format(version())
        version_lbl.setText(wrap_html(text, "h4"))
        text = translate("AboutDlg", "GUI framework for {code_aster}")
        text = text.format(
            code_aster=wrap_html("code_aster", "a", href="code_aster"))
        description_lbl.setText(wrap_html(text, "h3"))
        description_lbl.setTextInteractionFlags(Q.Qt.LinksAccessibleByMouse)
        description_lbl.linkActivated.connect(self._browseCodeAster)
        text = translate("AboutDlg", "License Information")
        license_lbl.setText(wrap_html(text, "a", href="license"))
        license_lbl.setAlignment(Q.Qt.AlignCenter)
        license_lbl.setTextInteractionFlags(Q.Qt.LinksAccessibleByMouse)
        license_lbl.linkActivated.connect(self._showLicense)
        text = translate("AboutDlg", "Credits")
        credits_lbl.setText(wrap_html(text, "a", href="credits"))
        credits_lbl.setAlignment(Q.Qt.AlignCenter)
        credits_lbl.setTextInteractionFlags(Q.Qt.LinksAccessibleByMouse)
        credits_lbl.linkActivated.connect(self._showCredits)
        text = "Copyright 2016 EDF R&D"
        copyright_lbl.setText(italic(text))
        copyright_lbl.setAlignment(Q.Qt.AlignCenter)
        self.info_te.setReadOnly(True)
        self.info_te.setMinimumWidth(450)
        ok_btn.setText(translate("AsterStudy", "&OK"))
        ok_btn.clicked.connect(self._showMain)

        palette = self.palette()
        palette.setColor(Q.QPalette.Window, Q.QColor("#f7f7f7"))
        self.setPalette(palette)
        palette.setColor(Q.QPalette.Window, Q.QColor("#ebebeb"))
        copyright_lbl.setPalette(palette)
        copyright_lbl.setAutoFillBackground(True)

        self.resize(self.minimumSizeHint())
Exemple #9
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()
Exemple #10
0
    def __init__(self, astergui, parent=None, **kwargs):
        """
        Create editor.

        Arguments:
            astergui (AsterGui): AsterGui instance.
            parent (Optional[QWidget]): Parent widget. Defaults to
                *None*.
            **kwargs: Keyword arguments.
        """
        super(DirsPanel, self).__init__(parent=parent,
                                        name=translate("AsterStudy",
                                                       "Set-up directories"),
                                        astergui=astergui,
                                        **kwargs)
        title = translate("AsterStudy", "Set-up directories")
        self.setWindowTitle(title)
        self.setPixmap(load_pixmap("as_pic_setup_dirs.png"))
        self.setObjectName("dirs_panel")

        completer = Q.QCompleter(Q.QDirModel(self), self)

        glayout = Q.QGridLayout(self)
        glayout.setContentsMargins(0, 0, 0, 0)

        label = Q.QLabel(translate("DirsPanel", "Input directory"), self)
        glayout.addWidget(label, 0, 0)

        self.in_dir = Q.QLineEdit(self)
        self.in_dir.setCompleter(completer)
        self.in_dir.setObjectName("dirs_panel_in_dir")
        glayout.addWidget(self.in_dir, 0, 1)

        button = Q.QPushButton(translate("AsterStudy", "Browse..."), self)
        button.mode = Directory.InDir
        button.setObjectName("dirs_panel_in_dir_browse")
        connect(button.clicked, self._browse)
        glayout.addWidget(button, 0, 2)

        label = Q.QLabel(translate("DirsPanel", "Output directory"), self)
        glayout.addWidget(label, 1, 0)

        self.out_dir = Q.QLineEdit(self)
        self.out_dir.setCompleter(completer)
        self.out_dir.setObjectName("dirs_panel_out_dir")
        glayout.addWidget(self.out_dir, 1, 1)

        button = Q.QPushButton(translate("AsterStudy", "Browse..."), self)
        button.mode = Directory.OutDir
        button.setObjectName("dirs_panel_out_dir_browse")
        connect(button.clicked, self._browse)
        glayout.addWidget(button, 1, 2)

        glayout.setRowStretch(2, 5)

        case = astergui.study().history.current_case
        self.in_dir.setText(case.in_dir)
        self.in_dir.home(False)
        self.out_dir.setText(case.out_dir)
        self.out_dir.home(False)
        self.setFocusProxy(self.in_dir)
Exemple #11
0
    def __init__(self, node, astergui, parent=None):  # pragma pylint: disable=too-many-locals
        """
        Create editor panel.

        Arguments:
            node (Stage, Unit): Object to manage.
            astergui (AsterGui): *AsterGui* instance.
            parent (Optional[QWidget]): Parent widget. Defaults to
                *None*.
        """
        #----------------------------------------------------------------------
        super(UnitPanel, self).__init__(parent=parent,
                                        name="",
                                        astergui=astergui)

        #----------------------------------------------------------------------
        self.node = node
        self.prev_unit = None
        self.unit = None

        #----------------------------------------------------------------------
        # set title
        title = translate("UnitPanel", "Edit data file") \
            if self.mode == UnitPanel.EditMode \
            else translate("UnitPanel", "Add data file")
        self._controllername = title
        self.setWindowTitle(title)
        # set icon
        pixmap = load_pixmap("as_pic_edit_file.png") \
            if self.mode == UnitPanel.EditMode \
            else load_pixmap("as_pic_new_file.png")
        self.setPixmap(pixmap)

        #----------------------------------------------------------------------
        # top-level layout
        v_layout = Q.QVBoxLayout(self)
        v_layout.setContentsMargins(0, 0, 0, 0)

        #----------------------------------------------------------------------
        # top level widget to easily manage read-only mode
        self.frame = Q.QWidget(self)
        v_layout.addWidget(self.frame)

        #----------------------------------------------------------------------
        # main layout
        glayout = Q.QGridLayout(self.frame)
        glayout.setContentsMargins(0, 0, 0, 0)

        #----------------------------------------------------------------------
        # 'Mode' controls
        label = Q.QLabel(translate("DataFiles", "Mode"), self.frame)
        glayout.addWidget(label, 0, 0)

        self.attr_combo = Q.QComboBox(self.frame)
        self.attr_combo.setObjectName("Mode")
        attr_list = [FileAttr.In, FileAttr.Out, FileAttr.InOut]
        for attr in attr_list:
            self.attr_combo.addItem(FileAttr.value2str(attr), attr)
        self.attr_combo.setCurrentIndex(-1)
        glayout.addWidget(self.attr_combo, 0, 1)

        #----------------------------------------------------------------------
        label = Q.QLabel(translate("DataFiles", "Filename"), self.frame)
        glayout.addWidget(label, 1, 0)

        self.file_combo = Q.QComboBox(self.frame)
        self.file_combo.setObjectName("Filename")
        glayout.addWidget(self.file_combo, 1, 1, 1, 2)

        self.file_btn = Q.QToolButton(self.frame)
        self.file_btn.setText("...")
        self.file_btn.setObjectName("Filename")
        glayout.addWidget(self.file_btn, 1, 3)

        #----------------------------------------------------------------------
        # 'Unit' controls
        label = Q.QLabel(translate("DataFiles", "Unit"), self.frame)
        glayout.addWidget(label, 2, 0)

        self.unit_edit = Q.QLineEdit(self.frame)
        self.unit_edit.setObjectName("Unit")
        self.unit_edit.setValidator(Q.QIntValidator(2, 99, self.unit_edit))
        glayout.addWidget(self.unit_edit, 2, 1)

        #----------------------------------------------------------------------
        # 'Exists' controls
        label = Q.QLabel(translate("DataFiles", "Exists"), self.frame)
        glayout.addWidget(label, 3, 0)

        self.exists_check = Q.QCheckBox(self.frame)
        self.exists_check.setObjectName("Exists")
        self.exists_check.setEnabled(False)
        glayout.addWidget(self.exists_check, 3, 1)

        #----------------------------------------------------------------------
        # 'Embedded' controls
        label = Q.QLabel(translate("DataFiles", "Embedded"), self.frame)
        glayout.addWidget(label, 4, 0)

        self.embedded_check = Q.QCheckBox(self.frame)
        self.embedded_check.setObjectName("Embedded")
        glayout.addWidget(self.embedded_check, 4, 1)

        #----------------------------------------------------------------------
        # tune layout
        glayout.setColumnStretch(1, 2)
        glayout.setColumnStretch(2, 2)
        glayout.setRowStretch(glayout.rowCount(), 10)

        #----------------------------------------------------------------------
        # initialize unit model
        file_model = UnitModel(self.stage)
        self.file_combo.setModel(file_model)
        self.file_combo.setCurrentIndex(-1)

        #----------------------------------------------------------------------
        # initialize controls from data model object
        if self.mode == UnitPanel.EditMode:
            self.setEditData(node)

        #----------------------------------------------------------------------
        # connections
        connect(self.file_combo.currentIndexChanged, self.updateControls)
        connect(self.file_combo.currentIndexChanged, self.updateButtonStatus)
        connect(self.file_btn.clicked, self.browseFile)
        connect(self.unit_edit.textChanged, self.updateButtonStatus)
        connect(self.attr_combo.currentIndexChanged, self.updateButtonStatus)
        connect(self.embedded_check.toggled, self.embeddedChanged)
        connect(file_model.rowsAboutToBeInserted, self.beforeUpdate)
        connect(file_model.rowsInserted, self.afterUpdate)
        connect(file_model.rowsAboutToBeRemoved, self.beforeUpdate)
        connect(file_model.rowsRemoved, self.afterUpdate)

        #----------------------------------------------------------------------
        # update status
        self.updateControls()