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())
def animate_stacked_widget( self, stackedwidget, from_, to, direction="vertical", line=None, to_btn=None, btn_layout=None ): """ animate changing of qstackedwidget """ # check to see if already animating if self.animating and self.stack_animation is not None: self.stack_animation.stop() from_widget = stackedwidget.widget(from_) to_widget = stackedwidget.widget(to) # get from geometry width = from_widget.frameGeometry().width() height = from_widget.frameGeometry().height() # offset # bottom to top if direction == "vertical" and from_ < to: offsetx = 0 offsety = height # top to bottom elif direction == "vertical" and from_ > to: offsetx = 0 offsety = -height elif direction == "horizontal" and from_ < to: offsetx = width offsety = 0 elif direction == "horizontal" and from_ > to: offsetx = -width offsety = 0 else: return # move to widget and show # set the geometry of the next widget to_widget.setGeometry(0 + offsetx, 0 + offsety, width, height) to_widget.show() to_widget.raise_() # animate # from widget animnow = QtCore.QPropertyAnimation(from_widget, "pos") animnow.setDuration(self.animation_speed) animnow.setEasingCurve(QtCore.QEasingCurve.InOutQuint) animnow.setStartValue(QtCore.QPoint(0, 0)) animnow.setEndValue(QtCore.QPoint(0 - offsetx, 0 - offsety)) # to widget animnext = QtCore.QPropertyAnimation(to_widget, "pos") animnext.setDuration(self.animation_speed) animnext.setEasingCurve(QtCore.QEasingCurve.InOutQuint) animnext.setStartValue(QtCore.QPoint(0 + offsetx, 0 + offsety)) animnext.setEndValue(QtCore.QPoint(0, 0)) # line animline = None if line is not None and to_btn is not None: animline = QtCore.QPropertyAnimation(line, "pos") animline.setDuration(self.animation_speed) animline.setEasingCurve(QtCore.QEasingCurve.InOutQuint) animline.setStartValue(QtCore.QPoint(line.geometry().x(), line.geometry().y())) animline.setEndValue(QtCore.QPoint(to_btn.geometry().x(), line.geometry().y())) # animation group self.stack_animation = QtCore.QParallelAnimationGroup() self.stack_animation.addAnimation(animnow) self.stack_animation.addAnimation(animnext) if animline is not None: self.stack_animation.addAnimation(animline) self.stack_animation.finished.connect( make_callback(self.animate_stacked_widget_finished, stackedwidget, from_, to, btn_layout, line) ) self.stack_animation.stateChanged.connect( make_callback(self.animate_stacked_widget_finished, stackedwidget, from_, to, btn_layout, line) ) self.animating = True self.stack_animation.start()