Esempio n. 1
0
 def ending_long_process(self, message=""):
     """
     Clear main window's status bar and restore mouse cursor.
     """
     QApplication.restoreOverrideCursor()
     self.show_message(message, timeout=2000)
     QApplication.processEvents()
Esempio n. 2
0
 def resize_to_contents(self):
     """Resize cells to contents"""
     QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
     self.resizeColumnsToContents()
     self.model().fetch_more(columns=True)
     self.resizeColumnsToContents()
     QApplication.restoreOverrideCursor()
Esempio n. 3
0
    def save_data(self, filename=None):
        """Save data"""
        if filename is None:
            filename = self.filename
            if filename is None:
                filename = getcwd_or_home()
            filename, _selfilter = getsavefilename(self, _("Save data"),
                                                   filename,
                                                   iofunctions.save_filters)
            if filename:
                self.filename = filename
            else:
                return False
        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        QApplication.processEvents()

        error_message = self.shellwidget.save_namespace(self.filename)
        self.shellwidget._kernel_reply = None

        QApplication.restoreOverrideCursor()
        QApplication.processEvents()
        if error_message is not None:
            QMessageBox.critical(self, _("Save data"),
                            _("<b>Unable to save current workspace</b>"
                              "<br><br>Error message:<br>%s") % error_message)
        self.save_button.setEnabled(self.filename is not None)
Esempio n. 4
0
    def save_data(self, filename=None):
        """Save data"""
        if filename is None:
            filename = self.filename
            if filename is None:
                filename = getcwd_or_home()
            filename, _selfilter = getsavefilename(self, _("Save data"),
                                                   filename,
                                                   iofunctions.save_filters)
            if filename:
                self.filename = filename
            else:
                return False
        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        QApplication.processEvents()

        error_message = self.shellwidget.save_namespace(self.filename)
        self.shellwidget._kernel_reply = None

        QApplication.restoreOverrideCursor()
        QApplication.processEvents()
        if error_message is not None:
            if 'Some objects could not be saved:' in error_message:
                save_data_message = (
                    _('<b>Some objects could not be saved:</b>')
                    + '<br><br><code>{obj_list}</code>'.format(
                        obj_list=error_message.split(': ')[1]))
            else:
                save_data_message = _(
                    '<b>Unable to save current workspace</b>'
                    '<br><br>Error message:<br>') + error_message
            QMessageBox.critical(self, _("Save data"), save_data_message)
        self.save_button.setEnabled(self.filename is not None)
Esempio n. 5
0
 def save_data(self, filename=None):
     """Save data"""
     if filename is None:
         filename = self.filename
         if filename is None:
             filename = getcwd()
         filename, _selfilter = getsavefilename(self, _("Save data"),
                                                filename,
                                                iofunctions.save_filters)
         if filename:
             self.filename = filename
         else:
             return False
     QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
     QApplication.processEvents()
     if self.is_internal_shell:
         wsfilter = self.get_internal_shell_filter('picklable',
                                                   check_all=True)
         namespace = wsfilter(self.shellwidget.interpreter.namespace).copy()
         error_message = iofunctions.save(namespace, filename)
     else:
         settings = self.get_view_settings()
         error_message = monitor_save_globals(self._get_sock(),
                                              settings, filename)
     QApplication.restoreOverrideCursor()
     QApplication.processEvents()
     if error_message is not None:
         QMessageBox.critical(self, _("Save data"),
                         _("<b>Unable to save current workspace</b>"
                           "<br><br>Error message:<br>%s") % error_message)
     self.save_button.setEnabled(self.filename is not None)
Esempio n. 6
0
File: base.py Progetto: slaclab/pydm
    def eventFilter(self, obj, event):
        """
        Filters events on this object.

        Params
        ------
        object : QObject
            The object that is being handled.
        event : QEvent
            The event that is happening.

        Returns
        -------
        bool
            True to stop the event from being handled further; otherwise
            return false.
        """
        channel = getattr(self, 'channel', None)
        if is_channel_valid(channel):
            status = self._write_access and self._connected

            if event.type() == QEvent.Leave:
                QApplication.restoreOverrideCursor()

            if event.type() == QEvent.Enter and not status:
                QApplication.setOverrideCursor(QCursor(Qt.ForbiddenCursor))

        return PyDMWidget.eventFilter(self, obj, event)
