Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
sortvisu.SortDemo Class Reference

List of all members.

Public Member Functions

def __init__
def resize
def c_qsort
def c_isort
def c_ssort
def c_bsort
def c_demo
def c_randomize
def c_uniform
def c_distinct
def run
def c_cancel
def c_step
def c_quit

Public Attributes

 master
 size
 busy
 array
 botframe
 botleftframe
 botrightframe
 b_qsort
 b_isort
 b_ssort
 b_bsort
 demo
 v_size
 m_size
 v_speed
 m_speed
 b_step
 b_randomize
 b_uniform
 b_distinct
 b_demo
 b_cancel
 b_quit

Detailed Description

Definition at line 484 of file sortvisu.py.


Constructor & Destructor Documentation

def sortvisu.SortDemo.__init__ (   self,
  master,
  size = 15 
)

Definition at line 486 of file sortvisu.py.

00486 
00487     def __init__(self, master, size=15):
00488         self.master = master
00489         self.size = size
00490         self.busy = 0
00491         self.array = Array(self.master)
00492 
00493         self.botframe = Frame(master)
00494         self.botframe.pack(side=BOTTOM)
00495         self.botleftframe = Frame(self.botframe)
00496         self.botleftframe.pack(side=LEFT, fill=Y)
00497         self.botrightframe = Frame(self.botframe)
00498         self.botrightframe.pack(side=RIGHT, fill=Y)
00499 
00500         self.b_qsort = Button(self.botleftframe,
00501                               text="Quicksort", command=self.c_qsort)
00502         self.b_qsort.pack(fill=X)
00503         self.b_isort = Button(self.botleftframe,
00504                               text="Insertion sort", command=self.c_isort)
00505         self.b_isort.pack(fill=X)
00506         self.b_ssort = Button(self.botleftframe,
00507                               text="Selection sort", command=self.c_ssort)
00508         self.b_ssort.pack(fill=X)
00509         self.b_bsort = Button(self.botleftframe,
00510                               text="Bubble sort", command=self.c_bsort)
00511         self.b_bsort.pack(fill=X)
00512 
00513         # Terrible hack to overcome limitation of OptionMenu...
00514         class MyIntVar(IntVar):
00515             def __init__(self, master, demo):
00516                 self.demo = demo
00517                 IntVar.__init__(self, master)
00518             def set(self, value):
00519                 IntVar.set(self, value)
00520                 if str(value) != '0':
00521                     self.demo.resize(value)
00522 
00523         self.v_size = MyIntVar(self.master, self)
00524         self.v_size.set(size)
00525         sizes = [1, 2, 3, 4] + list(range(5, 55, 5))
00526         if self.size not in sizes:
00527             sizes.append(self.size)
00528             sizes.sort()
00529         self.m_size = OptionMenu(self.botleftframe, self.v_size, *sizes)
00530         self.m_size.pack(fill=X)
00531 
00532         self.v_speed = StringVar(self.master)
00533         self.v_speed.set("normal")
00534         self.m_speed = OptionMenu(self.botleftframe, self.v_speed,
00535                                   "single-step", "normal", "fast", "fastest")
00536         self.m_speed.pack(fill=X)
00537 
00538         self.b_step = Button(self.botleftframe,
00539                              text="Step", command=self.c_step)
00540         self.b_step.pack(fill=X)
00541 
00542         self.b_randomize = Button(self.botrightframe,
00543                                   text="Randomize", command=self.c_randomize)
00544         self.b_randomize.pack(fill=X)
00545         self.b_uniform = Button(self.botrightframe,
00546                                   text="Uniform", command=self.c_uniform)
00547         self.b_uniform.pack(fill=X)
00548         self.b_distinct = Button(self.botrightframe,
00549                                   text="Distinct", command=self.c_distinct)
00550         self.b_distinct.pack(fill=X)
00551         self.b_demo = Button(self.botrightframe,
00552                              text="Demo", command=self.c_demo)
00553         self.b_demo.pack(fill=X)
00554         self.b_cancel = Button(self.botrightframe,
00555                                text="Cancel", command=self.c_cancel)
00556         self.b_cancel.pack(fill=X)
00557         self.b_cancel.config(state=DISABLED)
00558         self.b_quit = Button(self.botrightframe,
00559                              text="Quit", command=self.c_quit)
00560         self.b_quit.pack(fill=X)

