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

pluginID="URLNode"

[ID_MENU_ABOUT, ID_ICON_INS_URL]=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_url.bmp', wxBITMAP_TYPE_BMP)
        self._pluginsAPI.addToolbarItem( ID_ICON_INS_URL, control, 
                    "Insert a URL node", "Insert a URL node")
        EVT_TOOL(wxParent, ID_ICON_INS_URL, self.CBInsURLClick)

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


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

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


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


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







#>--------------------------------------------------------------------------
class NodeData(Mindmap_NodeDatas):
    "A node with url data"

    #>----------------------------------------------------------------------
    def __init__(self):
        Mindmap_NodeDatas.__init__(self)
        self.__url=""

    #>----------------------------------------------------------------------
    def setText(self, text=""):
        "set the node text"
        self.__url=""

    #>----------------------------------------------------------------------
    def saveToString(self):
        "Save the node data to a string"
        return self.__url


    #>----------------------------------------------------------------------
    def loadFromString(self, txt):
        "Load the node data from a string"
        self.__url=txt


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


    #>----------------------------------------------------------------------
    def loadFromList(self, lst):
        "Load the node data from a list"
        self.__url=lst


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


    #>----------------------------------------------------------------------
    def getNodeSize(self, dc):
        "Get the node size"
        myFont=wxFont(self._fontSize, wxDEFAULT, wxNORMAL, wxNORMAL)
        dc.SetFont(myFont)
        (w, h)=dc.GetTextExtent(self.__url)
        return (w+2*dc.GetCharWidth(), h)


    #>----------------------------------------------------------------------
    def drawRootNode(self, dc, x, y):
        "draw a node on a dc at a specified position"
        dc.BeginDrawing()
        myFont=wxFont(self._fontSize, wxDEFAULT, wxNORMAL, wxNORMAL)
        dc.SetFont(myFont)
        dc.SetTextForeground(wxBLUE)
        (w,h)=dc.GetTextExtent(self.__url)
        w+=dc.GetCharWidth()*2
        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.DrawText(self.__url, x-w/2+dc.GetCharWidth(), y-h/2)
        dc.SetTextForeground(wxBLACK)
        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)=dc.GetTextExtent(self.__url)
        w+=dc.GetCharWidth()*2
        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)
        myFont=wxFont(self._fontSize, wxDEFAULT, wxNORMAL, wxNORMAL)
        dc.SetFont(myFont)
        dc.SetPen(wxPen(wxBLACK, 1, wxSOLID))
        dc.SetTextForeground(wxBLUE)
        (textHeight, blankWidth) = (dc.GetCharHeight(), dc.GetCharWidth())
        dc.DrawText(self.__url, x+blankWidth, y-h)
        dc.SetTextForeground(wxBLACK)
                        

    #>----------------------------------------------------------------------
    def getRootLatexCode(self, dc, x, y):
        "Return the LaTeX code of the root, drawed as root"
        (w, h)=self.getNodeSize(dc)
        myFont=wxFont(self._fontSize, wxDEFAULT, wxNORMAL, wxNORMAL)
        dc.SetFont(myFont)
        (textHeight, blankWidth) = (dc.GetCharHeight(), dc.GetCharWidth())
        latexCode=""
        (w,h)=dc.GetTextExtent(self.__url)
        w+=dc.GetCharWidth()*2
        latexCode+="\put("+str(x)+","+str(y)+"){\oval(" + \
                           str(w+10+6) + "," + str(h+12) + ")}\n"
        latexCode+="\put("+str(x)+","+str(y)+"){\oval(" + \
                           str(w+10) + "," + str(h+6) + ")}\n"
        latexCode+="\put("+str(x)+","+str(y)+"){"+ \
                        "\makebox(0, 0){" + self.__url +"}}\n"
        return latexCode


    #>----------------------------------------------------------------------
    def getLatexCode(self, dc, x, y):
        "Return the node LaTeX code"
        (w, h)=self.getNodeSize(dc)
        myFont=wxFont(self._fontSize, wxDEFAULT, wxNORMAL, wxNORMAL)
        dc.SetFont(myFont)
        (textHeight, blankWidth) = (dc.GetCharHeight(), dc.GetCharWidth())
        latexCode=""
        latexCode+="\put("+str(x+blankWidth)+","+\
                           str(y+h-(indice+1)*textHeight)+"){"+ \
                    "\makebox(0, 0)[bl]{" + self.__url+"}}\n"
        return latexCode


    #>----------------------------------------------------------------------
    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('URLText', self.saveToString())
        return data


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

    #>------------------------------------------------------------------
    #def onDblClick(self):
        #"Handle double-click"
        
    #>------------------------------------------------------------------
    def launchURL(self):
        "launch the current URL in a browser"
        try:
            import webbrowser
            webbrowser.open(str(self.__url)) #todo : bug !!!
        except ImportError:
            wxMessageBox('Please point your browser at %s' % self.__url)


#>----------------------------------------------------------------------
class nodeEditionPanel(wxPanel):
    "Panel to edit node datas"
    #>------------------------------------------------------------------
    def __init__(self, parent, nodeDatas):
        "Init controls"
        self._myNodeDatas=nodeDatas
        wxPanel.__init__(self, parent, -1)
        editSizer = wxBoxSizer(wxHORIZONTAL)
        mainSizer = wxBoxSizer(wxVERTICAL)

        self._msg=wxStaticText(self, -1, "URL text : ")
        self._nodeText=wxTextCtrl(self, 100, 
                                  self._myNodeDatas.saveToString(),
                                  wxDefaultPosition, wxSize(360, 20))
        editSizer.Add(self._msg, 0, wxEXPAND)
        editSizer.Add(self._nodeText, 1, wxEXPAND)
        mainSizer.Add(editSizer, 0, wxEXPAND)
        editSizer.Fit(self)

        self._cmdLaunchURL=wxButton(self, 101, "launch URL")
        EVT_BUTTON(self, 101, self.onCmdLaunchURLClick)
        mainSizer.Add(self._cmdLaunchURL, 0, wxALIGN_CENTER)

        self.SetAutoLayout(true)
        self.SetSizer(mainSizer)
        mainSizer.Fit(self)
        self._nodeText.SetFocus()

    #>------------------------------------------------------------------
    def onCmdLaunchURLClick(self, event):
        "launch url"
        self.saveDatas()
        self._myNodeDatas.launchURL()


    #>------------------------------------------------------------------
    def saveDatas(self):
        "Save the panel datas"
        lst=[]
        self._myNodeDatas.loadFromList(self._nodeText.GetLineText(0))


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