@@ -108,25 +108,8 @@ def show_frame(self):
108
108
else :
109
109
self .after (10 , self .show_frame )
110
110
111
- def show_scan_cube_image (self ):
111
+ def show_scan_cube_status (self ):
112
112
113
- for idx , cube_name in enumerate (self .cubeScanList ):
114
- scanimg = {}
115
- try :
116
- scanimg = camera .cv_images [idx ]
117
- if self .scanImageFrame [cube_name ]['wraplength' ] != 10 :
118
- scanimg = Image .fromarray (scanimg ).resize ((108 ,97 ))
119
- scanout = ImageTk .PhotoImage (scanimg )
120
- self .scanImageFrame [cube_name ].configure (image = scanout )
121
- self .scanImageFrame [cube_name ].image = scanout
122
- self .scanImageFrame [cube_name ]['wraplength' ] = 10
123
- self .scanImageFrame [cube_name ]['text' ] = cube_name
124
- except IndexError :
125
- scanimg = {}
126
-
127
- self .after (100 , self .show_scan_cube_image )
128
-
129
- def show_scan_cube_label (self ):
130
113
for idx , sname in enumerate (self .cubeScanList ):
131
114
for crow in range (3 ):
132
115
for ccol in range (3 ):
@@ -140,8 +123,27 @@ def show_scan_cube_label(self):
140
123
if crow == 1 and ccol == 1 :
141
124
self .cubematrix [idx ][crow ][ccol ].config (text = sname )
142
125
self .cubematrix [idx ][crow ][ccol ].config (bg = self ._from_rgb (colorname ))
126
+ if not self .is_use_scan_cube_label :
127
+ self .cubematrix [idx ][crow ][ccol ].grid_remove ()
128
+ else :
129
+ self .cubematrix [idx ][crow ][ccol ].grid (row = crow , column = ccol , ipadx = 1 , ipady = 3 , padx = 2 , pady = 2 )
130
+
131
+ scanimg = {}
132
+ try :
133
+ scanimg = camera .cv_images [idx ]
134
+ if self .scanImageFrame [sname ]['wraplength' ] != 10 :
135
+ scanimg = Image .fromarray (scanimg ).resize ((108 ,97 ))
136
+ scanout = ImageTk .PhotoImage (scanimg )
137
+ self .scanImageFrame [sname ].configure (image = scanout )
138
+ self .scanImageFrame [sname ].image = scanout
139
+ self .scanImageFrame [sname ]['wraplength' ] = 10
140
+ self .scanImageFrame [sname ]['text' ] = sname
143
141
144
- self .after (100 , self .show_scan_cube_label )
142
+ except IndexError :
143
+ scanimg = {}
144
+
145
+
146
+ self .after (100 , self .show_scan_cube_status )
145
147
146
148
def __init__ (self , * args , ** kwargs ):
147
149
super (Solver , self ).__init__ (* args , ** kwargs )
@@ -159,7 +161,7 @@ def __init__(self, *args, **kwargs):
159
161
self .grip_labelframe .pack (side = 'left' , fill = tk .Y , ipadx = 2 , ipady = 2 , padx = 20 , pady = 20 )
160
162
161
163
# Side Grip/Stop Buttons
162
- self .button_names = ['Fix' , 'Release' , 'Infinite' , 'Stop' ]
164
+ self .button_names = ['Fix' , 'Release' , 'Infinite' , 'Stop' , 'Cube Status' ]
163
165
max_button_width = max (map (lambda x : len (x ), self .button_names ))
164
166
self .buttons = {}
165
167
for button_name in self .button_names :
@@ -216,19 +218,16 @@ def __init__(self, *args, **kwargs):
216
218
row_col = self .get_cube_row_col (sname )
217
219
row = row_col [0 ]
218
220
col = row_col [1 ]
219
- self .scanImageFrame [sname ] = tk .Label (self .cube_labelframe , text = "N" , compound = tk .CENTER , bg = "black " )
221
+ self .scanImageFrame [sname ] = tk .Label (self .cube_labelframe , text = sname , compound = tk .CENTER , bg = "lightgray " )
220
222
self .scanImageFrame [sname ].grid (row = row , column = col , padx = 3 , pady = 1 )
221
223
222
224
if self .is_use_scan_cube_label :
223
225
for crow in range (3 ):
224
226
for ccol in range (3 ):
225
227
self .cubematrix [idx ][crow ][ccol ] = tk .Label (self .scanImageFrame [sname ], text = sname , width = 3 , compound = tk .CENTER , bd = 2 , relief = "flat" , bg = "lightgray" )
226
- self .cubematrix [idx ][crow ][ccol ].grid (row = crow , column = ccol , ipadx = 1 , ipady = 3 , padx = 2 , pady = 2 )
228
+ # self.cubematrix[idx][crow][ccol].grid(row=crow, column=ccol, ipadx=1, ipady=3, padx=2, pady=2)
227
229
228
- if self .is_use_scan_cube_label :
229
- self .show_scan_cube_label ()
230
- else :
231
- self .show_scan_cube_image ()
230
+ self .show_scan_cube_status ()
232
231
233
232
self .show_frame ()
234
233
self .scanCubeReset ()
@@ -238,14 +237,12 @@ def scanCubeReset(self):
238
237
239
238
camera .cv_images = []
240
239
scanout = {}
241
- if not self .is_use_scan_cube_label :
242
- cube_image_file = './images/cube.jpg'
243
- if os .path .isfile (cube_image_file ):
244
- scanimg = cv2 .imread (cube_image_file , cv2 .IMREAD_COLOR )
245
- scanimg = cv2 .cvtColor (scanimg , cv2 .COLOR_BGR2RGB )
246
- scanimg = Image .fromarray (scanimg ).resize ((108 ,97 ))
247
- scanout = ImageTk .PhotoImage (scanimg )
248
-
240
+ cube_image_file = './images/cube.jpg'
241
+ if os .path .isfile (cube_image_file ):
242
+ scanimg = cv2 .imread (cube_image_file , cv2 .IMREAD_COLOR )
243
+ scanimg = cv2 .cvtColor (scanimg , cv2 .COLOR_BGR2RGB )
244
+ scanimg = Image .fromarray (scanimg ).resize ((108 ,97 ))
245
+ scanout = ImageTk .PhotoImage (scanimg )
249
246
250
247
for idx , cubename in enumerate (self .cubeScanList ):
251
248
if scanout :
@@ -259,9 +256,19 @@ def scanCubeReset(self):
259
256
camera .cubeColors [idx ][crow ][ccol ] = webcolors .name_to_rgb ("lightgray" )
260
257
261
258
def button_action (self , label ):
262
- if label == 'Stop' or label == 'fix' or label == 'release' or label == 'scramble' or label == 'infinite' :
259
+ if label == 'Stop' or label == 'fix' or label == 'release' or label == 'scramble' :
263
260
self .scanCubeReset ()
264
-
261
+ elif label == 'Infinite' :
262
+ self .scanCubeReset ()
263
+ #
264
+ elif label == 'Cube Status' :
265
+ if self .is_use_scan_cube_label :
266
+ self .is_use_scan_cube_label = False
267
+ self .buttons [label ].config (bg = "green" )
268
+ else :
269
+ self .is_use_scan_cube_label = True
270
+ self .buttons [label ].config (bg = "lightgray" )
271
+
265
272
self .pub .publish (self .channel , label )
266
273
267
274
def refresh_page (self ):
@@ -1351,8 +1358,6 @@ def fsm_runner():
1351
1358
rubiks .stop (hard = False ) # change state here
1352
1359
elif 'scramble cube' == msg :
1353
1360
rubiks .scramble (config = config ) # change state here
1354
- elif 'infinite' == msg :
1355
- rubiks .scramble (config = config ) # change state here
1356
1361
elif 'fix' == msg :
1357
1362
rubiks .command (config = config , type = 'system' , action = 'fix' ) # reflexive state here
1358
1363
elif 'release' == msg :
0 commit comments