TankorSmash

GUI2.py

Nov 17th, 2011
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.31 KB | None | 0 0
  1. from Tkinter import *  
  2. import squares
  3. import tkFont
  4. import threading
  5.  
  6.  
  7.  
  8. class Debug(Frame):
  9.     '''Main debug frame that updates with squares'''
  10.    
  11.     def __init__(self, parent=None, **options):
  12.         Frame.__init__(self, parent, **options)
  13.        
  14.         print 'packed debug'
  15.        
  16.         self.lbl_Title = Label(self, text='DEBUG!')
  17.        
  18.         self.lbl_Title.grid(column=0, row=0, sticky='we')
  19.         #self.lbl_Title.config(bg='black', )
  20.         #self.lbl_Title.rowconfigure(0, weight=2, )
  21.        
  22.         self.TEST = 123
  23.        
  24.         self.bind('a', (lambda event: self.changeTEST(222)),)
  25.        
  26.         self.grid(column = 0, row = 0,)
  27.         #self.build()
  28.        
  29.    
  30.     def update(self):
  31.         '''update entries, and send them over to squares'''
  32.        
  33.         pass
  34.    
  35.     def changeTEST(self, value):
  36.         '''change TEST to value'''
  37.         print 'changed TEST'
  38.         self.TEST = value
  39.    
  40.     def build(self):
  41.         '''create entry widgets'''
  42.         root.bind('<Destroy>', (lambda e:root.destroy))
  43.        
  44.         self.buildBasicStats(squares.circle)
  45.        
  46.         self.buildShooterStats(squares.circle)
  47.    
  48.     def buildBasicStats(self,subject):
  49.         '''use the subject.stats.basicStats dict to build a list
  50.        of entries that you can edit later in the GUI'''
  51.        
  52.         #create the frame
  53.         basic = Frame(self)
  54.         basic.config(bg='red',)
  55.        
  56.         #title label
  57.         basicTitle = Label(basic, text='Basic Stats')
  58.         basicTitle.grid(column= 0, sticky='we', columnspan=3 )
  59.         basicTitle.config(font =tkFont.Font(slant=tkFont.ITALIC))
  60.        
  61.         #italics
  62.         #ital = tkFont(slant=tkFont.ITALIC)
  63.         #bas
  64.        
  65.         r = 1 #values to increase
  66.         c = 1 # as loop goes on
  67.         for key, value in subject.stats.basicStats.items():
  68.            
  69.             #create a label/entry pair for k/v
  70.             lblKey = Label(basic, text=key + ':')
  71.             entValue = Entry(basic)
  72.            
  73.             #insert a value for the entry
  74.             entValue.insert(0, value)
  75.            
  76.             #pack em in with grid
  77.             lblKey.grid(column=0, row=r)
  78.             entValue.grid(column=1, row=r)
  79.            
  80.             #increase the values since the loop ran
  81.             r += 1
  82.             c += 1
  83.            
  84.         basic.grid()
  85.        
  86.     def buildShooterStats(self,subject):
  87.         '''use the subject.stats.shooterStats dict to build a list
  88.        of entries that you can edit later in the GUI'''
  89.        
  90.         #create the frame
  91.         shooter = Frame(self)
  92.         shooter.config(bg='red',)
  93.        
  94.         #title label
  95.         shooterTitle = Label(shooter, text='Shooter Stats')
  96.         shooterTitle.grid(column= 0, sticky='we', columnspan=3 )
  97.         shooterTitle.config(font =tkFont.Font(slant=tkFont.ITALIC))
  98.        
  99.         #italics
  100.         #ital = tkFont(slant=tkFont.ITALIC)
  101.         #bas
  102.        
  103.         r = 1 #values to increase
  104.         c = 1 # as loop goes on
  105.         for key, value in subject.stats.shooterStats.items():
  106.            
  107.             #create a label/entry pair for k/v
  108.             lblKey = Label(shooter, text=key + ':')
  109.             entValue = Entry(shooter)
  110.            
  111.             #insert a value for the entry
  112.             entValue.insert(0, value)
  113.            
  114.             #pack em in with grid
  115.             lblKey.grid(column=0, row=r)
  116.             entValue.grid(column=1, row=r)
  117.            
  118.             #increase the values since the loop ran
  119.             r += 1
  120.             c += 1
  121.            
  122.         shooter.grid()
  123.        
  124.            
  125.        
  126.    
  127.    
  128.     def buildBasicInfo(self, parent, subject):
  129.         '''going to just create a name and position entry for
  130.        the subject'''
  131.        
  132.         #called self because that's going to be root
  133.         basic = Frame(parent)
  134.        
  135.         basicTitle = Label(basic, text='Basic Info')
  136.         basicTitle.grid(column=0, sticky='w')
  137.        
  138.        
  139.         r = 1
  140.         for item in [subject.name, subject.pos]:
  141.             ent = Entry(basic)
  142.             ent.insert(0, item)
  143.             ent.grid(column = 0, row=r)
  144.             r += 1
  145.             #ent.bind('a', (lambda event: self.changeTEST(222)),)
  146.            
  147.         basic.grid(row=1)
  148.    
  149.     def buildMiscInfo(self, parent, subject):
  150.         '''add more fun stats, like kills and shots fired'''
  151.    
  152.         misc = Frame(parent)
  153.        
  154.         miscTitle = Label(misc, text='Misc Info')
  155.         miscTitle.grid(column=0, sticky='w')
  156.        
  157.         r = 1
  158.         for item in [subject.shooter.timesFired, ]:
  159.             ent = Entry(misc)
  160.             ent.insert(0, item)
  161.             ent.grid(row=r)
  162.             r += 1
  163.             #ent.bind('a', (lambda event: self.changeTEST(222)),)
  164.            
  165.         misc.grid(row=2)
  166. def run():
  167.     '''create and run the GUI '''
  168.     global root
  169.     root = Tk()
  170.     main = Debug(root)
  171.    
  172.     print root.geometry('0x0+1+1')
  173.     print '>>made root'
  174.     main.build()
  175.     print 'build basic'
  176.     root.mainloop()
  177.     print 'root closed<<'
  178.     #root.destroy()
  179.     #main.destroy()
  180.     #print 'root destroy'
  181.  
  182.     #kill the thread so I can open it again
  183.     #squares.thread_GUI2.
  184.  
  185.  
  186. if __name__ == '__main__':
  187.    
  188.     print 'Idiot. =D'
  189.  
Advertisement
Add Comment
Please, Sign In to add comment