28 from __future__
import division
31 VERSION =
'v.00.00 --- 2010 April 12'
35 if sys.version_info[0] >= 3:
37 import tkinter.font
as tkFont
38 import tkinter.messagebox
as tkMessageBox
49 if not 'profile' in dir():
82 prog = urmCutland.UrmCutlandProg(
'')
85 urm = urmCutland.UrmCutland()
96 monospace = tkFont.Font(w, size=10, family=
'courier')
99 hide_qJmnq1 = tk.IntVar()
103 hide_Tnn = tk.IntVar()
107 show_godel_numbers = tk.IntVar()
110 show_godel_prog = tk.IntVar()
113 show_godel_regs = tk.IntVar()
116 show_factors = tk.IntVar()
138 global nb_runned, num_inst, prog
140 src = str(l_src.get(
'1.0', tk.END))
142 prog = urmCutland.UrmCutlandProg(src)
144 prog = urmCutland.UrmCutlandProg(
'')
154 def inst_to_str(num):
156 global hide_qJmnq1, hide_Tnn, num_inst, prog, show_godel_numbers
158 c = (
'*' if num == num_inst
160 if ((hide_Tnn.get()
and (prog[num].inst() == urmCutland.T)
161 and (prog[num].a() == prog[num].b()))
162 or (hide_qJmnq1.get()
and (prog[num].inst() == urmCutland.J)
163 and (prog[num].
c() == num + 1))):
164 s = num_inst_to_str(num)
166 s =
'{0}{1}'.format(num_inst_to_str(num), prog[num])
167 if show_godel_numbers.get():
173 def num_inst_to_str(num):
175 global num_inst, prog
177 return (
'{{0:{0}}}){{1}}'.format(len(str(len(prog))))).format(num,
178 '*' if num == num_inst
184 """Exécute nb (ou toutes si nb == None) instructions du programme dans l'URM
186 Pre: nb: naturel ou None"""
187 global nb_runned, num_inst, prog, stop
189 b_run.config(relief=tk.SUNKEN, state=tk.DISABLED)
191 while ((nb ==
None)
or (nb > 0))
and (num_inst <= len(prog))
and (
not stop):
197 time.sleep(sleep_delay/1000)
199 num_inst = urm.run(prog, i=num_inst, nb=1)[0]
208 b_run.config(relief=tk.RAISED, state=tk.NORMAL)
217 tkMessageBox.showinfo(
'About...',
220 !!! Work in progress !!!
222 (c) Olivier Pirson --- DragonSoft
228 Python {3}""".format(VERSION, DSPython.DS_web, DSPython.VERSION, sys.version))
232 def cmd_clear_regs():
235 urm = urmCutland.UrmCutland()
243 l_prog.delete(0, tk.END)
244 l_src.delete(
'1.0', tk.END)
253 def cmd_compile_run():
264 def cmd_num_inst(event):
268 n = int(str(event.widget.get()))
277 if tkMessageBox.askyesno(
'Quit?',
'Quit URM of Cutland Tk?'):
284 global num_inst, nb_runned
296 urm = urmCutland.UrmCutland()
302 def cmd_select_inst(event):
303 global l_prog, num_inst
305 i = l_prog.curselection()
306 num_inst = (int(i[0]) + 1
if len(i) > 0
312 def cmd_change_delay(event):
313 global e_delay, sleep_delay
319 e_reg.delete(0, tk.END)
323 def cmd_change_reg(event):
324 global e_reg, num_reg, urm
327 if (s !=
'')
and (s[-1] ==
':'):
329 num_reg = max(1, int(s[:-1]))
330 e_reg.delete(0, tk.END)
333 e_reg.delete(0, tk.END)
334 e_reg.insert(tk.END,
':')
342 e_reg.delete(0, tk.END)
344 e_reg.delete(0, tk.END)
349 def cmd_select_reg(event):
350 global l_regs, num_reg
352 i = l_regs.curselection()
353 num_reg = (int(i[0]) + 1
if len(i) > 0
371 def update_godel_prog():
372 global godel_prog, l_godel_prog, prog
374 if show_godel_prog.get():
375 godel_prog = prog.godelnumber()
376 l_godel_prog.config(text=(
'{0}' if godel_prog < 10**20
377 else '{0:e}').format(godel_prog))
379 l_godel_prog.config(text=
'')
383 def update_godel_regs():
384 global godel_regs, l_godel_regs, urm
386 if show_godel_regs.get():
387 godel_regs = urm.godelnumber()
388 l_godel_regs.config(text=(
'{0}' if godel_regs < 10**20
389 else '{0:e}').format(godel_regs))
391 l_godel_regs.config(text=
'')
395 def update_nb_runned():
396 global l_nb_runned, nb_runned
398 l_nb_runned.config(text=
'{0} runned'.format(nb_runned))
402 def update_num_inst():
403 global l_inst, num_inst, num_inst_old
405 if num_inst_old == num_inst:
407 if (num_inst_old !=
None)
and (num_inst_old <= l_prog.size()):
408 l_prog.delete(num_inst_old - 1)
409 l_prog.insert(num_inst_old - 1, inst_to_str(num_inst_old))
410 if num_inst <= l_prog.size():
411 l_prog.delete(num_inst - 1)
412 l_prog.insert(num_inst - 1, inst_to_str(num_inst))
413 num_inst_old = num_inst
414 l_inst.config(text=num_inst_to_str(num_inst))
418 def update_num_reg():
419 global l_reg, num_reg, urm
421 l_reg.config(text=(
'{{0:{0}}}'.format(len(str(len(urm))))).format(num_reg))
426 global l_prog, num_inst, num_inst_old, prog
428 l_prog.delete(0, tk.END)
429 for i
in range(1, len(prog) + 1):
430 l_prog.insert(tk.END, inst_to_str(i))
431 num_inst_old = num_inst
439 def update_registers():
440 global l_regs, show_factors, urm
444 len_r = max(len_r, r)
445 len_r = len(str(len_r))
447 l_regs.delete(0, tk.END)
448 for i
in range(1, len(urm) + 1):
449 if show_factors.get()
and (urm[i] > 0):
450 p = factors.primaries(urm[i])
451 s = ((
'{{0:{0}}}: {{1:{1}}} = {{2}}'.format(len(str(len(urm))), len_r))
452 .format(i, urm[i], factors.primaries_str(p, times=
' .')))
454 s = ((
'{{0:{0}}}: {{1:{1}}} = {{2}}'.format(len(str(len(urm))), len_r))
455 .format(i, urm[i], factors.primaries_str(p)))
457 s = (
'{{0:{0}}}: {{1:{1}}}'.format(len(str(len(urm))), len_r)).format(i, urm[i])
458 l_regs.insert(tk.END, s)
468 w.title(
'URM of Cutland Tk (!!! Work in progress !!!)')
470 w.protocol(
'WM_DELETE_WINDOW', cmd_quit)
478 b_run = tk.Button(f, text=
'Compile & Run', command=cmd_compile_run)
479 b_run.grid(row=1, column=1)
480 tk.Frame(f, width=5).grid(row=1, column=2)
481 tk.Button(f, text=
'Restart', command=cmd_restart).grid(row=1, column=5)
482 tk.Frame(f, width=5).grid(row=1, column=6)
484 tk.Button(f, text=
'Step', command=cmd_step).grid(row=1, column=7)
485 tk.Button(f, text=
'Next', state=tk.DISABLED).grid(row=1, column=8)
486 tk.Button(f, text=
'Continue', state=tk.DISABLED).grid(row=1, column=9)
487 tk.Button(f, text=
'Finish', command=cmd_finish).grid(row=1, column=10)
488 tk.Frame(f, width=5).grid(row=1, column=11)
489 tk.Button(f, text=
'Stop', command=cmd_stop).grid(row=1, column=12)
491 tk.Frame(f, width=20).grid(row=1, column=13)
492 tk.Button(f, text=
'Help', state=tk.DISABLED).grid(row=1, column=14)
493 tk.Button(f, text=
'About', command=cmd_about).grid(row=1, column=15)
494 tk.Frame(f, width=5).grid(row=1, column=16)
495 tk.Button(f, text=
'Quit', command=cmd_quit).grid(row=1, column=17)
497 f.grid(row=1, column=1, sticky=tk.W)
499 tk.Frame(f, height=5).grid(row=2, column=1)
507 tk.Button(f, text=
'Load', state=tk.DISABLED).grid(row=1, column=1, sticky=tk.W)
508 tk.Button(f, text=
'Save', state=tk.DISABLED).grid(row=1, column=2, sticky=tk.W)
509 tk.Button(f, text=
'Clear', command=cmd_clear_regs).grid(row=1, column=3, sticky=tk.W)
510 tk.Frame(f, height=5).grid(row=2, column=1)
513 l_reg = tk.Label(f, text=
'', font=monospace)
514 l_reg.grid(row=3, column=1, sticky=tk.W)
517 e_reg = tk.Entry(f, width=5, font=monospace)
518 e_reg.bind(
'<Return>', cmd_change_reg)
520 e_reg.grid(row=3, column=2, sticky=tk.W)
522 tk.Label(f, text=
'Registers |').grid(row=3, column=3, sticky=tk.E)
525 l_regs = tk.Listbox(f, height=20, width=30, font=monospace)
526 l_regs.bind(
'<ButtonRelease-1>', cmd_select_reg)
527 l_regs.grid(row=4, column=1, columnspan=3, sticky=tk.N)
529 tk.Checkbutton(f, text=
"Gödel's number:", variable=show_godel_regs,
530 command=update_godel_regs).grid(row=5, column=1, sticky=tk.W)
532 l_godel_regs = tk.Label(f, text=godel_regs)
533 l_godel_regs.grid(row=5, column=2, columnspan=2, sticky=tk.W)
535 tk.Checkbutton(f, text=
'Show factors', variable=show_factors,
536 command=update_registers).grid(row=6, column=1, columnspan=3, sticky=tk.W)
539 tk.Button(f, text=
'Load', state=tk.DISABLED).grid(row=1, column=4, sticky=tk.W)
540 tk.Button(f, text=
'Save', state=tk.DISABLED).grid(row=1, column=5, sticky=tk.W)
541 tk.Button(f, text=
'Run', command=cmd_run).grid(row=1, column=6, sticky=tk.W)
542 tk.Frame(f, height=5).grid(row=2, column=4)
545 l_inst = tk.Label(f, text=num_inst_to_str(num_inst), font=monospace)
546 l_inst.grid(row=3, column=4, sticky=tk.W)
549 l_nb_runned = tk.Label(f, text=
'{0} runned'.format(nb_runned))
550 l_nb_runned.grid(row=3, column=5, sticky=tk.W)
552 tk.Label(f, text=
'Program |').grid(row=3, column=6, sticky=tk.E)
555 l_prog = tk.Listbox(f, height=20, width=25, font=monospace)
556 l_prog.bind(
'<ButtonRelease-1>', cmd_select_inst)
557 l_prog.grid(row=4, column=4, columnspan=3, sticky=tk.N)
559 tk.Checkbutton(f, text=
"Gödel's number:", variable=show_godel_prog,
560 command=update_godel_prog).grid(row=5, column=4, sticky=tk.W)
562 l_godel_prog = tk.Label(f, text=godel_prog)
563 l_godel_prog.grid(row=5, column=5, columnspan=2, sticky=tk.W)
565 tk.Checkbutton(f, text=
"Show Gödel's numbers", variable=show_godel_numbers,
566 command=update_prog).grid(row=6, column=4, columnspan=3, sticky=tk.W)
568 tk.Checkbutton(f, text=
'Hide', variable=hide_Tnn,
569 command=update_prog).grid(row=7, column=4, columnspan=1, sticky=tk.W)
570 tk.Label(f, text=
'T(n,n)', font=monospace).grid(row=7, column=5, columnspan=2, sticky=tk.W)
572 tk.Checkbutton(f, text=
'Hide', variable=hide_qJmnq1,
573 command=update_prog).grid(row=8, column=4, columnspan=3, sticky=tk.W)
574 tk.Label(f, text=
'q) J(m,n,q+1)', font=monospace).grid(row=8, column=5, columnspan=2, sticky=tk.W)
576 tk.Checkbutton(f, text=
'Delay:', variable=sleep,
577 command=
lambda : cmd_change_delay(
None)).grid(row=9, column=4,
578 columnspan=3, sticky=tk.W)
580 e_delay = tk.Entry(f, width=5)
581 e_delay.insert(tk.END, str(sleep_delay))
582 e_delay.bind(
'<Return>', cmd_change_delay)
584 e_delay.grid(row=9, column=5, sticky=tk.W)
585 tk.Label(f, text=
'ms').grid(row=9, column=6, sticky=tk.W)
588 tk.Button(f, text=
'Load', state=tk.DISABLED).grid(row=1, column=7, sticky=tk.W)
589 tk.Button(f, text=
'Save', state=tk.DISABLED).grid(row=1, column=8, sticky=tk.W)
590 tk.Button(f, text=
'Clear', command=cmd_clear_src).grid(row=1, column=9, sticky=tk.N)
591 tk.Button(f, text=
'Compile', command=cmd_compile).grid(row=1, column=10, sticky=tk.N)
592 tk.Frame(f, height=5).grid(row=7, column=1)
595 tk.Label(f, text=
'Source |').grid(row=3, column=7, columnspan=4, sticky=tk.E)
596 l_src = tk.Text(f, height=21, width=50, font=monospace)
597 l_src.grid(row=4, column=7, rowspan=2, columnspan=4, sticky=tk.N)
598 l_src.insert(tk.END,
"""3) i(ADD) # include ADD
600 10) J(3,4,11) # always next instruction
602 16) S(2) # R2 <- R2 + 1
603 17) S(2) # R2 <- R2 + 1""")
605 f.grid(row=3, column=1)