Beispiel #1
0
    def loadImage(self, relativeImagePath):
        """
        Replaces the underlying image (if any is loaded) to the image on given relative path

        Relative path is relative to the directory where the .imageset file resides
        (which is usually your project's imageset resource group path)
        """

        # If imageMonitor is null, then no images are being watched or the
        # editor is first being opened up
        # Otherwise, the image is being changed or switched, and the monitor
        # should update itself accordingly
        if self.imageMonitor != None:
            self.imageMonitor.removePath(self.getAbsoluteImageFile())

        self.imageFile = relativeImagePath
        self.setPixmap(QtGui.QPixmap(self.getAbsoluteImageFile()))
        self.transparencyBackground.setRect(self.boundingRect())

        # go over all image entries and set their position to force them to be constrained
        # to the new pixmap's dimensions
        for imageEntry in self.imageEntries:
            imageEntry.setPos(imageEntry.pos())
            imageEntry.updateDockWidget()

        self.visual.refreshSceneRect()

        # If imageMonitor is null, allocate and watch the loaded file
        if self.imageMonitor == None:
            self.imageMonitor = QtCore.QFileSystemWatcher(None)
            self.imageMonitor.fileChanged.connect(self.slot_imageChangedByExternalProgram)
        self.imageMonitor.addPath(self.getAbsoluteImageFile())
Beispiel #2
0
 def addFileMonitor(self, path):
     """Adds a file monitor to the specified file so CEED will alert the
     user that an external change happened to the file"""
     if self.fileMonitor is None:
         self.fileMonitor = QtCore.QFileSystemWatcher(self.mainWindow)
         self.fileMonitor.fileChanged.connect(self.slot_fileChangedByExternalProgram)
     self.fileMonitor.addPath(path)
 def __init__(self, launch_file, package=None, masteruri=None, argv=[]):
     '''
 Creates the LaunchConfig object. The launch file will be not loaded on 
 creation, first on request of Roscfg value.
 @param launch_file: The absolute or relative path with the launch file.
                    By using relative path a package must be valid for
                    remote launches.
 @type launch_file: C{str}
 @param package:  the package containing the launch file. If None the 
                 launch_file will be used to determine the launch file.
                 No remote launches a possible without a valid package.
 @type package: C{str} or C{None}
 @param masteruri: The URL of the ROS master.
 @type masteruri: C{str} or C{None}
 @param argv: the list the arguments needed for loading the given launch file
 @type argv: C{[str]}
 @raise roslaunch.XmlParseException: if the launch file can't be found.
 '''
     QtCore.QObject.__init__(self)
     self.__launchFile = launch_file
     self.__package = self.packageName(os.path.dirname(
         self.__launchFile))[0] if package is None else package
     self.__masteruri = masteruri if not masteruri is None else 'localhost'
     self.__roscfg = None
     self.argv = argv
     self.__reqTested = False
     self.global_param_done = [
     ]  # masteruri's where the global parameters are registered
     self.hostname = nm.nameres().getHostname(self.__masteruri)
     self.file_watcher = QtCore.QFileSystemWatcher()
     self.file_watcher.fileChanged.connect(self.on_file_changed)
     self.changed = {}
    def __init__(self, directory, regex, parent=None):
        super(NewFileWatcher, self).__init__(parent)

        print(u'Watching [{0}]'.format(directory))

        self._directory = Path(directory)
        self._regex = regex
        self._previous_files = self._matching_files()

        self._watch = QtCore.QFileSystemWatcher([unicode(directory)])
        self._watch.directoryChanged.connect(self.changed)
    def __init__(self, pParentDialog):
        super(NamespaceTableModel, self).__init__()

        self.mParentDialog = pParentDialog
        self.mRefFilePath = {}
        self.mRefFileReload = {}

        self.mSys = FBSystem()
        self.mWatcher = QtCore.QFileSystemWatcher()

        self.mOnlyRef = True
        self.mNamespaces = []
        self.mNamespacesFlag = []  # is loaded and file exist
        self.Init()
    def __init__(self, notemodel_dict):
        super(NoteListWidget, self).__init__()

        self.session_notemodel_dict = notemodel_dict

        self.itemDoubleClicked.connect(self._dblclick_pin_note)

        self.previous_item = None
        self.currentItemChanged.connect(self._update_previous_item)

        self._notes_dir = None
        self.dir_watcher = QtCore.QFileSystemWatcher(self)
        # self.dir_watcher.directoryChanged.connect(self.update_list)

        self.update_list()
Beispiel #7
0
    def open(self, filename):
        self.file_path = filename

        with open(filename) as f:
            self.file_contents = f.read()

        self.setPlainText(self.file_contents)

        self.parent_dir = os.path.abspath(
            os.path.join(self.file_path, os.pardir))

        # Watch the file we've opened
        self.fileSysWatcher = QtCore.QFileSystemWatcher()
        self.fileSysWatcher.addPath(self.parent_dir)
        QtCore.QObject.connect(self.fileSysWatcher,
                               QtCore.SIGNAL("directoryChanged(QString)"),
                               self, QtCore.SLOT("slotDirChanged(QString)"))
    def watch(self, widget, stylesheet_path):
        """
        Establishes a live link between a widget and a stylesheet.
        When modified, the stylesheet will be reapplied to the widget.
 
        Args:
            widget: (QtGui.QWidget) A widget to apply style to.
            stylesheet_path: (str) Absolute file path on disk to a .css stylesheet.
 
        Returns: (None)
        """
        self._widget_sheet_map[stylesheet_path].append(widget)

        self._watcher = QtCore.QFileSystemWatcher()
        self._watcher.addPath(stylesheet_path)

        self._watcher.fileChanged.connect(self.update)

        self.update()
Beispiel #9
0
    def initUI(self):
        """top menu bar and the text area"""
        # Menu bar
        menuBar = QtGui.QHBoxLayout()

        self.saveButton = QtGui.QPushButton("&Save", self)
        self.saveButton.clicked.connect(self.saveText)

        self.readButton = QtGui.QPushButton("&Reload", self)
        self.readButton.clicked.connect(self.loadText)

        menuBar.addWidget(self.saveButton)
        menuBar.addWidget(self.readButton)
        menuBar.addStretch(1)

        self.layout().addLayout(menuBar)

        # Text
        self.text = CustomTextEdit(self)
        self.text.setTabChangesFocus(True)

        # Font
        self.font = QtGui.QFont()
        self.font.setFamily("Inconsolata")
        self.font.setStyleHint(QtGui.QFont.Monospace)
        self.font.setFixedPitch(True)
        self.font.setPointSize(self.defaultFontSize)

        self.text.setFont(self.font)

        self.highlighter = ModifiedMarkdownHighlighter(self.text.document())

        # watch notebooks on the filesystem for changes
        self.fileSystemWatcher = QtCore.QFileSystemWatcher(self)

        self.layout().addWidget(self.text)
Beispiel #10
0
    def __init__(self, handlers=None):
        super(QtWatcher, self).__init__(handlers=handlers)

        self.__watcher = QtCore.QFileSystemWatcher()
        self.__watcher.fileChanged.connect(self.__on_event)
        self.__watcher.directoryChanged.connect(self.__on_event)
    def on_ex_simulate(self):
        """ Defines what happens on simulation button press.
            It shows the run window and starts a background process with dualsphysics running. Updates the window with useful info."""

        refocus_cwd()

        if Case.the().info.needs_to_run_gencase:
            # Warning window about save_case
            warning_dialog("You should run GenCase again. Otherwise, the obtained results may not be as expected")

        static_params_exe = [Case.the().get_out_xml_file_path(),
                             Case.the().get_out_folder_path(),
                             "-{device}".format(device=self.device_selector.currentText().lower()),
                             "-svres"]

        additional_parameters = list()
        if Case.the().info.run_additional_parameters:
            additional_parameters = Case.the().info.run_additional_parameters.split(" ")

        final_params_ex = static_params_exe + additional_parameters
        cmd_string = "{} {}".format(Case.the().executable_paths.dsphysics, " ".join(final_params_ex))

        run_dialog = RunDialog(case_name=Case.the().name, processor=self.device_selector.currentText(), number_of_particles=Case.the().info.particle_number, cmd_string=cmd_string, parent=get_fc_main_window())
        run_dialog.set_value(0)
        run_dialog.run_update(0, 0, None)
        Case.the().info.is_simulation_done = False

        run_fs_watcher = QtCore.QFileSystemWatcher()

        self.simulation_started.emit()

        # Cancel button handler
        def on_cancel():
            log(__("Stopping simulation"))
            if process:
                process.kill()
            run_dialog.hide_all()
            Case.the().info.is_simulation_done = True
            self.simulation_cancelled.emit()

        run_dialog.cancelled.connect(on_cancel)

        # Launch simulation and watch filesystem to monitor simulation
        filelist = [f for f in os.listdir(Case.the().path + "/" + Case.the().name + "_out/") if f.startswith("Part")]
        for f in filelist:
            os.remove(Case.the().path + "/" + Case.the().name + "_out/" + f)

        def on_dsph_sim_finished(exit_code):
            """ Simulation finish handler. Defines what happens when the process finishes."""

            # Reads output and completes the progress bar
            output = str(process.readAllStandardOutput().data(), encoding='utf-8')

            run_dialog.set_detail_text(str(output))
            run_dialog.run_complete()

            run_fs_watcher.removePath(Case.the().path + "/" + Case.the().name + "_out/")

            if exit_code == 0:
                # Simulation went correctly
                Case.the().info.is_simulation_done = True
                Case.the().info.needs_to_run_gencase = False
                self.simulation_complete.emit(True)
            else:
                # In case of an error
                Case.the().info.needs_to_run_gencase = True
                if "exception" in str(output).lower():
                    log("There was an error on the execution. Opening an error dialog for that.")
                    run_dialog.hide()
                    self.simulation_complete.emit(False)
                    error_dialog(__("An error occurred during execution. Make sure that parameters exist and are properly defined. "
                                    "You can also check your execution device (update the driver of your GPU). Read the details for more information."), str(output))
            save_case(Case.the().path, Case.the())

        # Launches a QProcess in background
        process = QtCore.QProcess(get_fc_main_window())
        process.finished.connect(on_dsph_sim_finished)

        process.start(Case.the().executable_paths.dsphysics, final_params_ex)

        def on_fs_change():
            """ Executed each time the filesystem changes. This updates the percentage of the simulation and its details."""
            run_file_data = ""
            with open(Case.the().path + "/" + Case.the().name + "_out/Run.out", "r") as run_file:
                run_file_data = run_file.readlines()

            # Fill details window
            run_dialog.set_detail_text("".join(run_file_data))

            # Set percentage scale based on timemax
            for l in run_file_data:
                if Case.the().execution_parameters.timemax == -1:
                    if "TimeMax=" in l:
                        Case.the().execution_parameters.timemax = float(l.split("=")[1])

            current_value: float = 0.0
            totalpartsout: int = 0
            last_estimated_time = None

            # Update execution metrics
            last_part_lines = list(filter(lambda x: "Part_" in x and "stored" not in x and "      " in x, run_file_data))
            if last_part_lines:
                current_value = (float(last_part_lines[-1].split(None)[1]) * float(100)) / float(Case.the().execution_parameters.timemax)
            else:
                current_value = None

            # Update particles out
            last_particles_out_lines = list(filter(lambda x: "(total: " in x and "Particles out:" in x, run_file_data))
            if last_particles_out_lines:
                totalpartsout = int(last_particles_out_lines[-1].split("(total: ")[1].split(")")[0])

            try:
                last_estimated_time = str(" ".join(last_part_lines[-1].split(None)[-2:]))
            except IndexError:
                last_estimated_time = None

            # Update run dialog
            run_dialog.run_update(current_value, totalpartsout, last_estimated_time)

        # Set filesystem watcher to the out directory.
        run_fs_watcher.addPath(Case.the().path + "/" + Case.the().name + "_out/")
        run_fs_watcher.directoryChanged.connect(on_fs_change)

        # Handle error on simulation start
        if process.state() == QtCore.QProcess.NotRunning:
            # Probably error happened.
            run_fs_watcher.removePath(Case.the().path + "/" + Case.the().name + "_out/")
            process = None
            error_dialog("Error on simulation start. Check that the DualSPHysics executable is correctly set.")
        else:
            run_dialog.show()
Beispiel #12
0
    def __init__(self,
                 case_name: str,
                 processor: str,
                 number_of_particles: int,
                 cmd_string="",
                 parent=None):
        super().__init__(parent=parent)

        self.run_watcher = QtCore.QFileSystemWatcher()
        self.cmd_string = cmd_string
        # Title and size
        self.setModal(False)
        self.setWindowTitle(__("DualSPHysics Simulation: {}%").format("0"))
        self.run_dialog_layout = QtGui.QVBoxLayout()

        # Information GroupBox
        self.run_group = QtGui.QGroupBox(__("Simulation Data"))
        self.run_group_layout = QtGui.QVBoxLayout()

        self.run_group_label_case = QtGui.QLabel(
            __("Case name: {}").format(case_name))
        self.run_group_label_proc = QtGui.QLabel(
            __("Simulation processor: {}").format(processor))
        self.run_group_label_part = QtGui.QLabel(
            __("Number of particles: {}").format(number_of_particles))
        self.run_group_label_partsout = QtGui.QLabel(
            self.PARTICLES_OUT_TEMPLATE.format(0))
        self.run_group_label_eta = QtGui.QLabel(self)
        self.run_group_label_eta.setText(
            self.ETA_TEMPLATE.format("Calculating..."))
        self.run_group_label_completed = QtGui.QLabel("<b>{}</b>".format(
            __("Simulation is complete.")))
        self.run_group_label_completed.setVisible(False)

        self.run_group_layout.addWidget(self.run_group_label_case)
        self.run_group_layout.addWidget(self.run_group_label_proc)
        self.run_group_layout.addWidget(self.run_group_label_part)
        self.run_group_layout.addWidget(self.run_group_label_partsout)
        self.run_group_layout.addWidget(self.run_group_label_eta)
        self.run_group_layout.addWidget(self.run_group_label_completed)
        self.run_group_layout.addStretch(1)

        self.run_group.setLayout(self.run_group_layout)

        # Progress Bar
        self.run_progbar_layout = QtGui.QHBoxLayout()
        self.run_progbar_bar = QtGui.QProgressBar()
        self.run_progbar_bar.setRange(0, 100)
        self.run_progbar_bar.setTextVisible(False)
        self.run_progbar_layout.addWidget(self.run_progbar_bar)

        # Buttons
        self.run_button_layout = QtGui.QHBoxLayout()
        self.run_button_warnings = QtGui.QPushButton(__("Show Warnings"))
        self.run_button_warnings.hide()
        self.run_button_details = QtGui.QPushButton(__("Details"))
        self.run_button_cancel = QtGui.QPushButton(__("Cancel Simulation"))
        self.run_button_layout.addWidget(self.run_button_warnings)
        self.run_button_layout.addStretch(1)
        self.run_button_layout.addWidget(self.run_button_details)
        self.run_button_layout.addWidget(self.run_button_cancel)

        # Defines run details
        self.run_details = QtGui.QWidget()
        self.run_details.setWindowTitle(__("Simulation details"))
        self.run_details_layout = QtGui.QVBoxLayout()
        self.run_details_layout.setContentsMargins(0, 0, 0, 0)

        self.run_details_text = QtGui.QTextEdit()
        self.run_details_text.setReadOnly(True)
        self.run_details_layout.addWidget(h_line_generator())
        self.run_details_layout.addWidget(self.run_details_text)
        self.run_details.hide()

        self.run_button_cancel.clicked.connect(self.cancelled.emit)
        self.run_button_details.clicked.connect(self.toggle_run_details)

        self.run_details.setLayout(self.run_details_layout)

        self.run_dialog_layout.addWidget(self.run_group)
        self.run_dialog_layout.addLayout(self.run_progbar_layout)
        self.run_dialog_layout.addLayout(self.run_button_layout)
        self.run_dialog_layout.addWidget(self.run_details)

        self.setLayout(self.run_dialog_layout)
        self.setMinimumWidth(self.MIN_WIDTH)
        self.adjustSize()
Beispiel #13
0
 def __init__(self, path, parent=None):
     QtCore.QObject.__init__(self, parent)
     self.m_fPath = path
     self.m_fsWatcher = QtCore.QFileSystemWatcher()
     self.m_fsWatcher.addPath(path)
     self.m_fsWatcher.fileChanged.connect(self.onFileChange)
Beispiel #14
0
main_groupbox.setLayout(gp_layout)
main_layout.addWidget(main_groupbox)
w.setLayout(main_layout)
w.show()
# endregion Main window definition

# region Sebastian fullscreen window
sebastian_window = QtGui.QDialog()
main_layout = QtGui.QHBoxLayout()
main_layout.setContentsMargins(0, 0, 0, 0)
_web_view = QtWebKit.QWebView()
_web_view.load(QtCore.QUrl(""))
_web_view.page().mainFrame().setScrollBarPolicy(
    QtCore.Qt.Orientation.Vertical,
    QtCore.Qt.ScrollBarPolicy.ScrollBarAlwaysOff)
filewatcher = QtCore.QFileSystemWatcher()
filewatcher.fileChanged.connect(on_file_change)
main_layout.addWidget(_web_view)
sebastian_window.setWindowState(QtCore.Qt.WindowFullScreen)
sebastian_window.setLayout(main_layout)
# endregion Sebastian fullscreen window

# region About window
about_window = QtGui.QDialog()
about_window.setFixedSize(420, 180)
about_window.setWindowFlags(QtCore.Qt.Dialog)
about_window.setWindowTitle('About Sebastian')
about_window_layout = QtGui.QVBoxLayout()
name_label = QtGui.QLabel("Software Name: Sebastian")
version_label = QtGui.QLabel("Software Version: " + __version__)
credits_label = QtGui.QLabel("Software Credits: " + ", ".join(__credits__))