Mercurial > traipse
comparison orpg/tools/toolBars.py @ 0:4385a7d0efd1 grumpy-goblin
Deleted and repushed it with the 'grumpy-goblin' branch. I forgot a y
author | sirebral |
---|---|
date | Tue, 14 Jul 2009 16:41:58 -0500 |
parents | |
children | 211ac836b6a0 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4385a7d0efd1 |
---|---|
1 # Copyright (C) 2000-2001 The OpenRPG Project | |
2 # | |
3 # openrpg-dev@lists.sourceforge.net | |
4 # | |
5 # This program is free software; you can redistribute it and/or modify | |
6 # it under the terms of the GNU General Public License as published by | |
7 # the Free Software Foundation; either version 2 of the License, or | |
8 # (at your option) any later version. | |
9 # | |
10 # This program is distributed in the hope that it will be useful, | |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 # GNU General Public License for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with this program; if not, write to the Free Software | |
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
18 # -- | |
19 # | |
20 # File: toolBars.py | |
21 # Author: Greg Copeland | |
22 # Maintainer: | |
23 # | |
24 # Description: Contains all of the toolbars used in the application. | |
25 # | |
26 # | |
27 | |
28 __version__ = "$Id: toolBars.py,v 1.13 2006/11/04 21:24:22 digitalxero Exp $" | |
29 | |
30 | |
31 ## | |
32 ## Module Loading | |
33 ## | |
34 from inputValidator import * | |
35 import string | |
36 import orpg.dirpath | |
37 | |
38 # DICE stuff | |
39 TB_IDC_D4 = wx.NewId() | |
40 TB_IDC_D6 = wx.NewId() | |
41 TB_IDC_D8 = wx.NewId() | |
42 TB_IDC_D10 = wx.NewId() | |
43 TB_IDC_D12 = wx.NewId() | |
44 TB_IDC_D20 = wx.NewId() | |
45 TB_IDC_D100 = wx.NewId() | |
46 TB_IDC_NUMDICE = wx.NewId() | |
47 TB_IDC_MODS = wx.NewId() | |
48 | |
49 # MAP stuff | |
50 TB_MAP_MODE = wx.NewId() | |
51 # Caution: the use of wxFRAME_TOOL_WINDOW screws up the window on GTK. Please don't use!!! | |
52 | |
53 class MapToolBar(wx.Panel): | |
54 """This is where all of the map related tools belong for quick reference.""" | |
55 def __init__( self, parent, id=-1, title="Map Tool Bar", size= wx.Size(300, 45), callBack=None ): | |
56 wx.Panel.__init__(self, parent, id, size=size) | |
57 self.callback = callBack | |
58 self.mapmode = 1 | |
59 self.modeicons = [orpg.dirpath.dir_struct["icon"]+"move.gif", | |
60 orpg.dirpath.dir_struct["icon"]+"draw.gif", | |
61 orpg.dirpath.dir_struct["icon"]+"tape.gif"] | |
62 # Make a sizer for everything to belong to | |
63 self.sizer = wx.BoxSizer( wx.HORIZONTAL ) | |
64 bm = wx.Image(orpg.dirpath.dir_struct["icon"]+"move.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() | |
65 self.butt = wx.BitmapButton( self, TB_MAP_MODE, bm ) | |
66 self.sizer.Add( self.butt,0, wx.ALIGN_CENTER ) | |
67 self.Bind(wx.EVT_BUTTON, self.onToolBarClick, id=TB_MAP_MODE) | |
68 # Build the toolbar now | |
69 # Stubbed, but nothing here yet! | |
70 # Now, attach the sizer to the panel and tell it to do it's magic | |
71 self.SetSizer(self.sizer) | |
72 self.SetAutoLayout(True) | |
73 self.Fit() | |
74 | |
75 def onToolBarClick(self,evt): | |
76 data = "" | |
77 id = evt.GetId() | |
78 data = "" | |
79 mode = 1 | |
80 if id == TB_MAP_MODE: | |
81 mode = 1 | |
82 self.mapmode +=1 | |
83 if self.mapmode >3: | |
84 self.mapmode = 1 | |
85 bm = wx.Image(self.modeicons[self.mapmode-1],wx.BITMAP_TYPE_GIF).ConvertToBitmap() | |
86 self.butt= wx.BitmapButton(self,TB_MAP_MODE,bm) | |
87 data = self.mapmode | |
88 if self.callback != None: | |
89 self.callback(mode,data) | |
90 | |
91 class DiceToolBar(wx.Panel): | |
92 """This is where all of the dice related tools belong for quick reference.""" | |
93 def __init__( self, parent, id=-1, title="Dice Tool Bar", size=wx.Size(300, 45), callBack=None ): | |
94 wx.Panel.__init__(self, parent, id, size=size) | |
95 # Save our post callback | |
96 self.callBack = callBack | |
97 # Make a sizer for everything to belong to | |
98 self.sizer = wx.BoxSizer( wx.HORIZONTAL ) | |
99 # Build the toolbar now | |
100 self.numDieText = wx.TextCtrl( self, TB_IDC_NUMDICE, "1", size= wx.Size(50, 25), | |
101 validator=MathOnlyValidator() ) | |
102 self.sizer.Add( self.numDieText, 1, wx.EXPAND | wx.ALIGN_LEFT ) | |
103 bm = wx.Image(orpg.dirpath.dir_struct["icon"]+"b_d4.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() | |
104 butt = wx.BitmapButton( self, TB_IDC_D4, bm, size=(bm.GetWidth(), bm.GetHeight()) ) | |
105 self.sizer.Add( butt, 0, wx.ALIGN_CENTER ) | |
106 self.Bind(wx.EVT_BUTTON, self.onToolBarClick, id=TB_IDC_D4) | |
107 bm = wx.Image(orpg.dirpath.dir_struct["icon"]+"b_d6.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() | |
108 butt = wx.BitmapButton( self, TB_IDC_D6, bm, size=(bm.GetWidth(), bm.GetHeight()) ) | |
109 self.sizer.Add( butt, 0, wx.ALIGN_CENTER ) | |
110 self.Bind(wx.EVT_BUTTON, self.onToolBarClick, id=TB_IDC_D6) | |
111 bm = wx.Image(orpg.dirpath.dir_struct["icon"]+"b_d8.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() | |
112 butt = wx.BitmapButton( self, TB_IDC_D8, bm, size=(bm.GetWidth(), bm.GetHeight()) ) | |
113 self.sizer.Add( butt, 0, wx.ALIGN_CENTER ) | |
114 self.Bind(wx.EVT_BUTTON, self.onToolBarClick, id=TB_IDC_D8) | |
115 bm = wx.Image(orpg.dirpath.dir_struct["icon"]+"b_d10.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() | |
116 butt = wx.BitmapButton( self, TB_IDC_D10, bm, size=(bm.GetWidth(), bm.GetHeight()) ) | |
117 self.sizer.Add( butt, 0, wx.ALIGN_CENTER ) | |
118 self.Bind(wx.EVT_BUTTON, self.onToolBarClick, id=TB_IDC_D10) | |
119 bm = wx.Image(orpg.dirpath.dir_struct["icon"]+"b_d12.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() | |
120 butt = wx.BitmapButton( self, TB_IDC_D12, bm, size=(bm.GetWidth(), bm.GetHeight()) ) | |
121 self.sizer.Add( butt, 0, wx.ALIGN_CENTER ) | |
122 self.Bind(wx.EVT_BUTTON, self.onToolBarClick, id=TB_IDC_D12) | |
123 bm = wx.Image(orpg.dirpath.dir_struct["icon"]+"b_d20.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() | |
124 butt = wx.BitmapButton( self, TB_IDC_D20, bm, size=(bm.GetWidth(), bm.GetHeight()) ) | |
125 self.sizer.Add( butt, 0, wx.ALIGN_CENTER ) | |
126 self.Bind(wx.EVT_BUTTON, self.onToolBarClick, id=TB_IDC_D20) | |
127 bm = wx.Image(orpg.dirpath.dir_struct["icon"]+"b_d100.gif", wx.BITMAP_TYPE_GIF).ConvertToBitmap() | |
128 butt = wx.BitmapButton( self, TB_IDC_D100, bm, size=(bm.GetWidth(), bm.GetHeight()) ) | |
129 self.sizer.Add( butt, 0, wx.ALIGN_CENTER ) | |
130 self.Bind(wx.EVT_BUTTON, self.onToolBarClick, id=TB_IDC_D100) | |
131 # Add our other text control to the sizer | |
132 self.dieModText = wx.TextCtrl( self, TB_IDC_MODS, "+0", size= wx.Size(50, 25), | |
133 validator=MathOnlyValidator() ) | |
134 self.sizer.Add( self.dieModText, 1, wx.EXPAND | wx.ALIGN_RIGHT ) | |
135 # Now, attach the sizer to the panel and tell it to do it's magic | |
136 self.SetSizer(self.sizer) | |
137 self.SetAutoLayout(True) | |
138 self.Fit() | |
139 | |
140 def onToolBarClick( self, evt ): | |
141 # Get our modifiers | |
142 numDie = self.numDieText.GetValue() | |
143 dieMod = self.dieModText.GetValue() | |
144 # Init the die roll text | |
145 if not len(numDie): | |
146 numDie = 1 | |
147 dieRoll = str(numDie) | |
148 # Figure out which die roll was selected | |
149 id = evt.GetId() | |
150 recycle_bin = {TB_IDC_D4: "d4", TB_IDC_D6: "d6", TB_IDC_D8: "d8", TB_IDC_D10: "d10", TB_IDC_D12: "d12", TB_IDC_D20: "d20", TB_IDC_D100: "d100"} | |
151 dieType = recycle_bin[id]; recycle_bin = {} | |
152 # To appease tdb...I personally disagree with this! | |
153 if len(dieMod) and dieMod[0] not in "*/-+": | |
154 dieMod = "+" + dieMod | |
155 # Build the complete die roll text now | |
156 rollString = "[" + dieRoll + dieType + dieMod + "]" | |
157 # Now, call the post method to send everything off with | |
158 if self.callBack != None: | |
159 self.callBack( rollString,1,1 ) |