Beispiel #1
0
    def eventFilter(self, obj: QObject, event: QEvent):
        """ Implementation of QObject::eventFilter()
            Intercept drag-and-drop events before they are passed to the QTableWidget.
            In response to the drop of a text (.txt or .csv) file, opens that file.

        @param obj: the "watched object" that events are intercepted from (self in our case)
        @param event: the event
        @return: whether the event is accepted or rejected for further processing.
        """

        if event.type() == QEvent.Drop:
            event.accept()
            mime = event.mimeData()
            if mime.hasText():
                file_path = mime.text()
                if file_path.endswith('.txt') or file_path.endswith('.csv'):
                    file_path = file_path.replace('file:///', '')
                    with open(file_path) as reader:
                        rows = reader.readlines()
                        if rows:
                            self.set_row_data(rows)
                            self.parent.setWindowTitle(os.path.basename(file_path))

            return True
        elif event.type() == QEvent.DragEnter:
            event.accept()
            return True
        return False
 def closeEvent(self, event: QEvent) -> None:
     """Trap exit."""
     quit_msg = "Are you sure you want to exit?"
     # noinspection PyCallByClass,PyTypeChecker
     reply = QMessageBox.question(self, 'Really exit?', quit_msg,
                                  QMessageBox.Yes, QMessageBox.No)
     if reply != QMessageBox.Yes:
         event.ignore()
         return
     # "Really sure?"
     if self.task_running:
         quit_msg = ("A TASK IS RUNNING! Are you <b>really</b> sure "
                     "you want to exit?")
         # noinspection PyCallByClass,PyTypeChecker
         reply = QMessageBox.question(self, 'Really exit?', quit_msg,
                                      QMessageBox.Yes, QMessageBox.No)
         if reply != QMessageBox.Yes:
             event.ignore()
             return
     # If subthreads aren't shut down, we get a segfault when we quit.
     # However, right now, signals aren't being processed because we're in
     # the GUI message loop. So we need to defer the call if subthreads are
     # running
     if not self.anything_running():
         self.exit_kill_log.emit()
         event.accept()  # actually quit
         return
     # Now stop everything
     log.warning("Waiting for threads to finish...")
     self.exit_pending = True
     if self.whisker_owner:
         self.whisker_owner.stop()
     # Will get a callback to whisker_owner_finished
     event.ignore()  # don't actually quit
Beispiel #3
0
 def keyPressEvent(self, event: QEvent):
     super().keyPressEvent(event)
     if event.key() in [Qt.Key_Space, Qt.Key_Escape]:
         event.accept()
         self.accept.emit()
     else:
         event.ignore()
Beispiel #4
0
 def closeEvent(self, evt: QtCore.QEvent):
     """All viewers in Scipyen should behave consistently.
     May by overridden in derived classes.
     """
     self.saveSettings()
     evt.accept()
     self.close()
Beispiel #5
0
    def keyPressEvent(self, event: QEvent):
        key = event.key()
        logger.info("keyPressEvent: %s", key)

        if key in [Qt.Key_Q]:
            event.accept()
            self.quit.emit()
        else:
            event.ignore()
Beispiel #6
0
    def closeEvent(self, event: QtCore.QEvent) -> None:
        """ Callback for exiting/closing plugin window

        Deletes points and relevant figure data before closing

        Args:
            event (QtCore.QEvent): qt close event (passed via signal)
        """

        event.accept()
Beispiel #7
0
 def event(self, a0: QtCore.QEvent) -> bool:
     if isinstance(a0, QtGui.QWheelEvent):
         sd = a0.angleDelta().y()
         sb = self.dlgAlts.ui.scrollArea.horizontalScrollBar()
         if sb is not None:
             sb.setValue(sb.value() + sd)
         a0.accept()
         return True
     else:
         return super(AltWidget, self).event(a0)
Beispiel #8
0
    def event(self, evt: QtCore.QEvent):
        """Generic event handler
        NOTE: This can be overriden in the derived :class:
        """
        evt.accept()

        if evt.type() in (QtCore.QEvent.FocusIn, QtCore.QEvent.WindowActivate):
            self.sig_activated.emit(self.ID)
            return True

        return super().event(evt)
Beispiel #9
0
    def closeEvent(self, event: QtCore.QEvent) -> None:
        """Close event."""

        if self._action is None:
            self._action = getattr(self.parent(), "_action")

        if self._action is not None:
            self.logger.debug("closeEvent para accion %r", self._action.name)
        self.closed.emit()
        event.accept()  # let the window close
        self.doCleanUp()
Beispiel #10
0
    def closeEvent(self, event: QtCore.QEvent) -> None:
        """ Callback for Main Window Exit/Close

        Calls individual close events on open plugins and accepts close event
        """
        for plugin in self.plugins.values():
            plugin.close()

        del self.contrast_window

        for bw in self.breakout_windows.values():
            bw.close()

        event.accept()
Beispiel #11
0
 def keyPressEvent(self, evt: QEvent) -> None:
     """
     Prevent accidentally closing dialog when editing complex widgets
     by ignoring Return and Escape
     """
     if evt.key() == Qt.Key_Enter or evt.key() == Qt.Key_Return:
         return evt.accept()
     super().keyPressEvent(evt)
