comparison orpg/mapper/miniatures_handler.py @ 71:449a8900f9ac ornery-dev

Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
author sirebral
date Thu, 20 Aug 2009 03:00:39 -0500
parents c54768cffbd4
children 37a11fea3304
comparison
equal deleted inserted replaced
70:52a5fa913008 71:449a8900f9ac
115 self.tooltip_delay_miliseconds = 500 115 self.tooltip_delay_miliseconds = 500
116 self.tooltip_timer = wx.CallLater(self.tooltip_delay_miliseconds, self.on_tooltip_timer) 116 self.tooltip_timer = wx.CallLater(self.tooltip_delay_miliseconds, self.on_tooltip_timer)
117 self.tooltip_timer.Stop() 117 self.tooltip_timer.Stop()
118 dt = myFileDropTarget(self) 118 dt = myFileDropTarget(self)
119 self.canvas.SetDropTarget(dt) 119 self.canvas.SetDropTarget(dt)
120 # wxInitAllImageHandlers() 120 #wxInitAllImageHandlers()
121 121
122 def build_ctrls(self): 122 def build_ctrls(self):
123 base_layer_handler.build_ctrls(self) 123 base_layer_handler.build_ctrls(self)
124 # add controls in reverse order! (unless you want them after the default tools) 124 # add controls in reverse order! (unless you want them after the default tools)
125 self.auto_label_cb = wx.CheckBox(self, wx.ID_ANY, ' Auto Label ', (-1,-1),(-1,-1)) 125 self.auto_label_cb = wx.CheckBox(self, wx.ID_ANY, ' Auto Label ', (-1,-1),(-1,-1))
126 self.auto_label_cb.SetValue(self.auto_label) 126 self.auto_label_cb.SetValue(self.auto_label)
127 self.min_url = wx.ComboBox(self, wx.ID_ANY, "http://", style=wx.CB_DROPDOWN | wx.CB_SORT) 127 self.min_url = wx.ComboBox(self, wx.ID_ANY, "http://", style=wx.CB_DROPDOWN | wx.CB_SORT)
128 self.localBrowse = wx.Button(self, wx.ID_ANY, 'Browse', style=wx.BU_EXACTFIT) 128 self.localBrowse = wx.Button(self, wx.ID_ANY, 'Browse', style=wx.BU_EXACTFIT)
129 minilist = createMaskedButton( self, orpg.dirpath.dir_struct["icon"]+'questionhead.gif', 'Edit miniature properties', wx.ID_ANY) 129 minilist = createMaskedButton( self, dir_struct["icon"]+'questionhead.gif', 'Edit miniature properties', wx.ID_ANY)
130 miniadd = wx.Button(self, wx.ID_OK, "Add Miniature", style=wx.BU_EXACTFIT) 130 miniadd = wx.Button(self, wx.ID_OK, "Add Miniature", style=wx.BU_EXACTFIT)
131 self.sizer.Add(self.auto_label_cb,0,wx.ALIGN_CENTER) 131 self.sizer.Add(self.auto_label_cb,0,wx.ALIGN_CENTER)
132 self.sizer.Add((6, 0)) 132 self.sizer.Add((6, 0))
133 self.sizer.Add(self.min_url, 1, wx.ALIGN_CENTER) 133 self.sizer.Add(self.min_url, 1, wx.ALIGN_CENTER)
134 self.sizer.Add((6, 0)) 134 self.sizer.Add((6, 0))
142 self.Bind(wx.EVT_BUTTON, self.on_browse, self.localBrowse) 142 self.Bind(wx.EVT_BUTTON, self.on_browse, self.localBrowse)
143 self.Bind(wx.EVT_CHECKBOX, self.on_label, self.auto_label_cb) 143 self.Bind(wx.EVT_CHECKBOX, self.on_label, self.auto_label_cb)
144 144
145 def on_browse(self, evt): 145 def on_browse(self, evt):
146 if not self.role_is_gm_or_player(): return 146 if not self.role_is_gm_or_player(): return
147 dlg = wx.FileDialog(None, "Select a Miniature to load", orpg.dirpath.dir_struct["user"]+'webfiles/', 147 dlg = wx.FileDialog(None, "Select a Miniature to load", dir_struct["user"]+'webfiles/',
148 wildcard="Image files (*.bmp, *.gif, *.jpg, *.png)|*.bmp;*.gif;*.jpg;*.png", style=wx.OPEN) 148 wildcard="Image files (*.bmp, *.gif, *.jpg, *.png)|*.bmp;*.gif;*.jpg;*.png", style=wx.OPEN)
149 if not dlg.ShowModal() == wx.ID_OK: 149 if not dlg.ShowModal() == wx.ID_OK:
150 dlg.Destroy() 150 dlg.Destroy()
151 return 151 return
152 file = open(dlg.GetPath(), "rb") 152 file = open(dlg.GetPath(), "rb")
160 dc = wx.ClientDC(self.canvas) 160 dc = wx.ClientDC(self.canvas)
161 self.canvas.PrepareDC(dc) 161 self.canvas.PrepareDC(dc)
162 dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale) 162 dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale)
163 x = dc.DeviceToLogicalX(0) 163 x = dc.DeviceToLogicalX(0)
164 y = dc.DeviceToLogicalY(0) 164 y = dc.DeviceToLogicalY(0)
165 thread.start_new_thread(self.canvas.layers['miniatures'].upload, (postdata, dlg.GetPath()), {'pos':cmpPoint(x,y)}) 165 thread.start_new_thread(self.canvas.layers['miniatures'].upload,
166 (postdata, dlg.GetPath()), {'pos':cmpPoint(x,y)})
166 else: 167 else:
167 try: min_url = component.get("cherrypy") + filename 168 try: min_url = component.get("cherrypy") + filename
168 except: return 169 except: return #chat.InfoPost('CherryPy is not started!')
169 min_url = dlg.GetDirectory().replace(orpg.dirpath.dir_struct["user"]+'webfiles' + os.sep, 170 min_url = dlg.GetDirectory().replace(dir_struct["user"]+'webfiles' + os.sep,
170 component.get("cherrypy")) + '/' + filename 171 component.get("cherrypy")) + '/' + filename
171 # build url 172 # build url
172 if min_url == "" or min_url == "http://": return 173 if min_url == "" or min_url == "http://": return
173 if min_url[:7] != "http://": min_url = "http://" + min_url 174 if min_url[:7] != "http://": min_url = "http://" + min_url
174 # make label 175 # make label
188 y = dc.DeviceToLogicalY(0) 189 y = dc.DeviceToLogicalY(0)
189 self.canvas.layers['miniatures'].add_miniature(id, min_url, pos=cmpPoint(x,y), label=min_label) 190 self.canvas.layers['miniatures'].add_miniature(id, min_url, pos=cmpPoint(x,y), label=min_label)
190 except: 191 except:
191 # When there is an exception here, we should be decrementing the serial_number for reuse!! 192 # When there is an exception here, we should be decrementing the serial_number for reuse!!
192 unablemsg= "Unable to load/resolve URL: " + min_url + " on resource \"" + min_label + "\"!!!\n\n" 193 unablemsg= "Unable to load/resolve URL: " + min_url + " on resource \"" + min_label + "\"!!!\n\n"
193 #print unablemsg
194 dlg = wx.MessageDialog(self,unablemsg, 'Url not found',wx.ICON_EXCLAMATION) 194 dlg = wx.MessageDialog(self,unablemsg, 'Url not found',wx.ICON_EXCLAMATION)
195 dlg.ShowModal() 195 dlg.ShowModal()
196 dlg.Destroy() 196 dlg.Destroy()
197 self.canvas.layers['miniatures'].rollback_serial() 197 self.canvas.layers['miniatures'].rollback_serial()
198 self.canvas.send_map_data() 198 self.canvas.send_map_data()