Esempio n. 7
0
    def load(self):

        QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)

        o_table = TableRowHandler(main_window=self.parent)

        if self.parent.clear_master_table_before_loading:
            TableHandler.clear_table(self.table_ui)

        for _row, _key in enumerate(self.json.keys()):

            _entry = self.json[_key]

            run_number = _key
            title = _entry['title']
            chemical_formula = _entry['resolved_conflict']['chemical_formula']
            # geometry = _entry['resolved_conflict']['geometry']
            mass_density = _entry['resolved_conflict']['mass_density']
            # sample_env_device = _entry['resolved_conflict']['sample_env_device']

            o_table.insert_row(row=_row,
                               title=title,
                               sample_runs=run_number,
                               sample_mass_density=mass_density,
                               sample_chemical_formula=chemical_formula)

        QApplication.restoreOverrideCursor()
Esempio n. 8
0
 def wrapper(*args, **kwargs):
     QApplication.setOverrideCursor(
         QCursor(Qt.WaitCursor))
     try:
         ret_val = func(*args, **kwargs)
     finally:
         QApplication.restoreOverrideCursor()
     return ret_val
Esempio n. 9
0
 def override_cursor(self, cursor):
     """
     Set new override cursor.
     :param cursor: New cursor.
     """
     self._override_cursor = cursor
     QApplication.restoreOverrideCursor()
     if cursor is not None:
         QApplication.setOverrideCursor(cursor)
    def from_oncat_config(self, insert_in_table=True):
        """using only the fields we are looking for (defined in the config.json file,
        this method retrieves the metadata of either the IPTS or the runs selected,
        and populate or not the Master table (if insert_in_table is True)"""

        QApplication.setOverrideCursor(QtCore.Qt.WaitCursor)

        self.parent.list_of_runs_not_found = []
        nexus_json = self.parent.nexus_json_from_template

        if self.parent.ui.run_radio_button.isChecked():

            # remove white space to string to make ONCat happy
            str_runs = str(self.parent.ui.run_number_lineedit.text())
            str_runs = remove_white_spaces(str_runs)
            #
            # nexus_json = pyoncatGetNexus(oncat=self.parent.parent.oncat,
            #                              instrument=self.parent.parent.instrument['short_name'],
            #                              runs=str_runs,
            #                              facility=self.parent.parent.facility,
            #                              )

            result = database_utilities.get_list_of_runs_found_and_not_found(str_runs=str_runs,
                                                                             oncat_result=nexus_json)
            list_of_runs_not_found = result['not_found']
            self.parent.list_of_runs_not_found = list_of_runs_not_found
            self.parent.list_of_runs_found = result['found']

        else:
            # ipts = str(self.parent.ui.ipts_combobox.currentText())
            #
            # nexus_json = pyoncatGetRunsFromIpts(oncat=self.parent.parent.oncat,
            #                                     instrument=self.parent.parent.instrument['short_name'],
            #                                     ipts=ipts,
            #                                     facility=self.parent.parent.facility)

            result = database_utilities.get_list_of_runs_found_and_not_found(oncat_result=nexus_json,
                                                                             check_not_found=False)

            self.parent.list_of_runs_not_found = result['not_found']
            self.parent.list_of_runs_found = result['found']

        if insert_in_table:
            self.parent.insert_in_master_table(nexus_json=nexus_json)
        else:
            self.isolate_metadata(nexus_json)
            self.parent.nexus_json = nexus_json

        QApplication.restoreOverrideCursor()

        if insert_in_table:
            self.parent.close()
Esempio n. 11
0
 def mouseMoveEvent(self, event):
     """Show Pointing Hand Cursor on error messages"""
     text = self.get_line_at(event.pos())
     if get_error_match(text):
         if not self.__cursor_changed:
             QApplication.setOverrideCursor(QCursor(Qt.PointingHandCursor))
             self.__cursor_changed = True
         event.accept()
         return
     if self.__cursor_changed:
         QApplication.restoreOverrideCursor()
         self.__cursor_changed = False
     self.QT_CLASS.mouseMoveEvent(self, event)
Esempio n. 12
0
 def leaveEvent(self, event):
     """
     Removes scope decorations and background from the editor and the panel
     if highlight_caret_scope, else simply update the scope decorations to
     match the caret scope.
     """
     super(FoldingPanel, self).leaveEvent(event)
     QApplication.restoreOverrideCursor()
     self._highlight_runner.cancel_requests()
     if not self.highlight_caret_scope:
         self._clear_scope_decos()
         self._mouse_over_line = None
         self._current_scope = None
     else:
         self._block_nbr = -1
         self._highlight_caret_scope()
     self.editor.repaint()
Esempio n. 13
0
    def eventFilter(self, widget, event):
        """A filter to control the zooming and panning of the figure canvas."""

        # ---- Zooming
        if event.type() == QEvent.Wheel:
            modifiers = QApplication.keyboardModifiers()
            if modifiers == Qt.ControlModifier:
                if event.angleDelta().y() > 0:
                    self.zoom_in()
                else:
                    self.zoom_out()
                return True
            else:
                return False

        # ---- Panning
        # Set ClosedHandCursor:
        elif event.type() == QEvent.MouseButtonPress:
            if event.button() == Qt.LeftButton:
                QApplication.setOverrideCursor(Qt.ClosedHandCursor)
                self._ispanning = True
                self.xclick = event.globalX()
                self.yclick = event.globalY()

        # Reset Cursor:
        elif event.type() == QEvent.MouseButtonRelease:
            QApplication.restoreOverrideCursor()
            self._ispanning = False

        # Move  ScrollBar:
        elif event.type() == QEvent.MouseMove:
            if self._ispanning:
                dx = self.xclick - event.globalX()
                self.xclick = event.globalX()

                dy = self.yclick - event.globalY()
                self.yclick = event.globalY()

                scrollBarH = self.horizontalScrollBar()
                scrollBarH.setValue(scrollBarH.value() + dx)

                scrollBarV = self.verticalScrollBar()
                scrollBarV.setValue(scrollBarV.value() + dy)

        return QWidget.eventFilter(self, widget, event)
Esempio n. 14
0
    def mouseMoveEvent(self, event):
        """
        Detect mouser over indicator and highlight the current scope in the
        editor (up and down decoration arround the foldable text when the mouse
        is over an indicator).

        :param event: event
        """
        super(FoldingPanel, self).mouseMoveEvent(event)
        th = TextHelper(self.editor)
        line = th.line_nbr_from_position(event.pos().y())
        if line >= 0:
            block = FoldScope.find_parent_scope(
                self.editor.document().findBlockByNumber(line-1))
            if TextBlockHelper.is_fold_trigger(block):
                if self._mouse_over_line is None:
                    # mouse enter fold scope
                    QApplication.setOverrideCursor(
                        QCursor(Qt.PointingHandCursor))
                if self._mouse_over_line != block.blockNumber() and \
                        self._mouse_over_line is not None:
                    # fold scope changed, a previous block was highlighter so
                    # we quickly update our highlighting
                    self._mouse_over_line = block.blockNumber()
                    self._highlight_block(block)
                else:
                    # same fold scope, request highlight
                    self._mouse_over_line = block.blockNumber()
                    self._highlight_runner.request_job(
                        self._highlight_block, block)
                self._highight_block = block
            else:
                # no fold scope to highlight, cancel any pending requests
                self._highlight_runner.cancel_requests()
                self._mouse_over_line = None
                QApplication.restoreOverrideCursor()
            self.repaint()
Esempio n. 15
0
 def mouse_move_stop(self):
     """
     Stop moving.
     """
     self.marker.mouse_move_stop()
     QApplication.restoreOverrideCursor()
