ExtraZopeCompanions.plug in.py :  » IDE » Boa-Constructor » boa-constructor-0.6.1 » Plug-ins » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » IDE » Boa Constructor 
Boa Constructor » boa constructor 0.6.1 » Plug ins » ExtraZopeCompanions.plug-in.py
import wx

import Preferences, Utils, Plugins

if not Plugins.transportInstalled('ZopeLib.ZopeExplorer'):
    raise Plugins.SkipPlugin, 'Zope support is not enabled'

from ZopeLib.ZopeCompanions import ZopeCompanion,DBAdapterZC
from Models import EditorHelper,Controllers,XMLSupport,HTMLSupport
from ZopeLib import ZopeEditorModels

class PythonMethodZC(ZopeCompanion):
    def create(self):
        mime, res = self.call(self.objPath,
              '/manage_addProduct/PythonMethod/manage_addPythonMethod',
              id=self.name, title='', params='', body='pass')

ZopeEditorModels.addZOAImage('Python Method', 'Images/ZOA/pymethod.png')
class ZopePythonMethodModel(ZopeEditorModels.ZopePythonSourceModel):
    modelIdentifier = 'ZopePythonMethod'
    defaultName = 'zopepythonmethod'
    bitmap = 'Module.png'
    imgIdx = ZopeEditorModels.ZOAIcons['Python Method']

Controllers.modelControllerReg[ZopePythonMethodModel] = ZopeEditorModels.ZopeController

class TransparentFolderZC(ZopeCompanion):
    def create(self):
        mime, res = self.call(self.objPath,
              'manage_addProduct/TransparentFolder/manage_addTransparentFolder',
              id=self.name, title='')

class LocalFSZC(ZopeCompanion):
    def create(self):
        mime, res = self.call(self.objPath,
              'manage_addProduct/LocalFS/manage_addLocalFS',
              id=self.name, title='', basepath='')

from ZopeLib.ZopeExplorer import DirNode,ZopeConnection,zopeClassMap
from Views import PySourceView,SourceViews

class LFSNode(DirNode): pass
ZopeEditorModels.addZOAImage('Local File System', 'Images/ZOA/fs.png')

class LFNode(LFSNode):
    Model = ZopeEditorModels.ZopeEditorModel
    additionalViews = ()
    supportedViews = {'Module': (PySourceView.PythonSourceView,),
                      'HTML': (HTMLSupport.HTMLSourceView,),
                      'XML': (XMLSupport.XMLSourceView,),
                     }

    def __init__(self, name, resourcepath, clipboard, imgIdx, parent, xmlrpcsvr,
          root, properties, metatype):
        Mod = Controllers.identifyFile(
              os.path.basename(resourcepath), localfs=False)[0]
        imgIdx = Mod.imgIdx
        self.defaultViews = self.supportedViews.get(Mod.modelIdentifier,
              (SourceViews.TextView,))

        LFSNode.__init__(self, name, resourcepath, clipboard, imgIdx,
              parent, xmlrpcsvr, root, properties, metatype)

    def load(self, mode='rb'):
        mode='rb'
        # XXX Can't seem to open with xml-rpc (use DAV for now)
        props = self.properties
        from ExternalLib.WebDAV.client import Resource
        r = Resource(('http://%(host)s:%(httpport)s/'+self.resourcepath) % props,
            props['username'], props['passwd'])
        return r.get().body

        #return self.getResource()()

    def save(self, filename, data, mode='wb'):
        mode='wb'
        props = self.properties
        zc = ZopeConnection()
        zc.connect(props['host'], props['httpport'],
                   props['username'], props['passwd'])
        from StringIO import StringIO
        file = StringIO(data)
        dirname, file.name = os.path.split(filename)
        zc.callkw(dirname, 'manage_upload',
              {'file': file, 'Content-Type': 'multipart/form-data'} )

    def isFolderish(self):
        return False


class LFDirNode(LFSNode):
    def __init__(self, name, resourcepath, clipboard, imgIdx, parent, xmlrpcsvr,
          root, properties, metatype):
        LFSNode.__init__(self, name, resourcepath, clipboard,
              EditorHelper.imgFolder, parent, xmlrpcsvr, root, properties, metatype)

zopeClassMap.update({
      'Local File System': LFSNode,
      'LocalFS::directory': LFDirNode,
      'LocalFS::file': LFNode})

class ZODBCDAZC(DBAdapterZC):
    def create(self):
        dlg = wx.TextEntryDialog(None, 'Enter the Connection String',
              'Z ODBC DB Adapter', '')
        try:
            if dlg.ShowModal() == wx.ID_OK:
                connId = dlg.GetValue()
                mime, res = self.call(self.objPath, 'manage_addZODBCConnection',
                      id=self.name, title='', connection=connId, check=1)
        finally:
            dlg.Destroy()

ZopeEditorModels.addZOAImage('Z ODBC Database Connection', 'Images/ZOA/db.png')

import PaletteStore
PaletteStore.paletteLists['Zope'].extend(['Python Method',
      'LocalFS', 'Transparent Folder', 'ZODBCDA'] )
PaletteStore.compInfo.update({'Python Method': ['PythonMethod', PythonMethodZC],
    'LocalFS': ['LocalFS', LocalFSZC],
    'Transparent Folder': ['TransparentFolder', TransparentFolderZC],
    'ZODBCDA': ['ZODBCDA', ZODBCDAZC], })
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.