Ejemplo n.º 1
0
 def mousePressEvent(self, event):
     if event.button() == Qt.RightButton:
         # Rewrite the mouse event to a left button event so the cursor is
         # moved to the location of the pointer.
         event = QMouseEvent(QEvent.MouseButtonPress, event.pos(),
                             Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)
     HintedTextEdit.mousePressEvent(self, event)
Ejemplo n.º 2
0
 def mousePressEvent(self, event):
     if event.button() == Qt.RightButton:
         # Rewrite the mouse event to a left button event so the cursor is
         # moved to the location of the pointer.
         event = QMouseEvent(QEvent.MouseButtonPress, event.pos(),
             Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)
     QPlainTextEdit.mousePressEvent(self, event)
    def leftDown(self, event):
        """
        Event handler for all LMB press events.
        """
        # Note: the code of SelectAtoms_GraphicsMode and SelectChunks_GraphicsMode .leftDown methods
        # is very similar, so I'm removing the redundant comments from
        # this one (SelectChunks_GraphicsMode); see SelectAtoms_GraphicsMode to find them.
        # [bruce 071022]

        self.set_cmdname('ChunkClick')
            # TODO: this should be set again later (during the same drag)
            # to a more specific command name.

        self.reset_drag_vars()
        env.history.statusbar_msg(" ")

        self.LMB_press_event = QMouseEvent(event)

        self.LMB_press_pt_xy = (event.pos().x(), event.pos().y())

        obj = self.get_obj_under_cursor(event)
        if obj is None: # Cursor over empty space.
            self.emptySpaceLeftDown(event)
            return

        method = getattr(obj, 'leftClick', None)
        if method:
            # This looks identical to the code from SelectAtoms_GraphicsMode.leftDown
            # which I just split into a separate method call_leftClick_method,
            # so I will shortly move that into our common superclass and
            # call it here instead of duplicating that code.
            #[bruce 071022 comment]
            gl_event_info = self.dragstart_using_GL_DEPTH( event,
                                                           more_info = True)
            self._drag_handler_gl_event_info = gl_event_info
            farQ_junk, hitpoint, wX, wY, depth, farZ = gl_event_info
            del wX, wY, depth, farZ
            try:
                retval = method(hitpoint, event, self)
            except:
                print_compact_traceback("exception ignored "\
                                        "in %r.leftClick: " % (obj,))
                return
            self.drag_handler = retval # needed even if this is None
            if self.drag_handler is not None:
                #the psuedoMoveMode left down might still be needed even when
                #drag handler is not None
                #(especially to get the self._leftDrag_movables)
                self._leftDown_preparation_for_dragging(obj, event)
                self.dragHandlerSetup(self.drag_handler, event)
                return

        self.doObjectSpecificLeftDown(obj, event)

        if self.glpane.modkeys is None:
            self._leftDown_preparation_for_dragging(obj, event)

        self.w.win_update()

        return # from SelectChunks_GraphicsMode.leftDown
Ejemplo n.º 4
0
 def mousePressEvent(self, event):
     self.drag_is_not_DND = False  # don't know yet
     qp = event.globalPos()  # clone the point to keep it constant
     self.mouse_press_qpoint = QPoint(qp.x(), qp.y())
     self.mouse_press_event = QMouseEvent(event.type(),
                                          QPoint(event.x(), event.y()),
                                          event.button(), event.buttons(),
                                          event.modifiers())
Ejemplo n.º 5
0
    def leftDown(self, event):
        """
        """
        self.reset_drag_vars()

        self.clear_leftA_variables()

        obj = self.get_obj_under_cursor(event)

        if obj is None:
            self.cursor_over_when_LMB_pressed = 'Empty Space'

        #@see dn_model.NanotubeSegment.isAncestorOf.
        #It checks whether the object under the
        #cursor (which is glpane.selobj) is contained within the NanotubeSegment
        #currently being edited
        #Example: If the object is an Atom, it checks whether the
        #atoms is a part of the dna segment. *being edited*
        #(i.e. self.comman.struct). If its not (e.g. its an atom of another
        #dna segment, then the this method returns . (leftDrag on structures
        #NOT being edited won't do anything-- a desirable effect)
        if self.command and hasattr(self.command.struct, 'isAncestorOf'):
            if not self.command.struct.isAncestorOf(obj):
                _superclass.leftDown(self, event)
                return
            else:
                #Optimization: This value will be used in self.leftDrag.
                # Instead of checking everytime whether the
                #self.command.struct contains the highlighted objetc
                #(glpane.selobj)
                _superclass.leftDown(self, event)
                self.cursor_over_when_LMB_pressed = 'Structure Being Edited'

        self.LMB_press_event = QMouseEvent(event)  # Make a copy of this event
        #and save it.
        # We will need it later if we change our mind and start selecting a 2D
        # region in leftDrag().Copying the event in this way is necessary
        #because Qt will overwrite  <event> later (in
        # leftDrag) if we simply set self.LMB_press_event = event.  mark 060220

        self.LMB_press_pt_xy = (event.pos().x(), event.pos().y())
        # <LMB_press_pt_xy> is the position of the mouse in window coordinates
        #when the LMB was pressed.
        #Used in mouse_within_stickiness_limit (called by leftDrag() and other
        #methods).
        # We don't bother to vertically flip y using self.height
        #(as mousepoints does),
        # since this is only used for drag distance within single drags.
        #Subclasses should override one of the following method if they need
        #to do additional things to prepare for dragging.
        self._leftDown_preparation_for_dragging(obj, event)
        return
Ejemplo n.º 6
0
 def handle_tap_hold(self, action, tp):
     etype = {
         'start': QEvent.MouseButtonPress,
         'update': QEvent.MouseMove,
         'end': QEvent.MouseButtonRelease
     }[action]
     ev = QMouseEvent(etype, self.current_position(tp),
                      tp.current_screen_position.toPoint(), Qt.LeftButton,
                      Qt.LeftButton, Qt.NoModifier)
     QApplication.sendEvent(self.parent(), ev)
     if action == 'end':
         ev = QContextMenuEvent(QContextMenuEvent.Other,
                                self.current_position(tp),
                                tp.current_screen_position.toPoint())
         # We have to use post event otherwise the popup remains an alien widget and does not receive events
         QApplication.postEvent(self.parent(), ev)
Ejemplo n.º 7
0
    def leftDown(self, event):
        """
        """
        self.reset_drag_vars()

        self.clear_leftA_variables()

        _superclass.leftDown(self, event)

        self.LMB_press_event = QMouseEvent(event)  # Make a copy of this event
        #and save it.
        # We will need it later if we change our mind and start selecting a 2D
        # region in leftDrag().Copying the event in this way is necessary
        #because Qt will overwrite  <event> later (in
        # leftDrag) if we simply set self.LMB_press_event = event.  mark 060220

        self.LMB_press_pt_xy = (event.pos().x(), event.pos().y())
Ejemplo n.º 8
0
 def handle_tap(self, tp):
     if self.close_open_menu():
         return
     view = self.parent()
     mf = view.document.mainFrame()
     r = mf.hitTestContent(self.current_position(tp))
     if r.linkElement().isNull():
         threshold = view.width() / 3.0
         attr = 'previous' if self.current_position(
             tp).x() <= threshold else 'next'
         getattr(view, '%s_page' % attr)()
     else:
         for etype in (QEvent.MouseButtonPress, QEvent.MouseButtonRelease):
             ev = QMouseEvent(etype, self.current_position(tp),
                              tp.current_screen_position.toPoint(),
                              Qt.LeftButton, Qt.LeftButton, Qt.NoModifier)
             QApplication.sendEvent(view, ev)
Ejemplo n.º 9
0
    def leftDown(self, event):
        """
        Handle left down event. Preparation for dragging and/or selection
        @param event: The mouse left down event.
        @type  event: QMouseEvent instance
        @see: self._leftDown_preparation_for_dragging
        """
        #The following variable stores a string. It is used in leftDrag related
        #methods to handle cases where the user may do a keypress *while* left
        #dragging, which would change the move type. This variable is assigned a
        #string value.See self.leftDownForTranslatation for an example.
        self.leftDownType = None

        self.clear_leftA_variables()  #bruce 070605 added this
        #(guess at what's needed)
        env.history.statusbar_msg("")

        self.reset_drag_vars()

        self.LMB_press_event = QMouseEvent(event)  # Make a copy of this event
        #and save it.
        # We will need it later if we change our mind and start selecting a 2D
        # region in leftDrag().Copying the event in this way is necessary
        #because Qt will overwrite  <event> later (in
        # leftDrag) if we simply set self.LMB_press_event = event.  mark 060220

        self.LMB_press_pt_xy = (event.pos().x(), event.pos().y())
        # <LMB_press_pt_xy> is the position of the mouse in window coordinates
        #when the LMB was pressed.
        #Used in mouse_within_stickiness_limit (called by leftDrag() and other
        #methods).
        # We don't bother to vertically flip y using self.height
        #(as mousepoints does),
        # since this is only used for drag distance within single drags.

        # If keyboard key 'A' is pressed OR if the corresponding toolbutton
        # in the propMgr is pressed,  set it up for constrained translation
        # and rotation along the axis and return.

        # @TODO: Should reuse the flag self.isConstrainedDragAlongAxis instead
        # of checking move/ rotate options independently. Better to associate
        # key 'A' with the appropriate option in the PM. Also, the
        # propMgr sets the moveOption flags of the graphics mode. PropMgr should
        # be prevented from using graphicsmode object for clarity. This is
        # one of the code cleanup and refactoring projects related to this command
        # (this is one of the things that hasn't completely cleanued up
        # during refactoring and major cleanup of the old modifyMode class code.
        # --Ninad 2008-04-09

        # Permit movable object picking upon left down.
        obj = self.get_obj_under_cursor(event)

        if self.isConstrainedDragAlongAxis or \
           self.moveOption == 'ROT_TRANS_ALONG_AXIS' or \
           self.rotateOption == 'ROT_TRANS_ALONG_AXIS':
            self.leftADown(obj, event)
            return

        # If highlighting is turned on, get_obj_under_cursor() returns atoms,
        # singlets, bonds, jigs,
        # or anything that can be highlighted and end up in glpane.selobj.
        # [bruce revised this comment, 060725]If highlighting is turned off,
        # get_obj_under_cursor() returns atoms and singlets (not bonds or jigs).
        # [not sure if that's still true -- probably not. bruce 060725 addendum]
        if obj is None:  # Cursor over empty space.
            self.emptySpaceLeftDown(event)
            return

        self.doObjectSpecificLeftDown(obj, event)

        #Subclasses should override one of the following method if they need
        #to do additional things to prepare for dragging.
        self._leftDown_preparation_for_dragging(obj, event)

        self.w.win_update()
        return