Пример #1
0
Файл: gui.py Проект: mwm126/mfix
    def __setup_simple_keyword_widgets(self):
        """
        Look for and connect simple keyword widgets to the project manager.
        Keyword informtation from the namelist doc strings is added to each
        keyword widget. The widget must be named: *_keyword_<keyword> where
        <keyword> is the actual keyword. For example:
        lineedit_keyword_run_name
        """

        # loop through all widgets looking for *_keyword_<keyword>
        for widget in widget_iter(self.ui):
            name_list = str(widget.objectName()).lower().split("_")

            if "keyword" in name_list:
                keyword = "_".join(name_list[name_list.index("keyword") + 1 :])

                # set the key attribute to the keyword
                widget.key = keyword

                # add info from keyword documentation
                if keyword in self.keyword_doc:
                    widget.setdtype(self.keyword_doc[keyword]["dtype"])

                    if "required" in self.keyword_doc[keyword]:
                        widget.setValInfo(req=self.keyword_doc[keyword]["required"] == "true")
                    if "validrange" in self.keyword_doc[keyword]:
                        if "max" in self.keyword_doc[keyword]["validrange"]:
                            widget.setValInfo(_max=self.keyword_doc[keyword]["validrange"]["max"])
                        if "min" in self.keyword_doc[keyword]["validrange"]:
                            widget.setValInfo(_min=self.keyword_doc[keyword]["validrange"]["min"])

                    if "initpython" in self.keyword_doc[keyword]:
                        widget.default(self.keyword_doc[keyword]["initpython"])

                    if isinstance(widget, QtGui.QComboBox) and widget.count() < 1:
                        widget.addItems(list(self.keyword_doc[keyword]["valids"].keys()))

                # register the widget with the project manager
                self.project.register_widget(widget, [keyword])

                # connect to unsaved method
                widget.value_updated.connect(self.unsaved)
Пример #2
0
Файл: gui.py Проект: mwm126/mfix
    def __init__(self, app, parent=None):
        QtGui.QMainWindow.__init__(self, parent)

        # reference to qapp instance
        self.app = app

        # load ui file
        self.customWidgets = {
            "LineEdit": LineEdit,
            "CheckBox": CheckBox,
            "ComboBox": ComboBox,
            "DoubleSpinBox": DoubleSpinBox,
            "SpinBox": SpinBox,
        }
        self.ui = uic.loadUi(os.path.join("uifiles", "gui.ui"), self)

        # load settings
        self.settings = QSettings("MFIX", "MFIX")

        # set title and icon
        self.setWindowTitle("MFIX")
        self.setWindowIcon(get_icon("mfix.png"))

        # build keyword documentation from namelist docstrings
        self.keyword_doc = buildKeywordDoc(os.path.join(SCRIPT_DIRECTORY, os.pardir, "model"))

        self.project = ProjectManager(self, self.keyword_doc)

        # --- data ---
        self.modebuttondict = {
            "modeler": self.ui.pushButtonModeler,
            "workflow": self.ui.pushButtonWorkflow,
            "developer": self.ui.pushButtonDeveloper,
        }

        self.booleanbtndict = {
            "union": self.ui.toolbutton_geometry_union,
            "intersection": self.ui.toolbutton_geometry_intersect,
            "difference": self.ui.toolbutton_geometry_difference,
        }
        self.animation_speed = 400
        self.animating = False
        self.stack_animation = None

        # --- icons ---
        # loop through all widgets, because I am lazy
        for widget in widget_iter(self.ui):
            if isinstance(widget, QtGui.QToolButton):
                name = str(widget.objectName())
                if "add" in name:
                    widget.setIcon(get_icon("add.png"))
                elif "delete" in name or "remove" in name:
                    widget.setIcon(get_icon("remove.png"))
                elif "copy" in name:
                    widget.setIcon(get_icon("copy.png"))

        self.ui.toolbutton_new.setIcon(get_icon("newfolder.png"))
        self.ui.toolbutton_open.setIcon(get_icon("openfolder.png"))
        self.ui.toolbutton_save.setIcon(get_icon("save.png"))

        self.ui.toolbutton_compile.setIcon(get_icon("build.png"))
        self.ui.toolbutton_run.setIcon(get_icon("play.png"))
        self.ui.toolbutton_restart.setIcon(get_icon("restart.png"))
        self.ui.toolbutton_interact.setIcon(get_icon("flash.png"))

        self.ui.toolbutton_add_geometry.setIcon(get_icon("geometry.png"))
        self.ui.toolbutton_add_filter.setIcon(get_icon("filter.png"))
        self.ui.toolbutton_geometry_union.setIcon(get_icon("union.png"))
        self.ui.toolbutton_geometry_intersect.setIcon(get_icon("intersect.png"))
        self.ui.toolbutton_geometry_difference.setIcon(get_icon("difference.png"))

        self.ui.toolButtonTFMSolidsDatabase.setIcon(get_icon("download.png"))

        # --- Connect Signals to Slots---
        # open/save/new project
        self.ui.toolbutton_open.pressed.connect(self.open_project)
        self.ui.toolbutton_save.pressed.connect(self.save_project)

        # mode (modeler, workflow, developer)
        for mode, btn in self.modebuttondict.items():
            btn.released.connect(make_callback(self.mode_changed, mode))

        # navigation tree
        self.ui.treewidget_model_navigation.itemSelectionChanged.connect(self.navigation_changed)

        # build/run/connect MFIX
        self.ui.build_mfix_button.pressed.connect(self.build_mfix)
        self.ui.run_mfix_button.pressed.connect(self.run_mfix)
        self.ui.connect_mfix_button.pressed.connect(self.connect_mfix)
        self.ui.clear_output_button.pressed.connect(self.clear_output)

        # --- Threads ---
        self.build_thread = BuildThread(self)
        self.run_thread = RunThread(self)
        self.clear_thread = ClearThread(self)

        def make_handler(qtextbrowser):
            " make a closure to read stdout from external process "

            def handle_line(line):
                " closure to read stdout from external process "

                log = logging.getLogger(__name__)
                log.debug(str(line).strip())
                cursor = qtextbrowser.textCursor()
                cursor.movePosition(cursor.End)
                cursor.insertText(line)
                qtextbrowser.ensureCursorVisible()

            return handle_line

        self.build_thread.line_printed.connect(make_handler(self.ui.command_output))
        self.run_thread.line_printed.connect(make_handler(self.ui.command_output))
        self.clear_thread.line_printed.connect(make_handler(self.ui.command_output))

        # --- setup simple widgets ---
        self.__setup_simple_keyword_widgets()

        # --- vtk setup ---
        self.__setup_vtk_widget()

        # --- workflow setup ---
        if NodeWidget is not None:
            self.__setup_workflow_widget()

        # --- default ---
        self.mode_changed("modeler")
        self.change_pane("geometry")

        # autoload last project
        if self.get_project_dir():
            self.open_project(self.get_project_dir())