1 | #!/usr/bin/env python3 |
||
2 | # -*- coding: utf-8 -*- |
||
3 | """ |
||
4 | This file contains the modified PlotWidget for Qudi. |
||
5 | |||
6 | Qudi is free software: you can redistribute it and/or modify |
||
7 | it under the terms of the GNU General Public License as published by |
||
8 | the Free Software Foundation, either version 3 of the License, or |
||
9 | (at your option) any later version. |
||
10 | |||
11 | Qudi is distributed in the hope that it will be useful, |
||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
14 | GNU General Public License for more details. |
||
15 | |||
16 | You should have received a copy of the GNU General Public License |
||
17 | along with Qudi. If not, see <http://www.gnu.org/licenses/>. |
||
18 | |||
19 | Copyright (c) the Qudi Developers. See the COPYRIGHT.txt file at the |
||
20 | top-level directory of this distribution and at <https://github.com/Ulm-IQO/qudi/> |
||
21 | """ |
||
22 | |||
23 | from pyqtgraph import PlotWidget |
||
24 | from qtpy import QtCore |
||
25 | from qtpy import QtWidgets |
||
26 | |||
27 | |||
28 | class PlotWidgetModified(PlotWidget): |
||
29 | """ Extend the PlotWidget Class with more adjustment possibilities. |
||
30 | |||
31 | This class can be promoted in the Qt designer. Here you can predefine or |
||
32 | redefined all methods and class variables, which should be used in the |
||
33 | Qt Designer before it will be loaded into the created ui file. |
||
34 | |||
35 | This class behaves like the normal PlotWidget class but extends its |
||
36 | functionality with modified mouse events. |
||
37 | """ |
||
38 | |||
39 | sigMouseClick = QtCore.Signal(object) |
||
40 | sigMouseReleased = QtCore.Signal(object) |
||
41 | |||
42 | def __init__(self, *args, **kargs): |
||
0 ignored issues
–
show
Unused Code
introduced
by
![]() |
|||
43 | PlotWidget.__init__(self,**kargs) |
||
44 | |||
45 | def mousePressEvent(self, ev): |
||
46 | """ Override the Qt method, which handels mouse press events. |
||
47 | |||
48 | @param QEvent ev: Event object which contains all the information at |
||
49 | the time the event was emitted. |
||
50 | |||
51 | That is basically a reimplementation of the mouseReleaseEvent function |
||
52 | of the PlotWidget. |
||
53 | """ |
||
54 | |||
55 | # Extend the received event ev with all the properties of a Qt mouse |
||
56 | # press event. |
||
57 | QtWidgets.QGraphicsView.mousePressEvent(self, ev) |
||
58 | |||
59 | # this signal will be catched by other methods if the mouse was clicked |
||
60 | # inside the PlotWidget. |
||
61 | self.sigMouseClick.emit(ev) |
||
62 | |||
63 | if not self.mouseEnabled: |
||
0 ignored issues
–
show
|
|||
64 | return |
||
65 | self.mousePressPos = ev.pos() |
||
66 | self.clickAccepted = ev.isAccepted() |
||
67 | |||
68 | if not self.clickAccepted: |
||
69 | self.scene().clearSelection() |
||
0 ignored issues
–
show
|
|||
70 | return ## Everything below disabled for now. |
||
71 | |||
72 | |||
73 | def mouseReleaseEvent(self, ev): |
||
74 | """ Override the Qt method, which handels mouse release events. |
||
75 | |||
76 | @param QEvent ev: Event object which contains all the information at |
||
77 | the time the event was emitted. |
||
78 | |||
79 | That is basically a reimplementation of the mouseReleaseEvent function |
||
80 | of the PlotWidget. |
||
81 | """ |
||
82 | # Extend the received event ev with all the properties of a Qt mouse |
||
83 | # press event. |
||
84 | QtWidgets.QGraphicsView.mouseReleaseEvent(self, ev) |
||
85 | |||
86 | # this signal will be catched by other methods if the mouse was clicked |
||
87 | # and afterwards release inside the PlotWidget. |
||
88 | self.sigMouseReleased.emit(ev) |
||
89 | if not self.mouseEnabled: |
||
0 ignored issues
–
show
|
|||
90 | return |
||
91 | |||
92 | self.lastButtonReleased = ev.button() |
||
93 | return ## Everything below disabled for now. |
||
94 | |||
95 |