-
Notifications
You must be signed in to change notification settings - Fork 7
/
eventfilter.py
233 lines (184 loc) · 6.65 KB
/
eventfilter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
# -*- coding: utf-8 -*-
#-------------------------------------------------
#-- event filter
#--
#-- microelly 2015
#--
#-- GNU Lesser General Public License (LGPL)
#-------------------------------------------------
__Version__='huhu'
__Author__="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
from PySide import QtGui,QtCore
import FreeCAD,tools,sys
from tools import *
# https://wiki.qt.io/Signals_and_Slots_in_PySide
def runextern(fn,arg1="",arg2=""):
'''
start an extern program with max 2 arguments
'''
import os
if os.path.exists(fn) and os.path.isfile(fn):
try:
import subprocess
DETACHED_PROCESS = 0x00000008
windows=False
if windows:
pid = subprocess.Popen([fn,arg1,arg2],creationflags=DETACHED_PROCESS).pid
else:
pid = subprocess.Popen([fn,arg1,arg2]).pid
except:
sayexc("exec error file: " + fn )
else:
sayexc("no access to file: " + fn)
import eventserver
reload(eventserver)
eventserver.start()
#-----------------------------
# trace
global tron
tron=False
global lastEvent
lastEvent=None
global keyPressed2
keyPressed2=False
global editmode
editmode=False
class EventFilter(QtCore.QObject):
def init(self):
self.enterleave=False
self.enterleave=True
def eventFilter(self, o, e):
global tron
global lastEvent
global keyPressed2
global editmode
if not hasattr(FreeCAD,'MM'):
FreeCAD.MM=0
# http://doc.qt.io/qt-5/qevent.html
z=str(e.type())
# not used events
if z == 'PySide.QtCore.QEvent.Type.ChildAdded' or \
z == 'PySide.QtCore.QEvent.Type.ChildRemoved'or \
z == 'PySide.QtCore.QEvent.Type.User' or \
z == 'PySide.QtCore.QEvent.Type.Paint' or \
z == 'PySide.QtCore.QEvent.Type.LayoutRequest' or\
z == 'PySide.QtCore.QEvent.Type.UpdateRequest' :
return QtGui.QWidget.eventFilter(self, o, e)
if z == 'PySide.QtCore.QEvent.Type.KeyPress':
# http://doc.qt.io/qt-4.8/qkeyevent.html
# ignore editors
if editmode:
return QtGui.QWidget.eventFilter(self, o, e)
# only first time key pressed
if not keyPressed2:
keyPressed2=True
#FreeCAD.Console.PrintMessage(" "+ str(e.key()) +" " )
#FreeCAD.Console.PrintMessage(e.modifiers())
# tastennamen ...
# if e.key() == QtCore.Qt.Key_A and (e.modifiers() & QtCore.Qt.SHIFT):
FreeCAD.MM=0
try:
# only two function keys implemented, no modifieres
if e.key()== QtCore.Qt.Key_F2:
FreeCAD.EventServer.speakWord.emit("F2")
say("------------F2-----------------")
return False
elif e.key()== QtCore.Qt.Key_F3:
FreeCAD.EventServer.speakWord.emit("F3")
else:
FreeCAD.EventServer.speakWord.emit(e.text())
except:
sayexc()
# end of a single key pressed
if z == 'PySide.QtCore.QEvent.Type.KeyRelease':
keyPressed2=False
# enter and leave a widget - editor widgets
if z == 'PySide.QtCore.QEvent.Type.Enter' or z == 'PySide.QtCore.QEvent.Type.Leave':
try:
# FreeCAD.Console.PrintMessage("Enter Leave\n")
#FreeCAD.Console.PrintMessage(e.type())
#FreeCAD.Console.PrintMessage(o)
#FreeCAD.Console.PrintMessage("!\n")
FreeCAD.MM=0
pass
except:
sayexc()
# deactive keys in editors context
if z == 'PySide.QtCore.QEvent.Type.Enter' and \
(o.__class__ == QtGui.QPlainTextEdit or o.__class__ == QtGui.QTextEdit):
editmode=True
elif z == 'PySide.QtCore.QEvent.Type.Leave' and \
(o.__class__ == QtGui.QPlainTextEdit or o.__class__ == QtGui.QTextEdit):
editmode=False
# mouse movement only leaves and enters
if z == 'PySide.QtCore.QEvent.Type.HoverMove' :
if FreeCAD.MM == 0:
# http://doc.qt.io/qt-5/qhoverevent.html
FreeCAD.Console.PrintMessage("old Pos: ")
FreeCAD.Console.PrintMessage(e.oldPos())
FreeCAD.Console.PrintMessage(", new Pos: ")
FreeCAD.Console.PrintMessage(e.pos())
FreeCAD.Console.PrintMessage("\n")
FreeCAD.MM=1
event=e
try:
if tron:
FreeCAD.Console.PrintMessage(str(event.type())+ " " + str(o) +'!!\n')
if event.type() == QtCore.QEvent.ContextMenu and o.__class__ == QtGui.QWidget:
# hier contextmenue rechte maus auschalten
# FreeCAD.Console.PrintMessage('!! cancel -------------------------------------context-----------\n')
# return True
pass
# wheel rotation
if event.type()== QtCore.QEvent.Type.Wheel:
# http://doc.qt.io/qt-4.8/qwheelevent.html
FreeCAD.Console.PrintMessage(str(event.type())+ " " + str(o) +'!!\n')
FreeCAD.Console.PrintMessage(str(e.delta()) + " " +str(e.pos()) + "\n")
return False
# mouse clicks
if event.type() == QtCore.QEvent.MouseButtonPress or \
event.type() == QtCore.QEvent.MouseButtonRelease or\
event.type() == QtCore.QEvent.MouseButtonDblClick:
FreeCAD.Console.PrintMessage(str(event.type())+ " " + str(o) +'!!\n')
FreeCAD.Console.PrintMessage( " mouse position: " +str(e.pos()) + "\n")
FreeCAD.Console.PrintMessage( " widget height: " +str(o.height()) + "\n")
FreeCAD.Console.PrintMessage( " widget width: " +str(o.width()) + "\n")
FreeCAD.Console.PrintMessage( " widget position: " +str(o.pos()) + "\n")
FreeCAD.Console.PrintMessage( " parent widget: " +str(o.parentWidget()) + "\n")
widget = QtGui.qApp.widgetAt(e.pos())
if widget:
FreeCAD.Console.PrintMessage("widget under mouse: " + str(widget) +" !--"+widget.objectName() +"--!\n")
# double clicked
if event.type() == QtCore.QEvent.MouseButtonDblClick and event.button() == QtCore.Qt.MidButton :
FreeCAD.Console.PrintMessage('two\n')
# middle
if event.button() == QtCore.Qt.MidButton or event.button() == QtCore.Qt.MiddleButton:
FreeCAD.Console.PrintMessage('!-------------------------------------!! X middle \n')
# return QtGui.QWidget.eventFilter(self, o, es)
if event.button() == QtCore.Qt.LeftButton:
FreeCAD.Console.PrintMessage('!! X one left\n')
# right mouse button when context menue deactivated
elif event.button() == QtCore.Qt.RightButton:
FreeCAD.Console.PrintMessage('!! X one right\n')
if event.type() == QtCore.QEvent.MouseButtonPress and o.__class__ == QtGui.QWidget:
FreeCAD.Console.PrintMessage('!! rechts widget -------------------------------------dfdfddf-----------\n')
return True
if event.type() == QtCore.QEvent.MouseButtonPress and o.__class__ == QtGui.QTextEdit:
FreeCAD.Console.PrintMessage('!! rechts textfeld ------------------------------------------------\n')
return True
except:
sayexc()
return QtGui.QWidget.eventFilter(self, o, e)
def start():
global keyPressed2
mw=QtGui.qApp
ef=EventFilter()
FreeCAD.eventfilter=ef
mw.installEventFilter(ef)
keyPressed2=False
def stop():
global keyPressed2
mw=QtGui.qApp
ef=FreeCAD.eventfilter
mw.removeEventFilter(ef)
keyPressed2=False