-
Notifications
You must be signed in to change notification settings - Fork 0
/
starcanvas.py
70 lines (59 loc) · 2.54 KB
/
starcanvas.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
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
class starCanvas(QLabel):
def __init__(self, mainwindow, ui_window):
QLabel.__init__(self)
self.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
self.mainwindow = mainwindow
self.ui_window = ui_window
self.pixmap = QPixmap("Resources/icon.png")
self.setPixmap(self.pixmap)
self.installEventFilter(self)
self.setMouseTracking(True)
self.Clicked = None
self.previous = None
self.drift = None
self.stage = 1
self.enabled = True
self.history = ['Drift history:']
def eventFilter(self, source, event):
if (source is self and event.type() == QEvent.MouseButtonRelease):
self.handleClick(event.pos())
return self.mainwindow.eventFilter(source, event)
def updateImage(self, image):
self.pixmap = QPixmap.fromImage(image)
self.setPixmap(self.pixmap)
self.update()
def paintEvent(self, QPaintEvent):
print (self.stage, self.previous, self.Clicked)
super(starCanvas, self).paintEvent(QPaintEvent)
if self.stage == 1 and self.previous and self.Clicked:
print ('Drawing drift')
painter = QPainter(self)
painter.setPen(QPen(Qt.red))
painter.drawLine(self.previous.x(),self.previous.y(),self.Clicked.x(),self.previous.y())
painter.setPen(QPen(Qt.green))
painter.drawLine(self.Clicked.x(),self.previous.y(),self.Clicked.x(),self.Clicked.y())
return
if self.Clicked and self.stage > 1:
print ('Drawing crosshairs')
painter = QPainter(self)
painter.setPen(QPen(Qt.red))
painter.drawLine(self.Clicked.x(),0,self.Clicked.x(),self.height())
painter.drawLine(0,self.Clicked.y(),self.width(),self.Clicked.y())
def drift_str(self):
return 'Azimuth drift: '+str(self.drift[0])+' / Altitude drift: '+str(self.drift[1])
def calculate_drift(self):
print (self.Clicked, self.previous)
drift_az = self.Clicked.x() - self.previous.x()
drift_alt = self.Clicked.y() - self.previous.y()
self.drift = (drift_az, drift_alt)
self.history.append('Azimuth: %s / Altitude: %s' %self.drift)
def handleClick(self, pos):
if not self.enabled:
return
self.Clicked = pos
if self.stage in (2,3,4):
self.ui_window.StatusBarButton.setEnabled(True)
self.update()