diff 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
line wrap: on
line diff
--- a/orpg/mapper/miniatures_handler.py	Thu Sep 17 03:23:03 2009 -0500
+++ b/orpg/mapper/miniatures_handler.py	Thu Sep 17 04:44:37 2009 -0500
@@ -33,7 +33,7 @@
 import time
 import mimetypes
 import urllib
-import xml.dom.minidom as minidom
+
 import wx
 from grid import GRID_RECTANGLE
 from grid import GRID_HEXAGON
@@ -167,38 +167,41 @@
             thread.start_new_thread(self.canvas.layers['miniatures'].upload, 
                                     (postdata, dlg.GetPath()), {'pos':cmpPoint(x,y)})
         else:
-            try: min_url = component.get("cherrypy") + filename
-            except: return #chat.InfoPost('CherryPy is not started!')
-            min_url = dlg.GetDirectory().replace(dir_struct["user"]+'webfiles' + os.sep, 
-                component.get("cherrypy")) + '/' + filename
-            # build url
-            if min_url == "" or min_url == "http://": return
-            if min_url[:7] != "http://": min_url = "http://" + min_url
-            # make label
-            if self.auto_label and min_url[-4:-3] == '.':
-                start = min_url.rfind("/") + 1
-                min_label = min_url[start:len(min_url)-4]
-                if self.use_serial: min_label = '%s %d' % ( min_label, self.canvas.layers['miniatures'].next_serial() )
-            else: min_label = ""
-            if self.min_url.FindString(min_url) == -1: self.min_url.Append(min_url)
-            try:
-                id = 'mini-' + self.canvas.frame.session.get_next_id()
-                # make the new mini appear in top left of current viewable map
-                dc = wx.ClientDC(self.canvas)
-                self.canvas.PrepareDC(dc)
-                dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale)
-                x = dc.DeviceToLogicalX(0)
-                y = dc.DeviceToLogicalY(0)
-                self.canvas.layers['miniatures'].add_miniature(id, min_url, pos=cmpPoint(x,y), label=min_label)
-            except:
-                # When there is an exception here, we should be decrementing the serial_number for reuse!!
-                unablemsg= "Unable to load/resolve URL: " + min_url + " on resource \"" + min_label + "\"!!!\n\n"
-                dlg = wx.MessageDialog(self,unablemsg, 'Url not found',wx.ICON_EXCLAMATION)
-                dlg.ShowModal()
-                dlg.Destroy()
-                self.canvas.layers['miniatures'].rollback_serial()
-            self.canvas.send_map_data()
-            self.canvas.Refresh(False)
+            self.CherryPy(dlg.GetDirectory(), filename)
+
+    def CherryPit(self, path, filename):
+        try: min_url = component.get("cherrypy") + filename
+        except: return #chat.InfoPost('CherryPy is not started!')
+        min_url = path.replace(orpg.dirpath.dir_struct["user"]+'webfiles', 
+                component.get("cherrypy")).replace(os.sep, '/') + '/' + filename
+        # build url
+        if min_url == "" or min_url == "http://": return
+        if min_url[:7] != "http://": min_url = "http://" + min_url
+        # make label
+        if self.auto_label and min_url[-4:-3] == '.':
+            start = min_url.rfind("/") + 1
+            min_label = min_url[start:len(min_url)-4]
+            if self.use_serial: min_label = '%s %d' % ( min_label, self.canvas.layers['miniatures'].next_serial() )
+        else: min_label = ""
+        if self.min_url.FindString(min_url) == -1: self.min_url.Append(min_url)
+        try:
+            id = 'mini-' + self.canvas.frame.session.get_next_id()
+            # make the new mini appear in top left of current viewable map
+            dc = wx.ClientDC(self.canvas)
+            self.canvas.PrepareDC(dc)
+            dc.SetUserScale(self.canvas.layers['grid'].mapscale,self.canvas.layers['grid'].mapscale)
+            x = dc.DeviceToLogicalX(0)
+            y = dc.DeviceToLogicalY(0)
+            self.canvas.layers['miniatures'].add_miniature(id, min_url, pos=cmpPoint(x,y), label=min_label)
+        except:
+            # When there is an exception here, we should be decrementing the serial_number for reuse!!
+            unablemsg= "Unable to load/resolve URL: " + min_url + " on resource \"" + min_label + "\"!!!\n\n"
+            dlg = wx.MessageDialog(self,unablemsg, 'Url not found',wx.ICON_EXCLAMATION)
+            dlg.ShowModal()
+            dlg.Destroy()
+            self.canvas.layers['miniatures'].rollback_serial()
+        self.canvas.send_map_data()
+        self.canvas.Refresh(False)
 
 
     def build_menu(self,label = "Miniature"):
@@ -614,7 +617,10 @@
         y = dc.DeviceToLogicalY(y)
         (imgtype,j) = mimetypes.guess_type(filename)
         postdata = urllib.urlencode({'filename':filename, 'imgdata':imgdata, 'imgtype':imgtype})
-        thread.start_new_thread(self.canvas.layers['miniatures'].upload, (postdata, filepath), {'pos':cmpPoint(x,y)})
+        if self.settings.get_setting('LocalorRemote') == 'Remote':
+            thread.start_new_thread(self.canvas.layers['miniatures'].upload, (postdata, filepath), {'pos':cmpPoint(x,y)})
+        else:
+            self.CherryPit(filepath, '')
 
     def on_tooltip_timer(self, *args):
         pos = args[0]