MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / SortDemo

Class SortDemo

tools/python-3.11.9-amd64/Tools/demo/sortvisu.py:484–623  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

482# Sort demo class -- usable as a Grail applet
483
484class SortDemo:
485
486 def __init__(self, master, size=15):
487 self.master = master
488 self.size = size
489 self.busy = 0
490 self.array = Array(self.master)
491
492 self.botframe = Frame(master)
493 self.botframe.pack(side=BOTTOM)
494 self.botleftframe = Frame(self.botframe)
495 self.botleftframe.pack(side=LEFT, fill=Y)
496 self.botrightframe = Frame(self.botframe)
497 self.botrightframe.pack(side=RIGHT, fill=Y)
498
499 self.b_qsort = Button(self.botleftframe,
500 text="Quicksort", command=self.c_qsort)
501 self.b_qsort.pack(fill=X)
502 self.b_isort = Button(self.botleftframe,
503 text="Insertion sort", command=self.c_isort)
504 self.b_isort.pack(fill=X)
505 self.b_ssort = Button(self.botleftframe,
506 text="Selection sort", command=self.c_ssort)
507 self.b_ssort.pack(fill=X)
508 self.b_bsort = Button(self.botleftframe,
509 text="Bubble sort", command=self.c_bsort)
510 self.b_bsort.pack(fill=X)
511
512 # Terrible hack to overcome limitation of OptionMenu...
513 class MyIntVar(IntVar):
514 def __init__(self, master, demo):
515 self.demo = demo
516 IntVar.__init__(self, master)
517 def set(self, value):
518 IntVar.set(self, value)
519 if str(value) != '0':
520 self.demo.resize(value)
521
522 self.v_size = MyIntVar(self.master, self)
523 self.v_size.set(size)
524 sizes = [1, 2, 3, 4] + list(range(5, 55, 5))
525 if self.size not in sizes:
526 sizes.append(self.size)
527 sizes.sort()
528 self.m_size = OptionMenu(self.botleftframe, self.v_size, *sizes)
529 self.m_size.pack(fill=X)
530
531 self.v_speed = StringVar(self.master)
532 self.v_speed.set("normal")
533 self.m_speed = OptionMenu(self.botleftframe, self.v_speed,
534 "single-step", "normal", "fast", "fastest")
535 self.m_speed.pack(fill=X)
536
537 self.b_step = Button(self.botleftframe,
538 text="Step", command=self.c_step)
539 self.b_step.pack(fill=X)
540
541 self.b_randomize = Button(self.botrightframe,

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected