PLGPictureNode.py :  » Business-Application » Gimini » gimini » 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 » Business Application » Gimini 
Gimini » gimini » PLGPictureNode.py
################################################################################
# Name      : PictureNode.py - gimini plugin
# Author    : C.Dutoit - dutoitc@hotmail.com - http://www.dutoitc.fr.st
# Goal      : Gimini "Text Node" plugin
# Date      : Jan 2002
################################################################################
from wxPython.wx import *
from gPluginsDialogs import *
from basePlugin import *
from PluginsAPI import *
from utils import assignID

pluginID="PictureNode"
[ID_MENU_ABOUT, ID_ICON_INS_PICTURE]=assignID(2)

#>--------------------------------------------------------------------------
class GiminiPlugin:
    "A gimini plugin"
    def __init__(self, wxParent, pluginsAPI):
        "Plugin initialisation"
        self._pluginsAPI=pluginsAPI
        self._wxParent=wxParent

        #create menu
        root=wxMenu("", wxMENU_TEAROFF)
        root.Append(ID_MENU_ABOUT, "About...")
        self._pluginsAPI.addToPluginMenu(pluginID, root)

        EVT_MENU(wxParent, ID_MENU_ABOUT, self.CBMnuAbout)


        #create toolbar entry
        control=wxBitmap('img'+os.sep+'ins_picture.bmp', wxBITMAP_TYPE_BMP)
        self._pluginsAPI.addToolbarItem( ID_ICON_INS_PICTURE, control, 
                    "Insert a picture node", "Insert a picture node")
        EVT_TOOL(wxParent, ID_ICON_INS_PICTURE, self.CBInsPictureClick)

        #Add a keyboard shortcut
        self._pluginsAPI.requestKeyboardShortcut(pluginID, WXK_INSERT , \
                                                 self.CBInsertNode)


    #>--------------------------------------------------------------------------
    def CBMnuAbout(self, event):
        "Show about box"
        dlg=wxMessageDialog(self._wxParent, 
                            "picture node plugin for Gimini", "",wxOK)
        dlg.ShowModal()

    #>--------------------------------------------------------------------------
    def getNodeData(self):
        "Get a node data for this plugin"
        return NodeData()

    #>--------------------------------------------------------------------------
    def CBInsPictureClick(self, event):
        "Handle click on 'insert picture' icon"
        nodeData=NodeData()
        self._pluginsAPI.addChildFromNodeData(nodeData)
        self._pluginsAPI.setDefaultPlugin(pluginID)

    #>--------------------------------------------------------------------------
    def CBInsertNode(self, event):
        "Insert node keyboard callback"
        nodeData=NodeData()
        self._pluginsAPI.addChildFromNodeData(nodeData)
        self._pluginsAPI.setDefaultPlugin(pluginID)



