105
|
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: mapper/min_dialogs.py
|
|
21 # Author: Chris Davis
|
|
22 # Maintainer:
|
|
23 # Version:
|
|
24 # $Id: min_dialogs.py,v 1.27 2006/11/13 02:23:16 digitalxero Exp $
|
|
25 #
|
|
26 # Description: This file contains some of the basic definitions for the chat
|
|
27 # utilities in the orpg project.
|
|
28
|
|
29 ##-----------------------------
|
|
30 ## token List Panel
|
|
31 ##-----------------------------
|
|
32
|
|
33 from tokens import *
|
|
34
|
|
35 class min_list_panel(wx.Dialog):
|
|
36
|
|
37 def __init__(self, parent,layers, log, pos =(-1,-1)):
|
|
38 wx.Dialog.__init__(self, parent,-1, log,pos = (-1,-1), size = (785,175), style=wx.RESIZE_BORDER)
|
|
39 listID = wx.NewId()
|
|
40 self.parent = parent
|
|
41 self.min = layers['tokens'].tokens
|
|
42 self.grid = layers['grid']
|
|
43 self.layers = layers
|
|
44 self.listID = listID
|
|
45 list_sizer = wx.BoxSizer(wx.VERTICAL)
|
|
46 self.list_sizer = list_sizer
|
|
47 listctrl = wx.ListCtrl(self, listID, style=wx.LC_REPORT | wx.SUNKEN_BORDER)
|
|
48 self.listctrl = listctrl
|
|
49 self.Centre(wx.BOTH)
|
|
50 self.log = log
|
|
51 self.list_sizer.Add(self.listctrl,1,wx.EXPAND)
|
|
52 self.listctrl.InsertColumn(0,"POS ")
|
|
53 self.listctrl.InsertColumn(0,"LOCKED")
|
|
54 self.listctrl.InsertColumn(0,"HEADING")
|
|
55 self.listctrl.InsertColumn(0,"FACING")
|
|
56 self.listctrl.InsertColumn(0,"LABEL")
|
|
57 self.listctrl.InsertColumn(0,"PATH")
|
|
58 self.listctrl.SetColumnWidth(1, wx.LIST_AUTOSIZE_USEHEADER)
|
|
59 self.listctrl.SetColumnWidth(2, wx.LIST_AUTOSIZE_USEHEADER)
|
|
60 self.listctrl.SetColumnWidth(3, wx.LIST_AUTOSIZE_USEHEADER)
|
|
61 self.listctrl.SetColumnWidth(4, wx.LIST_AUTOSIZE_USEHEADER)
|
|
62 self.listctrl.SetColumnWidth(5, wx.LIST_AUTOSIZE_USEHEADER)
|
|
63 self.list_sizer.Add(wx.Button(self, wx.ID_OK, "DONE"),0,wx.ALIGN_CENTER)
|
|
64 self.refresh()
|
|
65 self.Bind(wx.EVT_BUTTON, self.on_ok, id=wx.ID_OK)
|
|
66 self.listctrl.Bind(wx.EVT_COMMAND_RIGHT_CLICK, self.OnRightClick, id=listID)
|
|
67 self.listctrl.Bind(wx.EVT_RIGHT_UP, self.OnRightClick)
|
|
68 self.listctrl.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
|
|
69 self.SetSizer(self.list_sizer)
|
|
70 self.SetAutoLayout(True)
|
|
71 self.Fit()
|
|
72
|
|
73 def OnRightClick(self,event):
|
|
74 if self.listctrl.GetSelectedItemCount() > 0:
|
|
75 menu = wx.Menu()
|
|
76 lPopupID1 = wx.NewId()
|
|
77 lPopupID2 = wx.NewId()
|
|
78 lPopupID3 = wx.NewId()
|
|
79 menu.Append(lPopupID1, "&Edit")
|
|
80 menu.Append(lPopupID2, "&Delete")
|
|
81 menu.Append(lPopupID3, "To &Gametree")
|
|
82 self.Bind(wx.EVT_MENU, self.onEdit, id=lPopupID1)
|
|
83 self.Bind(wx.EVT_MENU, self.onDelete, id=lPopupID2)
|
|
84 self.Bind(wx.EVT_MENU, self.onToGametree, id=lPopupID3)
|
|
85 self.PopupMenu(menu, cmpPoint(self.x, self.y))
|
|
86 menu.Destroy()
|
|
87 event.Skip()
|
|
88
|
|
89 def refresh(self):
|
|
90 self.SetMinSize((600,175));
|
|
91 for m in self.min:
|
|
92 self.listctrl.InsertStringItem(self.min.index(m),self.min[self.min.index(m)].path)
|
|
93 self.listctrl.SetStringItem(self.min.index(m),1,self.min[self.min.index(m)].label)
|
|
94 self.listctrl.SetStringItem(self.min.index(m),2,`self.min[self.min.index(m)].heading`)
|
|
95 #self.listctrl.SetStringItem(self.min.index(m),3,`self.min[self.min.index(m)].face`)
|
|
96 self.listctrl.SetStringItem(self.min.index(m),4,`self.min[self.min.index(m)].locked`)
|
|
97 self.listctrl.SetStringItem(self.min.index(m),5,`self.min[self.min.index(m)].pos`)
|
|
98 oldcolumnwidth = self.listctrl.GetColumnWidth(0)
|
|
99 self.listctrl.SetColumnWidth(0, wx.LIST_AUTOSIZE)
|
|
100 if oldcolumnwidth < self.listctrl.GetColumnWidth(0): self.listctrl.SetColumnWidth(0, wx.LIST_AUTOSIZE)
|
|
101 else: self.listctrl.SetColumnWidth(0, oldcolumnwidth)
|
|
102 self.list_sizer=self.list_sizer
|
|
103
|
|
104 def onEdit(self,event):
|
|
105 min_list = []
|
|
106 min_index = []
|
|
107 loop_count = 0
|
|
108 item =-1
|
|
109 while True:
|
|
110 loop_count += 1
|
|
111 item = self.listctrl.GetNextItem(item,wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)
|
|
112 if item == -1: break
|
|
113 min_list.append(self.min[item])
|
|
114 min_index.append(item-loop_count+1)
|
|
115 if len(min_list) > 0: dlg = min_list_edit_dialog(self.parent,min_index, min_list,self.layers)
|
|
116 if dlg.ShowModal() == wx.ID_OK: pass
|
|
117 self.listctrl.DeleteAllItems()
|
|
118 self.refresh()
|
|
119 event.Skip()
|
|
120
|
|
121 def onDelete(self,event):
|
|
122 loop_count = 0
|
|
123 item = -1
|
|
124 while True:
|
|
125 loop_count += 1
|
|
126 item = self.listctrl.GetNextItem(item,wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)
|
|
127 if item == -1: break
|
|
128 self.layers["tokens"].del_token(self.min[item-loop_count+1])
|
|
129 self.listctrl.DeleteAllItems()
|
|
130 self.refresh()
|
|
131 event.Skip()
|
|
132
|
|
133 def onToGametree(self,event):
|
|
134 min_list = []
|
|
135 min_index = []
|
|
136 loop_count = 0
|
|
137 item =-1
|
|
138 while True:
|
|
139 loop_count += 1
|
|
140 item = self.listctrl.GetNextItem(item,wx.LIST_NEXT_ALL, wx.LIST_STATE_SELECTED)
|
|
141 if item == -1: break
|
|
142 min_list.append(self.min[item])
|
|
143 min_index.append(item-loop_count+1)
|
|
144 if len(min_list) > 0:
|
|
145 for sel_rmin in min_list:
|
|
146 #############
|
|
147 min_xml = sel_rmin.toxml(action="new")
|
|
148 node_begin = "<nodehandler module='map_token_nodehandler' class='map_token_handler' name='"
|
|
149
|
|
150 if sel_rmin.label: node_begin += sel_rmin.label + "'"
|
|
151 else: node_begin += "Unnamed token'"
|
|
152
|
|
153 node_begin += ">"
|
|
154 gametree = component.get('tree')
|
|
155 node_xml = node_begin + min_xml + '</nodehandler>'
|
|
156 print "Sending this XML to insert_xml:" + node_xml
|
|
157 gametree.insert_xml(node_xml)
|
|
158 #############
|
|
159 self.listctrl.DeleteAllItems()
|
|
160 self.refresh()
|
|
161 event.Skip()
|
|
162
|
|
163 def OnRightDown(self,event):
|
|
164 self.x = event.GetX()
|
|
165 self.y = event.GetY()
|
|
166 event.Skip()
|
|
167
|
|
168 def on_ok(self,evt):
|
|
169 self.EndModal(wx.ID_OK)
|
|
170
|
|
171 class min_list_edit_dialog(wx.Dialog):
|
|
172 def __init__(self,parent,min_index, min_list, layers):
|
|
173 wx.Dialog.__init__(self,parent,-1,"token List",wx.DefaultPosition,wx.Size(600,530))
|
|
174 self.layers = layers
|
|
175 grid = layers['grid']
|
|
176 min = layers['tokens']
|
|
177 self.min_list = min_list
|
|
178 self.min_index = min_index
|
|
179 self.min = min
|
|
180 sizer1 = wx.BoxSizer(wx.VERTICAL)
|
|
181 sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
182 self.grid = grid
|
|
183 editor = min_list_edit_panel(self, min_index, min_list,layers)
|
|
184 sizer1.Add(editor, 1, wx.EXPAND)
|
|
185 sizer.Add(wx.Button(self, wx.ID_OK, "OK"), 1, wx.EXPAND)
|
|
186 sizer.Add(wx.Size(10,10))
|
|
187 sizer.Add(wx.Size(10,10))
|
|
188 sizer.Add(wx.Button(self, wx.ID_CANCEL, "Cancel"), 1, wx.EXPAND)
|
|
189 sizer1.Add(sizer, 0, wx.EXPAND)
|
|
190 self.editor = editor
|
|
191 self.Bind(wx.EVT_BUTTON, self.on_ok, id=wx.ID_OK)
|
|
192 self.SetSizer(sizer1)
|
|
193 self.SetAutoLayout(True)
|
|
194 self.Fit()
|
|
195
|
|
196 def on_revert(self,evt):
|
|
197 pass
|
|
198
|
|
199 def on_ok(self,evt):
|
|
200 self.editor.on_ok(self.layers)
|
|
201 self.EndModal(wx.ID_OK)
|
|
202
|
|
203 class min_list_edit_panel(wx.Panel):
|
|
204 def __init__(self, parent, min_index, min_list,layers):
|
|
205 LABEL_COMBO = wx.NewId()
|
|
206 PATH_COMBO = wx.NewId()
|
|
207 POS_COMB = wx.NewId()
|
|
208 MIN_POS = wx.NewId()
|
|
209 POS_SPIN = wx.NewId()
|
|
210 self.grid = layers['grid']
|
|
211 self.min = layers['tokens'].tokens
|
|
212 self.min_list = min_list
|
|
213 self.min_index = min_index
|
|
214 self.layers = layers
|
|
215 wx.Panel.__init__(self, parent, -1)
|
|
216 self.min=min
|
|
217 listsizer = wx.StaticBoxSizer(wx.StaticBox(self,-1,"Token list properties"), wx.VERTICAL)
|
|
218 labelsizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
219 self.labelcheck = wx.CheckBox(self,-1,"Serialize")
|
|
220 labelsizer.Add(wx.StaticText(self, -1, "Label: "), 0, wx.EXPAND)
|
|
221 labelsizer.Add(self.labelcheck,wx.ALIGN_RIGHT,wx.EXPAND)
|
|
222 listsizer.Add(labelsizer,0, wx.EXPAND)
|
|
223 self.labelcombo = wx.ComboBox(self, LABEL_COMBO,"no change",style=wx.CB_DROPDOWN)
|
|
224 listsizer.Add(self.labelcombo,0, wx.EXPAND)
|
|
225 self.pathcombo = wx.ComboBox(self, PATH_COMBO, "no change",style=wx.CB_DROPDOWN)
|
|
226 self.positioncombo = wx.ComboBox(self, POS_COMB, "no change", choices=["no change"], style=wx.CB_READONLY)
|
|
227 #self.positioncombo.SetValue(`min_list[0].pos`)
|
|
228 self.labelcombo.Append("no change")
|
|
229 self.pathcombo.Append("no change")
|
|
230 for m in min_list:
|
|
231 self.labelcombo.Append(min_list[min_list.index(m)].label)
|
|
232 self.pathcombo.Append(min_list[min_list.index(m)].path)
|
|
233 self.positioncombo.Append(`min_list[min_list.index(m)].pos`)
|
|
234 listsizer.Add(wx.StaticText(self, -1, "Path:"), 0, wx.EXPAND)
|
|
235 listsizer.Add(self.pathcombo, 0, wx.EXPAND)
|
|
236 listsizer.Add(wx.Size(10,10))
|
|
237 self.heading = wx.RadioBox(self, MIN_HEADING, "Heading",
|
|
238 choices=["None","N","NE","E","SE","S","SW","W","NW","no change"], majorDimension=5, style=wx.RA_SPECIFY_COLS)
|
|
239 self.heading.SetSelection( 9 )
|
|
240 listsizer.Add( self.heading, 0, wx.EXPAND )
|
|
241 listsizer.Add(wx.Size(10,10))
|
|
242
|
|
243 ## Remove
|
|
244 #self.face = wx.RadioBox(self, MIN_FACE, "Facing",
|
|
245 # choices=["None","N","NE","E","SE","S","SW","W","NW","no change"], majorDimension=5, style=wx.RA_SPECIFY_COLS)
|
|
246 #self.face.SetSelection(9)
|
|
247 #listsizer.Add(self.face, 0, wx.EXPAND)
|
|
248
|
|
249 ###
|
|
250 ###Group together locked, Hide, and snap radioboxes in group2 box
|
|
251 ###
|
|
252 group2 = wx.BoxSizer(wx.HORIZONTAL)
|
|
253 self.locked = wx.RadioBox(self, MIN_LOCK, "Lock",
|
|
254 choices=["Don't lock","Lock","no change"],majorDimension=1,style=wx.RA_SPECIFY_COLS)
|
|
255 self.locked.SetSelection(2)
|
|
256 self.hide = wx.RadioBox(self, MIN_HIDE, "Hide",
|
|
257 choices=["Don't hide", "Hide", "no change"],majorDimension=1,style=wx.RA_SPECIFY_COLS)
|
|
258 self.hide.SetSelection(2)
|
|
259 self.snap = wx.RadioBox(self,MIN_ALIGN,"Snap",
|
|
260 choices=["Center","Top left","no change"],majorDimension=1,style=wx.RA_SPECIFY_COLS)
|
|
261 self.snap.SetSelection(2)
|
|
262 group2.Add(self.locked, 0, wx.EXPAND)
|
|
263 group2.Add(wx.Size(10,0))
|
|
264 group2.Add(self.hide, 0, wx.EXPAND)
|
|
265 group2.Add(wx.Size(10,0))
|
|
266 group2.Add(self.snap, 0, wx.EXPAND)
|
|
267 group2.Add(wx.Size(10,0))
|
|
268 listsizer.Add(group2,0,0)
|
|
269 ###
|
|
270 ###Group together the postion radiobox and the and its selection elements
|
|
271 ###
|
|
272 xpos = int(min_list[0].pos[0])
|
|
273 #xpos = int(`min_list[0].pos`[1:`min_list[0].pos`.index(',')])
|
|
274 ypos = int(min_list[0].pos[1])
|
|
275 #ypos = int(`min_list[0].pos`[`min_list[0].pos`.rfind(',')+1:len(`min_list[0].pos`)-1])
|
|
276 self.scx = wx.SpinCtrl(self, POS_SPIN, "", (-1,-1), wx.Size(75,25))
|
|
277 self.scx.SetRange(0,self.grid.return_grid()[0])
|
|
278 self.scx.SetValue(xpos)
|
|
279 self.scy = wx.SpinCtrl(self, POS_SPIN, "", (-1,-1), wx.Size(75,25))
|
|
280 self.scy.SetRange(0,self.grid.return_grid()[1])
|
|
281 self.scy.SetValue(1)
|
|
282 self.scy.SetValue(ypos)
|
|
283 positionbox = wx.BoxSizer(wx.HORIZONTAL)
|
|
284 self.poschoice = wx.RadioBox(self,MIN_POS,"Position",
|
|
285 choices=["Manual", "Existing", "no change"],majorDimension=1,style=wx.RA_SPECIFY_COLS)
|
|
286 self.poschoice.SetSelection(2)
|
|
287 positionbox.Add(self.poschoice,0,0)
|
|
288 ###
|
|
289 ### group together choices under position choice boxsizer
|
|
290 ###
|
|
291 poschoicebox = wx.BoxSizer(wx.VERTICAL)
|
|
292 ###
|
|
293 ### spinbox contains the x and y spinctrls
|
|
294 ###
|
|
295 spinbox = wx.BoxSizer(wx.HORIZONTAL)
|
|
296 group2.Add(positionbox,0, wx.EXPAND)
|
|
297 xpos = wx.StaticText(self, -1,"XPOS: ")
|
|
298 spinbox.Add(xpos,0, 0)
|
|
299 spinbox.Add(self.scx, 0, 0)
|
|
300 ypos = wx.StaticText(self, -1,"YPOS: ")
|
|
301 spinbox.Add(ypos,0, 0)
|
|
302 spinbox.Add(self.scy, 0, 0)
|
|
303 poschoicebox.Add(wx.Size(0,15))
|
|
304 poschoicebox.Add(spinbox,0,0)
|
|
305 ###
|
|
306 ### kludge is just a way to horizontaly position text. .Add doesn't seem to work.
|
|
307 ###
|
|
308 kluge = wx.BoxSizer(wx.HORIZONTAL)
|
|
309 klugetext = wx.StaticText(self, -1, " ")
|
|
310 kluge.Add(klugetext,0,0)
|
|
311 kluge.Add(self.positioncombo,0,0)
|
|
312 poschoicebox.Add(wx.Size(0,1))
|
|
313 poschoicebox.Add(kluge,0,0)
|
|
314 positionbox.Add(poschoicebox,0,0)
|
|
315 listsizer.Add(positionbox,0, 0)
|
|
316 self.listsizer = listsizer
|
|
317 #self.outline = wx.StaticBox(self,-1,"token list properties")
|
|
318 #listsizer.Add(self.outline,0, wx.EXPAND)
|
|
319 self.SetSizer(listsizer)
|
|
320 self.SetAutoLayout(True)
|
|
321 self.Fit()
|
|
322 self.Bind(wx.EVT_SPINCTRL, self.on_spin, id=POS_SPIN)
|
|
323 self.Bind(wx.EVT_TEXT, self.on_combo_box, id=POS_COMB)
|
|
324 #self.Bind(wx.EVT_SIZE, self.on_size)
|
|
325 self.Bind(wx.EVT_TEXT, self.on_text, id=MIN_LABEL)
|
|
326 self.Bind(wx.EVT_RADIOBOX, self.on_radio_box, id=MIN_HEADING)
|
|
327 self.Bind(wx.EVT_RADIOBOX, self.on_radio_box, id=MIN_FACE)
|
|
328
|
|
329 def on_ok(self,min):
|
|
330 self.min = min
|
|
331 for m in self.min_list:
|
|
332 if self.hide.GetSelection() !=2: m.hide = self.hide.GetSelection()
|
|
333 if self.heading.GetSelection() !=9: m.heading = self.heading.GetSelection()
|
|
334 #if self.face.GetSelection() !=9: m.face = self.face.GetSelection()
|
|
335 if self.locked.GetSelection() !=2: m.locked = self.locked.GetSelection()
|
|
336 if self.snap.GetSelection() !=2: m.snap_to_align = self.snap.GetSelection()
|
|
337 if self.labelcombo.GetValue() != "no change":
|
|
338 m.label = self.labelcombo.GetValue()
|
|
339 if self.labelcheck.GetValue(): m.label += " " + `self.layers['tokens'].next_serial()`
|
|
340 if self.pathcombo.GetValue() != "no change":
|
|
341 path = self.pathcombo.GetValue()
|
|
342 image = self.evaluate(path)
|
|
343 if str(image[1]) != '-1':
|
|
344 m.path = image[0]
|
|
345 m.bmp = image[1]
|
|
346 else:
|
|
347 image[-1] = -1
|
|
348 while image[1] == -1:
|
|
349 image = 0
|
|
350 self.dlg = wx.TextEntryDialog(self,
|
|
351 'You entered an invalid URL for the image path. Please Enter a valid URL or cancel to leave the old url unchanged')
|
|
352 if self.dlg.ShowModal() == wx.ID_OK:
|
|
353 path = self.dlg.GetValue()
|
|
354 image = self.evaluate(path)
|
|
355 if image[1] != -1:
|
|
356 m.path = image[0]
|
|
357 m.bmp = image[1]
|
|
358 self.dlg.Destroy()
|
|
359 else: break
|
|
360 if self.poschoice.GetSelection() !=2:
|
|
361 if self.poschoice.GetSelection() == 0: m.pos = cmpPoint(self.scx.GetValue(),self.scy.GetValue())
|
|
362 else:
|
|
363 pos = self.positioncombo.GetValue()
|
|
364 m.pos = cmpPoint(int(`pos`[2:`pos`.index(",")]),int(`pos`[`pos`.rfind(',')+1:len(`pos`)-2]))
|
|
365 self.layers["tokens"].canvas.send_map_data()
|
|
366
|
|
367 def evaluate(self, ckpath):
|
|
368 path = []
|
|
369 if ckpath[:7] != "http://": ckpath = "http://" + ckpath
|
|
370 path = self.check_path(ckpath)
|
|
371 return [ckpath, path]
|
|
372
|
|
373 def check_path(self, path):
|
|
374 if ImageHandler.Cache.has_key(path): return ImageHandler.Cache[path]
|
|
375 img = ImageHandler.directLoad(path)
|
|
376 if img is None: return -1
|
|
377 return img
|
|
378
|
|
379 def on_text(self,evt):
|
|
380 id=evt.GetId()
|
|
381
|
|
382 def on_spin(self,evt):
|
|
383 self.poschoice.SetSelection(0)
|
|
384
|
|
385 def on_combo_box(self,evt):
|
|
386 self.poschoice.SetSelection(1)
|
|
387
|
|
388 def on_radio_box(self,evt):
|
|
389 id=evt.GetId()
|
|
390 index = evt.GetInt()
|
|
391
|
|
392 def on_size(self,evt):
|
|
393 s = self.GetClientSizeTuple()
|
|
394 self.listsizer.SetDimension(20,20,s[0]-40,s[1]-40)
|
|
395 self.outline.SetDimensions(5,5,s[0]-10,s[1]-10)
|
|
396
|
|
397 ##-----------------------------
|
|
398 ## token Prop Panel
|
|
399 ##-----------------------------
|
|
400
|
|
401 MIN_LABEL = wx.NewId()
|
|
402 MIN_HEADING = wx.NewId()
|
|
403 MIN_FACE = wx.NewId()
|
|
404 MIN_HIDE = wx.NewId()
|
|
405 MIN_LOCK = wx.NewId()
|
|
406 MIN_ALIGN = wx.NewId()
|
|
407 wxID_MIN_WIDTH = wx.NewId()
|
|
408 wxID_MIN_HEIGHT = wx.NewId()
|
|
409 wxID_MIN_SCALING = wx.NewId()
|
|
410
|
|
411 class min_edit_panel(wx.Panel):
|
|
412 def __init__(self, parent, min):
|
|
413 wx.Panel.__init__(self, parent, -1)
|
|
414 self.min = min
|
|
415 sizer = wx.StaticBoxSizer(wx.StaticBox(self,-1,"token"), wx.VERTICAL)
|
|
416 sizerSize = wx.BoxSizer(wx.HORIZONTAL)
|
|
417 hSizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
418 self.label = wx.TextCtrl(self, MIN_LABEL, min.label)
|
|
419 sizer.Add(wx.StaticText(self, -1, "Label:"), 0, wx.EXPAND)
|
|
420 sizer.Add(self.label, 0, wx.EXPAND)
|
|
421 sizer.Add(wx.Size(10,10))
|
|
422 self.heading = wx.RadioBox(self, MIN_HEADING, "Heading",
|
|
423 choices=["None","N","NE",
|
|
424 "E","SE","S",
|
|
425 "SW","W","NW"],majorDimension=5,style=wx.RA_SPECIFY_COLS)
|
|
426 self.heading.SetSelection(min.heading)
|
|
427 #self.face = wx.RadioBox(self, MIN_FACE, "Facing",
|
|
428 # choices=["None","N","NE",
|
|
429 # "E","SE","S",
|
|
430 # "SW","W","NW"],majorDimension=5,style=wx.RA_SPECIFY_COLS)
|
|
431 #self.face.SetSelection(min.face)
|
|
432 self.locked = wx.CheckBox(self, MIN_LOCK, " Lock")
|
|
433 self.locked.SetValue(min.locked)
|
|
434 self.hide = wx.CheckBox(self, MIN_HIDE, " Hide")
|
|
435 self.hide.SetValue(min.hide)
|
|
436 sizer.Add(self.heading, 0, wx.EXPAND)
|
|
437 sizer.Add(wx.Size(10,10))
|
|
438 #sizer.Add(self.face, 0, wx.EXPAND)
|
|
439 sizer.Add(wx.Size(10,10))
|
|
440 #
|
|
441 #image resizing
|
|
442 #
|
|
443 self.min_width_old_value = str(self.min.bmp.GetWidth())
|
|
444 self.min_width = wx.TextCtrl(self, wxID_MIN_WIDTH, self.min_width_old_value)
|
|
445 sizerSize.Add(wx.StaticText(self, -1, "Width: "), 0, wx.ALIGN_CENTER)
|
|
446 sizerSize.Add(self.min_width, 1, wx.EXPAND)
|
|
447 sizerSize.Add(wx.Size(20, 25))
|
|
448
|
|
449 #TODO:keep in mind that self.min is a local copy???
|
|
450 self.min_height_old_value = str(self.min.bmp.GetHeight())
|
|
451 self.min_height = wx.TextCtrl(self, wxID_MIN_HEIGHT, self.min_height_old_value)
|
|
452 sizerSize.Add(wx.StaticText(self, -1, "Height: "),0,wx.ALIGN_CENTER)
|
|
453 sizerSize.Add(self.min_height, 1, wx.EXPAND)
|
|
454 self.min_scaling = wx.CheckBox(self, wxID_MIN_SCALING, "Lock scaling")
|
|
455 self.min_scaling.SetValue(True)
|
|
456 sizerSize.Add(self.min_scaling, 1, wx.EXPAND)
|
|
457 sizer.Add(sizerSize, 0, wx.EXPAND)
|
|
458 sizer.Add(wx.Size(10, 10))
|
|
459
|
|
460 # Now, add the last items on in their own sizer
|
|
461 hSizer.Add(self.locked, 0, wx.EXPAND)
|
|
462 hSizer.Add(wx.Size(10,10))
|
|
463 hSizer.Add(self.hide, 0, wx.EXPAND)
|
|
464
|
|
465 # Add the hSizer to the main sizer
|
|
466 sizer.Add( hSizer )
|
|
467 self.sizer = sizer
|
|
468 self.SetSizer(self.sizer)
|
|
469 self.SetAutoLayout(True)
|
|
470 self.Fit()
|
|
471
|
|
472 #self.Bind(wx.EVT_SIZE, self.on_size)
|
|
473 self.Bind(wx.EVT_TEXT, self.on_text, id=MIN_LABEL)
|
|
474 self.Bind(wx.EVT_TEXT, self.on_scaling, id=wxID_MIN_WIDTH)
|
|
475 self.Bind(wx.EVT_TEXT, self.on_scaling, id=wxID_MIN_HEIGHT)
|
|
476 self.Bind(wx.EVT_RADIOBOX, self.on_radio_box, id=MIN_HEADING)
|
|
477 #self.Bind(wx.EVT_RADIOBOX, self.on_radio_box, id=MIN_FACE)
|
|
478
|
|
479 def on_scaling(self, evt):
|
|
480 if self.min_scaling.GetValue() == False: return
|
|
481 elif self.min_width.GetValue() and wxID_MIN_WIDTH == evt.GetId() and self.min_width.GetInsertionPoint():
|
|
482 self.min_height.SetValue(str(int((float(self.min_width.GetValue()) / float(self.min_width_old_value)) * float(self.min_height_old_value))) )
|
|
483 elif self.min_height.GetValue() and wxID_MIN_HEIGHT == evt.GetId() and self.min_height.GetInsertionPoint():
|
|
484 self.min_width.SetValue(str(int((float(self.min_height.GetValue()) / float(self.min_height_old_value)) * float(self.min_width_old_value))) )
|
|
485
|
|
486 def update_min(self):
|
|
487 self.min.set_min_props(self.heading.GetSelection(),
|
|
488 #self.face.GetSelection(),
|
|
489 self.label.GetValue(),
|
|
490 self.locked.GetValue(),
|
|
491 self.hide.GetValue(),
|
|
492 self.min_width.GetValue(),
|
|
493 self.min_height.GetValue())
|
|
494
|
|
495 def on_radio_box(self,evt):
|
|
496 id = evt.GetId()
|
|
497 index = evt.GetInt()
|
|
498
|
|
499 def on_text(self,evt):
|
|
500 id = evt.GetId()
|
|
501
|
|
502 def on_size(self,evt):
|
|
503 s = self.GetClientSizeTuple()
|
|
504 self.sizer.SetDimension(20,20,s[0]-40,s[1]-40)
|
|
505 self.outline.SetDimensions(5,5,s[0]-10,s[1]-10)
|
|
506
|
|
507 class min_edit_dialog(wx.Dialog):
|
|
508 def __init__(self,parent,min):
|
|
509 #520,265
|
|
510 wx.Dialog.__init__(self,parent,-1,"token",wx.DefaultPosition,wx.Size(520,350))
|
|
511 (w,h) = self.GetClientSizeTuple()
|
|
512 mastersizer = wx.BoxSizer(wx.VERTICAL)
|
|
513 editor = min_edit_panel(self,min)
|
|
514 #editor.SetDimensions(0,0,w,h-25)
|
|
515 self.editor = editor
|
|
516 mastersizer.Add(editor, 1, wx.EXPAND)
|
|
517 mastersizer.Add(wx.Size(10,10))
|
|
518 sizer = wx.BoxSizer(wx.HORIZONTAL)
|
|
519 sizer.Add(wx.Button(self, wx.ID_OK, "OK"), 1, wx.EXPAND)
|
|
520 sizer.Add(wx.Size(10,10))
|
|
521 sizer.Add(wx.Button(self, wx.ID_CANCEL, "Cancel"), 1, wx.EXPAND)
|
|
522 #sizer.SetDimension(0,h-25,w,25)
|
|
523 mastersizer.Add(sizer, 0, wx.EXPAND)
|
|
524 self.SetSizer(mastersizer)
|
|
525 self.SetAutoLayout(True)
|
|
526 self.Fit()
|
|
527 self.Bind(wx.EVT_BUTTON, self.on_ok, id=wx.ID_OK)
|
|
528
|
|
529 def on_ok(self,evt):
|
|
530 self.editor.update_min()
|
|
531 self.EndModal(wx.ID_OK)
|