Real2Virtual202111

main_controller_01.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
-
|
!
-
!
-
|
|
!
-
!
-
|
|
|
|
!
 
 
 
 
 
 
 
-
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
!
-
!
 
 
 
 
 
-
!
-
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
!
 
 
 
 
 
 
-
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
!
 
 
-
|
|
|
|
|
|
|
|
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
!
 
 
 
 
 
-
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
|
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
!
 
 
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
|
|
|
|
|
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
-
!
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
## License: Apache 2.0. See LICENSE file in root directory.
## Copyright(c) 2017 Intel Corporation. All Rights Reserved.
 
#20230622
 
#####################################################
##              Align Depth to Color               ##
#####################################################
 
# First import the library
import os,sys
#import pyrealsense2 as rs
# Import Numpy for easy array manipulation
#import numpy as np
# Import OpenCV for easy image rendering
#import cv2
import copy
 
import socket
import threading
import sys
from tkinter import *
import tkinter as tk
from tkinter import scrolledtext
#from PIL import Image, ImageTk, ImageOps
import tkinter.ttk as ttk
from tkinter import messagebox
from tkinter import filedialog
import time
 
PORT = 9998
 
class Com:
    def __init__(self,host,window):
        self.host=host
        self.connected=False
        self.soc=None
        self.handle_thread=None
        self.message_window=window
    def set_message_window(self,window):
        print("set_message_window",end='')
        print(self.window)
        self.message_window=window
    def is_connected(sekf):
        return self.connected
    def connect_address(self,address):
        self.host=address
        self.connect()
    def connect(self):
        print("re connect to host "+self.host)
        if self.soc !=None:
            print("close the previous host, "+self.soc.gethostname())
            try:
                self.soc.close()
                self.soc=None
                time.sleep(2.0)
            except:
                print("close failed")
        try:
            #socket.socket ... socket を作成し、socに代入
            self.soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            #IPアドレスがhostのserver socketにsocを接続
            self.soc.connect((self.host,PORT))
        except Exception as e:
            print("connect error.")
            if self.message_window:
                self.message_window.write_message("error when connect to "+self.host+":"+str(PORT))
                self.connected=False
        #受信担当の関数handlerを物threadでうごかすhandle_threadを生成。
        self.handle_thread=threading.Thread(target=self.handler)
        #handle_threadをstart
        self.handle_thread.start()
        self.connected=True
        if self.message_window:
            self.message_window.write_message("connected to "+self.host+":"+str(PORT))
                
    def send_command(self,command):
        if self.soc!=None:
            try:
                self.soc.send(bytes(command,"utf-8"))
            except KeyboardInterrupt:
                if self.message_window:
                    self.message_window.write_message("error when sends "+command + " to "+self.host+":"+str(PORT))
                self.soc.close()
                exit()
        else:
            if self.host is not None:
                self.message_window.write_message("no socket when sends "+command + " to "+self.host+":"+str(PORT))
            else:
                self.message_window.write_message("no host assigned when sends "+command)
    #受信の処理。送信threadとは別に、並行して処理を行う。
    def handler(self):
        print("at client, connected, start handler")
        while self.soc is not None:
            try:
                data = self.soc.recv(1024)
                line="[receive]- {}".format(data.decode("utf-8"))
                print(line)
                #print(self.message_window)
                if self.message_window:
                    self.message_window.write_message("from "+self.host+":"+str(PORT)+", "+line)
                
            except Exception as e:
                if self.message_window:
                    self.message_window.write_message(self.host+":"+str(PORT)+" closed")
                if self.soc is not None:
                    self.soc.close()
                    self.soc=None
                tb=sys.exec_info()[2]
                print("message:{0}".format(e.with_traceback(tb)))
                break
    def close(self):
        self.soc.close()
        self.soc=None
 