Esempio n. 16
0
    def import_data(self, filenames=None):
        """Import data from text file"""
        title = _("Import data")
        if filenames is None:
            if self.filename is None:
                basedir = getcwd()
            else:
                basedir = osp.dirname(self.filename)
            filenames, _selfilter = getopenfilenames(self, title, basedir,
                                                     iofunctions.load_filters)
            if not filenames:
                return
        elif is_text_string(filenames):
            filenames = [filenames]

        for filename in filenames:
            self.filename = to_text_string(filename)
            ext = osp.splitext(self.filename)[1].lower()

            if ext not in iofunctions.load_funcs:
                buttons = QMessageBox.Yes | QMessageBox.Cancel
                answer = QMessageBox.question(self, title,
                            _("<b>Unsupported file extension '%s'</b><br><br>"
                              "Would you like to import it anyway "
                              "(by selecting a known file format)?"
                              ) % ext, buttons)
                if answer == QMessageBox.Cancel:
                    return
                formats = list(iofunctions.load_extensions.keys())
                item, ok = QInputDialog.getItem(self, title,
                                                _('Open file as:'),
                                                formats, 0, False)
                if ok:
                    ext = iofunctions.load_extensions[to_text_string(item)]
                else:
                    return

            load_func = iofunctions.load_funcs[ext]
                
            # 'import_wizard' (self.setup_io)
            if is_text_string(load_func):
                # Import data with import wizard
                error_message = None
                try:
                    text, _encoding = encoding.read(self.filename)
                    if self.is_internal_shell:
                        self.editor.import_from_string(text)
                    else:
                        base_name = osp.basename(self.filename)
                        editor = ImportWizard(self, text, title=base_name,
                                      varname=fix_reference_name(base_name))
                        if editor.exec_():
                            var_name, clip_data = editor.get_data()
                            monitor_set_global(self._get_sock(),
                                               var_name, clip_data)
                except Exception as error:
                    error_message = str(error)
            else:
                QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
                QApplication.processEvents()
                if self.is_internal_shell:
                    namespace, error_message = load_func(self.filename)
                    interpreter = self.shellwidget.interpreter
                    for key in list(namespace.keys()):
                        new_key = fix_reference_name(key,
                                     blacklist=list(interpreter.namespace.keys()))
                        if new_key != key:
                            namespace[new_key] = namespace.pop(key)
                    if error_message is None:
                        interpreter.namespace.update(namespace)
                else:
                    error_message = monitor_load_globals(self._get_sock(),
                                                         self.filename, ext)
                QApplication.restoreOverrideCursor()
                QApplication.processEvents()
    
            if error_message is not None:
                QMessageBox.critical(self, title,
                                     _("<b>Unable to load '%s'</b>"
                                       "<br><br>Error message:<br>%s"
                                       ) % (self.filename, error_message))
            self.refresh_table()
Esempio n. 17
0
 def ending_long_process(self, message=""):
     """Clear main window's status bar and restore mouse cursor."""
     QApplication.restoreOverrideCursor()
     self.show_message(message, timeout=2000)
     QApplication.processEvents()
Esempio n. 18
0
 def leaveEvent(self, event):
     """If cursor has not been restored yet, do it now"""
     if self.__cursor_changed:
         QApplication.restoreOverrideCursor()
         self.__cursor_changed = False
     self.QT_CLASS.leaveEvent(self, event)
Esempio n. 19
0
 def tab_released(self, event):
     """Method called when a tab from a QTabBar has been released."""
     QApplication.restoreOverrideCursor()
     self.moving = False
Esempio n. 20
0
 def resize_to_contents(self):
     QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
     self.dataTable.resizeColumnsToContents()
     self.dataModel.fetch_more(columns=True)
     self.dataTable.resizeColumnsToContents()
     QApplication.restoreOverrideCursor()
Esempio n. 21
0
 def restoreCursor():
     QApplication.restoreOverrideCursor()
Esempio n. 22
0
 def _hide(self):
     """Hide method helper."""
     QApplication.restoreOverrideCursor()
     self._timer_hide.start()
