added addon, with correct ordering of toolbars

This commit is contained in:
Frédéric Péters 2007-11-14 21:30:36 +01:00
parent a98a798fd8
commit d371718c82
7 changed files with 694 additions and 1 deletions

220
Addons.xcu.in Normal file
View File

@ -0,0 +1,220 @@
<?xml version="1.0" encoding="UTF-8"?>
<oor:component-data
xmlns:oor="http://openoffice.org/2001/registry"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
oor:name="Addons"
oor:package="org.openoffice.Office">
<node oor:name="AddonUI">
<node oor:name="OfficeToolBar">
<node oor:name="Tabellio.Orateurs" oor:op="replace">
<node oor:name="m4" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>service:org.entrouvert.openoffice.OrateurDialog?deputes</value>
</prop>
<prop oor:name="ImageIdentifier" oor:type="xs:string">
<value/>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value/>
<value xml:lang="en-US">Députés...</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument</value>
</prop>
</node>
<node oor:name="m5" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>service:org.entrouvert.openoffice.OrateurDialog?ministres</value>
</prop>
<prop oor:name="ImageIdentifier" oor:type="xs:string">
<value/>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value/>
<value xml:lang="en-US">Ministres et Président...</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument</value>
</prop>
</node>
<node oor:name="m6" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>service:org.entrouvert.openoffice.OrateurDialog?new</value>
</prop>
<prop oor:name="ImageIdentifier" oor:type="xs:string">
<value/>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value/>
<value xml:lang="en-US">Orateur Manuel...</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument</value>
</prop>
</node>
<node oor:name="m7" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>service:org.entrouvert.openoffice.DropdownButton?test</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value/>
<value xml:lang="en-US">Commission</value>
</prop>
<prop oor:name="ControlType" oor:type="xs:string">
<value>DropdownButton</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument</value>
</prop>
</node>
<node oor:name="m8" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>service:org.entrouvert.openoffice.StructureCheckDialog</value>
</prop>
<prop oor:name="ImageIdentifier" oor:type="xs:string">
<value/>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value/>
<value xml:lang="en-US">StructureCheck</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument</value>
</prop>
</node>
</node>
<node oor:name="Tabellio.Listes" oor:op="replace">
<node oor:name="m6" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>service:org.entrouvert.openoffice.DropdownButton?test</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value/>
<value xml:lang="en-US">Liste num</value>
</prop>
<prop oor:name="ControlType" oor:type="xs:string">
<value>DropdownButton</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument</value>
</prop>
</node>
<node oor:name="m7" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>service:org.entrouvert.openoffice.DropdownButton?test</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value/>
<value xml:lang="en-US">Liste Alpha.</value>
</prop>
<prop oor:name="ControlType" oor:type="xs:string">
<value>DropdownButton</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument</value>
</prop>
</node>
<node oor:name="m8" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>service:org.entrouvert.openoffice.DropdownButton?test</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value/>
<value xml:lang="en-US">Liste à puces</value>
</prop>
<prop oor:name="ControlType" oor:type="xs:string">
<value>DropdownButton</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument</value>
</prop>
</node>
<node oor:name="m9" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>service:org.entrouvert.openoffice.DropdownButton?test</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value/>
<value xml:lang="en-US">Liste Continue</value>
</prop>
<prop oor:name="ControlType" oor:type="xs:string">
<value>DropdownButton</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument</value>
</prop>
</node>
</node>
<!-- styles toolbar -->
<node oor:name="Tabellio.LegiStyles" oor:op="replace">
@TOOLBAR_LEGI_STYLES@
</node>
<node oor:name="Tabellio.LegisticStyles" oor:op="replace">
@TOOLBAR_LEGISTIC_STYLES@
</node>
</node>
<node oor:name="OfficeHelp">
<node oor:name="org.entrouvert.openoffice.OfficeHelp" oor:op="replace">
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument</value>
</prop>
<prop oor:name="URL" oor:type="xs:string">
<value>XXX</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value>About Tabellio</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
</node>
</node>
</node>
</oor:component-data>

View File

@ -1,4 +1,11 @@
tabellio.ott:
(cd template && zip ../tabellio.ott -r . -x '.svn')
.PHONY: tabellio.ott
addon/Addons.xcu: Addons.xcu.in
python styles.py < Addons.xcu.in > addon/Addons.xcu
tabellio.oxt: addon/Addons.xcu
(cd addon && zip ../tabellio.oxt -r . -x '.svn')
.PHONY: tabellio.ott tabellio.oxt

View File

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<manifest:manifest>
<manifest:file-entry manifest:full-path="pkg-desc/pkg-description.txt"
manifest:media-type="application/vnd.sun.star.package-bundle-description"/>
<manifest:file-entry manifest:full-path="Tabellio.py"
manifest:media-type="application/vnd.sun.star.uno-component;type=Python"/>
<manifest:file-entry manifest:full-path="Addons.xcu"
manifest:media-type="application/vnd.sun.star.configuration-data"/>
<manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data"
manifest:full-path="Office/UI/WriterWindowState.xcu"/>
</manifest:manifest>

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<oor:component-data xmlns:oor="http://openoffice.org/2001/registry"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
oor:name="WriterWindowState"
oor:package="org.openoffice.Office.UI">
<node oor:name="UIElements">
<node oor:name="States">
<node oor:name="private:resource/toolbar/addon_Tabellio.Orateurs" oor:op="replace">
<prop oor:name="UIName" oor:type="xs:string">
<value>Tabellio Orateurs</value>
</prop>
<prop oor:name="DockPos" oor:type="xs:string">
<value>0,5</value>
</prop>
</node>
<node oor:name="private:resource/toolbar/addon_Tabellio.Listes" oor:op="replace">
<prop oor:name="UIName" oor:type="xs:string">
<value>Tabellio Listes</value>
</prop>
<prop oor:name="DockPos" oor:type="xs:string">
<value>0,4</value>
</prop>
</node>
<node oor:name="private:resource/toolbar/addon_Tabellio.LegiStyles" oor:op="replace">
<prop oor:name="UIName" oor:type="xs:string">
<value>Tabellio Legi Styles</value>
</prop>
<prop oor:name="DockPos" oor:type="xs:string">
<value>0,2</value>
</prop>
</node>
<node oor:name="private:resource/toolbar/addon_Tabellio.LegisticStyles" oor:op="replace">
<prop oor:name="UIName" oor:type="xs:string">
<value>Tabellio Legistic Styles</value>
</prop>
<prop oor:name="DockPos" oor:type="xs:string">
<value>0,2</value>
</prop>
</node>
</node>
</node>
</oor:component-data>

353
addon/Tabellio.py Normal file
View File

@ -0,0 +1,353 @@
# -*- coding: UTF-8 -*-
import os
import tempfile
import urllib2
import uno
import unohelper
import string
from com.sun.star.task import XJobExecutor
from com.sun.star.awt import XActionListener
from com.sun.star.frame import XControlNotificationListener
from com.sun.star.beans import PropertyValue
from com.sun.star.awt import Rectangle
from com.sun.star.awt import WindowDescriptor
from com.sun.star.awt.WindowClass import MODALTOP
from com.sun.star.awt.VclWindowPeerAttribute import OK, OK_CANCEL, YES_NO, YES_NO_CANCEL, RETRY_CANCEL, DEF_OK, DEF_CANCEL, DEF_RETRY, DEF_YES, DEF_NO
def download(href):
download_cache_dir = os.path.join(tempfile.gettempdir(), 'tabellio-cache')
filename = '/'.join(urllib2.urlparse.urlparse(href)[1:3])
filename = filename.replace('/', os.path.sep)
cache_filename = os.path.join(download_cache_dir, filename)
cache_dir = os.path.split(cache_filename)[0]
if not os.path.exists(cache_dir):
os.makedirs(cache_dir)
if not os.path.exists(cache_filename):
try:
s = urllib2.urlopen(href).read()
except urllib2.HTTPError, e:
return None
except urllib2.URLError, e:
return None
open(cache_filename, 'w').write(s)
return cache_filename
class MyActionListener( unohelper.Base, XActionListener ):
def __init__(self, doc, combobox, dialog ):
self.nCount = 0
self.combobox = combobox
self.dialog = dialog
self.doc = doc
def actionPerformed(self, actionEvent):
try:
text = self.doc.Text
cursor = self.doc.getCurrentController().getViewCursor()
text.insertString(cursor, self.combobox.Text + ' ', 0)
self.dialog.endExecute()
except Exception, e:
print str(e)
# Show a message box with the UNO based toolkit
def MessageBox(ParentWin, MsgText, MsgTitle, MsgType="messbox", MsgButtons=OK):
MsgType = MsgType.lower()
#available msg types
MsgTypes = ("messbox", "infobox", "errorbox", "warningbox", "querybox")
if not ( MsgType in MsgTypes ):
MsgType = "messbox"
#describe window properties.
aDescriptor = WindowDescriptor()
aDescriptor.Type = MODALTOP
aDescriptor.WindowServiceName = MsgType
aDescriptor.ParentIndex = -1
aDescriptor.Parent = ParentWin
#aDescriptor.Bounds = Rectangle()
aDescriptor.WindowAttributes = MsgButtons
tk = ParentWin.getToolkit()
msgbox = tk.createWindow(aDescriptor)
msgbox.setMessageText(MsgText)
if MsgTitle :
msgbox.setCaptionText(MsgTitle)
return msgbox.execute()
class QueryDialog(unohelper.Base, XJobExecutor):
def __init__(self, ctx):
self.ctx = ctx
def trigger(self, args ):
desktop = self.ctx.ServiceManager.createInstanceWithContext(
"com.sun.star.frame.Desktop", self.ctx )
doc = desktop.getCurrentComponent()
TestQueryBox(doc)
class InfoDialog(unohelper.Base, XJobExecutor):
def __init__(self, ctx):
self.ctx = ctx
def trigger(self, args ):
desktop = self.ctx.ServiceManager.createInstanceWithContext(
"com.sun.star.frame.Desktop", self.ctx )
doc = desktop.getCurrentComponent()
TestInfoBox(doc)
class StyleApply(unohelper.Base, XJobExecutor):
def __init__(self, ctx):
self.ctx = ctx
def trigger(self, args):
style_name = args
desktop = self.ctx.ServiceManager.createInstanceWithContext(
"com.sun.star.frame.Desktop", self.ctx )
doc = desktop.getCurrentComponent()
text = doc.Text
cursor = doc.getCurrentController().getViewCursor()
try:
cursor.setPropertyValue('ParaStyleName', style_name)
except Exception, e:
print 'exc:', str(e)
class StructureCheckDialog(unohelper.Base, XJobExecutor):
def __init__(self, ctx):
self.ctx = ctx
def displayDialog(self):
smgr = self.ctx.ServiceManager
# create the dialog model and set the properties
dialogModel = smgr.createInstanceWithContext(
"com.sun.star.awt.UnoControlDialogModel", self.ctx)
dialogModel.PositionX = 100
dialogModel.PositionY = 200
dialogModel.Width = 210
dialogModel.Height = 130
dialogModel.Title = u"Analyse du document"
listModel = dialogModel.createInstance("com.sun.star.awt.UnoControlListBoxModel")
listModel.PositionX = 5
listModel.PositionY = 5
listModel.Width = 200
listModel.Height = 100
listModel.Name = 'errorList'
listErrors = []
for i, error in enumerate(self.errors):
listErrors.append(str(error))
listModel.StringItemList = tuple(listErrors)
dialogModel.insertByName("errorList", listModel)
# close button
buttonModel = dialogModel.createInstance(
"com.sun.star.awt.UnoControlButtonModel" )
buttonModel.PositionX = 155
buttonModel.PositionY = 110
buttonModel.Width = 50
buttonModel.Height = 14
buttonModel.Name = "myButtonName"
buttonModel.TabIndex = 0
buttonModel.Label = u"Fermer"
dialogModel.insertByName( "myButtonName", buttonModel)
# create the dialog control and set the model
controlContainer = smgr.createInstanceWithContext(
"com.sun.star.awt.UnoControlDialog", self.ctx)
controlContainer.setModel(dialogModel)
# create a peer
toolkit = smgr.createInstanceWithContext(
"com.sun.star.awt.ExtToolkit", self.ctx)
controlContainer.setVisible(False);
controlContainer.createPeer(toolkit, None)
# execute it
controlContainer.execute()
# dispose the dialog
controlContainer.dispose()
def trigger(self, args):
try:
desktop = self.ctx.ServiceManager.createInstanceWithContext(
"com.sun.star.frame.Desktop", self.ctx )
doc = desktop.getCurrentComponent()
text = doc.Text
cursor = text.createTextCursor()
cursor.gotoStart(False)
self.errors = []
print [x for x in dir(cursor) if 'page' in x.lower()]
while True:
self.errors.append(u"Page %s: %s" % (
cursor.PageNumberOffset,
cursor.ParaStyleName))
if not cursor.gotoNextParagraph(False):
break
if self.errors:
self.displayDialog()
except Exception, e:
print 'exc:', str(e)
class OrateurDialog(unohelper.Base, XJobExecutor):
def __init__(self, ctx):
self.ctx = ctx
def trigger(self, args):
ctx = self.ctx
desktop = self.ctx.ServiceManager.createInstanceWithContext(
"com.sun.star.frame.Desktop", self.ctx )
doc = desktop.getCurrentComponent()
if not args in ('deputes', 'ministres', 'new'):
parentwin = doc.CurrentController.Frame.ContainerWindow
return MessageBox(parentwin, 'Liste inconnue', 'Alerte', "infobox")
try:
if args != 'new':
list_filename = download('http://perso.entrouvert.org/~fred/%s.txt' % args)
if not list_filename:
parentwin = doc.CurrentController.Frame.ContainerWindow
return MessageBox(parentwin,
u'Échec au téléchargement de la liste', 'Alerte', "infobox")
smgr = ctx.ServiceManager
# create the dialog model and set the properties
dialogModel = smgr.createInstanceWithContext(
"com.sun.star.awt.UnoControlDialogModel", ctx)
dialogModel.PositionX = 100
dialogModel.PositionY = 200
dialogModel.Width = 155
dialogModel.Height = 50
if args == 'ministres':
dialogModel.Title = u"Insertion Ministres et Présidents"
elif args == 'deputes':
dialogModel.Title = u"Insertion Députés"
elif args == 'new':
dialogModel.Title = u'Insertion Orateur'
else:
dialogModel.Title = 'XXX'
# create the button model and set the properties
buttonModel = dialogModel.createInstance(
"com.sun.star.awt.UnoControlButtonModel" )
buttonModel.PositionX = 50
buttonModel.PositionY = 30
buttonModel.Width = 50;
buttonModel.Height = 14;
buttonModel.Name = "myButtonName";
buttonModel.TabIndex = 0;
buttonModel.Label = u"Insérer";
dialogModel.insertByName( "myButtonName", buttonModel)
text = dialogModel.createInstance('com.sun.star.awt.UnoControlFixedTextModel')
text.PositionX = 10
text.PositionY = 10
text.Width = 100
text.Height = 14
text.Label = u'Orateur :'
dialogModel.insertByName('label0', text)
if args == 'new':
comboboxModel = dialogModel.createInstance('com.sun.star.awt.UnoControlEditModel')
comboboxModel.PositionX = 50
comboboxModel.PositionY = 7
comboboxModel.Width = 100
comboboxModel.Height = 14
comboboxModel.MultiLine = False
comboboxModel.Name = 'myComboBox'
else:
comboboxModel = dialogModel.createInstance("com.sun.star.awt.UnoControlComboBoxModel" )
comboboxModel.PositionX = 50
comboboxModel.PositionY = 7
comboboxModel.Width = 100
comboboxModel.Height = 14
comboboxModel.Dropdown = True
comboboxModel.Name = 'myComboBox'
comboboxModel.StringItemList = tuple(
[unicode(x.strip(), 'utf-8') for x in open(list_filename).readlines() if x.strip()])
dialogModel.insertByName( "myComboBox", comboboxModel)
# create the dialog control and set the model
controlContainer = smgr.createInstanceWithContext(
"com.sun.star.awt.UnoControlDialog", ctx);
controlContainer.setModel(dialogModel);
# add the action listener
controlContainer.getControl("myButtonName").addActionListener(
MyActionListener(doc, comboboxModel, controlContainer))
# create a peer
toolkit = smgr.createInstanceWithContext(
"com.sun.star.awt.ExtToolkit", ctx);
controlContainer.setVisible(False);
controlContainer.createPeer(toolkit, None);
# execute it
controlContainer.execute()
# dispose the dialog
controlContainer.dispose()
except Exception,e:
print str(e)
g_ImplementationHelper = unohelper.ImplementationHelper()
g_ImplementationHelper.addImplementation(
QueryDialog,
"org.entrouvert.openoffice.QueryDialog",
("com.sun.star.task.Job",),)
g_ImplementationHelper.addImplementation(
InfoDialog,
"org.entrouvert.openoffice.InfoDialog",
("com.sun.star.task.Job",),)
g_ImplementationHelper.addImplementation(
OrateurDialog,
"org.entrouvert.openoffice.OrateurDialog",
("com.sun.star.task.Job",),)
g_ImplementationHelper.addImplementation(
StyleApply,
"org.entrouvert.openoffice.StyleApply",
("com.sun.star.task.Job",))
g_ImplementationHelper.addImplementation(
StructureCheckDialog,
"org.entrouvert.openoffice.StructureCheckDialog",
("com.sun.star.task.Job",))

View File

@ -0,0 +1,3 @@
Tabellio
Plop plop plop

57
styles.py Normal file
View File

@ -0,0 +1,57 @@
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import sys
legi_styles = [('Titre Préface', 'Titre'),
('Préface', 'Standard'),
('Partie', 'Titre 1'),
('Chap', 'Titre 2'),
('Sec 1', 'Titre 3'),
('Sec 1.1', 'Titre 4'),
('Sec 1.1.1', 'Titre 5'),
('Sec 1.1.1.1', 'Titre 6'),
('Ss-Titre', 'Titre 7'),
('Literal', 'Standard'),
('Note', 'Note en marge'),
('Para', 'Standard')
]
legistic_styles = [
('LPart', 'Lpart'),
('LLivre', 'LLivre'),
('LTitre', 'Ltitre'),
('LChapitre', 'Lchapitre'),
('LSection', 'Lsection'),
('LSous-Section', 'LSous-Section'),
('LArt', 'lart')
]
f = sys.stdin.read()
def get_xml(styles):
s = []
for c, style in enumerate(styles):
stylelabel, stylename = style
s.append('''
<node oor:name="m%(c)02d" oor:op="replace">
<prop oor:name="URL" oor:type="xs:string">
<value>service:org.entrouvert.openoffice.StyleApply?%(stylename)s</value>
</prop>
<prop oor:name="Title" oor:type="xs:string">
<value>%(stylelabel)s</value>
</prop>
<prop oor:name="Target" oor:type="xs:string">
<value>_self</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument</value>
</prop>
</node>''' % locals())
return '\n'.join(s)
print f.replace(
'@TOOLBAR_LEGI_STYLES@', get_xml(legi_styles)).replace(
'@TOOLBAR_LEGISTIC_STYLES@', get_xml(legistic_styles))