Beispiel #12
0
    def timerEvent(self, event: QEvent):
        '''
        A timer has expired. If we are waiting after clearing whole lines,
        the wait is over and it is time to start a new tetronimo.

        Otherwise, it is time to move the active tetronimo down one.

        (note: Bodnar's code tests that the timer in the event is actually
        the timer we started. This seems odd, what other timer's event would
        be delivered to this widget? So, not doing that.)

        TODO: if timer interval is to change with #lines, this is
        the place to stop the timer and restart it with a new interval.
        '''
        event.accept()
        if self.waitForNextTimer:
            self.waitForNextTimer = False
            self.newPiece()
        else:
            self.oneLineDown()
Beispiel #13
0
    def closeEvent(self, event: QEvent) -> None:
        if self._closing_state == ClosingState.CONFIRMED:
            self._api.gui.terminated.emit()
            event.accept()
        elif self._closing_state == ClosingState.WAITING_FOR_CONFIRMATION:
            event.ignore()
        elif self._closing_state == ClosingState.READY:

            def on_close(task: "asyncio.Future[bool]") -> None:
                if task.result():
                    self._closing_state = ClosingState.CONFIRMED
                    self.close()
                else:
                    self._closing_state = ClosingState.READY

            self._closing_state = ClosingState.WAITING_FOR_CONFIRMATION
            task = asyncio.ensure_future(
                self._api.gui.confirm_unsaved_changes())
            task.add_done_callback(on_close)
            event.ignore()
Beispiel #14
0
    def closeEvent(self, event: QtCore.QEvent) -> None:
        if self._closing_state == ClosingState.Confirmed:
            self._api.gui.terminated.emit()
            event.accept()
        elif self._closing_state == ClosingState.WaitingForConfirmation:
            event.ignore()
        elif self._closing_state == ClosingState.Ready:

            def on_close(task: "asyncio.Future[bool]") -> None:
                if task.result():
                    self._closing_state = ClosingState.Confirmed
                    self.close()
                else:
                    self._closing_state = ClosingState.Ready

            self._closing_state = ClosingState.WaitingForConfirmation
            task = asyncio.ensure_future(
                self._api.gui.confirm_unsaved_changes()
            )
            task.add_done_callback(on_close)
            event.ignore()
Beispiel #15
0
    def keyPressEvent(self, event: QEvent):
        '''
        Process a key press. Any key press (not release) while the
        focus is in the board comes here. The key code is event.key()
        and the names of keys are defined in the Qt namespace, see
        http://doc.qt.io/qt-5/qt.html#Key-enum

        If we can handle the event we do; else pass it to our parent.

        Note that in left, right and rotate keys, we could look at the return
        from tryMove() and if it is False, we could maybe implement the "wall
        kick" feature.
        '''

        if self.isStarted and self.curPiece is not NO_T_mo:
            key = event.key()
            if key in self.validKeys:
                event.accept()  # Tell Qt, we got this one
                if key == Qt.Key_P:
                    self.togglePause()
                elif key == Qt.Key_Left:
                    self.tryMove(self.curPiece, self.curX - 1, self.curY)
                elif key == Qt.Key_Right:
                    self.tryMove(self.curPiece, self.curX + 1, self.curY)
                elif key == Qt.Key_Down:
                    self.tryMove(self.curPiece.rotateRight(), self.curX,
                                 self.curY)
                elif key == Qt.Key_Up:
                    self.tryMove(self.curPiece.rotateLeft(), self.curX,
                                 self.curY)
                elif key == Qt.Key_Space:
                    self.dropDown()
                elif key == Qt.Key_D:
                    self.oneLineDown()
        if not event.isAccepted():
            '''either we are paused or not one of our keys'''
            super().keyPressEvent(event)
Beispiel #16
0
 def closeEvent(self, event: QtCore.QEvent) -> None:  # pylint: disable=invalid-name
     """Manage the close event."""
     self.signal_close.emit()
     event.accept()
 def closeEvent(self, event: QEvent) -> None:
     self.exit_kill_log.emit()
     event.accept()
Beispiel #18
0
 def closeEvent(self, e: QEvent):
     """ Closes the main window and saves window-size and -position. """
     self._context.config.setSize(self.size())
     self._context.config.setPosition(self.pos())
     e.accept()
Beispiel #19
0
	def closeEvent(self, e:QtCore.QEvent):
		print("Closing app...")
		self.config.close()
		e.accept()
 def keyPressEvent(self, e: QtCore.QEvent):
     if e.key() == 13:  # enter
         self.parent.confirm_peer_id.emit()
     else:
         e.accept()
Beispiel #21
0
 def mousePressEvent(self, event: QEvent):
     if event.button() == QtCore.Qt.RightButton:
         self.rightclicked.emit()
         event.accept()
     else:
         return super().mousePressEvent(event)
Beispiel #22
0
 def keyPressEvent(self, event: QtCore.QEvent) -> None:
     if event.key() == QtCore.Qt.Key_Return:
         event.accept()
         self.enterPressed.emit(tuple(s.text() for s in self.selectedItems()))
     else:
         super().keyPressEvent(event)