This repository has been archived by the owner on Nov 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
/
qtmtwindow.py
119 lines (94 loc) · 3.26 KB
/
qtmtwindow.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
import sys
import math
from OpenGL.GL import *
from PyQt4 import QtOpenGL, QtGui, QtCore
from PyQt4.Qt import Qt
from pymt import BaseWindow, getEventLoop
class MTDesignerWindow(BaseWindow):
pass
class QTMTWindow(QtOpenGL.QGLWidget):
def __init__(self, parent=None):
super(QTMTWindow, self).__init__(parent)
self.runing_pymt = False
self.pymt_window = False
self.object = 0
self.bg_color = QtGui.QColor(.5, .5, .5, 1.0)
self.startTimer(40)
self.is_running = False
self.want_leave = False
self.is_paused = False
def timerEvent(self, event):
self.update()
def minimumSizeHint(self):
return QtCore.QSize(640, 50)
def sizeHint(self):
return QtCore.QSize(800, 600)
def paintGL(self):
pymt_evloop = getEventLoop()
if pymt_evloop and self.pymt_window:
# leaving asked ?
if self.want_leave:
self.close_pymt_window()
return
# do idle only if it's not in paused
if not self.is_paused:
pymt_evloop.idle()
else:
# force bit to running = False,
# application can leave by itself
self.want_leave = False
self.is_running = False
glClearColor(0,1,0,1)
glClear(GL_COLOR_BUFFER_BIT)
def resizeGL(self, width, height):
if self.pymt_window:
self.pymt_window.size = (width, height)
def read_mouse_properties(self, event):
pos = event.pos()
x,y = pos.x(), pos.y()
button = 'left'
if event.button == Qt.RightButton:
button = 'right'
self.modifiers = []
kmods = event.modifiers()
if kmods & Qt.ShiftModifier:
self.modifiers.append('shift')
if kmods & Qt.ControlModifier:
self.modifiers.append('ctrl')
if kmods & Qt.AltModifier:
self.modifiers.append('alt')
if kmods & Qt.MetaModifier:
self.modifiers.append('meta')
return x, y, button, self.modifiers
def mousePressEvent(self, event):
if self.pymt_window:
x,y,b,m = self.read_mouse_properties(event)
self.pymt_window.dispatch_event('on_mouse_down', x,y,b,m)
def mouseMoveEvent(self, event):
if self.pymt_window:
x,y,b,m = self.read_mouse_properties(event)
self.pymt_window.dispatch_event('on_mouse_move', x,y,m)
def mouseReleaseEvent(self, event):
if self.pymt_window:
x,y,b,m = self.read_mouse_properties(event)
self.pymt_window.dispatch_event('on_mouse_up', x,y,b,m)
def reset(self):
self.resizeGL(self.width(), self.height())
self.is_running = True
self.is_paused = False
self.want_leave = False
def play(self):
self.is_paused = False
def stop(self):
self.want_leave = True
self.is_running = False
def pause(self):
self.is_paused = True
def close_pymt_window(self):
if self.pymt_window:
self.pymt_window.close()
self.pymt_window = None
def create_new_pymt_window(self):
self.close_pymt_window()
self.pymt_window = MTDesignerWindow()
self.reset()