Esempio n. 23
0
    def import_data(self, filenames=None):
        """Import data from text file"""
        title = _("Import data")
        if filenames is None:
            if self.filename is None:
                basedir = getcwd()
            else:
                basedir = osp.dirname(self.filename)
            filenames, _selfilter = getopenfilenames(self, title, basedir,
                                                     iofunctions.load_filters)
            if not filenames:
                return
        elif is_text_string(filenames):
            filenames = [filenames]

        for filename in filenames:
            self.filename = to_text_string(filename)
            ext = osp.splitext(self.filename)[1].lower()

            if ext not in iofunctions.load_funcs:
                buttons = QMessageBox.Yes | QMessageBox.Cancel
                answer = QMessageBox.question(
                    self, title,
                    _("<b>Unsupported file extension '%s'</b><br><br>"
                      "Would you like to import it anyway "
                      "(by selecting a known file format)?") % ext, buttons)
                if answer == QMessageBox.Cancel:
                    return
                formats = list(iofunctions.load_extensions.keys())
                item, ok = QInputDialog.getItem(self, title,
                                                _('Open file as:'), formats, 0,
                                                False)
                if ok:
                    ext = iofunctions.load_extensions[to_text_string(item)]
                else:
                    return

            load_func = iofunctions.load_funcs[ext]

            # 'import_wizard' (self.setup_io)
            if is_text_string(load_func):
                # Import data with import wizard
                error_message = None
                try:
                    text, _encoding = encoding.read(self.filename)
                    base_name = osp.basename(self.filename)
                    editor = ImportWizard(
                        self,
                        text,
                        title=base_name,
                        varname=fix_reference_name(base_name))
                    if editor.exec_():
                        var_name, clip_data = editor.get_data()
                        self.set_value(var_name, clip_data)
                except Exception as error:
                    error_message = str(error)
            else:
                QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
                QApplication.processEvents()
                if self.is_ipyclient:
                    error_message = self.shellwidget.load_data(
                        self.filename, ext)
                    self.shellwidget._kernel_reply = None
                else:
                    error_message = monitor_load_globals(
                        self._get_sock(), self.filename, ext)
                QApplication.restoreOverrideCursor()
                QApplication.processEvents()

            if error_message is not None:
                QMessageBox.critical(
                    self, title,
                    _("<b>Unable to load '%s'</b>"
                      "<br><br>Error message:<br>%s") %
                    (self.filename, error_message))
            self.refresh_table()
Esempio n. 24
0
 def resize_to_contents(self):
     QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
     self.dataTable.resizeColumnsToContents()
     self.dataModel.fetch_more(columns=True)
     self.dataTable.resizeColumnsToContents()
     QApplication.restoreOverrideCursor()
Esempio n. 25
0
 def _continue_initialization(self):
     """Load home page."""
     self.go_home()
     QApplication.restoreOverrideCursor()
Esempio n. 26
0
 def initialize_continued(self):
     """Load home page"""
     self.go_home()
     QApplication.restoreOverrideCursor()
Esempio n. 27
0
 def initialize_continued(self):
     """Load home page"""
     self.go_home()
     QApplication.restoreOverrideCursor()
Esempio n. 28
0
 def rehighlight(self):
     QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
     QSyntaxHighlighter.rehighlight(self)
     QApplication.restoreOverrideCursor()
Esempio n. 29
0
 def tab_released(self, event):
     """Method called when a tab from a QTabBar has been released."""
     QApplication.restoreOverrideCursor()
     self.moving = False
Esempio n. 30
0
def update_pointer(cursor=None):
    """Update application pointer."""
    if cursor is None:
        QApplication.restoreOverrideCursor()
    else:
        QApplication.setOverrideCursor(cursor)
Esempio n. 31
0
 def transition(self):
     """
     Get the state the machine should return to after the mouse button release: MoveMarkersState
     """
     QApplication.restoreOverrideCursor()
     return MoveMarkersState(self.machine)
Esempio n. 32
0
 def leaveEvent(self, event):
     """If cursor has not been restored yet, do it now"""
     if self.__cursor_changed:
         QApplication.restoreOverrideCursor()
         self.__cursor_changed = False
     self.QT_CLASS.leaveEvent(self, event)