class Coms:
    def __init__(self):
        self.coms=[None] #self.coms=[None,None, ...., None]
                         #... number of sub controllers
        
    def connect_all(self):
        self.coms[0]=Com("192.168.1.34",self.message_window)
        #self.coms[1]=Com("192.168.13.129",self.message_window)
        #self.coms[2]=Com("192.168.13.130",self.message_window)
        #self.coms[3]=Com("192.168.13.131",self.message_window)
        #self.coms[4]=Com("192.168.13.132")
        #self.coms[5]=Com("192.168.13.133")
        #self.coms[6]=Com("192.168.13.134")
        #self.coms[7]=Com("192.168.13.16")
        #self.coms[7]=Com("192.168.13.135")
        #self.coms[7]=Com("192.168.1.22")
 
        for i in range(len(self.coms)):
            self.coms[i].connect()
    def connect_com_to_address(self,i,address):
        print("connect_com_to_address("+str(i)+","+address+")")
        if i<0 :
            print("wrong plane number")
            return
        if i>len(self.coms) :
            print("wrong plane number")
        try:
            if self.coms[i] is not None:
                print("coms["+str(i)+"] is not None, connect, ")
                self.coms[i].connect_address(address)
            else:
                print("coms["+str(i)+"] is None, connect, ")
                self.coms[i]=Com(address,self.message_window)
                self.coms[i].connect()
            #self.coms[i].set_message_window(self.message_window)
        except Exception as e:
            print("coms["+str(i)+"] connect error")
            tb=sys.exec_info()[2]
            print("message:{0}".format(e.with_traceback(tb)))
 
    def set_message_window(self,window):
        #print(window)
        self.message_window=window
        for i in range(len(self.coms)):
            if self.coms[i]!=None:
                self.coms[i].set_message_window(window)
            else:
                print("coms["+str(i)+"] is None, set_message_window, ")
    def send_command_to_i(self,i,command):
        if self.coms[i]!=None:
            self.coms[i].send_command(command+"\n")
    def send_command_to_all(self,command):
        for i in range(len(self.coms)):
            if self.coms[i]!=None:
                self.coms[i].send_command(command+"\n")
    def close_all(self):
        for i in range(len(self.coms)):
            if self.coms[i]!=None:
                self.coms[i].close()
            
class Command_Panel:
    def __init__(self,root,coms):
        self.coms=coms
        self.root=root
        self.root.title("command panel")
        self.root.configure(background="white")
        self.root.geometry("850x800")
        self.notebook =ttk.Notebook(root)
        self.main_tab=tk.Frame(self.notebook, bg='white')
        self.script_tab=tk.Frame(self.notebook, bg='white')
        self.notebook.add(self.main_tab, text="main", underline=0)
        self.notebook.add(self.script_tab, text="script")
        self.notebook.pack(expand=True, fill='both', padx=10, pady=10)
 
        yy=10
        self.connect_label=Label(self.main_tab,text="Servers",width=10)
        self.connect_label.place(x=30,y=yy)
        self.connect_button=Button(self.main_tab, text="connect",bd=2,bg='white',command=self.click_connect_button, width=8, relief=RIDGE)
        self.connect_button.place(x=100,y=yy)
        self.set_id_label=Label(self.main_tab,text="set id",width=10)
        self.set_id_label.place(x=200,y=yy)
        self.set_id_button=Button(self.main_tab, text="set id",bd=2,bg='white',command=self.click_set_id_button, width=8, relief=RIDGE)
        self.set_id_button.place(x=270,y=yy)
 
        yy=40
        self.command_label=Label(self.main_tab,text="command", width=8)
        self.command_label.place(x=30,y=yy)
        self.command_field=Entry(self.main_tab,width=50)
        self.command_field.place(x=150,y=yy)
        self.enter_command_button=Button(self.main_tab,text="enter",bd=2,bg='white',command=self.enter_command,width=8,relief=RIDGE)
        self.enter_command_button.place(x=550,y=yy)
        self.run_script_button=Button(self.main_tab,text="run script",bd=2,bg='white',command=self.run_script,width=8,relief=RIDGE)
        self.run_script_button.place(x=650,y=yy)
 
        yy=70
        self.command_field_label_1=Label(self.main_tab,text="command for ith", width=15)
        self.command_field_label_1.place(x=30,y=yy)
        self.command_field_for_ith_server=Entry(self.main_tab,width=40)
        self.command_field_for_ith_server.place(x=150,y=yy)
        self.ith_server_field=Entry(self.main_tab,width=5)
        self.ith_server_field.place(x=450,y=yy)
        self.ith_enter_button=Button(self.main_tab,text="enter",bd=2,bg='white',command=self.enter_ith_command,width=8,relief=RIDGE)
        self.ith_enter_button.place(x=550,y=yy)
 
        yy=100
        self.command_field_label_2=Label(self.main_tab,text="command for all", width=15)
        self.command_field_label_2.place(x=30,y=yy)
        self.command_field_for_all_server=Entry(self.main_tab,width=50)
        self.command_field_for_all_server.place(x=150,y=yy)
        self.all_enter_button=Button(self.main_tab,text="enter",bd=2,bg='white',command=self.enter_all_command,width=8,relief=RIDGE)
        self.all_enter_button.place(x=550,y=yy)
        self.clear_message_button=Button(self.main_tab,text="clear_message",bd=2,bg='white',command=self.clear_message,width=8,relief=RIDGE)
        self.clear_message_button.place(x=650,y=yy)
 
        yy=130
        self.message_frame=tk.Frame(self.main_tab,width=50,height=30)
        self.message_frame.place(x=30,y=yy)
        self.message_area=scrolledtext.ScrolledText(self.message_frame)
        self.message_area.pack()
 
        yy=10
        self.dir_name_label=Label(self.script_tab,text="dir name",width=10)
        self.dir_name_label.place(x=30,y=yy)
        self.dir_name_field=Entry(self.script_tab,width=50)
        self.dir_name_field.place(x=100,y=yy)
        #self.read_button=Button(self.script_tab, text="read",bd=2,bg='white',command=self.click_read_button, width=8, relief=RIDGE)
        #self.read_button.place(x=500,y=yy)
        self.dir_button=Button(self.script_tab, text="directory",bd=2,bg='white',command=self.click_dir_button, width=10, relief=RIDGE)
        self.dir_button.place(x=570,y=yy)
 
        yy=50
        self.file_name_label=Label(self.script_tab,text="file name",width=10)
        self.file_name_label.place(x=30,y=yy)
        self.file_name_field=Entry(self.script_tab,width=50)
        self.file_name_field.place(x=100,y=yy)
        self.read_button=Button(self.script_tab, text="read",bd=2,bg='white',command=self.click_read_button, width=8, relief=RIDGE)
        self.read_button.place(x=500,y=yy)
        self.dir_button=Button(self.script_tab, text="select",bd=2,bg='white',command=self.click_select_file_button, width=10, relief=RIDGE)
        self.dir_button.place(x=570,y=yy)
 
        yy=100
        self.script_frame=tk.Frame(self.script_tab,width=50,height=100)
        self.script_frame.place(x=50,y=yy)
        self.script_area=scrolledtext.ScrolledText(self.script_frame)
        self.script_area.pack()
        
        #self.run_script()
        self.set_script()
 
    def set_script(self):
        #self.script_area.insert(tk.END,"self.ex(\"connect 0 to \\\"192.168.1.21\\\"\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"connect 1 to \\\"192.168.1.19\\\"\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"connect 2 to \\\"192.168.1.20\\\"\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"connect 3 to \\\"192.168.1.22\\\"\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"connect 4 to \\\"192.168.1.12\\\"\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"connect 5 to \\\"192.168.1.14\\\"\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"connect 6 to \\\"192.168.1.15\\\"\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"connect 7 to \\\"192.168.1.7\\\"\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"#connect 7 to \\\"192.168.1.22\\\"\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"send \\\"set depth 0\\\" to 0\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"send \\\"set depth 30\\\" to 1\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"send \\\"set depth 60\\\" to 2\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"send \\\"set depth 90\\\" to 3\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"send \\\"set depth 120\\\" to 4\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"send \\\"set depth 150\\\" to 5\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"send \\\"set depth 180\\\" to 6\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"send \\\"set depth 210\\\" to 7\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"send \\\"clear canvas\\\" to all\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"send \\\"add ball 170 170 100 120 red\\\" to all\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"send \\\"add ball 170 170 100 100 black\\\" to all\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"send \\\"add ball 250 350 80 90 green\\\" to all\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"send \\\"add ball 250 350 80 70 black\\\" to all\")\n")
        #self.script_area.insert(tk.END,"self.ex(\"send \\\"show canvas\\\" to all\")\n")
        self.script_area.insert(tk.END,"for i in range(20):\n")
        self.script_area.insert(tk.END,"\tself.ex(\"send \\\"clear canvas\\\" to all\")\n")
        self.script_area.insert(tk.END,"\tself.ex(\"send \\\"add ball 170 \"+str(70+20*i)+\" \"+str(70+10*i)+\" 120 red\\\" to all\")\n")
        self.script_area.insert(tk.END,"\tself.ex(\"send \\\"add ball 170 \"+str(70+20*i)+\" \"+str(70+10*i)+\" 100 black\\\" to all\")\n")
        self.script_area.insert(tk.END,"\tself.ex(\"send \\\"add ball 250 350 80 90 green\\\" to all\")\n")
        self.script_area.insert(tk.END,"\tself.ex(\"send \\\"add ball 250 350 80 70 black\\\" to all\")\n")
        self.script_area.insert(tk.END,"\tself.ex(\"send \\\"show canvas\\\" to all\")\n")
        self.script_area.insert(tk.END,"\ttime.sleep(0.5)\n")
 
    def click_read_button(self):
        fn=self.file_name_field.get()
        print("fn="+fn)
        f=None
        try:
            f=open(fn,"r")
        except Exception as e:
            print("file open error.")
            tb=sys.exec_info()[2]
            print("message:{0}".format(e.with_traceback(tb)))
            return
        try:
            self.script_area.delete(1.0,END)
            line=f.readline()
            while line:
                print(line)
                self.script_area.insert(END,line)
                line=f.readline()
            f.close()
        except Exception as e:
            print("file "+fn+" read error")
            tb=sys.exec_info()[2]
            print("message:{0}".format(e.with_traceback(tb)))
    def click_dir_button(self):
        iDir = os.path.abspath(os.path.dirname(__file__))
        folder_name=tk.filedialog.askdirectory(initialdir=iDir)
        if len(folder_name)==0:
            print("cancel selcting folder")
        else:
            self.dir_name_field.insert(END,folder_name)
    def click_select_file_button(self):
        fType = [("python", "*.py")]
        iDir=""
        xdir=self.dir_name_field.get()
        if xdir==None or xdir=="":
            iDir=os.path.abspath(os.path.dirname(__file__))
        else:
            iDir=xdir
        iFilePath=filedialog.askopenfilename(filetypes=fType, initialdir=iDir)
        if iFilePath==None or iFilePath=="":
            print("cancel")
        else:
            self.file_name_field.delete(0,END)
            self.file_name_field.insert(END,iFilePath)
 
    def enter_command(self):
        print("enter_command")
        self.ex()
        
    def run_script(self):
        self.script=self.script_area.get(0.,END)
        print("run_script:"+self.script)
        exec(self.script)
 
    def enter_ith_command(self):
        command=self.command_field_for_ith_server.get()
        ith_s=self.ith_server_field.get()
        ith=int(ith_s)
        print("send "+command+" to "+str(ith))
        self.write_message("send "+command+" to "+str(ith))
        self.coms.send_command_to_i(ith,command)
        self.command_field_for_ith_server.delete(0,END)
 
    def enter_all_command(self):
        command=self.command_field_for_all_server.get()
        print("send "+command+" to all")
        self.write_message("send "+command+" to all")
        self.coms.send_command_to_all(command)
        self.command_field_for_all_server.delete(0,END)
 
    def ex(self,command):
        print("parse "+command)
        command=self.r_b(command)
        if self.parse_command(command):
            self.write_message("OK")
            print("OK")
        else:
            self.write_message("ERROR")
            print("ERROR")
 
    def write_message(self, message):
        self.message_area.insert(tk.END,message)
        self.message_area.insert(tk.END,'\n')
    def clear_message(self):
        self.message_area.delete("1.0",END)
 
    def click_connect_button(self):
        self.coms.connect_all()
    def click_set_id_button(self):
        self.ex("send \"set id=\"y-l\"\" to 0")
        self.ex("send \"set id=\"y-r\"\" to 1")
        self.ex("send \"set id=\"x\"\" to 2")
        self.ex("send \"set id 90 \" to 3")
        self.ex("send \"set id 120 \" to 4")
        self.ex("send \"set id 150 \" to 5")
        self.ex("send \"set id 180 \" to 6")
        self.ex("send \"set id 210 \" to 7")
 
    #
    # command
    #    send "<command>" to <i>
    #    send "<command>" to all
    #    connect <i> to "<host ip>"
    #
    def parse_command(self,command):
        rest=[""]
        strc=[""]
        ix=[""]
        command=self.r_b(command)
        print("parse_command("+command+")")
        if self.parse_key("send ",command,rest):
            print("parse_key(send "+command+","+rest[0]+")")
            command=self.r_b(rest[0])
            if self.parse_String_Constant(command,strc,rest):
                print("strc="+strc[0]+",rest="+rest[0])
                command=self.r_b(rest[0])
                if self.parse_key("to ",command,rest):
                    command=self.r_b(rest[0])
                    if self.parse_key("all",command,rest):
                        self.write_message("send \""+strc[0]+"\" to all")
                        self.coms.send_command_to_all(strc[0])
                        #self.command_field_for_all_server.delete(0,END)
                        return True
                    elif self.parse_p_int(command,ix,rest):
                        self.write_message("send \""+strc[0]+"\" to "+str(ix[0]))
                        self.coms.send_command_to_i(ix[0],strc[0])
                        return True
                    return False
                return False
            return False
        if self.parse_key("connect ",command,rest):
            print("parse_key(connect "+command+","+rest[0]+")")
            command=self.r_b(rest[0])
            if self.parse_p_int(command,ix,rest):
                print("parse_p_int("+command+","+str(ix[0])+","+rest[0]+")")
                command=self.r_b(rest[0])
                if self.parse_key("to ",command,rest):
                    print("parse_key(to "+command+","+rest[0]+")")
                    command=self.r_b(rest[0])
                    if self.parse_String_Constant(command,strc,rest):
                        self.write_message("connect "+str(ix[0])+" to "+strc[0])
                        print("connect "+str(ix[0])+" to "+strc[0])
                        self.coms.connect_com_to_address(ix[0],strc[0])
                        return True
                    return False
                return False
            return False
        return False
    def parse_key(self,key,inx,rest):
        keylen=len(key)
        inlen=len(inx)
        if inx.startswith(key):
            rest[0]=inx[keylen:inlen]
            return True
        rest[0]=inx
        return False
 
    def parse_p_int(self,command,ix,rest):
        print("parse_p_int("+command+",ix,rest)")
        i=0
        c=command[0]
        if c in ['0','1','2','3','4','5','6','7','8','9']:
            clen=len(command)
            while True:
                i=i*10+int(c)
                command=command[1:clen]
                clen=len(command)
                if clen==0:
                    ix[0]=i
                    rest[0]=""
                    return True
                print("parse_p_int command="+command)
                c=command[0]
                if not (c in ['0','1','2','3','4','5','6','7','8','9']):
                    ix[0]=i
                    rest[0]=command
                    return True
        rest[0]=command
        ix[0]=0
        return False
 
    def r_b(self,inx):
        rx=[""]
        while self.parse_key(" ",inx,rx):
            inx=rx[0]
        return rx[0]
 
    def parse_String_Constant(self,inx,strc,rest):
        rx=[""]
        xstr=""
        if self.parse_key('"',inx,rx):
            inx=rx[0]
            fx=inx[0]
            xlen=len(inx)
            while fx!='"':
                if xlen==0:
                    return False
                if fx=='\\':
                   inx=inx[1:xlen]
                else:
                   xstr=xstr+fx
                xlen=len(inx)
                inx=inx[1:xlen]
                fx=inx[0]
            if self.parse_key('"',inx,rx):
                strc[0]=xstr
                rest[0]=rx[0]
                return True
        return False
 
 
if __name__=="__main__":
    root=Tk()
    coms=Coms()
    p=Command_Panel(root,coms)
    coms.set_message_window(p)
    root.mainloop()
    
 

Counter: 153, today: 1, yesterday: 0

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS