changeset 112:61fc775862f7 alpha

Traipse Alpha 'OpenRPG' {091009-00} 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: {091006} 00: Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images! 03: Changes made to the map for increased portability. SnowDog has changes planned in Core, though. Added an initial push to the BCG. Not much to see, just shows off how it is re-writing Main code. {091008} 00: Fix to remote admin commands 01: Minor fix to texted based server, works in /System/ folder Some Core changes to gametree to correctly disply Pretty Print, thanks David! {091009} 00: Fix to Splitter Nodes not being created. Plugin Control panel works with images now Fix to massive amounts of images loading; from Core
author sirebral
date Fri, 09 Oct 2009 23:26:21 -0500
parents 0c936d98f9eb
children f91b70c46908
files orpg/mapper/images.py orpg/templates/default_LobbyMessage.html orpg/templates/nodes/split.xml orpg/tools/pluginui.py
diffstat 4 files changed, 104 insertions(+), 83 deletions(-) [+]
line wrap: on
line diff
--- a/orpg/mapper/images.py	Thu Oct 08 09:10:55 2009 -0500
+++ b/orpg/mapper/images.py	Fri Oct 09 23:26:21 2009 -0500
@@ -25,131 +25,148 @@
 #
 # Description:
 #
-__version__ = "$Id: images.py,v 1.21 2007/12/11 04:07:15 digitalxero Exp $"
+from __future__ import with_statement
 
 import urllib
 import Queue
 import thread
 from threading import Lock
 import time
+from orpg.orpg_wx import *
+from orpg.orpgCore import *
 
-from orpg.orpg_wx import *
-from orpg.orpgCore import component
 from orpg.dirpath import dir_struct
 from orpg.tools.orpg_log import logger
-
-def singleton(cls):
-    instances = {}
-    def getinstance():
-        if cls not in instances:
-            instances[cls] = cls()
-        return instances[cls]
-    return getinstance()
+from orpg.tools.orpg_settings import settings
 
 class ImageHandlerClass(object):
     __cache = {}
     __fetching = {}
     __queue = Queue.Queue(0)
     __lock = Lock()
-    chat = component.get("chat")
+
+    def __new__(cls):
+        it = cls.__dict__.get("__it__")
+        if it is not None:
+            return it
+        cls.__it__ = it = object.__new__(cls)
+        return it
 
     def load(self, path, image_type, imageId):
-        """Load an image, with a intermideary fetching image shown while it loads in a background thread"""
-        if self.__cache.has_key(path): return wx.ImageFromMime(self.__cache[path][1], 
-                                                self.__cache[path][2]).ConvertToBitmap()
-        if not self.__fetching.has_key(path):
+        # Load an image, with a intermideary fetching image shown while it loads in a background thread
+        if self.__cache.has_key(path):
+            return wx.ImageFromMime(self.__cache[path][1],
+                                    self.__cache[path][2]).ConvertToBitmap()
+        if path not in self.__fetching:
             self.__fetching[path] = True
-            """Start Image Loading Thread"""
-            thread.start_new_thread(self.__loadThread, (path, image_type, imageId))
+            #Start Image Loading Thread
+            thread.start_new_thread(self.__loadThread,
+                                    (path, image_type, imageId))
         else:
-            if self.__fetching[path] is True: thread.start_new_thread(self.__loadCacheThread, (path, image_type, imageId))
-        return wx.Bitmap(dir_struct["icon"] + "fetching.png", wx.BITMAP_TYPE_PNG)
+            if self.__fetching[path]:
+                thread.start_new_thread(self.__loadCacheThread,
+                                        (path, image_type, imageId))
+        return wx.Bitmap(dir_struct["icon"] + "fetching.png",
+                         wx.BITMAP_TYPE_PNG)
 
     def directLoad(self, path):
-        """Directly load an image, no threads"""
-        if self.__cache.has_key(path): return wx.ImageFromMime(self.__cache[path][1], 
-                                                self.__cache[path][2]).ConvertToBitmap()
+        # Directly load an image, no threads
+        if path in self.__cache:
+            return wx.ImageFromMime(self.__cache[path][1],
+                                    self.__cache[path][2]).ConvertToBitmap()
+
         uriPath = urllib.unquote(path)
         try:
             d = urllib.urlretrieve(uriPath)
-            """We have to make sure that not only did we fetch something, but that
-               it was an image that we got back."""
+            # We have to make sure that not only did we fetch something, but that
+            # it was an image that we got back.
             if d[0] and d[1].getmaintype() == "image":
-                self.__cache[path] = (path, d[0], d[1].gettype(), None)
-                return wx.ImageFromMime(self.__cache[path][1], self.__cache[path][2]).ConvertToBitmap()
+                with self.__lock:
+                    self.__cache[path] = (path, d[0], d[1].gettype(), None)
+                return wx.ImageFromMime(self.__cache[path][1],
+                                        self.__cache[path][2]).ConvertToBitmap()
             else:
-                logger.exception(str("Image refused to load or URI did not reference a valid image: " + path), True)
+                logger.general("Image refused to load or URI did not "
+                               "reference a valid image: " + path, True)
                 return None
         except IOError:
-            logger.exception(str("Unable to resolve/open the specified URI; image was NOT loaded: " + path), True)
+            logger.general("Unable to resolve/open the specified URI; "
+                           "image was NOT loaded: " + path, True)
             return None
 
     def cleanCache(self):
-        """Shrinks the Cache down to the proper size"""
-        try: cacheSize = int(component.get('settings').get_setting("ImageCacheSize"))
-        except: cacheSize = 32
+        # Shrinks the Cache down to the proper size
+        try:
+            cacheSize = int(settings.get("ImageCacheSize"))
+        except:
+            cacheSize = 32
         cache = self.__cache.keys()
         cache.sort()
-        for key in cache[cacheSize:]: del self.__cache[key]
+        for key in cache[cacheSize:]:
+            del self.__cache[key]
 
     def flushCache(self):
-        """This function will flush all images contained within the image cache."""
-        self.__lock.acquire()
-        try:
+        # This function will flush all images contained within the image cache.
+        with self.__lock:
             self.__cache = {}
             self.__fetching = {}
-        finally: 
-            self.__lock.release()
             urllib.urlcleanup()
 
-    """Private Methods"""
+#Private Methods
     def __loadThread(self, path, image_type, imageId):
         uriPath = urllib.unquote(path)
-        self.__lock.acquire()
+
         try:
             d = urllib.urlretrieve(uriPath)
-            """We have to make sure that not only did we fetch something, but that
-               it was an image that we got back."""
+            # We have to make sure that not only did we fetch something, but that
+            # it was an image that we got back.
             if d[0] and d[1].getmaintype() == "image":
-                self.__cache[path] = (path, d[0], d[1].gettype(), imageId)
-                self.__queue.put((self.__cache[path], image_type, imageId))
-                if self.__fetching.has_key(path): del self.__fetching[path]
+                with self.__lock:
+                    self.__cache[path] = (path, d[0], d[1].gettype(), imageId)
+                    self.__queue.put((self.__cache[path], image_type, imageId))
+
+                if path in self.__fetching:
+                    del self.__fetching[path]
             else:
-                logger.exception(str("Image refused to load or URI did not reference a valid image: " + path), True)
+                logger.general("Image refused to load or URI did not "
+                               "reference a valid image: " + path, True)
                 del self.__fetching[path]
         except IOError:
             del self.__fetching[path]
-            logger.exception(str("Unable to resolve/open the specified URI; image was NOT loaded: " + path), True)
-        finally: self.__lock.release()
+            logger.general("Unable to resolve/open the specified URI; "
+                           "image was NOT laoded: " + path, True)
 
     def __loadCacheThread(self, path, image_type, imageId):
         try:
             st = time.time()
-            while self.__fetching.has_key(path) and self.__fetching[path] is not False:
+            while path in self.__fetching and self.__fetching[path] is not False:
                 time.sleep(0.025)
                 if (time.time()-st) > 120:
-                    logger.general("Timeout: " + path)
+                    logger.general("Timeout: " + path, True)
+                    del self.__fetching[path]
                     break
         except:
             del self.__fetching[path]
-            logger.exception(str("Unable to resolve/open the specified URI; image was NOT loaded: " + path), True)
-            return 
-        self.__lock.acquire()
-        try:
-            logger.info("Adding Image to Queue from Cache: " + str(self.__cache[path]), True)
-            self.__queue.put((self.__cache[path], image_type, imageId))
-        finally: self.__lock.release()
+            logger.general("Unable to resolve/open the specified URI; "
+                           "image was NOT loaded: " + path, True)
+            return
 
-    """Property Methods"""
+        with self.__lock:
+            if path in self.__cache:
+                logger.debug("Adding Image to Queue from Cache: " + str(self.__cache[path]))
+                self.__queue.put((self.__cache[path], image_type, imageId))
+            else:
+                self.__loadThread(path, image_type, imageId)
+
+    #Property Methods
     def _getCache(self):
         return self.__cache
 
     def _getQueue(self):
         return self.__queue
 
-    """Properties"""
+    #Properties
     Cache = property(_getCache)
     Queue = property(_getQueue)
 
-ImageHandler = singleton(ImageHandlerClass)
-component.add('ImageHandler', ImageHandler)
+ImageHandler = ImageHandlerClass()
\ No newline at end of file
--- a/orpg/templates/default_LobbyMessage.html	Thu Oct 08 09:10:55 2009 -0500
+++ b/orpg/templates/default_LobbyMessage.html	Fri Oct 09 23:26:21 2009 -0500
@@ -20,7 +20,8 @@
             Bernhard Bergbauer, Chris Blocher ,Ben Collins-Sussman, Robin Cook, Greg Copeland,
             Chris Davis, Michael Edwards, Andrew Ettinger, Dj Gilcrease, Todd Faris,
             Christopher Hickman, Paul Hosking, Scott Mackay, Brian Manning,
-            Jesse McConnell, Brian Osman, Rome Reginelli, Christopher Rouse, Dave Sanders and Mark Tarrabain.
+            Jesse McConnell, Brian Osman, Rome Reginelli, Christopher Rouse, Dave Sanders, Mark Tarrabain,
+            David Byron, and Tyler Starke.
             </td>
               </tr>
                 <tr>
--- a/orpg/templates/nodes/split.xml	Thu Oct 08 09:10:55 2009 -0500
+++ b/orpg/templates/nodes/split.xml	Fri Oct 09 23:26:21 2009 -0500
@@ -1,2 +1,3 @@
-
-<nodehandler class="splitter_handler" icon="divider" module="containers" name="Splitter" version="1.0"/>
\ No newline at end of file
+  <nodehandler class="splitter_handler" icon="divider" module="containers" name="Splitter" version="1.0">
+    <splitter_atts horizontal="0"/>
+  </nodehandler>
\ No newline at end of file
--- a/orpg/tools/pluginui.py	Thu Oct 08 09:10:55 2009 -0500
+++ b/orpg/tools/pluginui.py	Fri Oct 09 23:26:21 2009 -0500
@@ -51,9 +51,9 @@
         self.err_sizer.Add(self.errorMessage, 0, wx.EXPAND)
         self.main_sizer.Add(self.err_sizer, 0, wx.EXPAND)
         self.pluginList = wx.ListCtrl(self.panel, wx.ID_ANY, style=wx.LC_SINGLE_SEL|wx.LC_REPORT|wx.LC_HRULES|wx.LC_SORT_ASCENDING)
-        self.pluginList.InsertColumn(0, "Autostart")
-        self.pluginList.InsertColumn(1, "Name")
-        self.pluginList.InsertColumn(2, "Author")
+        #self.pluginList.InsertColumn(0, "Autostart")
+        self.pluginList.InsertColumn(0, "Name")
+        self.pluginList.InsertColumn(1, "Author")
         self.Bind(wx.EVT_LIST_ITEM_SELECTED, self._selectPlugin, self.pluginList)
         self.Bind(wx.EVT_LIST_ITEM_DESELECTED, self._deselectPlugin, self.pluginList)
         self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self._togglePlugin, self.pluginList)
@@ -166,14 +166,14 @@
     def _selectPlugin(self, evt):
         self._selectedPlugin = evt.GetIndex()
         self.__enablePluginBtns()
-        pname = self.pluginList.GetItem(self._selectedPlugin, 1).GetText()
+        pname = self.pluginList.GetItem(self._selectedPlugin, 0).GetText()
         info = self.available_plugins[pname]
 
         if info[0] in self.enabled_plugins:
             self.enableBtn.Disable()
         else:
             self.disableBtn.Disable()
-        if self.pluginList.GetItem(self._selectedPlugin, 0).GetText() == "X":
+        if pname in self.startplugs:
             self.autostartBtn.Label = "Disable Autostart"
 
         self.__doLayout()
@@ -185,14 +185,12 @@
 
     def _togglePlugin(self, evt):
         idx = evt.GetIndex()
-        pname = self.pluginList.GetItem(idx, 0).GetText()
+        pname = self.pluginList.GetItem(idx, 1).GetText()
         info = self.available_plugins[pname]
-
         if info[0] in self.enabled_plugins:
             self._disable(idx)
         else:
             self._enable(idx)
-
         self.pluginList.SetItemState(self._selectedPlugin, 0, wx.LIST_STATE_SELECTED)
 
     def _enableAll(self, evt):
@@ -206,7 +204,7 @@
         idx = self.__checkIdx(evt)
         if idx is None:
             return
-        pname = self.pluginList.GetItem(idx, 1).GetText()
+        pname = self.pluginList.GetItem(idx, 0).GetText()
         info = self.available_plugins[pname]
         info[1].menu_start()
 
@@ -227,14 +225,16 @@
 
     def _disableAll(self, evt):
         for entry in self.enabled_plugins.keys():
-            #idx = self.pluginList.FindItem(1, self.enabled_plugins[entry].name) #Old Method
-            self._disable(self.enabled_plugins[entry]) #New Method
+            #print self.pluginList.FindItem(1, self.enabled_plugins[entry])
+            idx = self.pluginList.FindItem(0, self.enabled_plugins[entry].name)
+            print self.pluginList
+            self._disable(idx) #New Method
 
     def _disable(self, evt):
         idx = self.__checkIdx(evt)
         if idx is None:
             return
-        pname = self.pluginList.GetItem(idx, 1).GetText()
+        pname = self.pluginList.GetItem(idx, 0).GetText()
         info = self.available_plugins[pname]
         info[1].menu_cleanup()
         try:
@@ -254,12 +254,12 @@
         idx = self.__checkIdx(evt)
         if idx is None:
             return
-        if self.pluginList.GetItem(idx, 1).GetText() in self.startplugs:
-            self.startplugs.remove(self.pluginList.GetItem(idx, 1).GetText())
+        if self.pluginList.GetItem(idx, 0).GetText() in self.startplugs:
+            self.startplugs.remove(self.pluginList.GetItem(idx, 0).GetText())
             self.pluginList.SetItemImage(idx, 0, 0)
             self.autostartBtn.Label = "Autostart"
         else:
-            self.startplugs.append(self.pluginList.GetItem(idx, 1).GetText())
+            self.startplugs.append(self.pluginList.GetItem(idx, 0).GetText())
             self.pluginList.SetItemImage(idx, 1, 0)
             self.autostartBtn.Label = "Disable Autostart"
 
@@ -304,15 +304,17 @@
         i = 0
         for plugname, info in self.available_plugins.iteritems():
             self.pluginNames.append(plugname)
-            idx = self.pluginList.InsertImageItem(self.pluginList.GetItemCount(), 0)
-            self.pluginList.SetStringItem(idx, 2, info[2])
-            self.pluginList.SetStringItem(idx, 1, plugname)
+            #idx = self.pluginList.InsertImageItem(self.pluginList.GetItemCount(), 0)
+            idx = self.pluginList.InsertStringItem(self.pluginList.GetItemCount(), plugname)
+            self.pluginList.SetStringItem(idx, 1, info[2])
+            self.pluginList.SetItemImage(idx, 0, 0)
+            #self.pluginList.SetStringItem(idx, 1, plugname)
             if plugname in self.startplugs:
                 self.pluginList.SetItemImage(idx, 1, 0)
                 self._enable(idx)
             self.pluginList.SetItemData(idx, i)
             i += 1
-        self.pluginList.SetColumnWidth(0, 75)
+        self.pluginList.SetColumnWidth(0, wx.LIST_AUTOSIZE)
         self.pluginList.SetColumnWidth(1, wx.LIST_AUTOSIZE)
         self.pluginList.SetColumnWidth(2, wx.LIST_AUTOSIZE)
         self.__doLayout()