class NodeData(Mindmap_NodeDatas):
    "Standard node data"
    #>----------------------------------------------------------------------
    def __init__(self):
        Mindmap_NodeDatas.__init__(self)
        self.__filename=""
        self.__picture=wxEmptyBitmap(20, 20)

    #>----------------------------------------------------------------------
    def getFilename(self):
        "Return the local filename"
        return self.__filename

    
    #>----------------------------------------------------------------------
    def loadFromFile(self, filename):
        self.__picture=wxBitmap(filename, wxBITMAP_TYPE_ANY)
        self.__filename=filename
        #try:
            #self.picture=wxBitmap(filename, wxBITMAP_TYPE_BMP_RESOURCE)
        #try:
            #self.picture=wxBitmap(filename, wxBITMAP_TYPE_GIF)
        #try:
            #self.picture=wxBitmap(filename, wxBITMAP_TYPE_XBM)
        #try:
            #self.picture=wxBitmap(filename, wxBITMAP_TYPE_XPM)
    

    
    #>----------------------------------------------------------------------
    def saveToString(self):
        "Save the node data to a string"
        return "@pct" + self.__filename+ " "


    #>----------------------------------------------------------------------
    def saveToList(self):
        "Save the datas to a list"
        return [self.__filename]


    #>----------------------------------------------------------------------
    def getSmallName(self):
        "Get a small name wich will represent the node"
        return self.__filename


    #>----------------------------------------------------------------------
    def getNodeSize(self, dc):
        "Get the node size"
        (w, h)=(self.__picture.GetWidth(), self.__picture.GetHeight())
        #w+=dc.GetCharWidth()*2
        return (w, h)


    #>----------------------------------------------------------------------
    def drawRootNode(self, dc, x, y):
        "Draw as root node"
        dc.BeginDrawing()
        myPen=wxPen(wxBLACK, 1, wxSOLID)
        dc.SetPen(myPen)
        myFont=wxFont(self._fontSize, wxDEFAULT, wxNORMAL, wxNORMAL)
        dc.SetFont(myFont)
        (w, h)=self.getNodeSize(dc)
        dc.DrawRoundedRectangle(x-w/2-3-5, y-h/2-6, w+10+6, h+12, 20)
        dc.DrawRoundedRectangle(x-w/2  -5, y-h/2-3, w+10,   h+6,  20)
        dc.DrawBitmap(self.__picture, x-w/2, y-h/2, TRUE)
        dc.EndDrawing()


    #>----------------------------------------------------------------------
    def getNodeRootSize(self, dc):
        "Get the node size when drawed as root"
        myPen=wxPen(wxBLACK, 1, wxSOLID)
        dc.SetPen(myPen)
        myFont=wxFont(self._fontSize, wxDEFAULT, wxNORMAL, wxNORMAL)
        dc.SetFont(myFont)
        (w, h)=self.getNodeSize(dc)
        w+=16
        h+=12
        return (w, h)


    #>----------------------------------------------------------------------
    def drawNodeDatas(self, dc, x, y):
        "Draw the node data; org is bottom-left"
        (w, h)=self.getNodeSize(dc)
        dc.DrawRectangle(x-1, y+1, w+2, -h-2)
        dc.DrawBitmap(self.__picture, x, y-h, TRUE)
        pass


    #>----------------------------------------------------------------------
    def getRootLatexCode(self, dc, x, y):
        "Return the LaTeX code of the root, drawed as root"
        return "\put("+str(x)+","+str(y)+"){pictures not yet supported}\n"

    #>----------------------------------------------------------------------
    def getLatexCode(self, dc, x, y):
        "Return the node LaTeX code"
        return "\put("+str(x)+","+str(y)+"){pictures not yet supported}\n"


    #>----------------------------------------------------------------------
    def getNodeEditionPanel(self, parent):
        """Return a canvas to integrate to the node edition dialog box wich
         will permit to edit the node datas"""
        return nodeEditionPanel(parent, self)


    #>------------------------------------------------------------------
    def getPluginID(self):
        "Return the plugin ID"
        return pluginID


    #>------------------------------------------------------------------
    def saveToXML(self):
        "Save the datas to xml"
        from xml.dom.minidom import Element
        data=Element("Data")
        data.setAttribute('Filename', self.__filename)
        return data


    #>------------------------------------------------------------------
    def loadFromXML(self, XMLdata):
        "Load the datas from xml"
        self.loadFromFile(XMLdata.getAttribute("Filename"))


#>----------------------------------------------------------------------
class nodeEditionPanel(wxPanel):
    "Panel to edit node datas"

    #>------------------------------------------------------------------
    def __init__(self, parent, nodeDatas):
        "Init and create controls"
        #Init
        wxPanel.__init__(self, parent, -1)
        self._nodeDatas=nodeDatas
        self._filename=self._nodeDatas.getFilename()
        
        #Create controls
        self._lblMsg=wxStaticText(self, -1, "Picture : ")
        self._lblFilename=wxStaticText(self, -1, self._filename)
        self._cmdChoosePicture=wxButton(self, 1, "&Choose...")
        EVT_BUTTON(self, 1, self._choosePicture)


        #Sizer
        mySizer = wxBoxSizer(wxHORIZONTAL)
        mySizer.Add(self._lblMsg, 0, wxEXPAND)
        mySizer.Add(self._lblFilename, 1, wxEXPAND)
        mySizer.Add(self._cmdChoosePicture, 0, wxEXPAND)
        self.SetAutoLayout(true)
        self.SetSizer(mySizer)
        mySizer.Fit(self)


    #>------------------------------------------------------------------
    def _choosePicture(self, event):
        "Display the <choose picture> dialog box; Callback"
        dlg=wxFileDialog(self, "Choose a picture", ".", "", "*.*", wxOPEN)
        if dlg.ShowModal()==wxID_OK:
            lst=dlg.GetPaths()
            self._filename=lst[0]
            self._lblMsg.SetLabel(self._filename)
            self.Refresh()
        dlg.Destroy()

    #>------------------------------------------------------------------
    def saveDatas(self):
        self._nodeDatas.loadFromFile(self._filename)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.