Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- # rename.py
- import wx
- import random
- import var
- import dnd_rolls_norm
- class main_panel(wx.Panel):
- """create a panel"""
- def __init__(self, parent, *args, **kwargs):
- """Create the DemoPanel."""
- wx.Panel.__init__(self, parent, *args, **kwargs)
- self.parent = parent
- guiSizMain = wx.GridBagSizer(4,4)
- lblPickScores = wx.StaticText(self,label = "Pick Scores")
- guiSizMain.Add(lblPickScores,pos = (0,0),
- flag = wx.ALIGN_CENTER|wx.TOP|wx.LEFT|wx.BOTTOM,
- border = 5)
- self.btnRoll = wx.Button(self,label = "Roll!")
- guiSizMain.Add(self.btnRoll,pos = (0,1),span = (1,5),flag = wx.EXPAND|wx.ALL,border = 3)
- # List of rolls for the radio boxes, can reuse? i have the others
- # commented out, but i may be able to remove them later when i make sure
- # i can select the result successfully (UPDATE: it worked!)
- rboxPick = ["Default","Strength","Dexterity","Constitution","Intelligence",
- "Wisdom","Charisma"]
- self.lblRoll1 = wx.StaticText(self,label = "0")
- guiSizMain.Add(self.lblRoll1,pos = (1,0),flag = wx.ALIGN_CENTER)
- self.rboxRoll1 = wx.RadioBox(self,label = "Roll One",choices = rboxPick)
- guiSizMain.Add(self.rboxRoll1,pos = (1,1),span = (1,5),flag = wx.EXPAND|wx.LEFT|wx.RIGHT,border = 5)
- self.lblRoll2 = wx.StaticText(self,label = "0")
- guiSizMain.Add(self.lblRoll2,pos = (2,0),flag = wx.ALIGN_CENTER)
- self.rboxRoll2 = wx.RadioBox(self,label = "Roll Two",choices = rboxPick)
- guiSizMain.Add(self.rboxRoll2,pos = (2,1),span = (1,5),flag = wx.EXPAND|wx.LEFT|wx.RIGHT,border = 5)
- self.lblRoll3 = wx.StaticText(self,label = "0")
- guiSizMain.Add(self.lblRoll3,pos = (3,0),flag = wx.ALIGN_CENTER)
- self.rboxRoll3 = wx.RadioBox(self,label = "Roll Three",choices = rboxPick)
- guiSizMain.Add(self.rboxRoll3,pos = (3,1),span = (1,5),flag = wx.EXPAND|wx.LEFT|wx.RIGHT,border = 5)
- self.lblRoll4 = wx.StaticText(self,label = "0")
- guiSizMain.Add(self.lblRoll4,pos = (4,0),flag = wx.ALIGN_CENTER)
- self.rboxRoll4 = wx.RadioBox(self,label = "Roll Four",choices = rboxPick)
- guiSizMain.Add(self.rboxRoll4,pos = (4,1),span = (1,5),flag = wx.EXPAND|wx.LEFT|wx.RIGHT,border = 5)
- self.lblRoll5 = wx.StaticText(self,label = "0")
- guiSizMain.Add(self.lblRoll5,pos = (5,0),flag = wx.ALIGN_CENTER)
- self.rboxRoll5 = wx.RadioBox(self,label = "Roll Five",choices = rboxPick)
- guiSizMain.Add(self.rboxRoll5,pos = (5,1),span = (1,5),flag = wx.EXPAND|wx.LEFT|wx.RIGHT,border = 5)
- self.lblRoll6 = wx.StaticText(self,label = "0")
- guiSizMain.Add(self.lblRoll6,pos = (6,0),flag = wx.ALIGN_CENTER)
- self.rboxRoll6 = wx.RadioBox(self,label = "Roll Six",choices = rboxPick)
- guiSizMain.Add(self.rboxRoll6,pos = (6,1),span = (1,5),flag = wx.EXPAND|wx.LEFT|wx.RIGHT,border = 5)
- # CONFUSING!
- # "pos" starts at 0, while "span" starts at 1
- self.tcLogger = wx.TextCtrl(self,style = wx.TE_MULTILINE)
- guiSizMain.Add(self.tcLogger,pos = (7,0),span = (1,6),
- flag = wx.EXPAND|wx.LEFT|wx.RIGHT,border = 5)
- self.tcLogger.AppendText("""Instructions
- 1. Click the "Roll!" button up top.
- - Scores will be placed in the empty slots on the left side.
- 2. Look at the scores and decide where you want to put them.
- 3. Click the correct label for each score.
- - Make sure you only assign one score to one ability.
- 4. Click "Assign" to finalize the assignment.""")
- # i am going to place anothe sizer down here for the buttons so they
- # aren't constrained by the grid above. I am actually probably going to
- # put another grid bag sizer down here
- #~ guiPanelBtn = wx.Panel(self)
- #~ guiSizBtn = wx.GridBagSizer(4,4)
- #~ self.btnPrev = wx.Button(self,label = "Previous",size = (90,28))
- #~ self.btnAssign = wx.Button(self,label = "Assign",size = (90,28))
- #~ self.btnNext = wx.Button(self,label = "Next",size = (90,28))
- #~ guiSizMain.Add(self.btnPrev,pos = (8,2))
- #~ guiSizMain.Add(self.btnAssign,pos = (8,3))
- #~ guiSizMain.Add(self.btnNext,pos = (8,4),flag = wx.RIGHT|wx.BOTTOM,border = 5)
- #~ self.btnNext.Disable()
- #~ self.btnPrev.Disable()
- # event binding
- self.btnRoll.Bind(wx.EVT_BUTTON,self.calc_rolls)
- # CONFUSING
- # these ALSO start from 0
- guiSizMain.AddGrowableCol(1)
- guiSizMain.AddGrowableRow(7)
- self.SetSizerAndFit(guiSizMain)
- #~ guiPanelBtn.SetSizer(guiSizBtn)
- #### clear the panel, move next ######################################
- def next_step(self,event):
- for child in self.GetChildren():
- child.Destroy()
- #### calculate the rolls #############################################
- def calc_rolls(self,event):
- self.tupAbilities = ["str","dex","con","int","wis","cha"]
- self.lstRollSet = []
- self.intRollNum = 0
- self.lstRollTotals = []
- for a in self.tupAbilities:
- # make 4 rolls for a given score
- while self.intRollNum < 4:
- self.intRoll = random.randrange(1,7)
- self.lstRollSet.append(self.intRoll)
- self.intRollNum += 1
- # reset the roll counter for the next score
- self.intRollNum = 0
- # sort and reverse list
- self.lstRollSet.sort()
- self.lstRollSet.reverse()
- # "drops" lowest (last) roll and brings them together
- self.intRollTotal = self.lstRollSet[0] + self.lstRollSet[1] + \
- self.lstRollSet[2]
- self.lstRollTotals.append(self.intRollTotal)
- # reset the list for roll sets
- del self.lstRollSet[:]
- self.lblRoll1.SetLabel(str(self.lstRollTotals[0]))
- self.lblRoll2.SetLabel(str(self.lstRollTotals[1]))
- self.lblRoll3.SetLabel(str(self.lstRollTotals[2]))
- self.lblRoll4.SetLabel(str(self.lstRollTotals[3]))
- self.lblRoll5.SetLabel(str(self.lstRollTotals[4]))
- self.lblRoll6.SetLabel(str(self.lstRollTotals[5]))
- self.btnRoll.Disable()
- #### check scores ####################################################
- # as a note, this score_checker function is very different from the cli
- # version of the program, only because on a gui, there is not a single
- # direction users can go.
- def score_checker(self,event):
- self.dictAbilities = {"str":0,"dex":0,"con":0,"int":0,"wis":0,"cha":0}
- self.tupAbilities = ("str","dex","con","int","wis","cha")
- self.tupAbilitiesLong = ("strength","dexterity","constitution","intelligence",
- "wisdom","charisma")
- strAbility1 = self.rboxRoll1.GetStringSelection().lower()
- strAbility2 = self.rboxRoll2.GetStringSelection().lower()
- strAbility3 = self.rboxRoll3.GetStringSelection().lower()
- strAbility4 = self.rboxRoll4.GetStringSelection().lower()
- strAbility5 = self.rboxRoll5.GetStringSelection().lower()
- strAbility6 = self.rboxRoll6.GetStringSelection().lower()
- # this seems to append "u" to the beginning of each item, pay no mind to
- # that, it doesn't seem to matter
- tupChecker = (strAbility1,strAbility2,strAbility3,strAbility4,strAbility5,strAbility6)
- if sorted(tupChecker) == sorted(self.tupAbilitiesLong) and self.lblRoll1.GetLabel() != "0":
- boolCheck = True
- intScore1 = int(self.lblRoll1.GetLabel())
- intScore2 = int(self.lblRoll2.GetLabel())
- intScore3 = int(self.lblRoll3.GetLabel())
- intScore4 = int(self.lblRoll4.GetLabel())
- intScore5 = int(self.lblRoll5.GetLabel())
- intScore6 = int(self.lblRoll6.GetLabel())
- self.dictAbilities[sorted(self.tupAbilities)[sorted(self.tupAbilitiesLong).index(strAbility1)]] = intScore1
- self.dictAbilities[sorted(self.tupAbilities)[sorted(self.tupAbilitiesLong).index(strAbility2)]] = intScore2
- self.dictAbilities[sorted(self.tupAbilities)[sorted(self.tupAbilitiesLong).index(strAbility3)]] = intScore3
- self.dictAbilities[sorted(self.tupAbilities)[sorted(self.tupAbilitiesLong).index(strAbility4)]] = intScore4
- self.dictAbilities[sorted(self.tupAbilities)[sorted(self.tupAbilitiesLong).index(strAbility5)]] = intScore5
- self.dictAbilities[sorted(self.tupAbilities)[sorted(self.tupAbilitiesLong).index(strAbility6)]] = intScore6
- print self.dictAbilities
- self.tcLogger.Clear()
- self.tcLogger.AppendText(str(self.dictAbilities))
- self.btnAssign.Disable()
- self.btnNext.Enable()
- elif self.lblRoll1.GetLabel() == "0":
- self.tcLogger.Clear()
- self.tcLogger.AppendText("You forgot to click roll!")
- else:
- self.tcLogger.Clear()
- self.tcLogger.AppendText("Check you abilities, make sure they are assigned correctly.")
- class button_panel(wx.Panel):
- """create a panel"""
- def __init__(self,parent,*args,**kwargs):
- """Create the DemoPanel."""
- wx.Panel.__init__(self,parent,*args,**kwargs)
- self.parent = parent
- guiSizBox = wx.BoxSizer(wx.HORIZONTAL)
- self.btnPrev = wx.Button(self,label = "Previous",size = (90,28))
- self.btnAssign = wx.Button(self,label = "Assign",size = (90,28))
- self.btnNext = wx.Button(self,label = "Next",size = (90,28))
- guiSizBox.Add(self.btnPrev)
- guiSizBox.Add(self.btnAssign)
- guiSizBox.Add(self.btnNext,flag = wx.RIGHT|wx.BOTTOM,border = 5)
- self.btnNext.Disable()
- self.btnPrev.Disable()
- # event binding
- self.btnAssign.Bind(wx.EVT_BUTTON,main_panel.score_checker(main_panel))
- # bind the next button, clears the panel and ends the file
- self.btnNext.Bind(wx.EVT_BUTTON,self.next_step)
- self.SetSizerAndFit(guiSizBox)
- #### clear the panel, move next ######################################
- def next_step(self,event):
- for child in main_panel.GetChildren():
- child.Destroy()
- class main_frame(wx.Frame):
- """Main Frame holding the main panel."""
- def __init__(self, *args, **kwargs):
- """Create the DemoFrame."""
- wx.Frame.__init__(self, *args, **kwargs)
- # Build the menu bar
- menuBar = wx.MenuBar()
- menuFile = wx.Menu()
- menuFileQuit = menuFile.Append(wx.ID_EXIT, text="&Quit")
- self.Bind(wx.EVT_MENU, self.OnQuit,menuFileQuit)
- menuBar.Append(menuFile, "&File")
- self.SetMenuBar(menuBar)
- p = wx.Panel(self)
- nb = wx.Notebook(p)
- # create the page windows as children of the notebook
- page1 = main_panel(nb)
- page2 = button_panel(nb)
- #page3 = PageThree(nb)
- # add the pages to the notebook with the label to show on the tab
- nb.AddPage(page1, "Page 1")
- nb.AddPage(page2, "Page 2")
- #nb.AddPage(page3, "Page 3")
- # finally, put the notebook in a sizer for the panel to manage
- # the layout
- sizer = wx.BoxSizer()
- sizer.Add(nb, 1, wx.EXPAND)
- #sizer.Add(button_panel,1,wx.EXPAND)
- p.SetSizer(sizer)
- self.Center()
- self.Show()
- def OnQuit(self, event=None):
- """Exit application."""
- self.Close()
- if __name__ == '__main__':
- app = wx.App(False)
- main_frame(None,size = (700,480),title='D&D Charcter Creator')
- app.MainLoop()
- Python 2.7.1 (r271:86832, Apr 15 2011, 12:11:58)
- [GCC 4.5.2 20110127 (prerelease)] on linux2
- Type "copyright", "credits" or "license()" for more information.
- >>> ================================ RESTART ================================
- >>>
- Traceback (most recent call last):
- File "/home/milo/Dropbox/doc/dev/py/unsorted/dnd_gen_gui/character/dnd_gui.py", line 284, in <module>
- main_frame(None,size = (700,480),title='D&D Charcter Creator')
- File "/home/milo/Dropbox/doc/dev/py/unsorted/dnd_gen_gui/character/dnd_gui.py", line 259, in __init__
- page2 = button_panel(nb)
- File "/home/milo/Dropbox/doc/dev/py/unsorted/dnd_gen_gui/character/dnd_gui.py", line 227, in __init__
- self.btnAssign.Bind(wx.EVT_BUTTON,main_panel.score_checker(main_panel))
- TypeError: unbound method score_checker() must be called with main_panel instance as first argument (got type instance instead)
- >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement