[Checkins] SVN: z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/ - caught up with ZPL provisions

Christian Theune ct at gocept.com
Wed Nov 29 16:50:36 EST 2006


Log message for revision 71333:
   - caught up with ZPL provisions
   - added ZEO plugin
   - cleaned up coding style and some insane methods
  

Changed:
  D   z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/MDIDemo.py
  U   z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/__init__.py
  U   z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/bases.py
  U   z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/main.py
  D   z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin1.py
  U   z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_fs.py
  A   z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_inspection.py
  U   z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_objdisp.py
  U   z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_tree.py
  A   z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_zeo.py
  U   z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/registry.py

-=-
Deleted: z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/MDIDemo.py
===================================================================
--- z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/MDIDemo.py	2006-11-29 16:17:59 UTC (rev 71332)
+++ z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/MDIDemo.py	2006-11-29 21:50:36 UTC (rev 71333)
@@ -1,91 +0,0 @@
-
-import  wx
-
-# Importing ScrolledWindow demo to make use of the MyCanvas 
-# class defined within.
-import  ScrolledWindow 
-import  images
-
-SHOW_BACKGROUND = 1
-
-#----------------------------------------------------------------------
-ID_New  = wx.NewId()
-ID_Exit = wx.NewId()
-#----------------------------------------------------------------------
-
-class MyParentFrame(wx.MDIParentFrame):
-    def __init__(self):
-        wx.MDIParentFrame.__init__(self, None, -1, "MDI Parent", size=(600,400))
-
-        self.winCount = 0
-        menu = wx.Menu()
-        menu.Append(ID_New, "&New Window")
-        menu.AppendSeparator()
-        menu.Append(ID_Exit, "E&xit")
-
-        menubar = wx.MenuBar()
-        menubar.Append(menu, "&File")
-        self.SetMenuBar(menubar)
-
-        self.CreateStatusBar()
-
-        self.Bind(wx.EVT_MENU, self.OnNewWindow, id=ID_New)
-        self.Bind(wx.EVT_MENU, self.OnExit, id=ID_Exit)
-
-        if SHOW_BACKGROUND:
-            self.bg_bmp = images.getGridBGBitmap()
-            self.GetClientWindow().Bind(
-                wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground
-                )
-
-
-    def OnExit(self, evt):
-        self.Close(True)
-
-
-    def OnNewWindow(self, evt):
-        self.winCount = self.winCount + 1
-        win = wx.MDIChildFrame(self, -1, "Child Window: %d" % self.winCount)
-        canvas = ScrolledWindow.MyCanvas(win)
-        win.Show(True)
-
-
-    def OnEraseBackground(self, evt):
-        dc = evt.GetDC()
-
-        if not dc:
-            dc = wx.ClientDC(self.GetClientWindow())
-
-        # tile the background bitmap
-        sz = self.GetClientSize()
-        w = self.bg_bmp.GetWidth()
-        h = self.bg_bmp.GetHeight()
-        x = 0
-        
-        while x < sz.width:
-            y = 0
-
-            while y < sz.height:
-                dc.DrawBitmap(self.bg_bmp, x, y)
-                y = y + h
-
-            x = x + w
-
-
-#----------------------------------------------------------------------
-
-if __name__ == '__main__':
-    class MyApp(wx.App):
-        def OnInit(self):
-            wx.InitAllImageHandlers()
-            frame = MyParentFrame()
-            frame.Show(True)
-            self.SetTopWindow(frame)
-            return True
-
-
-    app = MyApp(False)
-    app.MainLoop()
-
-
-

Modified: z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/__init__.py
===================================================================
--- z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/__init__.py	2006-11-29 16:17:59 UTC (rev 71332)
+++ z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/__init__.py	2006-11-29 21:50:36 UTC (rev 71333)
@@ -1,6 +1,6 @@
 ##############################################################################
 #
-# Copyright (c) 2004 Zope Corporation and Contributors.
+# Copyright (c) 2004-2006 Zope Corporation and Contributors.
 # All Rights Reserved.
 #
 # This software is subject to the provisions of the Zope Public License,
@@ -16,4 +16,4 @@
 
 __version__ = "0.0.1"
 __license__ = "ZPL"
-__title__ = u"ZODB browser"
\ No newline at end of file
+__title__ = u"ZODB browser"

Modified: z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/bases.py
===================================================================
--- z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/bases.py	2006-11-29 16:17:59 UTC (rev 71332)
+++ z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/bases.py	2006-11-29 21:50:36 UTC (rev 71333)
@@ -1,26 +1,43 @@
 # -*- coding: UTF-8 -*-
+##############################################################################
+#
+# Copyright (c) 2004-2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
 
 from wax import *
 from z3c.zodbbrowser.registry import getObjectPlugin
 
+
 class oneProperty(object):
-    u"""Data holder for one object property
-    """
+    u"""Data holder for one object property"""
+
     text = ''
     type = None
     expandable = False
     data = None
-    
+
     def __init__(self, **kw):
         self.__dict__.update(kw)
 
+
 class dataCollector(object):
-    u"""Data holder for object properties
-    Kind of property bag
+    u"""Data holder for object properties.
+
+    Kind of property bag.
+
     """
     def __init__(self):
         self._data=[]
-    
+
     def add(self, text='', property=None):
         u"""add one property of an object
         the property will be inspected if it's expandable
@@ -28,118 +45,126 @@
         plg = getObjectPlugin(text, property)
         expandable = plg.getExpandable()
         type = plg.getType()
-        
+
         self.addLL(oneProperty(text = text,
                     expandable = expandable,
                     data=property,
                     type=type))
-    
+
     def addLL(self, obj):
         u"""add one property of an object
         no inspection done, just appended to the list
         """
         self._data.append(obj)
-    
+
     def getAll(self):
         u"""get all property data
         """
         return self._data
 
+
 class BaseObjectPlugin(object):
-    u"""Plugin base for object inspection
-    """
+    u"""Plugin base for object inspection"""
+
     def __init__(self, context):
         self.context = context
-    
+
     def match(self, title):
         u"""return True if the context object can
         be handled by the current plugin
         """
         return False
-    
+
     def getChildren(self):
         u"""Get child objects of the context object
         """
         return dataCollector()
-    
+
     def getProps(self):
         u"""Get properties of the context object
         """
         return dataCollector()
-    
+
     def getExpandable(self):
         u"""Return if the object is expandable, has child somethings
         """
         return False
-    
+
     def getType(self):
         u"""return a type identifying the context object
         """
         return ''
 
+
 class BaseSourcePlugin(object):
     u"""Plugin base for data source
     """
     def __init__(self, mainframe):
         self.mainframe = mainframe
-    
+
     def open(self, parent):
         u"""open data source
         the user should select what to open e.g. with a dialog
         """
         pass
-    
+
     def close(self):
         u"""close the opened data source
         """
         pass
-    
+
     def getSupportedDisplays(self):
-        u"""get preferred/supported display modes of the data source
-        this/these will be looked up in the db_display registry for plugins
+        u"""Get preferred/supported display modes of the data source.
+
+        These will be looked up in the db_display registry for plugins.
+
         """
         return []
-    
+
     def getDataForDisplay(self, mode):
-        u"""get the data to be displayed
-        called by the display plugin
-        by the nature of the ZODB this is usually the root object
+        u"""Get the data to be displayed
+
+        Called by the display plugin.
+
+        (By the nature of the ZODB this is usually the root object)
+
         """
         return None
-    
+
     def getTitle(self):
-        u"""return a user-readable title for the display window
-        """
+        u"""Return a user-readable title for the display window"""
         return ""
 
+
 class BaseDisplayPlugin(MDIChildFrame):
     u"""Plugin base for data source display
     """
-    
+
     #window and plugin title
     title = u''
-    
+
     #def __init__(self, opener):
     #gets the data source passed
     #    pass
 
+
 class BaseObjDisplayPlugin(object):
     u"""Plugin base for object display, used for right-click
     """
-    
+
     #shortcut menu title
     title = u''
-    
+
     def __init__(self, context, form):
         self.context = context
         self.form = form
-    
+
     def getTitle(self):
         u"""get the text that should be displayed on the context menu
         """
         return self.title
-    
+
     def onClick(self):
         u"""start processing
         """
-        pass
\ No newline at end of file
+        pass

Modified: z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/main.py
===================================================================
--- z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/main.py	2006-11-29 16:17:59 UTC (rev 71332)
+++ z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/main.py	2006-11-29 21:50:36 UTC (rev 71333)
@@ -1,4 +1,17 @@
 # -*- coding: UTF-8 -*-
+##############################################################################
+#
+# Copyright (c) 2004-2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
 
 import os
 import sys
@@ -11,7 +24,7 @@
 except ImportError:
     print "You do not have `wax` installed, please download it from http://sourceforge.net/projects/waxgui"
 
-twist_buttons=1
+twist_buttons = 1
 
 from z3c.zodbbrowser import __title__
 from z3c.zodbbrowser.utils import *
@@ -20,54 +33,45 @@
 from z3c.zodbbrowser.registry import installplugins
 from z3c.zodbbrowser.treehandler import rootHandler, baseHandler
 
+
 class ZODBFrame(MDIParentFrame):
-    
-    #def __init__(self):
-    #    super(ZODBFrame, self).__init__(size=(640,480))
-    #    self.SetSize((800, 600))
-    
+
     def Body(self):
         self.SetTitle(__title__)
-        
+
         if WAX_VERSION_TUPLE < (0,3,33):
             ShowMessage(__title__,
                         "WARNING: wax version 0.3.33 required!")
-        
+
         self.CreateStatusBar()
-        self.SetStatusText("This is the statusbar")
-        
+        self.SetStatusText("")
+
         menubar = MenuBar(self)
 
         menu1 = Menu(self)
-        
-        opts = getSourcePlugins()
-        for title, ext, klass in opts:
-            menu1.Append("Open %s" % title,
+
+        for index, (title, ext, klass) in enumerate(getSourcePlugins()):
+            # XXX I'm assuming that we won't get more than 9
+            # source plugins ever.
+            menu1.Append("Open %s ...\tALT+%s" % (title, index+1),
                          curry(self.menuOpen, klass),
-                         "This the text in the statusbar")
-            
-        menu1.Append("&Open\tCTRL+O", self.menuOpen, 
-            "This the text in the statusbar")
+                         "Open a database from a %s" % title)
+
         menu1.Append("&Close", self.menuClose)
         menu1.AppendSeparator()
         menu1.Append("E&xit\tALT+X", self.menuExit, "Exit")
-        
+
         menubar.Append(menu1, "&File")
-        
+
         self.SetMenuBar(menubar)
-        
-        #self.Pack()
-        
-        #self.SetSize((800, 600))
-        #self.CenterOnScreen()
-    
+
     def menuOpen(self, openerklass, event=None):
         opener = openerklass(self)
         if opener.open(self):
             viewopts = opener.getSupportedDisplays()
-            
+
             frameklasses = getDBDisplayPlugins(viewopts)
-            
+
             klassindex = None
             if len(frameklasses) == 0:
                 ShowMessage(__title__,
@@ -79,7 +83,7 @@
                 opts = [ii.title for ii in frameklasses]
                 dlg = ChoiceDialog(self,
                                    title=__title__,
-                                   prompt="Choose an display method",
+                                   prompt="Choose a display method",
                                    choices=opts)
                 try:
                     result = dlg.ShowModal()
@@ -87,40 +91,31 @@
                         klassindex = dlg.choice
                 finally:
                     dlg.Destroy()
-            
+
             if klassindex is not None:
                 frame = frameklasses[klassindex](parent=self,
                                                  opener = opener)
                 frame.Show()
-    
+
     def menuClose(self, event):
-        #self.Close()
         while True:
             chld = self.GetActiveChild()
             if chld:
-                print 'close1'
                 chld.Close()
             else:
                 break
         pass
-    
+
     def menuExit(self, event):
         self.Destroy()
 
-class MyApp(wx.App):
-    def OnInit(self):
-        wx.InitAllImageHandlers()
-        frame = ZODBFrame()
-        frame.Show(True)
-        self.SetTopWindow(frame)
-        return True
 
 def main():
     installplugins()
-    
+
     app = Application(ZODBFrame)
-    #app = MyApp(False)
     app.MainLoop()
 
+
 if __name__ == '__main__':
     main()

Deleted: z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin1.py
===================================================================
--- z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin1.py	2006-11-29 16:17:59 UTC (rev 71332)
+++ z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin1.py	2006-11-29 21:50:36 UTC (rev 71333)
@@ -1,141 +0,0 @@
-# -*- coding: UTF-8 -*-
-
-#plugins for object inspection
-#object type determination may not be 100%
-
-import sys
-import copy
-from z3c.zodbbrowser.bases import dataCollector, BaseObjectPlugin
-from z3c.zodbbrowser.utils import *
-
-from ZODB.utils import oid_repr, serial_repr
-#force these attributes to be displayed
-forceAttr = [('_p_oid', oid_repr),('_p_serial',serial_repr)]
-
-class AnyObjectTypePlugin(BaseObjectPlugin):
-    u"""Plugin for any object type
-    this is the least specific plugin
-    also implements some base methods for more specific plugins
-    """
-    def match(self, title):
-        return True
-    
-    def getChildren(self):
-        return dataCollector()
-    
-    def getProps(self):
-        retval = dataCollector()
-        
-        try:
-            itemz = copy.copy(self.context.__dict__)
-            
-            for attr, formatter in forceAttr:
-                try:
-                    kdata = getattr(self.context, attr)
-                    
-                    if formatter:
-                        kdata=formatter(kdata)
-                        
-                    itemz[attr]=kdata
-                except:
-                    pass
-            
-            try:
-                keyz=itemz.keys()
-                keyz.sort()
-                for key in keyz:
-                    #if key.startswith('_'):
-                    #    continue
-                    #if key.startswith('__'):
-                    #    continue
-                    if key=='__parent__':
-                        continue
-                    kdata=itemz[key]
-                    
-                    retval.add(text = key, property=kdata)
-            except:
-                raise
-        except AttributeError:
-            pass
-        
-        return retval
-    
-    def getExpandable(self):
-        return False
-    
-    def getType(self):
-        try:
-            return self.context.__class__.__name__
-        except:
-            return str(type(self.context))
-
-class dictPlugin(AnyObjectTypePlugin):
-    u"""Plugin for dict or dict-alike object type
-    """
-    def match(self, title):
-        return isdict(self.context)
-    
-    def getChildren(self):
-        retval = dataCollector()
-        
-        keyz = self.context.keys()
-        try:
-            keyz.sort()
-        except:
-            try:
-                keyz=list(keyz)
-                keyz.sort()
-            except:
-                pass
-        
-        for key in keyz:
-            retval.add(text=safe_str(key), property=self.context[key])
-        
-        return retval
-    
-    def getExpandable(self):
-        return True
-    
-    def getType(self):
-        return 'dict'
-
-class listPlugin(AnyObjectTypePlugin):
-    u"""Plugin for list or list-alike object type
-    """
-    def match(self, title):
-        return islist(self.context)
-    
-    def getChildren(self):
-        retval = dataCollector()
-        
-        for d in self.context:
-            retval.add(text = safe_str(d), property=d)
-        
-        return retval
-    
-    def getExpandable(self):
-        return True
-    
-    def getType(self):
-        return 'list'
-
-class objectPlugin(AnyObjectTypePlugin):
-    u"""Plugin for `user-defined` object types
-    """
-    def match(self, title):
-        typ = str(type(self.context))
-        return '.' in typ
-    
-    def getExpandable(self):
-        return True
-    
-    def getType(self):
-        return 'obj'
-
-
-def main(PluginRegistry):
-    PluginRegistry['object'].extend([
-        (100,dictPlugin),
-        (200,listPlugin),
-        (sys.maxint-1, objectPlugin),
-        (sys.maxint, AnyObjectTypePlugin)])
\ No newline at end of file

Modified: z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_fs.py
===================================================================
--- z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_fs.py	2006-11-29 16:17:59 UTC (rev 71332)
+++ z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_fs.py	2006-11-29 21:50:36 UTC (rev 71333)
@@ -1,34 +1,48 @@
 # -*- coding: UTF-8 -*-
+##############################################################################
+#
+# Copyright (c) 2004-2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Plugin for ZODB FileStorage data source."""
 
-#plugin for ZODB FileStorage data source
-
 import transaction
 from ZODB import FileStorage, DB
 
 from wax import *
 from z3c.zodbbrowser.bases import BaseSourcePlugin
 
+
 class ZODBFSPlugin(BaseSourcePlugin):
+
     storage = None
     db = None
     connection = None
     root = None
     filename = ""
-    
+
     def open_direct(self, Path):
         """Open ZODB.
-    
-        Returns a tuple consisting of:(root,connection,db,storage)
+
+        Returns a tuple consisting of: (root, connection, db, storage).
+
         The same tuple must be passed to close_zodb() in order to close the DB.
+
         """
-        # Connect to DB
-        self.storage     = FileStorage.FileStorage(Path)
-        self.db          = DB(self.storage)
-        self.connection  = self.db.open()
-        self.root        = self.connection.root()
-        
+        self.storage = FileStorage.FileStorage(Path, read_only=True)
+        self.db = DB(self.storage)
+        self.connection = self.db.open()
+        self.root = self.connection.root()
         return True
-    
+
     def open(self, parent):
         dlg = FileDialog(parent, open=1)
         try:
@@ -38,34 +52,34 @@
                 return self.open_direct(self.filename)
         finally:
             dlg.Destroy()
-        
+
         return False
 
     def close(self):
         """Closes the ZODB.
-    
+
         This function MUST be called at the end of each program !!!
         """
-        print "closed"
-        
+        # XXX This is a bad place for this function:
+        # a) the code is duplicated in each source plugin
+        # b) if it MUST be called, we better make sure it is.
         transaction.abort()
-        
         self.connection.close()
         self.db.close()
         self.storage.close()
         self.filename = ""
-        
         return True
-    
+
     def getSupportedDisplays(self):
         return ['tree']
-    
+
     def getDataForDisplay(self, mode):
         return self.root
-    
+
     def getTitle(self):
         return self.filename
 
-def main(PluginRegistry):
-    PluginRegistry['source'].extend([
-        ('FileStorage','fs',ZODBFSPlugin)])
\ No newline at end of file
+
+def register(registry):
+    registry['source'].extend([
+        ('FileStorage', 'fs', ZODBFSPlugin)])

Copied: z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_inspection.py (from rev 71319, z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin1.py)
===================================================================
--- z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin1.py	2006-11-27 15:30:49 UTC (rev 71319)
+++ z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_inspection.py	2006-11-29 21:50:36 UTC (rev 71333)
@@ -0,0 +1,161 @@
+# -*- coding: UTF-8 -*-
+##############################################################################
+#
+# Copyright (c) 2004-2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Plugins for object inspection. 
+
+These reflect the most widely used object types and a fallback plugin for
+inspection of generic objects.
+
+Detection might not be 100% accurate.
+
+"""
+
+import sys
+import copy
+from z3c.zodbbrowser.bases import dataCollector, BaseObjectPlugin
+from z3c.zodbbrowser.utils import *
+
+from ZODB.utils import oid_repr, serial_repr
+
+#force these attributes to be displayed
+FORCE_ATTRIBUTES = [('_p_oid', oid_repr),
+             ('_p_serial', serial_repr)]
+
+class AnyObjectTypePlugin(BaseObjectPlugin):
+    u"""Plugin for any object type
+    this is the least specific plugin
+    also implements some base methods for more specific plugins
+    """
+    def match(self, title):
+        return True
+
+    def getChildren(self):
+        return dataCollector()
+
+    def getProps(self):
+        retval = dataCollector()
+
+        try:
+            itemz = copy.copy(self.context.__dict__)
+
+            for attr, formatter in FORCE_ATTRIBUTES:
+                try:
+                    kdata = getattr(self.context, attr)
+
+                    if formatter:
+                        kdata=formatter(kdata)
+
+                    itemz[attr]=kdata
+                except:
+                    pass
+
+            try:
+                keyz=itemz.keys()
+                keyz.sort()
+                for key in keyz:
+                    #if key.startswith('_'):
+                    #    continue
+                    #if key.startswith('__'):
+                    #    continue
+                    if key=='__parent__':
+                        continue
+                    kdata=itemz[key]
+
+                    retval.add(text = key, property=kdata)
+            except:
+                raise
+        except AttributeError:
+            pass
+
+        return retval
+
+    def getExpandable(self):
+        return False
+
+    def getType(self):
+        try:
+            return self.context.__class__.__name__
+        except:
+            return str(type(self.context))
+
+class dictPlugin(AnyObjectTypePlugin):
+    u"""Plugin for dict or dict-alike object type
+    """
+    def match(self, title):
+        return isdict(self.context)
+
+    def getChildren(self):
+        retval = dataCollector()
+
+        keyz = self.context.keys()
+        try:
+            keyz.sort()
+        except:
+            try:
+                keyz=list(keyz)
+                keyz.sort()
+            except:
+                pass
+
+        for key in keyz:
+            retval.add(text=safe_str(key), property=self.context[key])
+
+        return retval
+
+    def getExpandable(self):
+        return True
+
+    def getType(self):
+        return 'dict'
+
+class listPlugin(AnyObjectTypePlugin):
+    u"""Plugin for list or list-alike object type
+    """
+    def match(self, title):
+        return islist(self.context)
+
+    def getChildren(self):
+        retval = dataCollector()
+
+        for d in self.context:
+            retval.add(text = safe_str(d), property=d)
+
+        return retval
+
+    def getExpandable(self):
+        return True
+
+    def getType(self):
+        return 'list'
+
+class objectPlugin(AnyObjectTypePlugin):
+    u"""Plugin for `user-defined` object types
+    """
+    def match(self, title):
+        typ = str(type(self.context))
+        return '.' in typ
+
+    def getExpandable(self):
+        return True
+
+    def getType(self):
+        return 'obj'
+
+
+def register(registry):
+    registry['object'].extend([
+        (100, dictPlugin),
+        (200, listPlugin),
+        (sys.maxint-1, objectPlugin),
+        (sys.maxint, AnyObjectTypePlugin)])

Modified: z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_objdisp.py
===================================================================
--- z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_objdisp.py	2006-11-29 16:17:59 UTC (rev 71332)
+++ z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_objdisp.py	2006-11-29 21:50:36 UTC (rev 71333)
@@ -1,19 +1,31 @@
 # -*- coding: UTF-8 -*-
+##############################################################################
+#
+# Copyright (c) 2004-2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Plugin for object display (currently this is just for fun)"""
 
-#plugin for object display
-#currently this is just for fun
-
 from wax import *
 
 from z3c.zodbbrowser.bases import BaseObjDisplayPlugin
 
+
 class dictDispPlugin(BaseObjDisplayPlugin):
     title = u'dict details'
-    
+
     def onClick(self):
         dlg = MessageDialog(self.form, "A message", "dict details")
         dlg.ShowModal()
         dlg.Destroy()
 
-def main(PluginRegistry):
-    PluginRegistry['obj_display'].append(('dict',dictDispPlugin))
\ No newline at end of file
+def register(registry):
+    registry['obj_display'].append(('dict', dictDispPlugin))

Modified: z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_tree.py
===================================================================
--- z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_tree.py	2006-11-29 16:17:59 UTC (rev 71332)
+++ z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_tree.py	2006-11-29 21:50:36 UTC (rev 71333)
@@ -1,27 +1,38 @@
 # -*- coding: UTF-8 -*-
+##############################################################################
+#
+# Copyright (c) 2004-2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Plugin for object source display."""
 
-#plugin for object source display
-
 import wx
 from wax import *
 from z3c.zodbbrowser.bases import BaseDisplayPlugin
-twist_buttons=1
+twist_buttons = 1
 
 from z3c.zodbbrowser.treehandler import rootHandler, baseHandler
 
+
 class TreeDisplay(BaseDisplayPlugin):
-    """
-    MDIChildFrame - MDI parent formba helyezhető
-    """
-    
+    """MDIChildFrame - MDI parent"""
+
     #window title
     title = u"tree"
-    
+
     def __init__(self, *arg, **kw):
         kw['direction'] = 'v'
         self.opener = kw.pop('opener')
         self.root = self.opener.getDataForDisplay('tree')
-        
+
         super(TreeDisplay, self).__init__(*arg, **kw)
 
     def Body(self):
@@ -30,41 +41,37 @@
         one big textbox on the right side
         """
         self.SetTitle(self.title+" - "+self.opener.getTitle())
-        
+
         splitter = Splitter(self, size=(500, 300))
         self.tree = TreeView(splitter, twist_buttons=twist_buttons, has_buttons=1)
         self.tree.OnItemExpanded = self.OnItemExpanded
         self.tree.OnSelectionChanged = self.OnTreeSelectionChanged
         self.tree.OnRightDown = self.OnItemRightClick
-        
+
         self.textbox = TextBox(splitter, readonly=1, multiline=1)
         splitter.Split(self.tree, self.textbox, direction='v')
         self.AddComponent(splitter, expand='both')
-        
+
         self.filltree()
         self.Pack()
-        
-        #w=-1
-        #h=self.GetParent().GetClientSizeTuple()[1]
-        #self.SetSizeWH(-1,h)
-        
+
         self.SetSize(self.GetParent().GetClientSizeTuple())
-        
-    def addItem(self, text, data, item = None):
+
+    def addItem(self, text, data, item=None):
         if item:
             child = self.tree.AppendItem(item, text)
         else:
             child = self.tree.AddRoot(text)
-        
+
         data.loadedChild = False
         self.tree.SetPyData(child, data)
         if data.expandable:
             dummy = self.tree.AppendItem(child, "##expand##")
-    
+
     def filltree(self):
         zz = rootHandler(self.root, 'root', self)
         self.addItem("root", zz)
-    
+
     def OnItemExpanded(self, event):
         item = event.GetItem()
         if item:
@@ -77,7 +84,7 @@
                     for key, data in children:
                         self.addItem(key, data, item)
                 idata.onExpanded()
-    
+
     def OnTreeSelectionChanged(self, event):
         item = event.GetItem()
         if item:
@@ -86,29 +93,26 @@
                 data.onSelected()
             if data is None:
                 data = self.tree.GetItemText(item)
-        
-        #print str(data)
-        #event.Skip()
-    
+
     def OnItemRightClick(self, event):
-        #item = event.GetItem()
         item, flags = self.tree.HitTest(event.GetPosition())
         if flags in [wx.TREE_HITTEST_ONITEMBUTTON, wx.TREE_HITTEST_ONITEMLABEL]:
             data = self.tree.GetPyData(item)
             if isinstance(data, baseHandler):
                 self.tree.SelectItem(item)
                 data.onRightClick()
-        
+
     def setProps(self, data):
         u"""Write the data--information into the textbox"""
         self.textbox.SetValue(data['text'])
-    
+
     def closeDB(self):
         self.opener.close()
-    
+
     def OnClose(self, event):
         self.closeDB()
         event.Skip()
 
-def main(PluginRegistry):
-    PluginRegistry['db_display']['tree']=TreeDisplay
+
+def register(registry):
+    registry['db_display']['tree'] = TreeDisplay

Added: z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_zeo.py
===================================================================
--- z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_zeo.py	2006-11-29 16:17:59 UTC (rev 71332)
+++ z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_zeo.py	2006-11-29 21:50:36 UTC (rev 71333)
@@ -0,0 +1,102 @@
+# -*- coding: UTF-8 -*-
+##############################################################################
+#
+# Copyright (c) 2004-2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Plugin for ZODB ZEO storage."""
+
+import transaction
+from ZODB import DB
+import ZEO.ClientStorage
+
+from wax import *
+from z3c.zodbbrowser.bases import BaseSourcePlugin
+
+
+class OpenClientStorage(Dialog):
+    """An "open" dialog for ClientStorages."""
+
+    def Body(self):
+        label = Label(self, 'IP address')
+        self.AddComponent(label, expand='h', border=7)
+        self.ip = TextBox(self, size=(100,25))
+        self.ip.SetValue('127.0.0.1')
+        self.AddComponent(self.ip, expand='h', border=5)
+
+        label = Label(self, 'Port')
+        self.AddComponent(label, expand='h', border=7)
+        self.port = TextBox(self, size=(100,25))
+        self.port.SetValue('9000')
+        self.AddComponent(self.port, expand='h', border=5)
+
+
+class ClientStoragePlugin(BaseSourcePlugin):
+
+    storage = None
+    db = None
+    connection = None
+    root = None
+
+    def open_direct(self, address, port):
+        """Open ZODB.
+
+        Returns a tuple consisting of: (root, connection, db, storage)
+
+        The same tuple must be passed to close_zodb() in order to close the DB.
+
+        """
+        self.storage = ZEO.ClientStorage.ClientStorage(
+            (address, port), read_only=True)
+        self.db = DB(self.storage)
+        self.connection = self.db.open()
+        self.root = self.connection.root()
+        return True
+
+    def open(self, parent):
+        dlg = OpenClientStorage(parent, "Open ClientStorage")
+        try:
+            result = dlg.ShowModal()
+            if result == 'ok':
+                ip = dlg.ip.GetValue().encode('ascii')
+                port = int(dlg.port.GetValue())
+                return self.open_direct(ip, port)
+        finally:
+            dlg.Destroy()
+        return False
+
+    def close(self):
+        """Closes the ZODB.
+
+        This function MUST be called at the end of each program !!!
+        """
+        transaction.abort()
+
+        self.connection.close()
+        self.db.close()
+        self.storage.close()
+        self.filename = ""
+
+        return True
+
+    def getSupportedDisplays(self):
+        return ['tree']
+
+    def getDataForDisplay(self, mode):
+        return self.root
+
+    def getTitle(self):
+        return "ClientStorage at "
+
+
+def register(registry):
+    registry['source'].extend([
+        ('ClientStorage', 'cs', ClientStoragePlugin)])


Property changes on: z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/plugin_zeo.py
___________________________________________________________________
Name: svn:keywords
   + Id Rev Date
Name: svn:eol-style
   + native

Modified: z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/registry.py
===================================================================
--- z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/registry.py	2006-11-29 16:17:59 UTC (rev 71332)
+++ z3c.zodbbrowser/sandbox/src/z3c/zodbbrowser/registry.py	2006-11-29 21:50:36 UTC (rev 71333)
@@ -5,7 +5,6 @@
 import imp
 import sys
 import os
-import glob
 
 #plugin registry
 PluginRegistry = {}
@@ -66,60 +65,36 @@
                if (type == objtype) or (type == '*')]
     return matches
 
-def impmain(fname):
-    u"""import main from a given .py file"""
-    mname = os.path.splitext(fname)[0]
-    mpath, mname = os.path.split(mname)
-    oname = 'main'
-        
-    try:
-        x=imp.find_module(mname, [mpath])
-        try:
-            mod=imp.load_module('plugin1',x[0],x[1],x[2])
-        finally:
-            x[0].close()
-    except ImportError, v:
-        raise ValueError(
-            "Couldn't import %s, %s" % (mname, v)), None, sys.exc_info()[2]
-    
-    try:
-        obj = getattr(mod, oname)
-        return obj
-    except AttributeError:
-        # No such name, maybe it's a module that we still need to import
-        #try:
-        #    return __import__(mname+'.'+oname, *_import_chickens)
-        #except ImportError:
-        #
-        # We need to try to figure out what module the import
-        # error is complaining about.  If the import failed
-        # due to a failure to import some other module
-        # imported by the module we are importing, we want to
-        # know it. Unfortunately, the value of the import
-        # error is just a string error message. :( We can't
-        # pull it apart directly to see what module couldn't
-        # be imported. The only thing we can really do is to
-        # try to "screen scrape" the error message:
 
-        if str(sys.exc_info()[1]).find(oname) < 0:
-            # There seems to have been an error further down,
-            # so reraise the exception so as not to hide it.
-            raise
+def installplugins():
+    """Import and register all plugins.
 
-        raise ValueError(
-            "ImportError: Module %s has no global %s" % (mname, oname)) 
+    Plugins are all "plugin_*" modules from the same package as this registry.
 
-def installplugins():
-    u"""import and start the main() of each plugin_*.py
-    in the folder of our source
-    these should register/can register any plugin
-    through the passed PluginRegistry parameter"""
-    here = os.path.dirname(os.path.abspath(__file__))
-    #here = os.path.abspath(os.path.dirname(sys.argv[0]))
-    plugins = glob.glob(os.path.join(here, "plugin*.py"))
-    
-    for plg in plugins:
-        plgmain = impmain(plg)
-        plgmain(PluginRegistry)
-    
-    PluginRegistry['object'].sort()
\ No newline at end of file
+    Plugins are registered by calling their register_plugin() method with the
+    registry as the parameter.
+
+    """
+    base_package = ".".join(__name__.split('.')[:-1])
+
+    base_dir = os.path.dirname(os.path.realpath(__file__))
+
+    plugin_names = []
+    for name in os.listdir(base_dir):
+        if not name.startswith('plugin_'):
+            continue
+        if not name.endswith('.py'):
+            # XXX This is a huge simplification, but this "plugin" system
+            # is crude anyway.
+            continue
+        plugin_names.append(name[:-3])
+
+    plugin_parent = __import__(base_package, globals(), locals(), plugin_names)
+    for plugin_name in plugin_names:
+        plugin = getattr(plugin_parent, plugin_name)
+        plugin.register(PluginRegistry)
+
+    # Registered object plugins need to be sorted by their
+    # priority for searching. Ideally this should be using a BTree
+    # with the priority as a key.
+    PluginRegistry['object'].sort()



More information about the Checkins mailing list