Here is the caller graph for this function:


Member Function Documentation

def sortvisu.SortDemo.c_bsort (   self)

Definition at line 577 of file sortvisu.py.

00577 
00578     def c_bsort(self):
00579         self.run(bubblesort)

Definition at line 606 of file sortvisu.py.

00606 
00607     def c_cancel(self):
00608         if not self.busy:
00609             self.master.bell()
00610             return
00611         self.array.cancel()

def sortvisu.SortDemo.c_demo (   self)

Definition at line 580 of file sortvisu.py.

00580 
00581     def c_demo(self):
00582         self.run(demosort)

Definition at line 589 of file sortvisu.py.

00589 
00590     def c_distinct(self):
00591         self.run(distinct)

def sortvisu.SortDemo.c_isort (   self)

Definition at line 571 of file sortvisu.py.

00571 
00572     def c_isort(self):
00573         self.run(insertionsort)

def sortvisu.SortDemo.c_qsort (   self)

Definition at line 568 of file sortvisu.py.

00568 
00569     def c_qsort(self):
00570         self.run(quicksort)

def sortvisu.SortDemo.c_quit (   self)

Definition at line 620 of file sortvisu.py.

00620 
00621     def c_quit(self):
00622         if self.busy:
00623             self.array.cancel()
00624         self.master.after_idle(self.master.quit)
00625 
00626 
00627 # Main program -- for stand-alone operation outside Grail

Definition at line 583 of file sortvisu.py.

00583 
00584     def c_randomize(self):
00585         self.run(randomize)

def sortvisu.SortDemo.c_ssort (   self)

Definition at line 574 of file sortvisu.py.

00574 
00575     def c_ssort(self):
00576         self.run(selectionsort)

def sortvisu.SortDemo.c_step (   self)

Definition at line 612 of file sortvisu.py.

00612 
00613     def c_step(self):
00614         if not self.busy:
00615             self.master.bell()
00616             return
00617         self.v_speed.set("single-step")
00618         self.array.setspeed("single-step")
00619         self.array.step()

Definition at line 586 of file sortvisu.py.

00586 
00587     def c_uniform(self):
00588         self.run(uniform)

def sortvisu.SortDemo.resize (   self,
  newsize 
)

Definition at line 561 of file sortvisu.py.

00561 
00562     def resize(self, newsize):
00563         if self.busy:
00564             self.master.bell()
00565             return
00566         self.size = newsize
00567         self.array.setdata(range(1, self.size+1))

def sortvisu.SortDemo.run (   self,
  func 
)

Definition at line 592 of file sortvisu.py.

00592 
00593     def run(self, func):
00594         if self.busy:
00595             self.master.bell()
00596             return
00597         self.busy = 1
00598         self.array.setspeed(self.v_speed.get())
00599         self.b_cancel.config(state=NORMAL)
00600         try:
00601             func(self.array)
00602         except Array.Cancelled:
00603             pass
00604         self.b_cancel.config(state=DISABLED)
00605         self.busy = 0

Here is the caller graph for this function:


Member Data Documentation

Definition at line 490 of file sortvisu.py.

Definition at line 508 of file sortvisu.py.

Definition at line 553 of file sortvisu.py.

Definition at line 550 of file sortvisu.py.

Definition at line 547 of file sortvisu.py.

Definition at line 502 of file sortvisu.py.

Definition at line 499 of file sortvisu.py.

Definition at line 557 of file sortvisu.py.

Definition at line 541 of file sortvisu.py.

Definition at line 505 of file sortvisu.py.

Definition at line 537 of file sortvisu.py.

Definition at line 544 of file sortvisu.py.

Definition at line 492 of file sortvisu.py.

Definition at line 494 of file sortvisu.py.

Definition at line 496 of file sortvisu.py.

Definition at line 489 of file sortvisu.py.

Definition at line 515 of file sortvisu.py.

Definition at line 528 of file sortvisu.py.

Definition at line 533 of file sortvisu.py.

Definition at line 487 of file sortvisu.py.

Definition at line 488 of file sortvisu.py.

Definition at line 522 of file sortvisu.py.

Definition at line 531 of file sortvisu.py.


The documentation for this class was generated from the following file: