################################################################################
# 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))
|