-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.py
More file actions
200 lines (157 loc) · 7.29 KB
/
gui.py
File metadata and controls
200 lines (157 loc) · 7.29 KB
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
# -*- coding: utf-8 -*
import time
import bind_screen
import sys
import os
import subprocess
import random
import win32com.client
import win32api
from PyQt4 import QtCore
from PyQt4 import QtGui
def main():
app = QtGui.QApplication(sys.argv)
panel = QtGui.QWidget()
button_box_widget = ButtonBoxWidget(parent=panel)
panel_layout = QtGui.QVBoxLayout()
panel_layout.addWidget(button_box_widget)
panel.setLayout(panel_layout)
panel.setFixedSize(450, 300)
exec_command = sendCUI()
main_window = QtGui.QMainWindow()
main_window.setWindowTitle("BindScreen")
main_window.setCentralWidget(panel)
main_window.show()
# スクリプト実行
button_box_widget.start_button.clicked.connect(
lambda: exec_command.exec_command(button_box_widget.folder_path_box.text(),
button_box_widget.get_instruction_direction(),
button_box_widget.get_opening_direction(),
button_box_widget.init_time_box.text(),
button_box_widget.interval_time_box.text(),
button_box_widget.get_trim_checkbox(),
button_box_widget.get_zip_checkbox()
))
# スクリプト中断
button_box_widget.stop_button.clicked.connect(lambda: exec_command.send_interrpt())
# ファイルパスをセットする
button_box_widget.select_button.clicked.connect(
lambda: show_folder_dialog(button_box_widget))
app.exec_()
class ButtonBoxWidget(QtGui.QWidget):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent=parent)
self.setup_ui()
def setup_ui(self):
self.start_button = QtGui.QPushButton("実行", parent=self)
self.stop_button = QtGui.QPushButton("中断", parent=self)
self.select_button = QtGui.QPushButton("フォルダ選択", parent=self)
self.check_trim = QtGui.QCheckBox("画像のトリミングを行う", self)
self.check_zip = QtGui.QCheckBox("圧縮フォルダを出力する", self)
# 本の見開き方向
self.opening_directions_radio = QtGui.QButtonGroup()
self.opening_left_radio = QtGui.QRadioButton("左開き", parent=self)
self.opening_right_radio = QtGui.QRadioButton("右開き", parent=self)
self.opening_directions_radio.addButton(self.opening_left_radio)
self.opening_directions_radio.addButton(self.opening_right_radio)
# キーボード入力の方向
self.opening_instructions_radio = QtGui.QButtonGroup()
self.instruction_left_radio = QtGui.QRadioButton("左キー", parent=self)
self.instruction_right_radio = QtGui.QRadioButton("右キー", parent=self)
self.instruction_up_radio = QtGui.QRadioButton("上キー", parent=self)
self.instruction_down_radio = QtGui.QRadioButton("下キー", parent=self)
self.instruction_noinput_radio = QtGui.QRadioButton("入力なし", parent=self)
self.opening_instructions_radio.addButton(self.instruction_left_radio)
self.opening_instructions_radio.addButton(self.instruction_right_radio)
self.opening_instructions_radio.addButton(self.instruction_up_radio)
self.opening_instructions_radio.addButton(self.instruction_down_radio)
self.opening_instructions_radio.addButton(self.instruction_noinput_radio)
self.capture_label = QtGui.QLabel('キャプチャ間隔(秒)',self)
self.init_label = QtGui.QLabel('初期化時間(秒)',self)
self.input_key_label = QtGui.QLabel('--キー入力--',self)
self.opening_direction_label = QtGui.QLabel('--見開き方向--',self)
self.output_folder_path_label = QtGui.QLabel('出力先フォルダ',self)
# フォルダパス名
self.folder_path_box = QtGui.QLineEdit(self)
# 撮影間隔
self.interval_time_box = QtGui.QLineEdit(self)
# 初期化時間
self.init_time_box = QtGui.QLineEdit(self)
layout = QtGui.QGridLayout()
layout.addWidget(self.start_button, 0, 0)
layout.addWidget(self.stop_button, 0, 1)
layout.addWidget(self.init_label, 2, 0)
layout.addWidget(self.init_time_box, 2, 1)
layout.addWidget(self.capture_label, 1, 0)
layout.addWidget(self.interval_time_box, 1, 1)
layout.addWidget(self.opening_direction_label, 0, 3)
layout.addWidget(self.opening_left_radio, 1, 3)
layout.addWidget(self.opening_right_radio, 1, 4)
layout.addWidget(self.input_key_label, 3, 3)
layout.addWidget(self.instruction_left_radio, 5, 3)
layout.addWidget(self.instruction_right_radio, 5, 5)
layout.addWidget(self.instruction_up_radio, 4, 4)
layout.addWidget(self.instruction_down_radio, 6, 4)
layout.addWidget(self.instruction_noinput_radio, 5, 4)
layout.addWidget(self.folder_path_box, 7, 0, 7, 4)
layout.addWidget(self.output_folder_path_label, 8, 0)
layout.addWidget(self.select_button, 8, 1)
layout.addWidget(self.check_trim, 3, 0, 3, 2)
layout.addWidget(self.check_zip, 4, 0, 4, 2)
self.setLayout(layout)
def get_opening_direction(self):
"""本の見開きを取得"""
if self.opening_left_radio.isChecked() and not self.opening_right_radio.isChecked():
return "LEFT"
elif not self.opening_left_radio.isChecked() and self.opening_right_radio.isChecked():
return "RIGHT"
def get_instruction_direction(self):
"""キーボードの命令を取得"""
if self.instruction_left_radio.isChecked():
return "{LEFT}"
elif self.instruction_right_radio.isChecked():
return "{RIGHT}"
elif self.instruction_up_radio.isChecked():
return "{UP}"
elif self.instruction_down_radio.isChecked():
return "{DOWN}"
elif self.instruction_noinput_radio.isChecked():
return "NoneSendKey"
def get_zip_checkbox(self):
"""zipチェックボックスの状態を取得"""
if self.check_zip.isChecked():
return "--zip"
else:
return ""
def get_trim_checkbox(self):
"""トリミングチェックボックスの状態を取得"""
if self.check_trim.isChecked():
return "--trim"
else:
return ""
def show_folder_dialog(widget):
"""GUIフォルダ選択"""
fd = QtGui.QFileDialog()
folder_path = fd.getExistingDirectory()
widget.folder_path_box.setText('"' + folder_path + '"')
class sendCUI():
def __init__(self):
self.process = None
def exec_command(self, *args):
"""CUIの引数付き実行"""
self.cmd = 'python bind_screen.py'
print(args)
for arg in args:
self.cmd += ' ' + arg
print(self.cmd)
self.process = subprocess.Popen(self.cmd)
def send_interrpt(self):
"""プログラムの中断"""
if self.process == None:
print ("You didn't run a program")
return
win32api.TerminateProcess(int(self.process._handle), -1)
print("process is interrupted")
print("If you want to continue this program, you must delete selected sub directory")
if __name__ == '__main__':
main()