-
Notifications
You must be signed in to change notification settings - Fork 0
/
OBR_analyzer_simple_Eivind_NoGUI.py
259 lines (193 loc) · 8.7 KB
/
OBR_analyzer_simple_Eivind_NoGUI.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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
# "OBR_analyzer_simple" (v1.0)
# Copyright 2016 Soren Heinze
# soerenheinze <at> gmx <dot> de
# 5B1C 1897 560A EF50 F1EB 2579 2297 FAE4 D9B5 2A35
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# A small program to automatically press the correct buttons that a proprietary
# OBR-measurement/analyzing program analyzes the OBR rawdata.
# The files will also be saved automatically, assuming that CTRL + S
# is the shortcut to open the "save-file" dialogue of OBR-measurement program.
# For each analyzes the reference file will be changed.
#
# This program is a modification of the OBR_buttonpresser_simple.py program.
# It assumes that a "Load Reference File ..." option can be found 70 pixels
# below the "File" button in the menu bar.
# This is the case for a certain version of the proprietary
# OBR-measurement/analyzing program (stated in the accompanying manual to this
# program) for which the OBR_analyzer_simple program was tested for.
#
#
# I decided to restrict myself to the most basic programming statements
# (if possible) and NOT to use functions or classes.
# While I personally don't like this, I hope that this makes it easier for
# the interested but usually not programming user when she or he does not need
# to jump to different places or even files while trying to understand what's
# going on here.
import numpy as np
import win32api, win32con
from pymouse import PyMouse
from pykeyboard import PyKeyboard
from time import sleep, time
def click(x,y):
win32api.SetCursorPos((x,y))
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN,x,y,0,0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP,x,y,0,0)
# Instantiate a mouse and a keyboard.
# A PyMouse() and a PyKeyboard() have certain methods that allow
# easy access to typical features of such peripherals like moving the
# pointer to a certain position or pressing keyboard buttons.
mouse = PyMouse()
keyboard = PyKeyboard()
# Just reminding the user of sth. very important.
highest_numbers=np.arange(27,329,12)
start_heres=np.arange(16,317,12)
analysis_time=5
save_time=5
RRef=True
base_filenames=["F_08_fibre 1_","F_08_fibre 2_","F_08_fibre 3_","F_08_fibre 4_"]
#base_filename="F_08_fibre 1_"
# Instructions for the user what to do, so that the program can determine the
# position of the <FILE> Button
print """\n
Move the mouse pointer over the <FILE> Button in the MENU BAR of the OBR program.
DON'T click the mouse!
The console must remain the active window!
Once this is done, press ENTER (the position of the <FILE> Button will
be detected).
DON'T MOVE THE WINDOW OF THE OBR-PROGRAM AFTERWARDS!\n
"""
# Using raw_input() I make sure that the program will halt here and wait
# for ENTER.
raw_input('Press ENTER when the mouse is over the <FILE> Button.')
print "\n\n<<<<<<<< <FILE> Button position determined >>>>>>>>"
# Here the position of the mouse pointer is determined.
# .position() returns a tuple that contains the x- and y-coordinates
# of the pointer at the time this method is called.
file_button_position = mouse.position()
# file_button_position[0] / file_button_position[1] retrieves the first / second
# entry of the tuple that contains the x- and y-coordinates of the
# <FILE> Button
load_reference_button_position = (file_button_position[0], (file_button_position[1] + 70))
# Some more information for the user.
print """\n
ATTENTION: DON'T MOVE THE WINDOW OF THE OBR-PROGRAM
After pressing ENTER again the OBR window will become active and the
automatic analysis will start.
DON'T make this console the active window after pressing ENTER.
It will work even if you can't see this console.\n
"""
# Wait here for the user to start the automatic measurements.
raw_input('Press ENTER now to start the automatic measurements. >>>')
for base_filename in base_filenames:
#for i in range(0,1000):
start_here= 1 #start_heres[i]
highest_number = 428 #highest_numbers[i]
# Give the user a summary of the input information.
print "\n-----------------------\n"
print "ATTENTION: DON'T MOVE THE WINDOW OF THE OBR-PROGRAM!\n"
print "Automated Measurements have started.\n"
print "Highest file number: %s" % highest_number
print "Starting with measurement: %s" % start_here
print "Base-filename: %s" % base_filename
print "\n-----------------------\n"
## ## ## ## ## Here the analysis-loop starts ## ## ## ## ##
counter = start_here - 1
while counter < highest_number:
# Increase the file number counter
counter += 1
# The numbering of the files should be with four leading zeros but counter
# is just a regular number.
# .zfill() puts leading zeros in front of a number. However, .zfill() can
# be used just on a string. Thus I first convert the number to a string.
load_file_number = str(counter).zfill(4)
if RRef:
new_reference_file_number = str((counter - 1)).zfill(4)
elif not RRef:
print('hi')
new_reference_file_number = str((Refnum)).zfill(4)
print(new_reference_file_number)
# Make the correct filename, by concatenating the base-filename and
# the number for the measurement that is performed.
load_file = base_filename + load_file_number
new_reference_file = base_filename + new_reference_file_number
save_file_older_reference = load_file + '_older_reference'
# First of all I need to make the OBR measurement/analyze program
# the active window. I do this by simply clicking it at a position the
# does not contain anything.
click(load_reference_button_position[0], load_reference_button_position[1])
# Load the new file to be analyzed.
# .press_key() is a method of a PyKeyboard-instance that presses and holds
# the given key and does NOT release it until release_key() is called.
# keyboard.control_l_key selects the left CTRL-key
keyboard.press_key(keyboard.control_l_key)
# .tap_key() taps the given key.
keyboard.tap_key('l')
# Don't forget to release the pressed CTR-key.
keyboard.release_key(keyboard.control_l_key)
# I put in sleep() statements all over this loop to give the
# analysis-PC some time to "settle" between commands.
sleep(0.8)
keyboard.tap_key(keyboard.return_key)
sleep(0.8)
keyboard.tap_key('y')
sleep(0.8)
load_filetoluna=load_file + '.obr'
keyboard.type_string(load_filetoluna)
sleep(0.8)
keyboard.tap_key(keyboard.return_key)
# It takes some time to analyze the file.
sleep(analysis_time)
#if RRef:
## Now save the file.
#keyboard.press_key(keyboard.control_l_key)
#keyboard.tap_key('s')
#keyboard.release_key(keyboard.control_l_key)
#sleep(1)
## This is the file analyzed with the "older" reference.
#keyboard.type_string(save_file_older_reference)
#sleep(1)
#keyboard.tap_key(keyboard.return_key)
#sleep(save_time)
# Load the new reference (which will be the previous measurement file).
click(load_reference_button_position[0], load_reference_button_position[1])
click(file_button_position[0], file_button_position[1])
sleep(0.8)
click(load_reference_button_position[0], load_reference_button_position[1])
keyboard.tap_key(keyboard.return_key)
sleep(0.8)
new_reference_filetoluna=new_reference_file + '.obr'
print(new_reference_filetoluna)
keyboard.type_string(new_reference_filetoluna)
sleep(0.8)
keyboard.tap_key(keyboard.return_key)
sleep(0.8)
# When a reference file is loaded the OBR program opens a popup
# saying this to the user. It may take some time before this popup
# appears.
keyboard.tap_key(keyboard.return_key)
# The loaded file will now be analyzed with the new reference.
sleep(analysis_time)
# And save this file, too.
keyboard.press_key(keyboard.control_l_key)
keyboard.tap_key('s')
keyboard.release_key(keyboard.control_l_key)
sleep(0.8)
keyboard.type_string(load_file)
sleep(0.8)
keyboard.tap_key(keyboard.return_key)
sleep(save_time)
print "Analyzed %s" % load_file
# To give the user some time to abort the program.
sleep(0.8)