-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathui.py
executable file
·178 lines (144 loc) · 6.42 KB
/
ui.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
#!/usr/bin/env python
__author__ = 'Baumfaust'
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QRubberBand, QWidget, QLabel, QHBoxLayout
from PyQt5.QtCore import QRect, QThread, pyqtSignal, QSize, Qt
from PyQt5.QtGui import QPixmap, QImage, QColor
from ui_main import Ui_MainWindow
from getthefish import GetTheFish, Point
class ThreadRunner(QThread):
def __init__(self, object):
QThread.__init__(self)
self.fish = object
def run(self):
self.fish.run = True
self.fish.fishing()
def stopFishing(self):
self.fish.run = False
class ScreenshotWidget(QWidget):
colorPicked = pyqtSignal()
def __init__(self):
super(ScreenshotWidget, self).__init__()
layout = QHBoxLayout()
label = QLabel()
pixmap = QPixmap("img.png")
label.setPixmap(pixmap)
layout.addWidget(label)
self.setLayout(layout)
self.resize(pixmap.width(), pixmap.height())
self.show()
def getBobberColor(self):
return self.color
def mousePressEvent(self, event):
pos = event.pos()
pm = self.grab(QRect(pos.x(), pos.y(), 1, 1))
i = pm.toImage()
self.color = QColor(i.pixel(0, 0))
self.colorPicked.emit()
class SelectAreaWidget(QLabel):
areaSelected = pyqtSignal()
def __init__(self):
super(SelectAreaWidget, self).__init__()
self.rubberBand = None
pixmap = QApplication.primaryScreen().grabWindow(0)
self.setPixmap(pixmap)
self.showFullScreen()
self.show()
def mousePressEvent(self, event):
if event.button() == Qt.RightButton:
if self.rubberBand:
self.rubberBand.hide()
self.close()
if event.button() == Qt.LeftButton:
self.origin = event.pos()
if not self.rubberBand:
self.rubberBand = QRubberBand(QRubberBand.Rectangle, None)
self.rubberBand.setGeometry(QRect(self.origin, QSize()))
self.rubberBand.show()
def mouseMoveEvent(self, event):
if self.rubberBand:
self.rubberBand.setGeometry(QRect(self.origin, event.pos()).normalized())
def mouseReleaseEvent(self, event):
if self.rubberBand:
self.destination = event.pos()
self.areaSelected.emit()
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.selectAreaWidget = None
self.rubberBand = QRubberBand(QRubberBand.Rectangle, self)
self.screenshotWidget = None
color = QColor(72, 41, 12).name(QColor.HexRgb)
self.ui.hexColorLabel.setText(color)
self.ui.bobberColorLabel.setStyleSheet("QLabel { background-color : " + color + "; }")
self.fish = GetTheFish()
self.fish.gui = True
self.updateGui()
self.thread = ThreadRunner(self.fish)
# connects
self.ui.colorButton.clicked.connect(self.openScreenshot)
self.ui.startButton.clicked.connect(self.toggleFishing)
self.ui.areaButton.clicked.connect(self.take_screenshot)
self.ui.thresholdBobberSpinBox.valueChanged.connect(self.guiUpdated)
self.ui.thresholdCatchSpinBox.valueChanged.connect(self.guiUpdated)
self.ui.jumpToBobberCheck.stateChanged.connect(self.guiUpdated)
self.ui.verboseCheck.stateChanged.connect(self.guiUpdated)
def updateGui(self):
self.ui.thresholdBobberSpinBox.setValue(self.fish.fishConfig.thresholdBobber)
self.ui.thresholdCatchSpinBox.setValue(self.fish.fishConfig.thresholdCatch)
self.ui.jumpToBobberCheck.setChecked(self.fish.fishConfig.jumpToBobber)
self.ui.verboseCheck.setChecked(self.fish.fishConfig.verbose)
self.ui.posStartLabel.setText(
str(self.fish.fishConfig.startPos.x) + ", " + str(self.fish.fishConfig.startPos.y))
self.ui.posEndLabel.setText(
str(self.fish.fishConfig.endPos.x) + ", " + str(self.fish.fishConfig.endPos.y))
def guiUpdated(self):
self.fish.fishConfig.thresholdBobber = self.ui.thresholdBobberSpinBox.value()
self.fish.fishConfig.thresholdCatch = self.ui.thresholdCatchSpinBox.value()
self.fish.fishConfig.jumpToBobber = self.ui.jumpToBobberCheck.isChecked()
self.fish.fishConfig.verbose = self.ui.verboseCheck.isChecked()
if self.selectAreaWidget:
self.fish.fishConfig.startPos = Point(self.selectAreaWidget.origin.x(), self.selectAreaWidget.origin.y())
self.fish.fishConfig.endPos = Point(self.selectAreaWidget.destination.x(), self.selectAreaWidget.destination.y())
self.ui.posStartLabel.setText(
str(self.fish.fishConfig.startPos.x) + ", " + str(self.fish.fishConfig.startPos.y))
self.ui.posEndLabel.setText(
str(self.fish.fishConfig.endPos.x) + ", " + str(self.fish.fishConfig.endPos.y))
self.fish.save()
def toggleFishing(self):
if self.thread.isRunning():
self.thread.stopFishing()
self.ui.startButton.setText("Start")
else:
self.thread.start()
self.ui.startButton.setText("Stop")
def bobberColorPicked(self):
color = QColor( self.screenshotWidget.getBobberColor()).name(QColor.HexRgb)
self.ui.hexColorLabel.setText(color)
self.ui.bobberColorLabel.setStyleSheet("QLabel { background-color : " + color + "; }")
def openScreenshot(self):
self.screenshotWidget = ScreenshotWidget()
self.screenshotWidget.colorPicked.connect(self.bobberColorPicked)
def take_screenshot(self):
self.selectAreaWidget = SelectAreaWidget()
self.selectAreaWidget.areaSelected.connect(self.guiUpdated)
sys._excepthook = sys.excepthook
def my_exception_hook(exctype, value, traceback):
# Print the error and traceback
print(exctype, value, traceback)
# Call the normal Exception hook after
sys._excepthook(exctype, value, traceback)
sys.exit(1)
# Set the exception hook to our wrapping function
sys.excepthook = my_exception_hook
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
window = MainWindow()
window.show()
try:
sys.exit(app.exec_())
except:
pass