Advertisement
Guest User

Untitled

a guest
Aug 16th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 13.24 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. # -*- coding: utf-8 -*-
  4.  
  5.  
  6.  
  7. # rename.py
  8.  
  9.  
  10.  
  11. import wx
  12.  
  13. import random
  14.  
  15.  
  16.  
  17. import var
  18.  
  19. import dnd_rolls_norm
  20.  
  21.  
  22.  
  23. class main_panel(wx.Panel):
  24.  
  25.     """create a panel"""
  26.  
  27.     def __init__(self, parent, *args, **kwargs):
  28.  
  29.         """Create the DemoPanel."""
  30.  
  31.         wx.Panel.__init__(self, parent, *args, **kwargs)
  32.  
  33.  
  34.  
  35.         self.parent = parent
  36.  
  37.  
  38.  
  39.         guiSizMain = wx.GridBagSizer(4,4)
  40.  
  41.  
  42.  
  43.         lblPickScores = wx.StaticText(self,label = "Pick Scores")
  44.  
  45.         guiSizMain.Add(lblPickScores,pos = (0,0),
  46.  
  47.                        flag = wx.ALIGN_CENTER|wx.TOP|wx.LEFT|wx.BOTTOM,
  48.  
  49.                        border = 5)
  50.  
  51.  
  52.  
  53.         self.btnRoll = wx.Button(self,label = "Roll!")
  54.  
  55.         guiSizMain.Add(self.btnRoll,pos = (0,1),span = (1,5),flag = wx.EXPAND|wx.ALL,border = 3)
  56.  
  57.  
  58.  
  59.         # List of rolls for the radio boxes, can reuse? i have the others
  60.  
  61.         # commented out, but i may be able to remove them later when i make sure
  62.  
  63.         # i can select the result successfully (UPDATE: it worked!)
  64.  
  65.         rboxPick = ["Default","Strength","Dexterity","Constitution","Intelligence",
  66.  
  67.                      "Wisdom","Charisma"]
  68.  
  69.  
  70.  
  71.         self.lblRoll1 = wx.StaticText(self,label = "0")
  72.  
  73.         guiSizMain.Add(self.lblRoll1,pos = (1,0),flag = wx.ALIGN_CENTER)
  74.  
  75.         self.rboxRoll1 = wx.RadioBox(self,label = "Roll One",choices = rboxPick)
  76.  
  77.         guiSizMain.Add(self.rboxRoll1,pos = (1,1),span = (1,5),flag = wx.EXPAND|wx.LEFT|wx.RIGHT,border = 5)
  78.  
  79.  
  80.  
  81.         self.lblRoll2 = wx.StaticText(self,label = "0")
  82.  
  83.         guiSizMain.Add(self.lblRoll2,pos = (2,0),flag = wx.ALIGN_CENTER)
  84.  
  85.         self.rboxRoll2 = wx.RadioBox(self,label = "Roll Two",choices = rboxPick)
  86.  
  87.         guiSizMain.Add(self.rboxRoll2,pos = (2,1),span = (1,5),flag = wx.EXPAND|wx.LEFT|wx.RIGHT,border = 5)
  88.  
  89.  
  90.  
  91.         self.lblRoll3 = wx.StaticText(self,label = "0")
  92.  
  93.         guiSizMain.Add(self.lblRoll3,pos = (3,0),flag = wx.ALIGN_CENTER)
  94.  
  95.         self.rboxRoll3 = wx.RadioBox(self,label = "Roll Three",choices = rboxPick)
  96.  
  97.         guiSizMain.Add(self.rboxRoll3,pos = (3,1),span = (1,5),flag = wx.EXPAND|wx.LEFT|wx.RIGHT,border = 5)
  98.  
  99.  
  100.  
  101.         self.lblRoll4 = wx.StaticText(self,label = "0")
  102.  
  103.         guiSizMain.Add(self.lblRoll4,pos = (4,0),flag = wx.ALIGN_CENTER)
  104.  
  105.         self.rboxRoll4 = wx.RadioBox(self,label = "Roll Four",choices = rboxPick)
  106.  
  107.         guiSizMain.Add(self.rboxRoll4,pos = (4,1),span = (1,5),flag = wx.EXPAND|wx.LEFT|wx.RIGHT,border = 5)
  108.  
  109.  
  110.  
  111.         self.lblRoll5 = wx.StaticText(self,label = "0")
  112.  
  113.         guiSizMain.Add(self.lblRoll5,pos = (5,0),flag = wx.ALIGN_CENTER)
  114.  
  115.         self.rboxRoll5 = wx.RadioBox(self,label = "Roll Five",choices = rboxPick)
  116.  
  117.         guiSizMain.Add(self.rboxRoll5,pos = (5,1),span = (1,5),flag = wx.EXPAND|wx.LEFT|wx.RIGHT,border = 5)
  118.  
  119.  
  120.  
  121.         self.lblRoll6 = wx.StaticText(self,label = "0")
  122.  
  123.         guiSizMain.Add(self.lblRoll6,pos = (6,0),flag = wx.ALIGN_CENTER)
  124.  
  125.         self.rboxRoll6 = wx.RadioBox(self,label = "Roll Six",choices = rboxPick)
  126.  
  127.         guiSizMain.Add(self.rboxRoll6,pos = (6,1),span = (1,5),flag = wx.EXPAND|wx.LEFT|wx.RIGHT,border = 5)
  128.  
  129.  
  130.  
  131.         # CONFUSING!
  132.  
  133.         # "pos" starts at 0, while "span" starts at 1
  134.  
  135.         self.tcLogger = wx.TextCtrl(self,style = wx.TE_MULTILINE)
  136.  
  137.         guiSizMain.Add(self.tcLogger,pos = (7,0),span = (1,6),
  138.  
  139.                        flag = wx.EXPAND|wx.LEFT|wx.RIGHT,border = 5)
  140.  
  141.  
  142.  
  143.         self.tcLogger.AppendText("""Instructions
  144.  
  145.  
  146.  
  147. 1. Click the "Roll!" button up top.
  148.  
  149.    - Scores will be placed in the empty slots on the left side.
  150.  
  151.  
  152.  
  153. 2. Look at the scores and decide where you want to put them.
  154.  
  155.  
  156.  
  157. 3. Click the correct label for each score.
  158.  
  159.    - Make sure you only assign one score to one ability.
  160.  
  161.  
  162.  
  163. 4. Click "Assign" to finalize the assignment.""")
  164.  
  165.  
  166.  
  167.         # i am going to place anothe sizer down here for the buttons so they
  168.  
  169.         # aren't constrained by the grid above. I am actually probably going to
  170.  
  171.         # put another grid bag sizer down here
  172.  
  173.         #~ guiPanelBtn = wx.Panel(self)
  174.  
  175.         #~ guiSizBtn = wx.GridBagSizer(4,4)
  176.  
  177.  
  178.  
  179.         #~ self.btnPrev = wx.Button(self,label = "Previous",size = (90,28))
  180.  
  181.         #~ self.btnAssign = wx.Button(self,label = "Assign",size = (90,28))
  182.  
  183.         #~ self.btnNext = wx.Button(self,label = "Next",size = (90,28))
  184.  
  185.         #~ guiSizMain.Add(self.btnPrev,pos = (8,2))
  186.  
  187.         #~ guiSizMain.Add(self.btnAssign,pos = (8,3))
  188.  
  189.         #~ guiSizMain.Add(self.btnNext,pos = (8,4),flag = wx.RIGHT|wx.BOTTOM,border = 5)
  190.  
  191.  
  192.  
  193.         #~ self.btnNext.Disable()
  194.  
  195.         #~ self.btnPrev.Disable()
  196.  
  197.  
  198.  
  199.         # event binding
  200.  
  201.         self.btnRoll.Bind(wx.EVT_BUTTON,self.calc_rolls)
  202.  
  203.  
  204.  
  205.         # CONFUSING
  206.  
  207.         # these ALSO start from 0
  208.  
  209.         guiSizMain.AddGrowableCol(1)
  210.  
  211.         guiSizMain.AddGrowableRow(7)
  212.  
  213.         self.SetSizerAndFit(guiSizMain)
  214.  
  215.         #~ guiPanelBtn.SetSizer(guiSizBtn)
  216.  
  217.  
  218.  
  219.     ####    clear the panel, move next    ######################################
  220.  
  221.     def next_step(self,event):
  222.  
  223.         for child in self.GetChildren():
  224.  
  225.             child.Destroy()
  226.  
  227.  
  228.  
  229.  
  230.  
  231.     ####    calculate the rolls    #############################################
  232.  
  233.     def calc_rolls(self,event):
  234.  
  235.         self.tupAbilities = ["str","dex","con","int","wis","cha"]
  236.  
  237.         self.lstRollSet = []
  238.  
  239.         self.intRollNum = 0
  240.  
  241.         self.lstRollTotals = []
  242.  
  243.  
  244.  
  245.         for a in self.tupAbilities:
  246.  
  247.             # make 4 rolls for a given score
  248.  
  249.             while self.intRollNum < 4:
  250.  
  251.                 self.intRoll = random.randrange(1,7)
  252.  
  253.                 self.lstRollSet.append(self.intRoll)
  254.  
  255.                 self.intRollNum += 1
  256.  
  257.  
  258.  
  259.             # reset the roll counter for the next score
  260.  
  261.             self.intRollNum = 0
  262.  
  263.  
  264.  
  265.             # sort and reverse list
  266.  
  267.             self.lstRollSet.sort()
  268.  
  269.             self.lstRollSet.reverse()
  270.  
  271.  
  272.  
  273.             # "drops" lowest (last) roll and brings them together
  274.  
  275.             self.intRollTotal = self.lstRollSet[0] + self.lstRollSet[1] + \
  276.  
  277.                                 self.lstRollSet[2]
  278.  
  279.             self.lstRollTotals.append(self.intRollTotal)
  280.  
  281.  
  282.  
  283.             # reset the list for roll sets
  284.  
  285.             del self.lstRollSet[:]
  286.  
  287.  
  288.  
  289.         self.lblRoll1.SetLabel(str(self.lstRollTotals[0]))
  290.  
  291.         self.lblRoll2.SetLabel(str(self.lstRollTotals[1]))
  292.  
  293.         self.lblRoll3.SetLabel(str(self.lstRollTotals[2]))
  294.  
  295.         self.lblRoll4.SetLabel(str(self.lstRollTotals[3]))
  296.  
  297.         self.lblRoll5.SetLabel(str(self.lstRollTotals[4]))
  298.  
  299.         self.lblRoll6.SetLabel(str(self.lstRollTotals[5]))
  300.  
  301.  
  302.  
  303.         self.btnRoll.Disable()
  304.  
  305.  
  306.  
  307.     ####    check scores    ####################################################
  308.  
  309.     # as a note, this score_checker function is very different from the cli
  310.  
  311.     # version of the program, only because on a gui, there is not a single
  312.  
  313.     # direction users can go.
  314.  
  315.     def score_checker(self,event):
  316.  
  317.         self.dictAbilities = {"str":0,"dex":0,"con":0,"int":0,"wis":0,"cha":0}
  318.  
  319.         self.tupAbilities = ("str","dex","con","int","wis","cha")
  320.  
  321.         self.tupAbilitiesLong = ("strength","dexterity","constitution","intelligence",
  322.  
  323.                             "wisdom","charisma")
  324.  
  325.  
  326.  
  327.         strAbility1 = self.rboxRoll1.GetStringSelection().lower()
  328.  
  329.         strAbility2 = self.rboxRoll2.GetStringSelection().lower()
  330.  
  331.         strAbility3 = self.rboxRoll3.GetStringSelection().lower()
  332.  
  333.         strAbility4 = self.rboxRoll4.GetStringSelection().lower()
  334.  
  335.         strAbility5 = self.rboxRoll5.GetStringSelection().lower()
  336.  
  337.         strAbility6 = self.rboxRoll6.GetStringSelection().lower()
  338.  
  339.  
  340.  
  341.         # this seems to append "u" to the beginning of each item, pay no mind to
  342.  
  343.         # that, it doesn't seem to matter
  344.  
  345.         tupChecker = (strAbility1,strAbility2,strAbility3,strAbility4,strAbility5,strAbility6)
  346.  
  347.  
  348.  
  349.         if sorted(tupChecker) == sorted(self.tupAbilitiesLong) and self.lblRoll1.GetLabel() != "0":
  350.  
  351.             boolCheck = True
  352.  
  353.             intScore1 = int(self.lblRoll1.GetLabel())
  354.  
  355.             intScore2 = int(self.lblRoll2.GetLabel())
  356.  
  357.             intScore3 = int(self.lblRoll3.GetLabel())
  358.  
  359.             intScore4 = int(self.lblRoll4.GetLabel())
  360.  
  361.             intScore5 = int(self.lblRoll5.GetLabel())
  362.  
  363.             intScore6 = int(self.lblRoll6.GetLabel())
  364.  
  365.  
  366.  
  367.             self.dictAbilities[sorted(self.tupAbilities)[sorted(self.tupAbilitiesLong).index(strAbility1)]] = intScore1
  368.  
  369.             self.dictAbilities[sorted(self.tupAbilities)[sorted(self.tupAbilitiesLong).index(strAbility2)]] = intScore2
  370.  
  371.             self.dictAbilities[sorted(self.tupAbilities)[sorted(self.tupAbilitiesLong).index(strAbility3)]] = intScore3
  372.  
  373.             self.dictAbilities[sorted(self.tupAbilities)[sorted(self.tupAbilitiesLong).index(strAbility4)]] = intScore4
  374.  
  375.             self.dictAbilities[sorted(self.tupAbilities)[sorted(self.tupAbilitiesLong).index(strAbility5)]] = intScore5
  376.  
  377.             self.dictAbilities[sorted(self.tupAbilities)[sorted(self.tupAbilitiesLong).index(strAbility6)]] = intScore6
  378.  
  379.  
  380.  
  381.             print self.dictAbilities
  382.  
  383.             self.tcLogger.Clear()
  384.  
  385.             self.tcLogger.AppendText(str(self.dictAbilities))
  386.  
  387.  
  388.  
  389.             self.btnAssign.Disable()
  390.  
  391.             self.btnNext.Enable()
  392.  
  393.  
  394.  
  395.         elif self.lblRoll1.GetLabel() == "0":
  396.  
  397.             self.tcLogger.Clear()
  398.  
  399.             self.tcLogger.AppendText("You forgot to click roll!")
  400.  
  401.  
  402.  
  403.         else:
  404.  
  405.             self.tcLogger.Clear()
  406.  
  407.             self.tcLogger.AppendText("Check you abilities, make sure they are assigned correctly.")
  408.  
  409.  
  410.  
  411. class button_panel(wx.Panel):
  412.  
  413.     """create a panel"""
  414.  
  415.     def __init__(self,parent,*args,**kwargs):
  416.  
  417.         """Create the DemoPanel."""
  418.  
  419.         wx.Panel.__init__(self,parent,*args,**kwargs)
  420.  
  421.  
  422.  
  423.         self.parent = parent
  424.  
  425.  
  426.  
  427.         guiSizBox = wx.BoxSizer(wx.HORIZONTAL)
  428.  
  429.  
  430.  
  431.         self.btnPrev = wx.Button(self,label = "Previous",size = (90,28))
  432.  
  433.         self.btnAssign = wx.Button(self,label = "Assign",size = (90,28))
  434.  
  435.         self.btnNext = wx.Button(self,label = "Next",size = (90,28))
  436.  
  437.         guiSizBox.Add(self.btnPrev)
  438.  
  439.         guiSizBox.Add(self.btnAssign)
  440.  
  441.         guiSizBox.Add(self.btnNext,flag = wx.RIGHT|wx.BOTTOM,border = 5)
  442.  
  443.  
  444.  
  445.         self.btnNext.Disable()
  446.  
  447.         self.btnPrev.Disable()
  448.  
  449.  
  450.  
  451.         # event binding
  452.  
  453.         self.btnAssign.Bind(wx.EVT_BUTTON,main_panel.score_checker(main_panel))
  454.  
  455.         # bind the next button, clears the panel and ends the file
  456.  
  457.         self.btnNext.Bind(wx.EVT_BUTTON,self.next_step)
  458.  
  459.  
  460.  
  461.         self.SetSizerAndFit(guiSizBox)
  462.  
  463.  
  464.  
  465.     ####    clear the panel, move next    ######################################
  466.  
  467.     def next_step(self,event):
  468.  
  469.         for child in main_panel.GetChildren():
  470.  
  471.             child.Destroy()
  472.  
  473.  
  474.  
  475. class main_frame(wx.Frame):
  476.  
  477.     """Main Frame holding the main panel."""
  478.  
  479.     def __init__(self, *args, **kwargs):
  480.  
  481.         """Create the DemoFrame."""
  482.  
  483.         wx.Frame.__init__(self, *args, **kwargs)
  484.  
  485.  
  486.  
  487.         # Build the menu bar
  488.  
  489.         menuBar = wx.MenuBar()
  490.  
  491.         menuFile = wx.Menu()
  492.  
  493.  
  494.  
  495.         menuFileQuit = menuFile.Append(wx.ID_EXIT, text="&Quit")
  496.  
  497.         self.Bind(wx.EVT_MENU, self.OnQuit,menuFileQuit)
  498.  
  499.  
  500.  
  501.         menuBar.Append(menuFile, "&File")
  502.  
  503.         self.SetMenuBar(menuBar)
  504.  
  505.  
  506.  
  507.         p = wx.Panel(self)
  508.  
  509.         nb = wx.Notebook(p)
  510.  
  511.  
  512.  
  513.         # create the page windows as children of the notebook
  514.  
  515.         page1 = main_panel(nb)
  516.  
  517.         page2 = button_panel(nb)
  518.  
  519.         #page3 = PageThree(nb)
  520.  
  521.  
  522.  
  523.         # add the pages to the notebook with the label to show on the tab
  524.  
  525.         nb.AddPage(page1, "Page 1")
  526.  
  527.         nb.AddPage(page2, "Page 2")
  528.  
  529.         #nb.AddPage(page3, "Page 3")
  530.  
  531.  
  532.  
  533.         # finally, put the notebook in a sizer for the panel to manage
  534.  
  535.         # the layout
  536.  
  537.         sizer = wx.BoxSizer()
  538.  
  539.         sizer.Add(nb, 1, wx.EXPAND)
  540.  
  541.         #sizer.Add(button_panel,1,wx.EXPAND)
  542.  
  543.         p.SetSizer(sizer)
  544.  
  545.  
  546.  
  547.         self.Center()
  548.  
  549.         self.Show()
  550.  
  551.  
  552.  
  553.     def OnQuit(self, event=None):
  554.  
  555.         """Exit application."""
  556.  
  557.         self.Close()
  558.  
  559.  
  560.  
  561.  
  562.  
  563. if __name__ == '__main__':
  564.  
  565.     app = wx.App(False)
  566.  
  567.     main_frame(None,size = (700,480),title='D&D Charcter Creator')
  568.  
  569.     app.MainLoop()
  570.  
  571.  
  572.  
  573.  
  574. Python 2.7.1 (r271:86832, Apr 15 2011, 12:11:58)
  575. [GCC 4.5.2 20110127 (prerelease)] on linux2
  576. Type "copyright", "credits" or "license()" for more information.
  577. >>> ================================ RESTART ================================
  578. >>>
  579.  
  580. Traceback (most recent call last):
  581.   File "/home/milo/Dropbox/doc/dev/py/unsorted/dnd_gen_gui/character/dnd_gui.py", line 284, in <module>
  582.     main_frame(None,size = (700,480),title='D&D Charcter Creator')
  583.   File "/home/milo/Dropbox/doc/dev/py/unsorted/dnd_gen_gui/character/dnd_gui.py", line 259, in __init__
  584.     page2 = button_panel(nb)
  585.   File "/home/milo/Dropbox/doc/dev/py/unsorted/dnd_gen_gui/character/dnd_gui.py", line 227, in __init__
  586.     self.btnAssign.Bind(wx.EVT_BUTTON,main_panel.score_checker(main_panel))
  587. TypeError: unbound method score_checker() must be called with main_panel instance as first argument (got type instance instead)
  588. >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement