comparison orpg/mapper/miniatures_handler.py @ 88:763a04270cf6 alpha

Traipse Alpha 'OpenRPG' {090917-02} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc''s main goal is to offer more advanced features and enhance the productivity of the user. Update Summary: 00: Adds menu changes to draw attention to important updates, errors, or other events. (image info coming soon) Traipse URL is not included in the repos tab and is set as default. 01: Fixes Copy for Windows and Linux (finally!!) users. Fixes incomplete update to Grid and List nodes. Fixes incomplete update to Chat Commands. 02: Fixes problems with Remote Image Upload. Fixes Drop and Drag of Minis to Map CherryPy can now use any image in the webfiles/ folder and sub-folders. CherryPy can now Drop and Drag Minis to the Map.
author sirebral
date Thu, 17 Sep 2009 04:44:37 -0500
parents 37a11fea3304
children 118fbe111922
comparison
equal deleted inserted replaced
87:eb1b275699c4 88:763a04270cf6
31 from min_dialogs import * 31 from min_dialogs import *
32 import thread 32 import thread
33 import time 33 import time
34 import mimetypes 34 import mimetypes
35 import urllib 35 import urllib
36 import xml.dom.minidom as minidom 36
37 import wx 37 import wx
38 from grid import GRID_RECTANGLE 38 from grid import GRID_RECTANGLE
39 from grid import GRID_HEXAGON 39 from grid import GRID_HEXAGON
40 from grid import GRID_ISOMETRIC 40 from grid import GRID_ISOMETRIC
41 import os 41 import os
165 x = dc.DeviceToLogicalX(0) 165 x = dc.DeviceToLogicalX(0)
166 y = dc.DeviceToLogicalY(0) 166 y = dc.DeviceToLogicalY(0)
167 thread.start_new_thread(self.canvas.layers['miniatures'].upload, 167 thread.start_new_thread(self.canvas.layers['miniatures'].upload,
168 (postdata, dlg.GetPath()), {'pos':cmpPoint(x,y)}) 168 (postdata, dlg.GetPath()), {'pos':cmpPoint(x,y)})
169 else: 169 else:
170 try: min_url = component.get("cherrypy") + filename 170 self.CherryPy(dlg.GetDirectory(), filename)
171 except: return #chat.InfoPost('CherryPy is not started!') 171
172 min_url = dlg.GetDirectory().replace(dir_struct["user"]+'webfiles' + os.sep, 172 def CherryPit(self, path, filename):
173 component.get("cherrypy")) + '/' + filename 173 try: min_url = component.get("cherrypy") + filename
174 # build url 174 except: return #chat.InfoPost('CherryPy is not started!')
175 if min_url == "" or min_url == "http://": return 175 min_url = path.replace(orpg.dirpath.dir_struct["user"]+'webfiles',
176 if min_url[:7] != "http://": min_url = "http://" + min_url 176 component.get("cherrypy")).replace(os.sep, '/') + '/' + filename
177 # make label 177 # build url
178 if self.auto_label and min_url[-4:-3] == '.': 178 if min_url == "" or min_url == "http://": return
179 start = min_url.rfind("/") + 1 179 if min_url[:7] != "http://": min_url = "http://" + min_url
180 min_label = min_url[start:len(min_url)-4] 180 # make label
181 if self.use_serial: min_label = '%s %d' % ( min_label, self.canvas.layers['miniatures'].next_serial() ) 181 if self.auto_label and min_url[-4:-3] == '.':
182 else: min_label = "" 182 start = min_url.rfind("/") + 1
183 if self.min_url.FindString(min_url) == -1: self.min_url.Append(min_url) 183 min_label = min_url[start:len(min_url)-4]
184 try: 184 if self.use_serial: min_label = '%s %d' % ( min_label, self.canvas.layers['miniatures'].next_serial() )
185 id = 'mini-' + self.canvas.frame.session.get_next_id() 185 else: min_label = ""
186 # make the new mini appear in top left of current viewable map 186 if self.min_url.FindString(min_url) == -1: self.min_url.Append(min_url)
187 dc = wx.ClientDC(self.canvas) 187 try:
188 self.canvas.PrepareDC(dc) 188 id = 'mini-' + self.canvas.frame.session.get_next_id()
189 dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale) 189 # make the new mini appear in top left of current viewable map
190 x = dc.DeviceToLogicalX(0) 190 dc = wx.ClientDC(self.canvas)
191 y = dc.DeviceToLogicalY(0) 191 self.canvas.PrepareDC(dc)
192 self.canvas.layers['miniatures'].add_miniature(id, min_url, pos=cmpPoint(x,y), label=min_label) 192 dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale)
193 except: 193 x = dc.DeviceToLogicalX(0)
194 # When there is an exception here, we should be decrementing the serial_number for reuse!! 194 y = dc.DeviceToLogicalY(0)
195 unablemsg= "Unable to load/resolve URL: " + min_url + " on resource \"" + min_label + "\"!!!\n\n" 195 self.canvas.layers['miniatures'].add_miniature(id, min_url, pos=cmpPoint(x,y), label=min_label)
196 dlg = wx.MessageDialog(self,unablemsg, 'Url not found',wx.ICON_EXCLAMATION) 196 except:
197 dlg.ShowModal() 197 # When there is an exception here, we should be decrementing the serial_number for reuse!!
198 dlg.Destroy() 198 unablemsg= "Unable to load/resolve URL: " + min_url + " on resource \"" + min_label + "\"!!!\n\n"
199 self.canvas.layers['miniatures'].rollback_serial() 199 dlg = wx.MessageDialog(self,unablemsg, 'Url not found',wx.ICON_EXCLAMATION)
200 self.canvas.send_map_data() 200 dlg.ShowModal()
201 self.canvas.Refresh(False) 201 dlg.Destroy()
202 self.canvas.layers['miniatures'].rollback_serial()
203 self.canvas.send_map_data()
204 self.canvas.Refresh(False)
202 205
203 206
204 def build_menu(self,label = "Miniature"): 207 def build_menu(self,label = "Miniature"):
205 base_layer_handler.build_menu(self,label) 208 base_layer_handler.build_menu(self,label)
206 self.main_menu.AppendSeparator() 209 self.main_menu.AppendSeparator()
612 dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale) 615 dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale)
613 x = dc.DeviceToLogicalX(x) 616 x = dc.DeviceToLogicalX(x)
614 y = dc.DeviceToLogicalY(y) 617 y = dc.DeviceToLogicalY(y)
615 (imgtype,j) = mimetypes.guess_type(filename) 618 (imgtype,j) = mimetypes.guess_type(filename)
616 postdata = urllib.urlencode({'filename':filename, 'imgdata':imgdata, 'imgtype':imgtype}) 619 postdata = urllib.urlencode({'filename':filename, 'imgdata':imgdata, 'imgtype':imgtype})
617 thread.start_new_thread(self.canvas.layers['miniatures'].upload, (postdata, filepath), {'pos':cmpPoint(x,y)}) 620 if self.settings.get_setting('LocalorRemote') == 'Remote':
621 thread.start_new_thread(self.canvas.layers['miniatures'].upload, (postdata, filepath), {'pos':cmpPoint(x,y)})
622 else:
623 self.CherryPit(filepath, '')
618 624
619 def on_tooltip_timer(self, *args): 625 def on_tooltip_timer(self, *args):
620 pos = args[0] 626 pos = args[0]
621 dc = wx.ClientDC(self.canvas) 627 dc = wx.ClientDC(self.canvas)
622 self.canvas.PrepareDC(dc) 628 self.canvas.PrepareDC(dc)