2007-11-14 21:30:36 +01:00
# -*- coding: UTF-8 -*-
2010-03-03 15:58:04 +01:00
# TabellioOOo - OpenOffice.org extension
# Copyright (C) 2007-2010 Parlement de la Communauté française de Belgique
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2007-11-14 21:30:36 +01:00
import os
2009-03-11 11:54:29 +01:00
import csv
2008-07-08 14:29:18 +02:00
import string
2007-12-02 22:41:44 +01:00
import sys
2007-11-14 21:30:36 +01:00
import tempfile
2007-11-26 12:13:56 +01:00
import xml . dom . minidom
2007-11-29 12:04:09 +01:00
import socket
2009-10-07 10:31:13 +02:00
import random
2010-01-06 12:53:18 +01:00
import time
2007-11-29 12:04:09 +01:00
if hasattr ( socket , ' setdefaulttimeout ' ) :
2008-02-18 15:15:58 +01:00
socket . setdefaulttimeout ( 30 )
2007-11-14 21:30:36 +01:00
2015-04-25 19:08:04 +02:00
import urllib . request , urllib . error , urllib . parse
import urllib . parse
2007-11-14 21:30:36 +01:00
import uno
import unohelper
2007-11-27 19:19:19 +01:00
2009-01-14 17:19:45 +01:00
from com . sun . star . container import NoSuchElementException
2007-11-14 21:30:36 +01:00
from com . sun . star . task import XJobExecutor
2007-11-27 19:19:19 +01:00
from com . sun . star . awt import XActionListener , XItemListener
2007-11-14 21:30:36 +01:00
from com . sun . star . frame import XControlNotificationListener
2007-11-26 12:13:56 +01:00
from com . sun . star . frame import XDispatch
2008-03-02 15:31:41 +01:00
from com . sun . star . frame import XDispatchProvider
from com . sun . star . frame import FeatureStateEvent
from com . sun . star . beans import PropertyValue , NamedValue
from com . sun . star . frame import ControlCommand
2008-06-25 01:31:56 +02:00
from com . sun . star . task import XJob
2007-11-14 21:30:36 +01:00
from com . sun . star . awt import WindowDescriptor
2007-11-27 21:53:00 +01:00
from com . sun . star . awt import FontDescriptor
2007-11-14 21:30:36 +01:00
2008-07-08 20:45:24 +02:00
from com . sun . star . awt . FontWeight import BOLD , NORMAL
2007-11-14 21:30:36 +01:00
from com . sun . star . awt . WindowClass import MODALTOP
2011-06-03 11:32:12 +02:00
from com . sun . star . awt . VclWindowPeerAttribute import OK
2007-11-14 21:30:36 +01:00
2009-03-11 11:54:29 +01:00
from com . sun . star . text . ControlCharacter import APPEND_PARAGRAPH
2009-04-17 16:54:30 +02:00
from com . sun . star . ui . dialogs . TemplateDescription import FILESAVE_SIMPLE
2010-03-04 10:27:55 +01:00
### Utility functions
2008-11-26 16:48:01 +01:00
def debug_print ( * args ) :
2011-06-03 11:32:12 +02:00
''' Print a message on the console (if possible) '''
2008-11-26 16:48:01 +01:00
if sys . platform . startswith ( ' win ' ) :
2010-03-04 10:27:55 +01:00
# there is no stdout/stderr on windows
2008-11-26 16:48:01 +01:00
return
2015-04-25 19:08:04 +02:00
if type ( args ) in ( str , str ) :
print ( args , file = sys . stderr )
2008-11-26 16:48:01 +01:00
else :
for a in args :
2015-04-25 19:08:04 +02:00
print ( a , end = ' ' , file = sys . stderr )
print ( ' ' , file = sys . stderr )
2008-11-26 16:48:01 +01:00
2009-10-07 16:19:09 +02:00
def debug_unodir ( unoobj ) :
2011-06-03 13:31:33 +02:00
''' Introspect an object to get all its methods and properties. '''
2009-10-07 16:19:09 +02:00
2011-06-03 13:31:33 +02:00
from com . sun . star . beans . MethodConcept import ALL as ALLMETHS
from com . sun . star . beans . PropertyConcept import ALL as ALLPROPS
2009-10-07 16:19:09 +02:00
2011-06-03 13:31:33 +02:00
ctx = uno . getComponentContext ( )
introspection = ctx . ServiceManager . createInstanceWithContext (
2009-10-07 16:19:09 +02:00
' com.sun.star.beans.Introspection ' , ctx )
2011-06-03 13:31:33 +02:00
access = introspection . inspect ( unoobj )
2009-10-07 16:19:09 +02:00
2011-06-03 13:31:33 +02:00
return { ' methods ' : [ x . getName ( ) for x in access . getMethods ( ALLMETHS ) ] ,
' properties ' : [ x . getName ( ) for x in access . getMethods ( ALLPROPS ) ] }
2009-10-07 16:19:09 +02:00
2009-03-11 11:54:29 +01:00
xlate = {
2015-04-25 19:08:04 +02:00
' \N{ACUTE ACCENT} ' : " ' " ,
' \N{BROKEN BAR} ' : ' | ' ,
' \N{DIVISION SIGN} ' : ' / ' ,
' \N{LATIN CAPITAL LETTER A WITH ACUTE} ' : ' A ' ,
' \N{LATIN CAPITAL LETTER A WITH CIRCUMFLEX} ' : ' A ' ,
' \N{LATIN CAPITAL LETTER A WITH DIAERESIS} ' : ' A ' ,
' \N{LATIN CAPITAL LETTER A WITH GRAVE} ' : ' A ' ,
' \N{LATIN CAPITAL LETTER A WITH RING ABOVE} ' : ' A ' ,
' \N{LATIN CAPITAL LETTER A WITH TILDE} ' : ' A ' ,
' \N{LATIN CAPITAL LETTER AE} ' : ' Ae ' ,
' \N{LATIN CAPITAL LETTER C WITH CEDILLA} ' : ' C ' ,
' \N{LATIN CAPITAL LETTER E WITH ACUTE} ' : ' E ' ,
' \N{LATIN CAPITAL LETTER E WITH CIRCUMFLEX} ' : ' E ' ,
' \N{LATIN CAPITAL LETTER E WITH DIAERESIS} ' : ' E ' ,
' \N{LATIN CAPITAL LETTER E WITH GRAVE} ' : ' E ' ,
' \N{LATIN CAPITAL LETTER ETH} ' : ' Th ' ,
' \N{LATIN CAPITAL LETTER I WITH ACUTE} ' : ' I ' ,
' \N{LATIN CAPITAL LETTER I WITH CIRCUMFLEX} ' : ' I ' ,
' \N{LATIN CAPITAL LETTER I WITH DIAERESIS} ' : ' I ' ,
' \N{LATIN CAPITAL LETTER I WITH GRAVE} ' : ' I ' ,
' \N{LATIN CAPITAL LETTER N WITH TILDE} ' : ' N ' ,
' \N{LATIN CAPITAL LETTER O WITH ACUTE} ' : ' O ' ,
' \N{LATIN CAPITAL LETTER O WITH CIRCUMFLEX} ' : ' O ' ,
' \N{LATIN CAPITAL LETTER O WITH DIAERESIS} ' : ' O ' ,
' \N{LATIN CAPITAL LETTER O WITH GRAVE} ' : ' O ' ,
' \N{LATIN CAPITAL LETTER O WITH STROKE} ' : ' O ' ,
' \N{LATIN CAPITAL LETTER O WITH TILDE} ' : ' O ' ,
' \N{LATIN CAPITAL LETTER THORN} ' : ' th ' ,
' \N{LATIN CAPITAL LETTER U WITH ACUTE} ' : ' U ' ,
' \N{LATIN CAPITAL LETTER U WITH CIRCUMFLEX} ' : ' U ' ,
' \N{LATIN CAPITAL LETTER U WITH DIAERESIS} ' : ' U ' ,
' \N{LATIN CAPITAL LETTER U WITH GRAVE} ' : ' U ' ,
' \N{LATIN CAPITAL LETTER Y WITH ACUTE} ' : ' Y ' ,
' \N{LATIN SMALL LETTER A WITH ACUTE} ' : ' a ' ,
' \N{LATIN SMALL LETTER A WITH CIRCUMFLEX} ' : ' a ' ,
' \N{LATIN SMALL LETTER A WITH DIAERESIS} ' : ' a ' ,
' \N{LATIN SMALL LETTER A WITH GRAVE} ' : ' a ' ,
' \N{LATIN SMALL LETTER A WITH RING ABOVE} ' : ' a ' ,
' \N{LATIN SMALL LETTER A WITH TILDE} ' : ' a ' ,
' \N{LATIN SMALL LETTER AE} ' : ' ae ' ,
' \N{LATIN SMALL LETTER C WITH CEDILLA} ' : ' c ' ,
' \N{LATIN SMALL LETTER E WITH ACUTE} ' : ' e ' ,
' \N{LATIN SMALL LETTER E WITH CIRCUMFLEX} ' : ' e ' ,
' \N{LATIN SMALL LETTER E WITH DIAERESIS} ' : ' e ' ,
' \N{LATIN SMALL LETTER E WITH GRAVE} ' : ' e ' ,
' \N{LATIN SMALL LETTER ETH} ' : ' th ' ,
' \N{LATIN SMALL LETTER I WITH ACUTE} ' : ' i ' ,
' \N{LATIN SMALL LETTER I WITH CIRCUMFLEX} ' : ' i ' ,
' \N{LATIN SMALL LETTER I WITH DIAERESIS} ' : ' i ' ,
' \N{LATIN SMALL LETTER I WITH GRAVE} ' : ' i ' ,
' \N{LATIN SMALL LETTER N WITH TILDE} ' : ' n ' ,
' \N{LATIN SMALL LETTER O WITH ACUTE} ' : ' o ' ,
' \N{LATIN SMALL LETTER O WITH CIRCUMFLEX} ' : ' o ' ,
' \N{LATIN SMALL LETTER O WITH DIAERESIS} ' : ' o ' ,
' \N{LATIN SMALL LETTER O WITH GRAVE} ' : ' o ' ,
' \N{LATIN SMALL LETTER O WITH STROKE} ' : ' o ' ,
' \N{LATIN SMALL LETTER O WITH TILDE} ' : ' o ' ,
' \N{LATIN SMALL LETTER SHARP S} ' : ' ss ' ,
' \N{LATIN SMALL LETTER THORN} ' : ' th ' ,
' \N{LATIN SMALL LETTER U WITH ACUTE} ' : ' u ' ,
' \N{LATIN SMALL LETTER U WITH CIRCUMFLEX} ' : ' u ' ,
' \N{LATIN SMALL LETTER U WITH DIAERESIS} ' : ' u ' ,
' \N{LATIN SMALL LETTER U WITH GRAVE} ' : ' u ' ,
' \N{LATIN SMALL LETTER Y WITH ACUTE} ' : ' y ' ,
' \N{LATIN SMALL LETTER Y WITH DIAERESIS} ' : ' y ' ,
2009-03-11 11:54:29 +01:00
}
def latin1_to_ascii ( unicrap ) :
""" This takes a UNICODE string and replaces Latin-1 characters with
something equivalent in 7 - bit ASCII . It returns a plain ASCII string .
This function makes a best effort to convert Latin - 1 characters into
ASCII equivalents . It does not just strip out the Latin - 1 characters .
All characters in the standard 7 - bit ASCII range are preserved .
In the 8 th bit range all the Latin - 1 accented letters are converted
to unaccented equivalents . Most symbol characters are converted to
something meaningful . Anything not converted is deleted .
< http : / / aspn . activestate . com / ASPN / Cookbook / Python / Recipe / 251871 >
"""
r = " "
for i in unicrap :
2015-04-25 19:08:04 +02:00
if i in xlate :
2009-03-11 11:54:29 +01:00
r + = xlate [ i ]
elif ord ( i ) > = 0x80 :
pass
else :
r + = str ( i )
return r
2009-09-10 11:58:25 +02:00
def normalize_filename ( filename ) :
2011-06-03 11:32:12 +02:00
''' Normalize a filename received from OOo (as a RFC 1738 URL) so it can
get accessed by Python file functions afterwards '''
2015-04-25 19:08:04 +02:00
filename = str ( urllib . parse . unquote ( str ( filename [ 7 : ] ) ) , ' utf-8 ' )
2009-09-10 11:58:25 +02:00
if sys . platform . startswith ( ' win ' ) :
# Note on behaviour on Windows:
# when on a lettered disk, it returns file:///Z:/foobar
# on a share, it returns file://name-of-the-share/boobar
if filename [ 0 ] != ' / ' :
# windows share
filename = ' \\ \\ ' + filename
elif filename [ 2 ] == ' : ' :
filename = filename [ 1 : ]
filename = filename . replace ( ' / ' , ' \\ ' )
return filename
2009-03-11 11:54:29 +01:00
2008-11-26 16:48:01 +01:00
2008-07-12 17:52:35 +02:00
class DownloadError ( Exception ) :
pass
2011-06-03 11:32:12 +02:00
def display_exception ( ctx = None ) :
2010-03-04 10:27:55 +01:00
''' Display exception in a message dialog '''
2011-12-13 11:17:48 +01:00
# it allows to trace errors that would otherwise be swallowed by
# OpenOffice.org, and to get them displayed to terminal for easier
# handling, on non-Windows platforms.
2008-03-02 15:31:41 +01:00
import traceback
2009-04-30 21:57:17 +02:00
if not sys . platform . startswith ( ' win ' ) :
2010-03-04 10:27:55 +01:00
# also print trace on stdout/stderr on non-Windows platform
2009-04-30 21:57:17 +02:00
traceback . print_exc ( )
if not ctx :
return
2015-04-25 19:08:04 +02:00
s = ' \n ' . join ( traceback . format_exception ( sys . exc_info ( ) [ 0 ] , sys . exc_info ( ) [ 1 ] , sys . exc_info ( ) [ 2 ] ) )
2009-04-30 21:57:17 +02:00
smgr = ctx . ServiceManager
desktop = smgr . createInstanceWithContext ( ' com.sun.star.frame.Desktop ' , ctx )
doc = desktop . getCurrentComponent ( )
parentwin = doc . CurrentController . Frame . ContainerWindow
MessageBox ( parentwin , s , ' Exception ' )
2008-03-02 15:31:41 +01:00
2011-06-03 11:32:12 +02:00
# from danny/OOoLib:
2007-11-26 14:39:00 +01:00
def makePropertyValue ( cName = None , uValue = None , nHandle = None , nState = None ) :
""" Create a com.sun.star.beans.PropertyValue struct and return it.
"""
oPropertyValue = PropertyValue ( )
if cName != None :
oPropertyValue . Name = cName
if uValue != None :
oPropertyValue . Value = uValue
if nHandle != None :
oPropertyValue . Handle = nHandle
if nState != None :
oPropertyValue . State = nState
return oPropertyValue
2008-03-02 15:31:41 +01:00
def makeNamedList ( items ) :
2008-07-09 16:13:11 +02:00
p = NamedValue ( )
2008-03-02 15:31:41 +01:00
p . Name = ' List '
p . Value = uno . Any ( ' []string ' , items )
return ( p , )
2010-06-11 13:53:22 +02:00
def get_url_opener ( ctx ) :
2011-06-03 11:32:12 +02:00
''' Return a urllib2 opener object, configured with appropriate proxy
settings '''
2010-06-11 13:53:22 +02:00
oConfigAccess = getConfigAccess ( ctx ,
' /org.entrouvert.openoffice.tabellio.Configuration ' , False )
2010-07-22 10:41:27 +02:00
try :
proxy_server_url = oConfigAccess . getByName ( ' ProxyServerURL ' ) . strip ( )
except : # com.sun.star.container.NoSuchElementException
# this happens in some case of extension misconfiguration, ignore
proxy_server_url = ' '
2010-06-21 11:03:13 +02:00
if proxy_server_url in ( ' system ' , ' ' ) :
2015-04-25 19:08:04 +02:00
return urllib . request . build_opener ( )
2010-06-11 13:53:22 +02:00
if proxy_server_url == ' none ' :
2015-04-25 19:08:04 +02:00
proxy_handler = urllib . request . ProxyHandler ( { } )
2010-06-11 13:53:22 +02:00
else :
2015-04-25 19:08:04 +02:00
proxy_handler = urllib . request . ProxyHandler ( { ' http ' : proxy_server_url } )
return urllib . request . build_opener ( proxy_handler )
2007-11-26 14:39:00 +01:00
2010-06-11 13:53:22 +02:00
def download ( ctx , href ) :
2010-03-04 10:27:55 +01:00
''' Download and cache files '''
2012-02-22 13:36:13 +01:00
if sys . platform . startswith ( ' win ' ) :
download_cache_dir = ' c: \\ temp '
2015-04-25 19:08:04 +02:00
filename = urllib . parse . urlparse ( href ) [ 2 ] . strip ( ' / ' )
2012-02-22 13:36:13 +01:00
else :
download_cache_dir = os . path . join ( tempfile . gettempdir ( ) , ' tabellio-cache ' )
2015-04-25 19:08:04 +02:00
filename = ' / ' . join ( urllib . parse . urlparse ( href ) [ 1 : 3 ] )
2012-02-22 13:36:13 +01:00
filename = filename . replace ( ' / ' , os . path . sep )
2007-11-14 21:30:36 +01:00
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 )
2010-01-06 12:53:18 +01:00
if not os . path . exists ( cache_filename ) or time . time ( ) - os . stat ( cache_filename ) . st_mtime > 7200 :
2007-11-14 21:30:36 +01:00
try :
2010-06-11 13:53:22 +02:00
s = get_url_opener ( ctx ) . open ( href ) . read ( )
2015-04-25 19:08:04 +02:00
except ( urllib . error . HTTPError , urllib . error . URLError , socket . timeout ) as e :
2010-01-06 12:53:18 +01:00
if os . path . exists ( cache_filename ) :
return cache_filename
2007-11-29 12:04:09 +01:00
return None
2012-02-22 13:36:13 +01:00
fd = open ( cache_filename , ' wb ' )
fd . write ( s )
fd . close ( )
2007-11-14 21:30:36 +01:00
return cache_filename
2011-06-03 11:32:12 +02:00
def get_text_node_content ( node ) :
''' Return the content of a text node '''
rc = ' '
for n in node . childNodes :
if n . nodeType == n . TEXT_NODE :
rc = rc + n . data
2007-11-26 12:13:56 +01:00
return rc
2007-11-14 21:30:36 +01:00
2010-03-08 12:15:20 +01:00
def get_mode ( ctx ) :
oConfigAccess = getConfigAccess ( ctx ,
' /org.entrouvert.openoffice.tabellio.Configuration ' , False )
return oConfigAccess . getByName ( ' Mode ' )
2008-07-14 14:55:53 +02:00
class RemoteObject :
2010-03-04 10:27:55 +01:00
'''
Class to handle objects described in a remote XML file , so they can be
inserted in the document .
'''
2008-07-09 18:13:57 +02:00
_attrs = [ ]
2008-07-09 18:28:24 +02:00
aspres = 0
2008-07-08 22:17:44 +02:00
def __init__ ( self , node ) :
2008-07-09 18:13:57 +02:00
for attr in self . _attrs :
try :
2011-06-03 11:32:12 +02:00
setattr ( self , attr , get_text_node_content (
node . getElementsByTagName ( attr ) [ 0 ] ) . strip ( ) )
2008-07-09 18:13:57 +02:00
except IndexError :
setattr ( self , attr , None )
2008-07-08 22:17:44 +02:00
def get_name ( self ) :
2015-04-25 19:08:04 +02:00
return ' %s %s ' % ( self . name , self . firstname )
2008-07-08 22:17:44 +02:00
2009-01-14 12:25:25 +01:00
def get_download_url ( cls , ctx ) :
oConfigAccess = getConfigAccess ( ctx ,
' /org.entrouvert.openoffice.tabellio.Configuration ' , False )
inserts_base_url = oConfigAccess . getByName ( ' InsertsRootURL ' )
download_url = inserts_base_url + cls . _download_file
return download_url
get_download_url = classmethod ( get_download_url )
def get_nodes ( cls , ctx ) :
2010-06-11 13:53:22 +02:00
list_filename = download ( ctx , cls . get_download_url ( ctx ) )
2008-07-09 18:13:57 +02:00
if not list_filename :
2008-07-12 17:52:35 +02:00
raise DownloadError ( )
2008-07-09 18:13:57 +02:00
dom = xml . dom . minidom . parseString ( open ( list_filename ) . read ( ) )
2008-07-14 14:55:53 +02:00
nodes = dom . childNodes [ 0 ] . getElementsByTagName ( cls . _node_name )
return nodes
get_nodes = classmethod ( get_nodes )
2008-07-08 22:17:44 +02:00
_cache = None
2009-01-14 12:25:25 +01:00
def values ( cls , ctx ) :
2008-07-08 22:17:44 +02:00
if cls . _cache :
return cls . _cache
2009-01-14 12:25:25 +01:00
cls . _cache = [ cls ( x ) for x in cls . get_nodes ( ctx ) ]
2008-07-09 18:13:57 +02:00
return cls . _cache
values = classmethod ( values )
2008-07-08 22:17:44 +02:00
2010-06-21 11:05:19 +02:00
def insert ( self , ctx , doc , cursor ) :
2015-04-25 19:08:04 +02:00
cursor . Text . insertString ( cursor , self . get_name ( ) . replace ( ' ' , ' ' ) , 0 )
2008-12-22 14:19:40 +01:00
2010-03-08 12:15:20 +01:00
def insert_speaker_closing ( self , ctx , doc , cursor ) :
if get_mode ( ctx ) == ' PFB ' :
2015-04-25 19:08:04 +02:00
doc . Text . insertString ( cursor , ' .- ' , 0 )
2010-03-08 12:15:20 +01:00
else :
2015-04-25 19:08:04 +02:00
doc . Text . insertString ( cursor , ' . – ' , 0 )
2010-03-08 12:15:20 +01:00
2008-07-09 18:13:57 +02:00
2008-07-14 14:55:53 +02:00
class Deputy ( RemoteObject ) :
2010-03-04 10:27:55 +01:00
'''
Class to handle description of a deputy
'''
2009-03-11 11:54:29 +01:00
_attrs = ( ' id ' , ' firstname ' , ' name ' , ' title ' , ' comppol ' , ' classname ' , ' sexe ' )
2009-01-14 12:25:25 +01:00
_download_file = ' Parls.xml '
2008-07-09 18:13:57 +02:00
_node_name = ' SParlSpeaker '
def get_long_name ( self ) :
2015-04-25 19:08:04 +02:00
return ' %s %s %s ( %s ) ' % ( self . title , self . firstname , self . name , self . comppol )
2008-07-09 18:13:57 +02:00
2009-01-14 12:25:25 +01:00
def values ( cls , ctx ) :
2008-07-09 18:13:57 +02:00
if cls . _cache :
return cls . _cache
2009-01-14 12:25:25 +01:00
cls . _cache = [ cls ( x ) for x in cls . get_nodes ( ctx ) if x . getElementsByTagName ( ' firstname ' ) ]
2008-07-08 22:17:44 +02:00
return cls . _cache
values = classmethod ( values )
2008-07-09 13:16:36 +02:00
def insert_as_speaker ( self , ctx , doc , cursor ) :
2010-03-04 10:27:55 +01:00
# Add an annotation next to the document, with a reference to deputy
# internal id
2009-01-14 17:47:42 +01:00
annotation = doc . createInstance ( ' com.sun.star.text.TextField.Annotation ' )
annotation . setPropertyValue ( ' Author ' , ' ' )
text = ' type: TABELLIO \n ref id: %s \n classname: %s ' % ( self . id , self . classname )
annotation . setPropertyValue ( ' Content ' , text )
doc . Text . insertTextContent ( cursor , annotation , False )
2008-07-09 13:16:36 +02:00
cursor . setPropertyValue ( ' CharWeight ' , BOLD )
2015-04-25 19:08:04 +02:00
doc . Text . insertString ( cursor , self . get_long_name ( ) . replace ( ' ' , ' ' ) , 0 )
2010-03-08 12:15:20 +01:00
self . insert_speaker_closing ( ctx , doc , cursor )
2008-07-09 13:16:36 +02:00
cursor . setPropertyValue ( ' CharWeight ' , NORMAL )
2009-03-11 11:54:29 +01:00
def get_ascii_name ( self ) :
return latin1_to_ascii ( ' %s %s ' % ( self . firstname , self . name ) )
def get_deputy_id ( cls , firstname , lastname , ctx = None ) :
2010-03-04 10:27:55 +01:00
'''
Lookup a deputy while ignoring case and accentuated characters
'''
2009-03-11 11:54:29 +01:00
ascii_name = latin1_to_ascii ( ' %s %s ' % ( firstname , lastname ) ) . lower ( )
for deputy in cls . values ( ctx = ctx ) :
if ascii_name == deputy . get_ascii_name ( ) . lower ( ) :
return deputy . id
return None
get_deputy_id = classmethod ( get_deputy_id )
2008-07-14 14:55:53 +02:00
class Minister ( RemoteObject ) :
2010-03-04 10:27:55 +01:00
'''
Class to handle the description of a minister
'''
2008-07-09 18:13:57 +02:00
_attrs = ( ' id ' , ' firstname ' , ' name ' , ' title ' , ' classname ' , ' fonc ' )
2009-01-14 12:25:25 +01:00
_download_file = ' Ministres.xml '
2008-07-09 18:13:57 +02:00
_node_name = ' SMinistreSpeaker '
2008-07-08 22:17:44 +02:00
2008-07-09 16:26:46 +02:00
def get_long_name ( self ) :
2015-04-25 19:08:04 +02:00
return ' %s %s %s ' % ( self . title , self . firstname , self . name )
2008-07-09 16:26:46 +02:00
2010-03-26 09:36:46 +01:00
def get_function_with_correct_case ( self , ctx ) :
2011-05-04 18:25:39 +02:00
if not self . fonc :
self . fonc = ' '
2010-03-26 09:36:46 +01:00
fonc = self . fonc . strip ( )
fonc = fonc . replace ( ' Ministre ' , ' ministre ' )
if get_mode ( ctx ) == ' PCF ' :
2015-04-25 19:08:04 +02:00
fonc = fonc . replace ( ' Président ' , ' président ' )
fonc = fonc . replace ( ' Vice-président ' , ' vice-président ' )
2010-03-26 09:36:46 +01:00
return fonc
2008-07-09 13:16:36 +02:00
def insert_as_speaker ( self , ctx , doc , cursor ) :
2010-03-04 10:27:55 +01:00
# Add an annotation next to the document, with a reference to minister
# internal id
2009-01-14 17:47:42 +01:00
annotation = doc . createInstance ( ' com.sun.star.text.TextField.Annotation ' )
annotation . setPropertyValue ( ' Author ' , ' ' )
text = ' type: TABELLIO \n ref id: %s \n classname: %s ' % ( self . id , self . classname )
annotation . setPropertyValue ( ' Content ' , text )
doc . Text . insertTextContent ( cursor , annotation , False )
2008-07-09 13:16:36 +02:00
cursor . setPropertyValue ( ' CharWeight ' , BOLD )
2015-04-25 19:08:04 +02:00
doc . Text . insertString ( cursor , self . get_long_name ( ) . replace ( ' ' , ' ' ) , 0 )
2011-05-04 18:25:39 +02:00
fonc = self . get_function_with_correct_case ( ctx )
if fonc :
if get_mode ( ctx ) == ' PCF ' :
cursor . setPropertyValue ( ' CharWeight ' , NORMAL )
2015-04-25 19:08:04 +02:00
doc . Text . insertString ( cursor , ' , ' , 0 )
2011-05-04 18:25:39 +02:00
doc . Text . insertString ( cursor , fonc , 0 )
if get_mode ( ctx ) == ' PFB ' :
cursor . setPropertyValue ( ' CharWeight ' , NORMAL )
2010-03-08 12:15:20 +01:00
self . insert_speaker_closing ( ctx , doc , cursor )
2008-07-09 13:16:36 +02:00
2008-07-08 22:17:44 +02:00
2008-07-14 14:55:53 +02:00
class President ( RemoteObject ) :
2010-03-04 10:27:55 +01:00
'''
Class to handle the description of the president
'''
2010-06-21 11:15:34 +02:00
_attrs = ( ' id ' , ' firstname ' , ' name ' , ' title ' , ' classname ' , ' function ' , ' sexe ' )
2009-01-14 12:25:25 +01:00
_download_file = ' President.xml '
2008-07-09 18:28:24 +02:00
_node_name = ' SParlSpeaker '
aspres = 1
def get_long_name ( self ) :
2010-06-21 11:15:34 +02:00
if self . sexe == ' M ' :
2015-04-25 19:08:04 +02:00
return ' M. le Président '
2010-06-21 11:15:34 +02:00
else :
2015-04-25 19:08:04 +02:00
return ' Mme la Présidente '
2008-07-09 18:28:24 +02:00
2009-01-14 12:25:25 +01:00
def get_nodes ( cls , ctx ) :
2010-06-11 13:53:22 +02:00
list_filename = download ( ctx , cls . get_download_url ( ctx ) )
2008-07-09 18:28:24 +02:00
if not list_filename :
2008-07-12 17:52:35 +02:00
raise DownloadError ( )
2008-07-09 18:28:24 +02:00
dom = xml . dom . minidom . parseString ( open ( list_filename ) . read ( ) )
# this document has only one element, and it is not embedded into a
# list
return [ dom . childNodes [ 0 ] ]
2008-07-14 14:55:53 +02:00
get_nodes = classmethod ( get_nodes )
2008-07-09 18:28:24 +02:00
def insert_as_speaker ( self , ctx , doc , cursor ) :
2010-03-04 10:27:55 +01:00
# Add an annotation next to the document, with a reference to minister
# internal id
2009-01-14 17:47:42 +01:00
annotation = doc . createInstance ( ' com.sun.star.text.TextField.Annotation ' )
annotation . setPropertyValue ( ' Author ' , ' ' )
text = ' type: TABELLIO \n ref id: %s \n classname: %s ' % ( self . id , self . classname )
annotation . setPropertyValue ( ' Content ' , text )
doc . Text . insertTextContent ( cursor , annotation , False )
2008-07-09 18:28:24 +02:00
cursor . setPropertyValue ( ' CharWeight ' , BOLD )
2015-04-25 19:08:04 +02:00
doc . Text . insertString ( cursor , self . get_long_name ( ) . replace ( ' ' , ' ' ) , 0 )
2010-03-08 12:15:20 +01:00
self . insert_speaker_closing ( ctx , doc , cursor )
2008-07-09 18:28:24 +02:00
cursor . setPropertyValue ( ' CharWeight ' , NORMAL )
2008-07-14 14:55:53 +02:00
class PresCom ( RemoteObject ) :
2010-03-04 10:27:55 +01:00
'''
Class to handle a president of commission
'''
2011-05-06 15:09:05 +02:00
_attrs = ( ' id ' , ' firstname ' , ' name ' , ' title ' , ' classname ' , ' com_code ' , ' sexe ' , ' function ' )
2009-01-14 12:25:25 +01:00
_download_file = ' PresComs.xml '
2008-07-09 18:28:24 +02:00
_node_name = ' SPresComSpeaker '
2011-05-06 15:09:05 +02:00
classname = ' PresCom '
2008-07-09 18:28:24 +02:00
def get_name ( self ) :
2015-04-25 19:08:04 +02:00
return ' %s %s ( %s ) ' % ( self . name , self . firstname , self . com_code )
2008-07-09 18:28:24 +02:00
2010-06-21 11:19:43 +02:00
def get_long_name ( self , ctx ) :
if get_mode ( ctx ) == ' PCF ' :
if self . sexe == ' M ' :
2015-04-25 19:08:04 +02:00
function = ' le président '
2010-06-21 11:19:43 +02:00
else :
2015-04-25 19:08:04 +02:00
function = ' la présidente '
return ' %s %s ' % ( self . title , function )
2010-03-26 09:44:46 +01:00
else :
2011-05-06 15:09:05 +02:00
if self . function :
2015-04-25 19:08:04 +02:00
return ' %s %s %s , %s ' % ( self . title , self . firstname , self . name , self . function )
2010-06-21 11:19:43 +02:00
if self . sexe == ' M ' :
2015-04-25 19:08:04 +02:00
function = ' président '
2010-06-21 11:19:43 +02:00
else :
2015-04-25 19:08:04 +02:00
function = ' présidente '
return ' %s %s %s , %s ' % ( self . title , self . firstname , self . name , function )
2008-07-09 18:28:24 +02:00
def insert_as_speaker ( self , ctx , doc , cursor ) :
2010-03-04 10:27:55 +01:00
# Add an annotation next to the document, with a reference to minister
# internal id
2009-01-14 17:47:42 +01:00
annotation = doc . createInstance ( ' com.sun.star.text.TextField.Annotation ' )
annotation . setPropertyValue ( ' Author ' , ' ' )
text = ' type: TABELLIO \n ref id: %s \n classname: %s ' % ( self . id , self . classname )
annotation . setPropertyValue ( ' Content ' , text )
doc . Text . insertTextContent ( cursor , annotation , False )
2008-07-09 18:28:24 +02:00
cursor . setPropertyValue ( ' CharWeight ' , BOLD )
2015-04-25 19:08:04 +02:00
doc . Text . insertString ( cursor , self . get_long_name ( ctx ) . replace ( ' ' , ' ' ) , 0 )
2010-03-08 12:15:20 +01:00
self . insert_speaker_closing ( ctx , doc , cursor )
2008-07-09 18:28:24 +02:00
cursor . setPropertyValue ( ' CharWeight ' , NORMAL )
2010-06-21 11:27:42 +02:00
class GenericPresCom ( PresCom ) :
'''
Class to handle a random president of commission
'''
sex = None
id = ' XXX '
classname = ' GenericPresCom '
def __init__ ( self , sex ) :
self . sex = sex
def get_name ( self ) :
if self . sex == ' M ' :
2015-04-25 19:08:04 +02:00
return ' M. le Président '
2010-06-21 11:27:42 +02:00
else :
2015-04-25 19:08:04 +02:00
return ' Mme la Présidente '
2010-06-21 11:27:42 +02:00
def get_long_name ( self , ctx ) :
return self . get_name ( )
def insert_as_speaker ( self , ctx , doc , cursor ) :
annotation = doc . createInstance ( ' com.sun.star.text.TextField.Annotation ' )
annotation . setPropertyValue ( ' Author ' , ' ' )
text = ' type: TABELLIO \n ref id: %s \n classname: %s ' % ( self . id , self . classname )
annotation . setPropertyValue ( ' Content ' , text )
doc . Text . insertTextContent ( cursor , annotation , False )
cursor . setPropertyValue ( ' CharWeight ' , BOLD )
2015-04-25 19:08:04 +02:00
doc . Text . insertString ( cursor , self . get_long_name ( ctx ) . replace ( ' ' , ' ' ) , 0 )
2010-06-21 11:27:42 +02:00
self . insert_speaker_closing ( ctx , doc , cursor )
cursor . setPropertyValue ( ' CharWeight ' , NORMAL )
2008-07-14 14:55:53 +02:00
class Commission ( RemoteObject ) :
2010-03-04 10:27:55 +01:00
'''
Class to handle a commission
'''
2008-07-14 14:55:53 +02:00
_attrs = ( ' id ' , ' nom ' , ' code ' , ' classname ' )
2009-01-14 12:25:25 +01:00
_download_file = ' Commissions.xml '
2008-07-14 14:55:53 +02:00
_node_name = ' MCOMSInfo '
def get_name ( self ) :
if len ( self . nom ) > 60 :
2015-04-25 19:08:04 +02:00
return self . nom [ : self . nom [ : 65 ] . rindex ( ' ' ) ] + ' ... ( %s ) ' % self . code
2008-07-14 14:55:53 +02:00
return self . nom
def get_long_name ( self ) :
return self . nom
2009-10-07 11:02:30 +02:00
def insert ( self , ctx , cursor ) :
cursor . Text . insertString ( cursor , self . get_long_name ( ) , 0 )
2008-07-09 18:28:24 +02:00
2008-07-08 22:17:44 +02:00
2010-06-21 11:27:42 +02:00
def get_min_pres_menu_items ( ctx ) :
values = Minister . values ( ctx ) + President . values ( ctx ) + PresCom . values ( ctx )
values . append ( GenericPresCom ( ' M ' ) )
values . append ( GenericPresCom ( ' F ' ) )
return values
2009-03-12 14:13:48 +01:00
class SnippetDoc ( RemoteObject ) :
2010-03-04 10:27:55 +01:00
'''
Class to handle a snippet document
'''
2009-03-12 14:13:48 +01:00
_download_file = ' Docs.xml '
_node_name = ' document '
def __init__ ( self , node ) :
2011-06-03 11:32:12 +02:00
self . title = get_text_node_content ( node )
2009-03-12 14:13:48 +01:00
self . filename = node . getAttribute ( ' filename ' )
2007-11-27 21:53:00 +01:00
class CloseListener ( unohelper . Base , XActionListener ) :
2010-03-04 10:27:55 +01:00
'''
Listener to close the dialogs
'''
2007-11-27 21:53:00 +01:00
def __init__ ( self , dialog ) :
self . dialog = dialog
2008-02-18 15:15:58 +01:00
2007-11-27 21:53:00 +01:00
def actionPerformed ( self , actionEvent ) :
self . dialog . endExecute ( )
2008-07-14 16:08:00 +02:00
class InsertSpeakerDlgListener ( unohelper . Base , XActionListener ) :
2010-03-04 10:27:55 +01:00
'''
Listener for the insert speaker dialog box
'''
2008-07-09 13:23:55 +02:00
def __init__ ( self , ctx , doc , combobox , dialog , values ) :
self . ctx = ctx
2007-11-14 21:30:36 +01:00
self . combobox = combobox
self . dialog = dialog
self . doc = doc
2008-07-09 13:23:55 +02:00
self . values = values
2009-01-14 12:25:25 +01:00
RemoteObject . ctx = ctx
2010-03-04 10:27:55 +01:00
2007-11-14 21:30:36 +01:00
def actionPerformed ( self , actionEvent ) :
try :
cursor = self . doc . getCurrentController ( ) . getViewCursor ( )
2008-07-14 16:08:00 +02:00
string = self . combobox . Text
t = [ x for x in self . values if x . get_name ( ) == string ]
if not t :
raise Exception ( ' Unknown ' )
t [ 0 ] . insert_as_speaker ( self . ctx , self . doc , cursor )
2007-11-14 21:30:36 +01:00
self . dialog . endExecute ( )
2008-03-02 15:31:41 +01:00
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2007-11-14 21:30:36 +01:00
2010-03-04 10:27:55 +01:00
2007-11-14 21:30:36 +01:00
def MessageBox ( ParentWin , MsgText , MsgTitle , MsgType = " messbox " , MsgButtons = OK ) :
2010-03-04 10:27:55 +01:00
''' Show a message box with the UNO based toolkit '''
2007-11-14 21:30:36 +01:00
MsgType = MsgType . lower ( )
2010-03-04 10:27:55 +01:00
2007-11-14 21:30:36 +01:00
#available msg types
MsgTypes = ( " messbox " , " infobox " , " errorbox " , " warningbox " , " querybox " )
2010-03-04 10:27:55 +01:00
2007-11-14 21:30:36 +01:00
if not ( MsgType in MsgTypes ) :
MsgType = " messbox "
2010-03-04 10:27:55 +01:00
2007-11-14 21:30:36 +01:00
#describe window properties.
aDescriptor = WindowDescriptor ( )
aDescriptor . Type = MODALTOP
aDescriptor . WindowServiceName = MsgType
aDescriptor . ParentIndex = - 1
aDescriptor . Parent = ParentWin
aDescriptor . WindowAttributes = MsgButtons
2010-03-04 10:27:55 +01:00
2007-11-14 21:30:36 +01:00
tk = ParentWin . getToolkit ( )
msgbox = tk . createWindow ( aDescriptor )
2010-03-04 10:27:55 +01:00
2015-04-25 19:08:04 +02:00
msgbox . MessageText = MsgText
2007-11-14 21:30:36 +01:00
if MsgTitle :
2015-04-25 19:08:04 +02:00
msgbox . CaptionText = MsgTitle
2010-03-04 10:27:55 +01:00
2007-11-14 21:30:36 +01:00
return msgbox . execute ( )
class StyleApply ( unohelper . Base , XJobExecutor ) :
2010-03-04 10:27:55 +01:00
'''
Job to apply a style to the current paragraph ; it is used in styles and
legistic styles toolbars .
'''
2007-11-14 21:30:36 +01:00
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 ( )
cursor = doc . getCurrentController ( ) . getViewCursor ( )
try :
2013-10-06 12:09:55 +02:00
text = doc . Text
textcursor = text . createTextCursorByRange ( cursor . getStart ( ) )
numberingrules = textcursor . getPropertyValue ( ' NumberingRules ' )
if numberingrules :
textcursor . setPropertyValue ( ' NumberingRules ' , None )
2007-11-14 21:30:36 +01:00
cursor . setPropertyValue ( ' ParaStyleName ' , style_name )
2013-06-12 15:39:26 +02:00
if style_name == ' TitreSynthese ' :
2015-04-25 19:08:04 +02:00
cursor . Text . insertString ( cursor , ' Résumé ' , 0 )
2012-10-25 14:54:45 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
cursor . setPropertyValue ( ' ParaStyleName ' , ' Text body ' )
2013-10-27 11:35:06 +01:00
dispatchHelper = self . ctx . ServiceManager . createInstanceWithContext (
' com.sun.star.frame.DispatchHelper ' , self . ctx )
cursor = text . createTextCursor ( )
view_cursor = doc . getCurrentController ( ) . getViewCursor ( )
cursor . gotoRange ( view_cursor , False )
frame = doc . getCurrentController ( ) . getFrame ( )
dispatchHelper . executeDispatch ( frame , ' .uno:GoToStartOfLine ' , ' ' , 0 , ( ) )
dispatchHelper . executeDispatch ( frame , ' .uno:EndOfParaSel ' , ' ' , 0 , ( ) )
dispatchHelper . executeDispatch ( frame , ' .uno:ResetAttributes ' , ' ' , 0 , ( ) )
view_cursor . gotoRange ( cursor , False )
2008-03-02 15:31:41 +01:00
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2007-11-14 21:30:36 +01:00
2008-07-14 14:03:23 +02:00
class ListStyleApply ( unohelper . Base , XJobExecutor ) :
2010-03-04 10:27:55 +01:00
'''
Job to apply a list style .
'''
2008-07-14 14:03:23 +02:00
def __init__ ( self , ctx ) :
self . ctx = ctx
def trigger ( self , args ) :
2010-03-04 10:27:55 +01:00
'''
Style current paragraph as list , argument should be one of ARABIC ,
CHARS_UPPER_LETTER , CHARS_LOWER_LETTER , ROMAN_UPPER , ROMAN_LOWER ,
or DASH .
'''
2013-10-06 11:58:47 +02:00
log = [ ]
2008-07-14 14:03:23 +02:00
try :
2009-10-07 16:18:27 +02:00
style = args
2008-07-14 14:03:23 +02:00
desktop = self . ctx . ServiceManager . createInstanceWithContext (
' com.sun.star.frame.Desktop ' , self . ctx )
doc = desktop . getCurrentComponent ( )
text = doc . Text
cursor = doc . getCurrentController ( ) . getViewCursor ( )
2010-02-24 14:02:44 +01:00
# look at the previous paragraph, if it's already a list item, then
# it's better not to create a new list, but adding to the existing
# list; this makes it possible to repeatedly click on the "listize"
# toolbar button over consecuting paragraphs
previouspara_textcursor = text . createTextCursorByRange ( cursor . getStart ( ) )
previouspara_textcursor . gotoPreviousParagraph ( False )
numberingrules = None
if previouspara_textcursor . ParaStyleName == ' Text body ' :
level = previouspara_textcursor . getPropertyValue ( ' NumberingLevel ' )
numberingrules = previouspara_textcursor . getPropertyValue ( ' NumberingRules ' )
if numberingrules :
props = numberingrules . getByIndex ( level )
2011-06-03 13:48:11 +02:00
for prop in props :
if prop . Name == ' NumberingType ' and (
( prop . Value == 0 and style == ' CHARS_UPPER_LETTER ' ) or
( prop . Value == 1 and style == ' CHARS_LOWER_LETTER ' ) or
( prop . Value == 2 and style == ' ROMAN_UPPER ' ) or
( prop . Value == 3 and style == ' ROMAN_LOWER ' ) or
( prop . Value == 4 and style == ' ARABIC ' ) ) :
# found a similar numbering rule in the
# previous paragraph, keep on using it
break
2010-02-24 14:02:44 +01:00
else :
numberingrules = None
2010-03-04 10:27:55 +01:00
# Back to current paragraph
2009-10-07 16:18:27 +02:00
textcursor = text . createTextCursorByRange ( cursor . getStart ( ) )
level = textcursor . getPropertyValue ( ' NumberingLevel ' )
if numberingrules is None :
2010-02-24 14:02:44 +01:00
numberingrules = textcursor . getPropertyValue ( ' NumberingRules ' )
if numberingrules is None :
2014-10-22 13:53:52 +02:00
log . append ( ' using new numbering rules array ' )
2010-02-24 14:02:44 +01:00
numberingrules = doc . createInstance ( ' com.sun.star.text.NumberingRules ' )
2014-10-22 13:53:52 +02:00
else :
log . append ( ' using numbering rules of current paragraph ' )
else :
log . append ( ' using numbering rules of previous paragraph ' )
2009-10-07 16:18:27 +02:00
props = numberingrules . getByIndex ( level )
2013-10-06 11:58:47 +02:00
found_bullet_char_prop = False
found_bullet_fontname_prop = False
2014-10-22 13:43:41 +02:00
log . append ( ' style level %s as %s ' % ( level , style ) )
2009-10-07 16:18:27 +02:00
for i , prop in enumerate ( props ) :
2014-10-22 16:39:43 +02:00
log . append ( ' initial prop: %s : %r ' % ( prop . Name , prop . Value ) )
2009-10-07 16:18:27 +02:00
if prop . Name == ' CharStyleName ' :
2010-03-08 11:13:28 +01:00
if style in ( ' DASH ' , ' BULLET ' ) :
2009-10-07 16:18:27 +02:00
prop . Value = ' Bullet Symbols '
else :
prop . Value = ' Numbering Symbols '
2014-10-22 13:43:41 +02:00
log . append ( ' -> changed to %r ' % prop . Value )
2014-10-22 16:39:43 +02:00
elif prop . Name == ' BulletChar ' and style in ( ' DASH ' , ' BULLET ' ) :
2013-10-06 11:58:47 +02:00
found_bullet_char_prop = True
2010-03-08 11:13:28 +01:00
if style == ' DASH ' :
prop . Value = ' - '
else :
prop . Value = ' ◦ '
2014-10-22 13:43:41 +02:00
log . append ( ' -> changed to %r ' % prop . Value )
2009-10-07 16:18:27 +02:00
elif prop . Name == ' NumberingType ' :
if style == ' CHARS_UPPER_LETTER ' :
prop . Value = 0
elif style == ' CHARS_LOWER_LETTER ' :
prop . Value = 1
elif style == ' ROMAN_UPPER ' :
prop . Value = 2
elif style == ' ROMAN_LOWER ' :
prop . Value = 3
elif style == ' ARABIC ' :
prop . Value = 4
else :
prop . Value = 6
2014-10-22 13:43:41 +02:00
log . append ( ' -> changed to %r ' % prop . Value )
2013-10-06 11:58:47 +02:00
elif prop . Name == ' BulletFontName ' :
if style in ( ' DASH ' , ' BULLET ' ) :
prop . Value = ' '
2014-10-22 13:43:41 +02:00
log . append ( ' -> changed to %r ' % prop . Value )
2009-10-07 16:18:27 +02:00
2013-10-06 11:58:47 +02:00
if style in ( ' DASH ' , ' BULLET ' ) :
2009-10-07 16:18:27 +02:00
props = list ( props )
2013-10-06 11:58:47 +02:00
if not found_bullet_char_prop :
if style == ' DASH ' :
props . append ( makePropertyValue ( ' BulletChar ' , ' - ' ) )
else :
props . append ( makePropertyValue ( ' BulletChar ' , ' ◦ ' ) )
2014-10-22 13:43:41 +02:00
log . append ( ' -> add BulletChar as %r ' % props [ - 1 ] . Value )
2013-10-06 11:58:47 +02:00
if not found_bullet_fontname_prop :
2014-10-22 13:43:41 +02:00
log . append ( ' -> add BulletFontName ' )
2013-10-06 11:58:47 +02:00
props . append ( makePropertyValue ( ' BulletFontName ' , ' ' ) )
2009-10-07 16:18:27 +02:00
props = tuple ( props )
uno . invoke ( numberingrules , ' replaceByIndex ' ,
2014-10-22 13:54:16 +02:00
( level , uno . Any ( " []com.sun.star.beans.PropertyValue " , props ) ) )
2009-10-07 16:18:27 +02:00
textcursor . setPropertyValue ( ' NumberingRules ' , numberingrules )
2015-04-25 19:08:04 +02:00
except Exception as e :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2008-07-14 14:03:23 +02:00
2014-10-22 13:43:41 +02:00
log . append ( ' \n Exception data: ' )
log . append ( ' %s ' % type ( e ) )
log . append ( ' %r ' % e . __dict__ )
2013-10-06 11:58:47 +02:00
desktop = self . ctx . ServiceManager . createInstanceWithContext (
' com.sun.star.frame.Desktop ' , self . ctx )
doc = desktop . getCurrentComponent ( )
parentwin = doc . CurrentController . Frame . ContainerWindow
MessageBox ( parentwin , ' \n ' . join ( log ) , ' Debug ' )
2008-07-14 14:03:23 +02:00
2007-11-29 12:26:27 +01:00
class StructureError :
2010-03-04 10:27:55 +01:00
'''
Class describing an error in the structure of the document
'''
2007-11-29 12:26:27 +01:00
type = None
paragraph_index = 0
page_no = None
para_style = None
def __init__ ( self , type , * args ) :
self . type = type
if type == ' skipped some level ' :
self . lastStyle = args [ 0 ] . replace ( ' Heading ' , ' Titre ' )
self . currentStyle = args [ 1 ] . replace ( ' Heading ' , ' Titre ' )
def get_short ( self ) :
2011-06-03 10:57:09 +02:00
''' Get a short summary of the error '''
2007-11-29 12:26:27 +01:00
if self . type == ' same level without content ' :
2015-04-25 19:08:04 +02:00
return ' Deux titres consécutifs sans contenu intermédiaire '
2007-11-29 12:26:27 +01:00
if self . type == ' skipped some level ' :
2015-04-25 19:08:04 +02:00
return ' Saut de titre (niveau %s à %s ) ' % ( self . lastStyle , self . currentStyle )
2007-11-29 12:26:27 +01:00
if self . type == ' went below top level ' :
2015-04-25 19:08:04 +02:00
return ' Niveau mal placé (trop bas) '
2007-11-29 12:26:27 +01:00
if self . type == ' started legistic section too low ' :
2015-04-25 19:08:04 +02:00
return ' Les parties légistiques doivent démarrer à un niveau supérieur '
2007-12-03 17:18:44 +01:00
if self . type == ' preface in wrong place ' :
2015-04-25 19:08:04 +02:00
return ' La préface est placée à un mauvais endroit '
2013-12-16 10:05:06 +01:00
if self . type == ' two prefaces ' :
2015-04-25 19:08:04 +02:00
return ' Le document contient deux préfaces '
2010-02-24 10:58:28 +01:00
if self . type == ' word-copy-paste-horizontal-line ' :
2015-04-25 19:08:04 +02:00
return ' Ligne horizontale, vraisemblablement copié/collé '
2013-12-02 15:29:14 +01:00
if self . type == ' paragraph-filled-with-nothing-but-spaces ' :
2015-04-25 19:08:04 +02:00
return ' Paragraphe composé uniquement d \' espaces '
2007-11-29 12:26:27 +01:00
def get_long ( self ) :
2011-06-03 10:57:09 +02:00
''' Get a longer description of the error '''
2007-11-29 12:26:27 +01:00
if self . type == ' same level without content ' :
2015-04-25 19:08:04 +02:00
return ''' Deux titres de même niveau se suivent et il n ' y a aucun contenu entre les deux '''
2007-11-29 12:26:27 +01:00
if self . type == ' skipped some level ' :
2015-04-25 19:08:04 +02:00
return ''' Hiérarchie du document non respectée. Passage sans intermédiaire du niveau %s au niveau %s . ''' % ( self . lastStyle , self . currentStyle )
2007-11-29 12:26:27 +01:00
if self . type == ' went below top level ' :
2015-04-25 19:08:04 +02:00
return ' Niveau mal placé (trop bas) '
2007-11-29 12:26:27 +01:00
if self . type == ' started legistic section too low ' :
2015-04-25 19:08:04 +02:00
return ''' Erreur de hiérarchie légistique. Une partie légistique ne peut démarrer au niveau section ou sous-section. Les choix possibles sont Partie, Livre, Titre ou chapitre. '''
2007-12-03 17:18:44 +01:00
if self . type == ' preface in wrong place ' :
2015-04-25 19:08:04 +02:00
return ''' La préface doit se trouver à la base du document ou au niveau " Partie " . '''
2013-12-16 10:05:06 +01:00
if self . type == ' two prefaces ' :
2015-04-25 19:08:04 +02:00
return ' Une seule préface est autorisée dans le document. '
2010-02-24 10:58:28 +01:00
if self . type == ' word-copy-paste-horizontal-line ' :
2015-04-25 19:08:04 +02:00
return ''' Une ligne horizontale provient généralement d ' un ''' \
''' copié/collé depuis Microsoft Word d ' un texte ''' \
''' contenant une note de bas de page. '''
2013-12-02 15:29:14 +01:00
if self . type == ' paragraph-filled-with-nothing-but-spaces ' :
2015-04-25 19:08:04 +02:00
return ' Paragraphe composé uniquement d \' espaces '
2007-11-29 12:26:27 +01:00
2007-11-27 19:19:19 +01:00
class StructureCheckListListener ( unohelper . Base , XItemListener ) :
2010-03-04 10:27:55 +01:00
'''
Listener for the structure check dialog
'''
2007-11-27 19:19:19 +01:00
def __init__ ( self , dialog , doc , errors ) :
self . dialog = dialog
self . doc = doc
self . errors = errors
def itemStateChanged ( self , event ) :
try :
label = self . dialog . getControl ( ' detail ' )
error = self . errors [ event . Selected ]
2007-11-29 12:26:27 +01:00
label . setText ( error . get_long ( ) )
2007-11-27 19:19:19 +01:00
text = self . doc . Text
cursor = text . createTextCursor ( )
cursor . gotoStart ( False )
2007-11-29 12:26:27 +01:00
for i in range ( error . paragraph_index ) :
2007-11-27 19:19:19 +01:00
cursor . gotoNextParagraph ( False )
view_cursor = self . doc . getCurrentController ( ) . getViewCursor ( )
view_cursor . gotoRange ( cursor , False )
2008-03-02 15:31:41 +01:00
except :
2011-06-03 11:32:12 +02:00
display_exception ( )
2007-11-27 19:19:19 +01:00
2008-02-18 11:46:01 +01:00
class StructureCheckDialog ( unohelper . Base , XActionListener ) :
2010-03-04 10:27:55 +01:00
'''
Dialog to display the result ot a structure check
'''
2015-04-25 19:08:04 +02:00
def __init__ ( self , ctx , doc , errors , continue_action = None , continue_label = ' Continuer ' ) :
2008-02-18 11:46:01 +01:00
self . ctx = ctx
self . continue_action = continue_action
self . continue_label = continue_label
self . doc = doc
self . errors = errors
def show ( self ) :
smgr = self . ctx . ServiceManager
2008-02-18 15:15:58 +01:00
# create the dialog model and set the properties
dialogModel = smgr . createInstanceWithContext (
2008-02-18 11:46:01 +01:00
' com.sun.star.awt.UnoControlDialogModel ' , self . ctx )
dialogModel . PositionX = 100
dialogModel . PositionY = 200
dialogModel . Width = 210
dialogModel . Height = 130
2015-04-25 19:08:04 +02:00
dialogModel . Title = ' Analyse du document '
2008-02-18 11:46:01 +01:00
2008-02-18 15:38:36 +01:00
listModel = addWidget ( dialogModel , ' errorList ' , ' ListBox ' , 5 , 5 , 200 , 70 )
2008-02-18 11:46:01 +01:00
listErrors = [ ]
for i , error in enumerate ( self . errors ) :
2010-02-24 10:58:28 +01:00
if error . type == ' word-copy-paste-horizontal-line ' :
2015-04-25 19:08:04 +02:00
listErrors . append ( ' Page %s : %s ' % ( error . page_no , error . get_short ( ) ) )
2010-02-24 10:58:28 +01:00
else :
2015-04-25 19:08:04 +02:00
listErrors . append ( ' Page %s : %s : %s ' % ( error . page_no ,
2008-02-18 11:46:01 +01:00
error . para_style . replace ( ' Heading ' , ' Titre ' ) , error . get_short ( ) ) )
listModel . StringItemList = tuple ( listErrors )
2008-02-18 15:38:36 +01:00
text = addWidget ( dialogModel , ' detail ' , ' FixedText ' , 5 , 80 , 200 , 22 )
2008-02-18 11:46:01 +01:00
text . MultiLine = True
2015-04-25 19:08:04 +02:00
text . Label = ' '
2008-02-18 11:46:01 +01:00
if self . continue_action :
# continue button
2008-02-18 15:38:36 +01:00
button = addWidget ( dialogModel , ' continueButton ' , ' Button ' , 155 , 110 , 50 , 14 )
button . TabIndex = 0
2015-04-25 19:08:04 +02:00
button . Label = ' Continuer '
2008-02-18 11:46:01 +01:00
2008-02-18 15:38:36 +01:00
button = addWidget ( dialogModel , ' closeButton ' , ' Button ' , 95 , 110 , 50 , 14 )
button . TabIndex = 1
2015-04-25 19:08:04 +02:00
button . Label = ' Annuler '
2008-02-18 15:38:36 +01:00
else :
button = addWidget ( dialogModel , ' closeButton ' , ' Button ' , 155 , 110 , 50 , 14 )
button . TabIndex = 0
2015-04-25 19:08:04 +02:00
button . Label = ' Fermer '
2008-02-18 11:46:01 +01:00
2008-02-18 15:15:58 +01:00
# create the dialog control and set the model
controlContainer = smgr . createInstanceWithContext (
2008-02-18 11:46:01 +01:00
' com.sun.star.awt.UnoControlDialog ' , self . ctx )
controlContainer . setModel ( dialogModel )
if self . continue_action :
controlContainer . getControl ( ' continueButton ' ) . setActionCommand ( ' continue ' )
controlContainer . getControl ( ' continueButton ' ) . addActionListener ( self )
controlContainer . getControl ( ' closeButton ' ) . addActionListener ( self )
controlContainer . getControl ( ' errorList ' ) . addItemListener (
StructureCheckListListener ( controlContainer , self . doc , self . errors ) )
self . dialog = controlContainer
2008-02-18 15:15:58 +01:00
# create a peer
2008-02-18 11:46:01 +01:00
toolkit = smgr . createInstanceWithContext (
' com.sun.star.awt.ExtToolkit ' , self . ctx )
controlContainer . setVisible ( False )
controlContainer . createPeer ( toolkit , None )
controlContainer . setVisible ( True )
def actionPerformed ( self , actionEvent ) :
self . dialog . setVisible ( False )
self . dialog . dispose ( )
if actionEvent . ActionCommand == ' continue ' :
self . continue_action ( self . doc )
2008-02-18 11:14:57 +01:00
def check_structure ( doc ) :
''' Check structure of the document, returns a list of errors '''
errors = [ ]
text = doc . Text
view_cursor = doc . getCurrentController ( ) . getViewCursor ( )
cursor = text . createTextCursor ( )
cursor . gotoStart ( False )
lastStyle = None
lastLegisticStyle = None
seenContent = False
seenLegiContent = False
topLevel = 0
topLegisticLevel = 0
2008-02-18 17:41:32 +01:00
styles = [ ' Partie ' , ' Chap ' , ' Sec 1 ' , ' Sec 1.1 ' , ' Sec 1.1.1 ' , ' Sec 1.1.1.1 ' , ' Ss-Titre ' ]
2009-09-16 09:37:01 +02:00
legistic_styles = [ ' Lpart ' , ' LLivre ' , ' Ltitre ' , ' Lchapitre ' , ' Lsection ' , ' Lsoussection ' ]
2008-02-18 11:14:57 +01:00
paragraph_index = 0
2013-12-16 10:05:06 +01:00
seen_preface = False
2008-02-18 11:14:57 +01:00
while True :
error = None
currentStyle = cursor . ParaStyleName
if currentStyle in styles :
if lastStyle :
last_level = styles . index ( lastStyle )
new_level = styles . index ( currentStyle )
if new_level == last_level :
if not seenContent :
2008-11-26 16:48:01 +01:00
debug_print ( ' lastStyle: ' , lastStyle )
debug_print ( ' currentStyle: ' , currentStyle )
2008-07-09 16:35:01 +02:00
# 'same level without content' check has been disabled
# http://bugzilla.entrouvert.org/show_bug.cgi?id=56
#error = StructureError('same level without content')
2008-02-18 11:14:57 +01:00
seenContent = False
elif new_level == last_level + 1 :
# ok
seenContent = False
elif new_level > last_level + 1 :
2009-09-16 09:37:01 +02:00
debug_print ( ' skipped some level ' , lastStyle , currentStyle )
2008-02-18 11:14:57 +01:00
error = StructureError ( ' skipped some level ' , lastStyle , currentStyle )
seenContent = False
elif new_level < topLevel :
error = StructureError ( ' went below top level ' )
seenContent = False
lastStyle = currentStyle
lastLegisticStyle = None
topLegisticLevel = None
elif currentStyle in legistic_styles :
if lastLegisticStyle :
last_legistic_level = legistic_styles . index ( lastLegisticStyle )
new_legistic_level = legistic_styles . index ( currentStyle )
2008-04-04 11:32:59 +02:00
if new_legistic_level == last_legistic_level :
2008-02-18 11:14:57 +01:00
if not seenLegiContent :
error = StructureError ( ' same level without content ' )
seenLegiContent = False
2008-04-04 11:32:59 +02:00
elif new_legistic_level == last_legistic_level + 1 :
2008-02-18 11:14:57 +01:00
# ok
seenLegiContent = False
2008-04-04 11:32:59 +02:00
elif new_legistic_level > last_legistic_level + 1 :
2009-09-16 09:37:01 +02:00
debug_print ( ' skipped some level ' , lastStyle , currentStyle )
2008-02-18 11:14:57 +01:00
error = StructureError ( ' skipped some level ' , lastStyle , currentStyle )
seenLegiContent = False
2008-04-04 11:32:59 +02:00
elif new_legistic_level < topLegisticLevel :
2008-02-18 11:14:57 +01:00
error = StructureError ( ' went below top level ' )
seenLegiContent = False
else :
# first time in a legistic section
new_legistic_level = legistic_styles . index ( currentStyle )
if new_legistic_level > legistic_styles . index ( ' Lchapitre ' ) :
error = StructureError ( ' started legistic section too low ' )
topLegisticLevel = new_legistic_level
lastLegisticStyle = currentStyle
elif currentStyle == ' TitrePreface ' :
# preface can only happen <book> or <part>
if lastStyle :
last_level = styles . index ( lastStyle )
if last_level > 0 :
error = StructureError ( ' preface in wrong place ' )
2013-12-16 10:05:06 +01:00
if seen_preface :
error = StructureError ( ' two prefaces ' )
seen_preface = True
2010-02-24 10:58:28 +01:00
if currentStyle == ' Horizontal Line ' :
# this is added when copy/pasting footnotes from Microsoft Word
error = StructureError ( ' word-copy-paste-horizontal-line ' )
2008-02-18 11:14:57 +01:00
else :
if currentStyle not in ( ' Standard ' , ' Larttitre ' ) :
2008-11-26 16:48:01 +01:00
debug_print ( ' unknown style: ' , currentStyle )
2008-02-18 11:14:57 +01:00
seenContent = True
seenLegiContent = True
2013-12-02 15:29:14 +01:00
cursor . gotoEndOfParagraph ( True )
2015-04-25 19:08:04 +02:00
s = cursor . String . replace ( ' ' , ' ' ) . replace ( ' \t ' , ' ' ) . replace ( ' \xa0 ' , ' ' )
2013-12-02 15:29:14 +01:00
if cursor . String and s == ' ' : # paragraph filled with nothing but spaces
2013-12-29 23:05:11 +01:00
#error = StructureError('paragraph-filled-with-nothing-but-spaces')
# do not mark this as an error, they will be ignored automatically
# by odf2legi
pass
2013-12-02 15:29:14 +01:00
2008-02-18 11:14:57 +01:00
if error :
view_cursor . gotoRange ( cursor , False )
error . paragraph_index = paragraph_index
error . page_no = view_cursor . getPage ( )
error . para_style = cursor . ParaStyleName
errors . append ( error )
paragraph_index + = 1
if not cursor . gotoNextParagraph ( False ) :
break
2010-03-04 10:27:55 +01:00
2008-02-18 11:14:57 +01:00
return errors
2008-02-18 11:16:31 +01:00
class StructureCheck ( unohelper . Base , XJobExecutor ) :
2010-03-04 10:27:55 +01:00
'''
Job to perform a structure check
'''
2007-11-14 21:30:36 +01:00
def __init__ ( self , ctx ) :
self . ctx = ctx
def trigger ( self , args ) :
try :
desktop = self . ctx . ServiceManager . createInstanceWithContext (
" com.sun.star.frame.Desktop " , self . ctx )
2007-11-27 19:19:19 +01:00
self . doc = desktop . getCurrentComponent ( )
2008-02-18 11:14:57 +01:00
self . errors = check_structure ( self . doc )
2007-11-14 21:30:36 +01:00
if self . errors :
2008-02-18 11:14:57 +01:00
text = self . doc . Text
cursor = text . createTextCursor ( )
view_cursor = self . doc . getCurrentController ( ) . getViewCursor ( )
2007-11-29 12:26:27 +01:00
cursor . gotoStart ( False )
for i in range ( self . errors [ 0 ] . paragraph_index ) :
cursor . gotoNextParagraph ( False )
view_cursor . gotoRange ( cursor , False )
2008-02-18 11:46:01 +01:00
dialog = StructureCheckDialog ( self . ctx , self . doc , self . errors )
dialog . show ( )
2007-12-03 17:18:44 +01:00
else :
parentwin = self . doc . CurrentController . Frame . ContainerWindow
2008-02-18 15:15:58 +01:00
return MessageBox ( parentwin ,
2015-04-25 19:08:04 +02:00
' Vérification de la structure terminée ' ,
2007-12-03 17:18:44 +01:00
' Tabellio ' , ' infobox ' )
2008-03-02 15:31:41 +01:00
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2007-11-14 21:30:36 +01:00
2008-07-14 16:08:00 +02:00
class SpeakerDialog ( unohelper . Base , XJobExecutor ) :
2010-03-04 10:27:55 +01:00
'''
Job to display an insert speaker dialog
'''
2007-11-14 21:30:36 +01:00
def __init__ ( self , ctx ) :
self . ctx = ctx
def trigger ( self , args ) :
2010-03-04 10:27:55 +01:00
'''
Arg should be one of deputes , ministres , new , commissions
'''
2007-11-14 21:30:36 +01:00
ctx = self . ctx
desktop = self . ctx . ServiceManager . createInstanceWithContext (
2008-07-14 16:08:00 +02:00
' com.sun.star.frame.Desktop ' , self . ctx )
2007-11-14 21:30:36 +01:00
doc = desktop . getCurrentComponent ( )
2007-11-26 12:13:56 +01:00
if not args in ( ' deputes ' , ' ministres ' , ' new ' , ' commissions ' ) :
2007-11-14 21:30:36 +01:00
parentwin = doc . CurrentController . Frame . ContainerWindow
return MessageBox ( parentwin , ' Liste inconnue ' , ' Alerte ' , " infobox " )
try :
2008-07-14 16:08:00 +02:00
if args not in ( ' deputes ' , ' ministres ' ) :
parentwin = doc . CurrentController . Frame . ContainerWindow
return MessageBox ( parentwin , ' Liste inconnue ' , ' Alerte ' , " infobox " )
2007-11-14 21:30:36 +01:00
smgr = ctx . ServiceManager
2008-02-18 15:15:58 +01:00
# create the dialog model and set the properties
dialogModel = smgr . createInstanceWithContext (
2008-07-14 16:08:00 +02:00
' com.sun.star.awt.UnoControlDialogModel ' , ctx )
2007-11-14 21:30:36 +01:00
dialogModel . PositionX = 100
dialogModel . PositionY = 200
dialogModel . Width = 155
dialogModel . Height = 50
2008-07-14 16:08:00 +02:00
2007-11-14 21:30:36 +01:00
if args == ' ministres ' :
2015-04-25 19:08:04 +02:00
dialogModel . Title = " Insertion Ministres et Présidents "
2007-11-14 21:30:36 +01:00
elif args == ' deputes ' :
2015-04-25 19:08:04 +02:00
dialogModel . Title = " Insertion Députés "
2007-11-14 21:30:36 +01:00
2008-02-18 15:15:58 +01:00
# create the button model and set the properties
2008-02-18 15:38:36 +01:00
button = addWidget ( dialogModel , ' insertButton ' , ' Button ' , 50 , 30 , 50 , 14 )
button . TabIndex = 0
2015-04-25 19:08:04 +02:00
button . Label = " Insérer "
2008-02-18 15:38:36 +01:00
text = addWidget ( dialogModel , ' label0 ' , ' FixedText ' , 10 , 10 , 100 , 14 )
2015-04-25 19:08:04 +02:00
text . Label = ' Orateur : '
2007-11-14 21:30:36 +01:00
2008-07-14 16:08:00 +02:00
combobox = addWidget ( dialogModel , ' insertWidget ' , ' ComboBox ' , 50 , 7 , 100 , 14 )
combobox . Dropdown = True
2007-11-26 12:13:56 +01:00
2008-07-14 16:08:00 +02:00
if args == ' deputes ' :
2009-01-14 12:25:25 +01:00
values = Deputy . values ( ctx )
2008-07-14 16:08:00 +02:00
elif args == ' ministres ' :
2010-06-21 11:27:42 +02:00
values = get_min_pres_menu_items ( ctx )
2008-07-14 16:08:00 +02:00
combobox . StringItemList = tuple ( [ x . get_name ( ) for x in values ] )
2007-11-14 21:30:36 +01:00
2008-02-18 15:15:58 +01:00
# create the dialog control and set the model
controlContainer = smgr . createInstanceWithContext (
2008-07-14 16:08:00 +02:00
' com.sun.star.awt.UnoControlDialog ' , ctx )
2008-02-18 11:14:57 +01:00
controlContainer . setModel ( dialogModel )
2007-11-14 21:30:36 +01:00
# add the action listener
2008-02-18 15:38:36 +01:00
controlContainer . getControl ( ' insertButton ' ) . addActionListener (
2008-07-14 16:08:00 +02:00
InsertSpeakerDlgListener ( self . ctx , doc , combobox , controlContainer , values ) )
2007-11-14 21:30:36 +01:00
2008-07-14 16:08:00 +02:00
toolkit = smgr . createInstanceWithContext ( ' com.sun.star.awt.ExtToolkit ' , ctx )
2008-02-18 11:14:57 +01:00
controlContainer . setVisible ( False )
controlContainer . createPeer ( toolkit , None )
2007-11-14 21:30:36 +01:00
controlContainer . execute ( )
controlContainer . dispose ( )
2008-03-02 15:31:41 +01:00
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2007-11-14 21:30:36 +01:00
2008-07-14 15:55:05 +02:00
class InsertManualSpeakerDlgListener ( unohelper . Base , XActionListener ) :
2010-03-04 10:27:55 +01:00
'''
Listener for the manual speaker insert dialog
'''
2008-07-14 15:55:05 +02:00
def __init__ ( self , ctx , doc , entry , dialog ) :
self . ctx = ctx
self . entry = entry
self . doc = doc
self . dialog = dialog
def actionPerformed ( self , actionEvent ) :
try :
cursor = self . doc . getCurrentController ( ) . getViewCursor ( )
string = self . entry . Text
2010-03-26 09:39:13 +01:00
annotation = self . doc . createInstance ( ' com.sun.star.text.TextField.Annotation ' )
annotation . setPropertyValue ( ' Author ' , ' ' )
text = ' type: TABELLIO \n classname: SPEAKER '
annotation . setPropertyValue ( ' Content ' , text )
self . doc . Text . insertTextContent ( cursor , annotation , False )
2008-07-14 15:55:05 +02:00
cursor . setPropertyValue ( ' CharWeight ' , BOLD )
2015-04-25 19:08:04 +02:00
self . doc . Text . insertString ( cursor , string . replace ( ' ' , ' ' ) , 0 )
self . doc . Text . insertString ( cursor , ' . – ' , 0 )
2008-07-14 15:55:05 +02:00
cursor . setPropertyValue ( ' CharWeight ' , NORMAL )
self . dialog . endExecute ( )
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2008-07-14 15:55:05 +02:00
class ManualSpeakerDialog ( unohelper . Base , XJobExecutor ) :
2010-03-04 10:27:55 +01:00
'''
Dialog for manual speaker insert
'''
2008-07-14 15:55:05 +02:00
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 ( )
try :
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
2015-04-25 19:08:04 +02:00
dialogModel . Title = ' Insertion d \' un orateur manuel '
2008-07-14 15:55:05 +02:00
# create the button model and set the properties
button = addWidget ( dialogModel , ' insertButton ' , ' Button ' , 50 , 30 , 50 , 14 )
button . TabIndex = 0
2015-04-25 19:08:04 +02:00
button . Label = " Insérer "
2008-07-14 15:55:05 +02:00
text = addWidget ( dialogModel , ' label0 ' , ' FixedText ' , 10 , 10 , 100 , 14 )
2015-04-25 19:08:04 +02:00
text . Label = ' Orateur : '
2008-07-14 15:55:05 +02:00
entry = addWidget ( dialogModel , ' insertWidget ' , ' Edit ' , 50 , 7 , 100 , 14 )
entry . MultiLine = False
# 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 ( ' insertButton ' ) . addActionListener (
InsertManualSpeakerDlgListener ( self . ctx , doc , entry , controlContainer ) )
toolkit = smgr . createInstanceWithContext ( ' com.sun.star.awt.ExtToolkit ' , ctx )
controlContainer . setVisible ( False )
controlContainer . createPeer ( toolkit , None )
controlContainer . execute ( )
controlContainer . dispose ( )
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2008-07-14 15:55:05 +02:00
2011-03-15 12:39:58 +01:00
def getConfigAccess ( ctx , cNodePath , bWriteAccess = False ) :
oConfigProvider = ctx . ServiceManager . createInstance (
' com.sun.star.configuration.ConfigurationProvider ' )
2007-11-26 14:39:00 +01:00
if bWriteAccess :
2007-11-29 11:42:39 +01:00
cServiceName = ' com.sun.star.configuration.ConfigurationUpdateAccess '
2007-11-26 14:39:00 +01:00
else :
2007-11-29 11:42:39 +01:00
cServiceName = ' com.sun.star.configuration.ConfigurationAccess '
2007-11-26 14:39:00 +01:00
oConfigAccess = oConfigProvider . createInstanceWithArguments ( cServiceName ,
2011-03-15 12:39:58 +01:00
( makePropertyValue ( ' nodepath ' , cNodePath ) , ) )
2007-11-26 14:39:00 +01:00
return oConfigAccess
2008-06-25 01:31:56 +02:00
def set_toolbar_visibility ( ctx , visibility ) :
oConfigAccess = getConfigAccess ( ctx , ' /org.openoffice.Office.Addons/AddonUI ' )
oElement = oConfigAccess . getByName ( ' OfficeToolBar ' )
toolbar_names = oElement . getElementNames ( )
desktop = ctx . ServiceManager . createInstanceWithContext (
' com.sun.star.frame.Desktop ' , ctx )
doc = desktop . getCurrentComponent ( )
2009-01-14 17:19:45 +01:00
if not doc :
components = desktop . getComponents ( ) . createEnumeration ( )
while components . hasMoreElements ( ) :
try :
doc = components . nextElement ( )
except NoSuchElementException :
break
break
2008-06-25 01:31:56 +02:00
layout_manager = doc . CurrentController . Frame . LayoutManager
if visibility is False :
for toolbar in toolbar_names :
layout_manager . hideElement ( ' private:resource/toolbar/addon_ %s ' % toolbar )
else :
for toolbar in toolbar_names :
layout_manager . showElement ( ' private:resource/toolbar/addon_ %s ' % toolbar )
2008-07-12 17:52:35 +02:00
try :
2009-01-14 12:25:25 +01:00
President . get_nodes ( ctx )
2015-04-25 19:08:04 +02:00
except DownloadError as e :
2008-07-12 17:52:35 +02:00
parentwin = doc . CurrentController . Frame . ContainerWindow
MessageBox ( parentwin ,
2015-04-25 19:08:04 +02:00
' Les listes d \' orateurs n \' ont pu être chargées (problème de réseau?) ' ,
2011-06-03 11:32:12 +02:00
' Tabellio ' , ' errorbox ' )
2008-06-25 01:31:56 +02:00
2007-11-26 14:39:00 +01:00
class ShowHideToolbars ( unohelper . Base , XJobExecutor ) :
2010-03-04 10:27:55 +01:00
'''
Job to display or hide toolbars
'''
2007-11-26 14:39:00 +01:00
def __init__ ( self , ctx ) :
self . ctx = ctx
def trigger ( self , args ) :
ctx = self . ctx
try :
2008-06-25 01:31:56 +02:00
set_toolbar_visibility ( ctx , args != ' hide ' )
2008-03-02 15:31:41 +01:00
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2007-11-26 14:39:00 +01:00
2007-11-27 21:53:00 +01:00
class AboutDialog ( unohelper . Base , XJobExecutor ) :
2010-03-04 10:27:55 +01:00
'''
Job to display an about Tabellio dialog
'''
2007-11-27 21:53:00 +01:00
def __init__ ( self , ctx ) :
self . ctx = ctx
def getLogoUrl ( self ) :
oConfigAccess = getConfigAccess ( self . ctx ,
' /org.entrouvert.openoffice.tabellio.FileLocations ' , False )
exp = self . ctx . getValueByName ( ' /singletons/com.sun.star.util.theMacroExpander ' )
path = oConfigAccess . getByName ( ' ImageLogo ' )
url = exp . expandMacros ( path )
return url
def trigger ( self , args ) :
ctx = self . ctx
try :
smgr = self . ctx . ServiceManager
2008-02-18 15:15:58 +01:00
dialogModel = smgr . createInstanceWithContext (
2007-11-27 21:53:00 +01:00
' com.sun.star.awt.UnoControlDialogModel ' , self . ctx )
dialogModel . Width = 210
dialogModel . Height = 100
2015-04-25 19:08:04 +02:00
dialogModel . Title = ' À propos de Tabellio '
2007-11-27 21:53:00 +01:00
2008-02-18 15:38:36 +01:00
logo = addWidget ( dialogModel , ' logo ' , ' ImageControl ' , 5 , 5 , 155 / 2 , 155 / 2 )
2007-11-27 21:53:00 +01:00
logo . ImageURL = self . getLogoUrl ( )
2008-02-18 15:38:36 +01:00
text = addWidget ( dialogModel , ' title ' , ' FixedText ' , 5 + 155 / 2 + 5 , 5 , 100 , 25 )
2015-04-25 19:08:04 +02:00
text . Label = ' Tabellio³ '
2007-11-27 21:53:00 +01:00
fdesc = FontDescriptor ( )
fdesc . Weight = 200
fdesc . Height = 16
text . FontDescriptor = fdesc
# close button
2008-02-18 15:38:36 +01:00
button = addWidget ( dialogModel , ' closeButton ' , ' Button ' , 155 , 80 , 50 , 14 )
button . TabIndex = 0
2015-04-25 19:08:04 +02:00
button . Label = ' Fermer '
2007-11-27 21:53:00 +01:00
2008-02-18 15:15:58 +01:00
# create the dialog control and set the model
controlContainer = smgr . createInstanceWithContext (
2008-02-18 15:38:36 +01:00
' com.sun.star.awt.UnoControlDialog ' , self . ctx )
2007-11-27 21:53:00 +01:00
controlContainer . setModel ( dialogModel )
controlContainer . getControl ( ' closeButton ' ) . addActionListener (
CloseListener ( controlContainer ) )
2008-02-18 15:15:58 +01:00
# create a peer
toolkit = smgr . createInstanceWithContext (
2008-02-18 11:14:57 +01:00
' com.sun.star.awt.ExtToolkit ' , ctx )
2007-11-27 21:53:00 +01:00
2008-02-18 11:14:57 +01:00
controlContainer . setVisible ( False )
controlContainer . createPeer ( toolkit , None )
2007-11-27 21:53:00 +01:00
# execute it
controlContainer . execute ( )
2008-02-18 15:15:58 +01:00
# dispose the dialog
2007-11-27 21:53:00 +01:00
controlContainer . dispose ( )
2008-03-02 15:31:41 +01:00
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2007-11-27 21:53:00 +01:00
2007-11-28 11:52:12 +01:00
def addWidget ( dialog , name , type , x , y , w , h ) :
2010-03-04 10:27:55 +01:00
''' Utility function to add a widget to a dialog '''
2007-11-28 11:52:12 +01:00
widget = dialog . createInstance ( ' com.sun.star.awt.UnoControl %s Model ' % type )
widget . Name = name
widget . PositionX = x
widget . PositionY = y
widget . Width = w
widget . Height = h
dialog . insertByName ( name , widget )
return widget
2007-11-28 13:26:36 +01:00
2007-11-29 11:42:39 +01:00
class ConfigurationDlgListener ( unohelper . Base , XActionListener ) :
2010-03-04 10:27:55 +01:00
'''
Listener for the configuration dialog
'''
2007-11-29 11:42:39 +01:00
def __init__ ( self , ui ) :
self . ui = ui
def actionPerformed ( self , actionEvent ) :
try :
oConfigAccess = getConfigAccess ( self . ui . ctx ,
' /org.entrouvert.openoffice.tabellio.Configuration ' , True )
2010-03-04 10:27:55 +01:00
2009-01-14 12:25:25 +01:00
oConfigAccess . PreviewServerURL = self . ui . preview_server_url . Text
oConfigAccess . InsertsRootURL = self . ui . inserts_root_url . Text
2010-06-11 13:53:22 +02:00
oConfigAccess . ProxyServerURL = self . ui . proxy_server_url . Text
2010-03-08 12:15:20 +01:00
oConfigAccess . Mode = self . ui . mode . Text
2007-11-29 11:42:39 +01:00
oConfigAccess . commitChanges ( )
self . ui . dialog . endExecute ( )
2008-03-02 15:31:41 +01:00
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ui . ctx )
2007-11-29 11:42:39 +01:00
class ConfigurationDialog ( unohelper . Base , XJobExecutor ) :
2010-03-04 10:27:55 +01:00
'''
Configuration dialog
'''
2007-11-29 11:42:39 +01:00
def __init__ ( self , ctx ) :
self . ctx = ctx
def trigger ( self , args ) :
ctx = self . ctx
try :
smgr = self . ctx . ServiceManager
desktop = smgr . createInstanceWithContext (
' com.sun.star.frame.Desktop ' , self . ctx )
self . doc = doc = desktop . getCurrentComponent ( )
2008-02-18 15:15:58 +01:00
dialogModel = smgr . createInstanceWithContext (
2007-11-29 11:42:39 +01:00
' com.sun.star.awt.UnoControlDialogModel ' , self . ctx )
2009-09-09 22:14:46 +02:00
dialogModel . Width = 140
2010-06-11 13:53:22 +02:00
dialogModel . Height = 140
2015-04-25 19:08:04 +02:00
dialogModel . Title = ' Configuration '
2007-11-29 11:42:39 +01:00
2009-09-09 22:14:46 +02:00
label = addWidget ( dialogModel , ' previewServerUrlLabel ' , ' FixedText ' , 5 , 5 , 100 , 10 )
2015-04-25 19:08:04 +02:00
label . Label = ' URL du serveur de prévisualisation '
2009-01-14 12:25:25 +01:00
self . preview_server_url = addWidget ( dialogModel ,
2009-09-09 22:14:46 +02:00
' preview_server_url ' , ' Edit ' , 10 , 15 , 125 , 14 )
2007-11-29 11:42:39 +01:00
2009-09-09 22:14:46 +02:00
label = addWidget ( dialogModel , ' insertsRootUrlLabel ' , ' FixedText ' , 5 , 35 , 100 , 10 )
2015-04-25 19:08:04 +02:00
label . Label = ' URL racine pour les insertions '
2009-01-14 12:25:25 +01:00
self . inserts_root_url = addWidget ( dialogModel ,
2009-09-09 22:14:46 +02:00
' inserts_root_url ' , ' Edit ' , 10 , 45 , 125 , 14 )
2007-11-29 11:42:39 +01:00
2010-06-11 13:53:22 +02:00
label = addWidget ( dialogModel , ' proxyServerUrlLabel ' , ' FixedText ' , 5 , 65 , 100 , 10 )
2015-04-25 19:08:04 +02:00
label . Label = ' URL du proxy '
2010-06-11 13:53:22 +02:00
self . proxy_server_url = addWidget ( dialogModel ,
' proxy_server_url ' , ' Edit ' , 10 , 75 , 125 , 14 )
label = addWidget ( dialogModel , ' modeLabel ' , ' FixedText ' , 5 , 95 , 100 , 10 )
2015-04-25 19:08:04 +02:00
label . Label = ' Mode '
2010-06-11 13:53:22 +02:00
self . mode = addWidget ( dialogModel ,
' mode ' , ' ComboBox ' , 10 , 105 , 125 , 14 )
2010-03-08 12:15:20 +01:00
self . mode . Dropdown = True
2015-04-25 19:08:04 +02:00
self . mode . StringItemList = ( ( ' PCF ' , ' PFB ' ) )
2010-03-08 12:15:20 +01:00
self . mode . Text = self . mode . StringItemList [ 0 ]
2007-11-29 11:42:39 +01:00
oConfigAccess = getConfigAccess ( self . ctx ,
' /org.entrouvert.openoffice.tabellio.Configuration ' , False )
2009-01-14 12:25:25 +01:00
self . preview_server_url . Text = oConfigAccess . getByName ( ' PreviewServerURL ' )
self . inserts_root_url . Text = oConfigAccess . getByName ( ' InsertsRootURL ' )
2010-06-11 13:53:22 +02:00
self . proxy_server_url . Text = oConfigAccess . getByName ( ' ProxyServerURL ' )
2010-03-08 12:15:20 +01:00
self . mode . Text = oConfigAccess . getByName ( ' Mode ' )
2007-11-29 11:42:39 +01:00
# save button
2010-06-11 13:53:22 +02:00
saveButton = addWidget ( dialogModel , ' saveButton ' , ' Button ' , 85 , 125 , 50 , 14 )
2015-04-25 19:08:04 +02:00
saveButton . Label = ' Enregistrer '
2007-11-29 11:42:39 +01:00
# cancel button
2010-06-11 13:53:22 +02:00
cancelButton = addWidget ( dialogModel , ' cancelButton ' , ' Button ' , 30 , 125 , 50 , 14 )
2015-04-25 19:08:04 +02:00
cancelButton . Label = ' Annuler '
2007-11-29 11:42:39 +01:00
2008-02-18 15:15:58 +01:00
# create the dialog control and set the model
self . dialog = controlContainer = smgr . createInstanceWithContext (
2007-11-29 11:42:39 +01:00
' com.sun.star.awt.UnoControlDialog ' , self . ctx )
controlContainer . setModel ( dialogModel )
controlContainer . getControl ( ' cancelButton ' ) . addActionListener (
CloseListener ( controlContainer ) )
controlContainer . getControl ( ' saveButton ' ) . addActionListener (
ConfigurationDlgListener ( self ) )
2008-02-18 15:15:58 +01:00
# create a peer
toolkit = smgr . createInstanceWithContext (
2008-02-18 11:14:57 +01:00
' com.sun.star.awt.ExtToolkit ' , ctx )
2007-11-29 11:42:39 +01:00
2008-02-18 11:14:57 +01:00
controlContainer . setVisible ( False )
controlContainer . createPeer ( toolkit , None )
2007-11-29 11:42:39 +01:00
# execute it
controlContainer . execute ( )
2008-02-18 15:15:58 +01:00
# dispose the dialog
2007-11-29 11:42:39 +01:00
controlContainer . dispose ( )
2008-03-02 15:31:41 +01:00
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2007-11-14 21:30:36 +01:00
2008-11-06 15:39:12 +01:00
2010-03-04 10:27:55 +01:00
class InsertVote ( unohelper . Base , XJobExecutor ) :
'''
Job to insert the result of a vote
'''
2008-11-06 15:39:12 +01:00
2009-03-11 11:54:29 +01:00
def __init__ ( self , ctx ) :
self . ctx = ctx
def trigger ( self , args ) :
try :
smgr = self . ctx . ServiceManager
desktop = smgr . createInstanceWithContext ( ' com.sun.star.frame.Desktop ' , self . ctx )
doc = desktop . getCurrentComponent ( )
filepicker = smgr . createInstance ( ' com.sun.star.ui.dialogs.FilePicker ' )
filepicker . appendFilter ( ' *.txt ' , ' *.txt ' )
2009-10-07 11:10:16 +02:00
if filepicker . execute ( ) == 0 : # cancel
return
2009-03-11 11:54:29 +01:00
filenames = filepicker . getFiles ( )
if not filenames :
return
# OOo returns the filenames as RFC 1738 URLs
2009-09-10 11:58:25 +02:00
filename = normalize_filename ( filenames [ 0 ] )
2009-03-11 11:54:29 +01:00
self . insert_vote_result ( filename , doc )
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2009-03-11 11:54:29 +01:00
def format_list_of_deputes ( self , deputes ) :
2011-06-03 11:32:12 +02:00
''' Format a list of deputies, to have them grouped by gender and
prefixed by the appropriate titles . ( e . g . MM . for a group of
mens ) '''
2009-03-11 11:54:29 +01:00
deputes . sort ( lambda x , y : cmp ( x . name . lower ( ) , y . name . lower ( ) ) )
deputes . reverse ( )
r = [ ]
if len ( deputes ) == 2 :
# special case, join them with 'et'
depute1 = deputes [ 0 ]
depute2 = deputes [ 1 ]
if depute1 . sexe == depute2 . sexe :
2011-06-03 13:31:41 +02:00
if depute1 . sexe == ' M ' :
2009-03-11 11:54:29 +01:00
r . append ( ' MM. ' )
else :
r . append ( ' Mmes ' )
r . append ( ' %s %s ' % ( depute1 . name , depute1 . firstname ) )
r . append ( ' et ' )
r . append ( ' %s %s ' % ( depute2 . name , depute2 . firstname ) )
else :
if depute1 . sexe == ' M ' :
title = ' M. '
else :
title = ' Mme '
r . append ( ' %s %s %s ' % ( title , depute1 . name , depute1 . firstname ) )
r . append ( ' et ' )
if depute2 . sexe == ' M ' :
title = ' M. '
else :
title = ' Mme '
r . append ( ' %s %s %s ' % ( title , depute2 . name , depute2 . firstname ) )
r . append ( ' . ' )
return ' ' . join ( r )
while deputes :
depute = deputes . pop ( )
if r :
r . append ( ' , ' )
if len ( deputes ) == 0 or deputes [ - 1 ] . sexe != depute . sexe :
if depute . sexe == ' M ' :
title = ' M. '
else :
title = ' Mme '
r . append ( ' %s %s %s ' % ( title , depute . name , depute . firstname ) )
else :
if depute . sexe == ' M ' :
r . append ( ' MM. ' )
else :
r . append ( ' Mmes ' )
r . append ( ' %s %s ' % ( depute . name , depute . firstname ) )
while deputes and deputes [ - 1 ] . sexe == depute . sexe :
depute = deputes . pop ( )
r . append ( ' , %s %s ' % ( depute . name , depute . firstname ) )
r . append ( ' . ' )
return ' ' . join ( r )
def insert_vote_result ( self , filename , doc ) :
2011-06-03 11:32:12 +02:00
''' Insert the result of a vote (taken from a text file) in the current
document . '''
2009-03-11 11:54:29 +01:00
cursor = doc . getCurrentController ( ) . getViewCursor ( )
deputies_dict = { }
for d in Deputy . values ( self . ctx ) :
deputies_dict [ d . id ] = d
votes_by_deputy = { }
2011-06-03 11:32:12 +02:00
missing_deputies = [ ]
2009-03-11 11:54:29 +01:00
2015-04-25 19:08:04 +02:00
for line_no , vote in enumerate ( csv . reader ( open ( filename ) , delimiter = ' \t ' ) ) :
2009-03-11 11:54:29 +01:00
parti = vote [ 3 ]
2015-04-25 19:08:04 +02:00
lastname = str ( vote [ 4 ] , ' iso-8859-1 ' )
firstname = str ( vote [ 5 ] , ' iso-8859-1 ' )
2009-03-11 11:54:29 +01:00
type = vote [ 6 ] # 0, +, - or AB
dep_id = Deputy . get_deputy_id ( firstname , lastname , ctx = self . ctx )
if dep_id is None :
2011-06-03 11:32:12 +02:00
# it was not possible to find this person, keep track of this,
# it will be used to display a dialog at the end.
2011-06-03 12:07:05 +02:00
missing_deputies . append ( ( line_no + 1 , ' %s %s ' % ( firstname , lastname ) ) )
2009-03-11 11:54:29 +01:00
continue
votes_by_deputy [ dep_id ] = type
2011-06-03 11:32:12 +02:00
# count the different kind of votes
2009-03-11 11:54:29 +01:00
nb_yes = len ( [ x for x in votes_by_deputy if votes_by_deputy . get ( x ) == ' + ' ] )
nb_no = len ( [ x for x in votes_by_deputy if votes_by_deputy . get ( x ) == ' - ' ] )
nb_abst = len ( [ x for x in votes_by_deputy if votes_by_deputy . get ( x ) == ' AB ' ] )
nb_null = len ( [ x for x in votes_by_deputy if votes_by_deputy . get ( x ) == ' 0 ' ] )
if nb_yes == 0 :
2015-04-25 19:08:04 +02:00
str_yes = ' Aucun membre n \' a répondu oui. '
2009-03-11 11:54:29 +01:00
elif nb_yes == 1 :
2015-04-25 19:08:04 +02:00
str_yes = ' 1 membre a répondu oui. '
2009-03-11 11:54:29 +01:00
else :
2015-04-25 19:08:04 +02:00
str_yes = ' %s membres ont répondu oui. ' % nb_yes
2009-03-11 11:54:29 +01:00
if nb_no == 0 :
2015-04-25 19:08:04 +02:00
str_no = ' Aucun membre n \' a répondu non. '
2009-03-11 11:54:29 +01:00
elif nb_no == 1 :
2015-04-25 19:08:04 +02:00
str_no = ' 1 membre a répondu non. '
2009-03-11 11:54:29 +01:00
else :
2015-04-25 19:08:04 +02:00
str_no = ' %s membres ont répondu non. ' % nb_no
2009-03-11 11:54:29 +01:00
if nb_abst == 0 :
2015-04-25 19:08:04 +02:00
str_abst = ' Aucun membre ne s \' est abstenu. '
2009-03-11 11:54:29 +01:00
elif nb_abst == 1 :
2015-04-25 19:08:04 +02:00
str_abst = ' 1 membre s \' est abstenu. '
2009-03-11 11:54:29 +01:00
else :
2015-04-25 19:08:04 +02:00
str_abst = ' %s membres se sont abstenus. ' % nb_abst
2009-03-11 11:54:29 +01:00
def insert_string ( str ) :
2009-10-07 11:02:30 +02:00
cursor . Text . insertString ( cursor , str , False )
2009-03-11 11:54:29 +01:00
2015-04-25 19:08:04 +02:00
insert_string ( ' %s membres ont pris part au vote. ' % sum ( ( nb_yes , nb_no , nb_abst ) ) )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
if nb_no + nb_abst + nb_null == 0 :
2011-06-03 11:32:12 +02:00
# -> everyone agree, the text is adopted
2015-04-25 19:08:04 +02:00
insert_string ( ' Tous ont répondu oui. ' )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2015-04-25 19:08:04 +02:00
insert_string ( ''' En conséquence, [mettre ici l ' objet du vote] est adopté. Il sera soumis à la sanction du Gouvernement de la Communauté française. / est adopté et l ' article est modifié. ''' )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
deputes = [ deputies_dict [ x ] for x in votes_by_deputy ]
2015-04-25 19:08:04 +02:00
insert_string ( ' Ont pris part au vote: ' )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
insert_string ( self . format_list_of_deputes ( deputes ) )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
elif nb_yes > nb_no :
2011-06-03 11:32:12 +02:00
# -> the text is adopted
2009-03-11 11:54:29 +01:00
insert_string ( str_yes )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
if nb_no :
insert_string ( str_no )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
if nb_abst :
insert_string ( str_abst )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
2015-04-25 19:08:04 +02:00
insert_string ( ''' En conséquence, [mettre ici l ' objet du vote] est adopté. Il sera soumis à la sanction du Gouvernement de la Communauté française. / est adopté et l ' article est modifié. ''' )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
deputes = [ deputies_dict [ x ] for x in votes_by_deputy if votes_by_deputy . get ( x ) == ' + ' ]
2015-04-25 19:08:04 +02:00
insert_string ( ' Ont répondu oui: ' )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
insert_string ( self . format_list_of_deputes ( deputes ) )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
deputes = [ deputies_dict [ x ] for x in votes_by_deputy if votes_by_deputy . get ( x ) == ' - ' ]
if deputes :
2015-04-25 19:08:04 +02:00
insert_string ( ' Ont répondu non: ' )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
insert_string ( self . format_list_of_deputes ( deputes ) )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
deputes = [ deputies_dict [ x ] for x in votes_by_deputy if votes_by_deputy . get ( x ) == ' AB ' ]
if deputes :
2015-04-25 19:08:04 +02:00
insert_string ( ' Se sont abstenus: ' )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
insert_string ( self . format_list_of_deputes ( deputes ) )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
elif nb_no > nb_yes :
2011-06-03 11:32:12 +02:00
# -> the text is rejected
2009-03-11 11:54:29 +01:00
insert_string ( str_no )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
if nb_yes :
insert_string ( str_yes )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
if nb_abst :
insert_string ( str_abst )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
2015-04-25 19:08:04 +02:00
insert_string ( ''' En conséquence, [mettre ici l ' objet du vote] est rejeté. / est rejeté. L ' article est adopté. ''' )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
deputes = [ deputies_dict [ x ] for x in votes_by_deputy if votes_by_deputy . get ( x ) == ' - ' ]
2015-04-25 19:08:04 +02:00
insert_string ( ' Ont répondu non: ' )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
insert_string ( self . format_list_of_deputes ( deputes ) )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
deputes = [ deputies_dict [ x ] for x in votes_by_deputy if votes_by_deputy . get ( x ) == ' + ' ]
if deputes :
2015-04-25 19:08:04 +02:00
insert_string ( ' Ont répondu oui: ' )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
insert_string ( self . format_list_of_deputes ( deputes ) )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
deputes = [ deputies_dict [ x ] for x in votes_by_deputy if votes_by_deputy . get ( x ) == ' AB ' ]
if deputes :
2015-04-25 19:08:04 +02:00
insert_string ( ' Se sont abstenus: ' )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
insert_string ( self . format_list_of_deputes ( deputes ) )
2009-10-07 11:02:30 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-03-11 11:54:29 +01:00
2011-06-03 11:32:12 +02:00
if missing_deputies :
# there were persons that could not be found, notify the user now
parentwin = doc . CurrentController . Frame . ContainerWindow
s = ' \n ' . join ( ' %s ( %s ) ' % x for x in missing_deputies )
MessageBox ( parentwin ,
2015-04-25 19:08:04 +02:00
''' Attention, des lignes n ' ont pu être insérées: \n %s ''' % s ,
2011-06-03 11:32:12 +02:00
' Tabellio ' , ' infobox ' )
2010-03-04 10:27:55 +01:00
2009-03-12 14:13:48 +01:00
class InsertStandardTextDialog ( unohelper . Base , XActionListener ) :
2010-03-04 10:27:55 +01:00
'''
Dialog to insert a standard snippet of text
'''
2009-03-12 14:13:48 +01:00
def __init__ ( self , ctx , doc ) :
self . ctx = ctx
self . doc = doc
def show ( self ) :
smgr = self . ctx . ServiceManager
dialogModel = smgr . createInstanceWithContext (
' com.sun.star.awt.UnoControlDialogModel ' , self . ctx )
dialogModel . Width = 210
2012-02-22 13:37:45 +01:00
dialogModel . Height = 200
2015-04-25 19:08:04 +02:00
dialogModel . Title = " Insertion de texte standard "
2009-03-12 14:13:48 +01:00
self . snippets = SnippetDoc . values ( self . ctx )
2012-02-22 13:37:45 +01:00
self . listbox = addWidget ( dialogModel , ' listbox ' , ' ListBox ' , 5 , 5 , 200 , 170 )
2009-03-12 14:13:48 +01:00
self . listbox . StringItemList = tuple ( [ x . title for x in self . snippets ] )
2012-02-22 13:37:45 +01:00
button = addWidget ( dialogModel , ' insertButton ' , ' Button ' , 155 , 180 , 50 , 14 )
2009-03-12 14:13:48 +01:00
button . TabIndex = 0
2012-02-22 13:37:45 +01:00
button . DefaultButton = True
2015-04-25 19:08:04 +02:00
button . Label = ' Insérer '
2009-03-12 14:13:48 +01:00
2012-02-22 13:37:45 +01:00
button = addWidget ( dialogModel , ' closeButton ' , ' Button ' , 95 , 180 , 50 , 14 )
2009-03-12 14:13:48 +01:00
button . TabIndex = 1
2015-04-25 19:08:04 +02:00
button . Label = ' Annuler '
2009-03-12 14:13:48 +01:00
# create the dialog control and set the model
controlContainer = smgr . createInstanceWithContext (
' com.sun.star.awt.UnoControlDialog ' , self . ctx )
controlContainer . setModel ( dialogModel )
self . dialog = controlContainer
controlContainer . getControl ( ' insertButton ' ) . setActionCommand ( ' insert ' )
controlContainer . getControl ( ' insertButton ' ) . addActionListener ( self )
controlContainer . getControl ( ' closeButton ' ) . addActionListener ( self )
toolkit = smgr . createInstanceWithContext ( ' com.sun.star.awt.ExtToolkit ' , self . ctx )
controlContainer . setVisible ( False )
controlContainer . createPeer ( toolkit , None )
controlContainer . execute ( )
controlContainer . dispose ( )
def actionPerformed ( self , actionEvent ) :
try :
if actionEvent . ActionCommand == ' insert ' :
snippets = SnippetDoc . values ( self . ctx )
if self . listbox . SelectedItems :
snippet = self . snippets [ self . listbox . SelectedItems [ 0 ] ]
text = self . doc . Text
2009-04-30 11:53:25 +02:00
cursor = text . createTextCursorByRange (
self . doc . getCurrentController ( ) . getViewCursor ( ) . getStart ( ) )
2009-03-12 14:13:48 +01:00
oConfigAccess = getConfigAccess ( self . ctx ,
' /org.entrouvert.openoffice.tabellio.Configuration ' , False )
inserts_base_url = oConfigAccess . getByName ( ' InsertsRootURL ' )
2015-04-25 19:08:04 +02:00
if type ( snippet . filename ) is str :
2012-02-22 13:36:58 +01:00
snippet . filename = snippet . filename . encode ( ' utf-8 ' )
2015-04-25 19:08:04 +02:00
document_url = inserts_base_url + urllib . parse . quote ( snippet . filename )
2009-03-12 14:13:48 +01:00
2012-02-22 13:36:58 +01:00
filename = download ( self . ctx , document_url )
url = unohelper . systemPathToFileUrl ( os . path . abspath ( filename ) )
cursor . insertDocumentFromURL ( url , ( ) )
2009-03-12 14:13:48 +01:00
self . dialog . endExecute ( )
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2009-03-12 14:13:48 +01:00
class InsertStandardText ( unohelper . Base , XJobExecutor ) :
2010-03-04 10:27:55 +01:00
'''
Job to display the dialog to insert a standard snippet of text
'''
2009-03-12 14:13:48 +01:00
def __init__ ( self , ctx ) :
self . ctx = ctx
2009-03-11 11:54:29 +01:00
2009-03-12 14:13:48 +01:00
def trigger ( self , args ) :
try :
desktop = self . ctx . ServiceManager . createInstanceWithContext (
" com.sun.star.frame.Desktop " , self . ctx )
doc = desktop . getCurrentComponent ( )
dialog = InsertStandardTextDialog ( self . ctx , doc )
dialog . show ( )
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2009-03-11 11:54:29 +01:00
2009-04-24 10:43:44 +02:00
class ImportDalet ( unohelper . Base , XJobExecutor ) :
2010-03-04 10:27:55 +01:00
'''
Job to insert a serie of documents from dalet
'''
2009-04-24 10:43:44 +02:00
def __init__ ( self , ctx ) :
self . ctx = ctx
def trigger ( self , args ) :
try :
desktop = self . ctx . ServiceManager . createInstanceWithContext (
' com.sun.star.frame.Desktop ' , self . ctx )
2009-04-30 21:55:28 +02:00
doc = desktop . getCurrentComponent ( )
2009-04-24 10:43:44 +02:00
filepicker = self . ctx . ServiceManager . createInstance (
' com.sun.star.ui.dialogs.FilePicker ' )
filepicker . appendFilter ( ' *.xml ' , ' *.xml ' )
2009-10-07 11:10:16 +02:00
if filepicker . execute ( ) == 0 : # cancel
return
2009-04-24 10:43:44 +02:00
filenames = filepicker . getFiles ( )
if not filenames :
return
2009-09-10 11:58:25 +02:00
filename = normalize_filename ( filenames [ 0 ] )
2009-04-30 21:55:28 +02:00
2009-04-24 10:43:44 +02:00
doc = desktop . getCurrentComponent ( )
self . import_dalet ( filename , doc )
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2009-04-24 10:43:44 +02:00
def import_dalet ( self , filename , doc ) :
dalet = xml . dom . minidom . parseString ( open ( filename ) . read ( ) )
2009-04-29 21:39:27 +02:00
paths = [ ]
2009-04-24 10:43:44 +02:00
for transcription in dalet . getElementsByTagName ( ' FrenchTranscription ' ) :
fullpath = transcription . getElementsByTagName ( ' FullPath ' ) [ 0 ]
2011-06-03 11:32:12 +02:00
clipcaption = get_text_node_content (
transcription . parentNode . getElementsByTagName ( ' ClipCaption ' ) [ 0 ] )
document_url = get_text_node_content ( fullpath )
2009-04-30 21:55:28 +02:00
if document_url . startswith ( ' \\ \\ ' ) :
# on a windows share
document_url = ' file:// ' + document_url [ 2 : ] . replace ( ' \\ ' , ' / ' )
2009-04-29 21:39:27 +02:00
paths . append ( ( clipcaption , document_url ) )
2010-03-04 10:27:55 +01:00
2009-04-29 21:39:27 +02:00
paths . sort ( )
2009-04-30 21:55:28 +02:00
cursor = doc . Text . createTextCursor ( )
2009-04-29 21:39:27 +02:00
for caption , document_url in paths :
2009-04-24 10:43:44 +02:00
cursor . gotoEnd ( False )
cursor . insertDocumentFromURL ( document_url , ( ) )
2010-06-23 10:34:57 +02:00
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
# insert the caption as a review note
cursor . setPropertyValue ( ' CharBackColor ' , 16776960 )
cursor . Text . insertString ( cursor , ' --- %s --- ' % caption , False )
cursor . setPropertyValue ( ' CharBackColor ' , - 1 )
cursor . Text . insertControlCharacter ( cursor , APPEND_PARAGRAPH , False )
2009-04-24 10:43:44 +02:00
cursor . gotoEnd ( False )
2007-11-30 22:12:50 +01:00
class Preview ( unohelper . Base , XJobExecutor ) :
2010-03-04 10:27:55 +01:00
'''
Job to perform a preview of the current document
'''
2007-11-30 22:12:50 +01:00
def __init__ ( self , ctx ) :
self . ctx = ctx
def trigger ( self , args ) :
ctx = self . ctx
try :
smgr = self . ctx . ServiceManager
desktop = smgr . createInstanceWithContext (
' com.sun.star.frame.Desktop ' , self . ctx )
doc = desktop . getCurrentComponent ( )
2008-02-18 11:14:57 +01:00
errors = check_structure ( doc )
if errors :
2008-02-18 11:46:01 +01:00
dialog = StructureCheckDialog ( self . ctx , doc , errors ,
continue_action = self . preview , continue_label = ' Plop ' )
dialog . show ( )
else :
self . preview ( doc )
2008-03-02 15:31:41 +01:00
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2008-02-18 11:14:57 +01:00
2008-02-18 11:46:01 +01:00
def preview ( self , doc ) :
parentwin = doc . CurrentController . Frame . ContainerWindow
2007-11-30 22:12:50 +01:00
2008-02-18 11:46:01 +01:00
# saving odt to local file
temp_file = os . path . join ( tempfile . gettempdir ( ) , ' preview.odt ' )
doc . storeToURL ( unohelper . systemPathToFileUrl ( temp_file ) , ( ) )
2007-11-30 22:12:50 +01:00
2009-01-14 12:25:25 +01:00
oConfigAccess = getConfigAccess ( self . ctx ,
' /org.entrouvert.openoffice.tabellio.Configuration ' , False )
href = oConfigAccess . getByName ( ' PreviewServerURL ' )
2007-11-30 22:12:50 +01:00
2008-02-18 11:46:01 +01:00
try :
2015-04-25 19:08:04 +02:00
url = get_url_opener ( self . ctx ) . open ( href , data = open ( temp_file , ' rb ' ) . read ( ) )
2008-02-18 11:46:01 +01:00
s = url . read ( )
2015-04-25 19:08:04 +02:00
except socket . timeout as e :
2008-02-18 11:46:01 +01:00
parentwin = doc . CurrentController . Frame . ContainerWindow
return MessageBox ( parentwin , ' Timeout sur le serveur ' , ' Alerte ' , ' infobox ' )
2010-03-04 10:27:55 +01:00
2008-02-18 11:46:01 +01:00
if url . headers [ ' Content-type ' ] == ' text/plain ' :
# error
return MessageBox ( parentwin , s , ' Alerte ' , ' infobox ' )
2007-12-02 23:51:45 +01:00
2009-10-07 10:31:13 +02:00
temp_pdf_file = os . path . join ( tempfile . gettempdir ( ) ,
' tabellio-preview- %s .pdf ' % random . randint ( 100000 , 999999 ) )
2015-04-25 19:08:04 +02:00
open ( temp_pdf_file , ' wb ' ) . write ( s )
2007-11-30 22:12:50 +01:00
2008-02-18 11:46:01 +01:00
if sys . platform . startswith ( ' win ' ) :
os . system ( ' start file:// %s ' % temp_pdf_file )
else :
os . system ( ' xdg-open %s & ' % temp_pdf_file )
2007-11-30 22:12:50 +01:00
2008-07-08 21:45:03 +02:00
2009-03-11 11:54:29 +01:00
class ExportAsLegi ( unohelper . Base , XJobExecutor ) :
2010-03-04 10:27:55 +01:00
'''
Job to export current document as legi
'''
2009-03-11 11:54:29 +01:00
def __init__ ( self , ctx ) :
self . ctx = ctx
def trigger ( self , args ) :
ctx = self . ctx
try :
smgr = self . ctx . ServiceManager
desktop = smgr . createInstanceWithContext (
' com.sun.star.frame.Desktop ' , self . ctx )
doc = desktop . getCurrentComponent ( )
errors = check_structure ( doc )
if errors :
dialog = StructureCheckDialog ( self . ctx , doc , errors ,
2009-04-17 16:54:30 +02:00
continue_action = self . do_export , continue_label = ' Plop ' )
2009-03-11 11:54:29 +01:00
dialog . show ( )
else :
2009-04-17 16:54:30 +02:00
self . do_export ( doc )
2009-03-11 11:54:29 +01:00
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2009-03-11 11:54:29 +01:00
2009-04-17 16:54:30 +02:00
def do_export ( self , doc ) :
2009-03-11 11:54:29 +01:00
parentwin = doc . CurrentController . Frame . ContainerWindow
2009-04-17 16:54:30 +02:00
smgr = self . ctx . ServiceManager
filepicker = smgr . createInstance ( ' com.sun.star.ui.dialogs.FilePicker ' )
filepicker . initialize ( ( FILESAVE_SIMPLE , ) )
2010-06-24 10:42:57 +02:00
filepicker . appendFilter ( ' *.legi ' , ' *.legi ' )
2009-10-07 11:10:16 +02:00
if filepicker . execute ( ) == 0 : # cancel
return
2009-04-17 16:54:30 +02:00
filenames = filepicker . getFiles ( )
2009-04-24 10:05:29 +02:00
if not filenames :
return
2009-09-10 11:58:25 +02:00
filename = normalize_filename ( filenames [ 0 ] )
2009-04-17 16:54:30 +02:00
2009-03-11 11:54:29 +01:00
# saving odt to local file
temp_file = os . path . join ( tempfile . gettempdir ( ) , ' preview.odt ' )
doc . storeToURL ( unohelper . systemPathToFileUrl ( temp_file ) , ( ) )
oConfigAccess = getConfigAccess ( self . ctx ,
' /org.entrouvert.openoffice.tabellio.Configuration ' , False )
href = oConfigAccess . getByName ( ' PreviewServerURL ' ) + ' legi '
try :
2015-04-25 19:08:04 +02:00
url = get_url_opener ( self . ctx ) . open ( href , data = open ( temp_file , ' rb ' ) . read ( ) )
2009-03-11 11:54:29 +01:00
s = url . read ( )
2015-04-25 19:08:04 +02:00
except socket . timeout as e :
2009-03-11 11:54:29 +01:00
parentwin = doc . CurrentController . Frame . ContainerWindow
return MessageBox ( parentwin , ' Timeout sur le serveur ' , ' Alerte ' , ' infobox ' )
2010-03-04 10:27:55 +01:00
2009-03-11 11:54:29 +01:00
if url . headers [ ' Content-type ' ] == ' text/plain ' :
# error
return MessageBox ( parentwin , s , ' Alerte ' , ' infobox ' )
2015-04-25 19:08:04 +02:00
open ( filename , ' wb ' ) . write ( s )
2009-03-11 11:54:29 +01:00
2010-03-04 10:27:55 +01:00
2011-01-27 15:03:58 +01:00
class PcfLogonDlg ( unohelper . Base , XActionListener ) :
2011-06-03 11:32:12 +02:00
'''
Dialog to log on PCF document store
'''
2011-01-27 15:03:58 +01:00
def __init__ ( self , ctx , doc , logon_callback ) :
self . ctx = ctx
self . doc = doc
self . logon_callback = logon_callback
def display ( self ) :
try :
smgr = self . ctx . ServiceManager
desktop = smgr . createInstanceWithContext (
' com.sun.star.frame.Desktop ' , self . ctx )
self . doc = doc = desktop . getCurrentComponent ( )
self . dialog = dialogModel = smgr . createInstanceWithContext (
' com.sun.star.awt.UnoControlDialogModel ' , self . ctx )
dialogModel . Width = 130
dialogModel . Height = 55
2015-04-25 19:08:04 +02:00
dialogModel . Title = ' Authentification '
2011-01-27 15:03:58 +01:00
label = addWidget ( dialogModel , ' usernameLabel ' , ' FixedText ' , 5 , 5 , 40 , 15 )
2015-04-25 19:08:04 +02:00
label . Label = ' Identifiant '
2011-01-27 15:03:58 +01:00
self . username = addWidget ( dialogModel , ' username ' , ' Edit ' , 55 , 2 , 70 , 14 )
label = addWidget ( dialogModel , ' passwordLabel ' , ' FixedText ' , 5 , 20 , 40 , 15 )
2015-04-25 19:08:04 +02:00
label . Label = ' Mot de passe '
2011-01-27 15:03:58 +01:00
self . password = addWidget ( dialogModel , ' password ' , ' Edit ' , 55 , 17 , 70 , 14 )
2011-03-17 17:20:40 +01:00
self . password . EchoChar = 42
2011-01-27 15:03:58 +01:00
# login button
saveButton = addWidget ( dialogModel , ' loginButton ' , ' Button ' , 75 , 35 , 50 , 14 )
2015-04-25 19:08:04 +02:00
saveButton . Label = " S ' identifer "
2011-04-15 10:28:14 +02:00
saveButton . DefaultButton = True
2011-01-27 15:03:58 +01:00
# cancel button
cancelButton = addWidget ( dialogModel , ' cancelButton ' , ' Button ' , 20 , 35 , 50 , 14 )
2015-04-25 19:08:04 +02:00
cancelButton . Label = ' Annuler '
2011-01-27 15:03:58 +01:00
# create the dialog control and set the model
self . dialog = controlContainer = smgr . createInstanceWithContext (
' com.sun.star.awt.UnoControlDialog ' , self . ctx )
controlContainer . setModel ( dialogModel )
controlContainer . getControl ( ' cancelButton ' ) . addActionListener (
CloseListener ( controlContainer ) )
controlContainer . getControl ( ' loginButton ' ) . addActionListener ( self )
# 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 ( )
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2011-01-27 15:03:58 +01:00
def actionPerformed ( self , actionEvent ) :
2011-04-15 10:28:14 +02:00
2011-03-17 17:34:01 +01:00
try :
2011-01-27 15:03:58 +01:00
self . dialog . endExecute ( )
2011-04-15 10:28:14 +02:00
cursor = self . doc . getCurrentController ( ) . getViewCursor ( )
2011-01-27 15:03:58 +01:00
# this was captured once between the Word Add-in and the
# tabellio procedure server
dauth = { ' username ' : self . username . Text ,
' password ' : self . password . Text }
data = ' verb=DispatchClassMethodXML&className=SERVICE& ' \
2015-04-25 19:08:04 +02:00
' methodName=Logon&xmlRqst= %s ' % urllib . parse . quote (
2011-01-27 15:03:58 +01:00
' <MLogon> ' \
' <cvers>1,+0,+1,+0</cvers> ' \
' <pwd> %(password)s </pwd> ' \
' <usr> %(username)s </usr> ' \
' </MLogon> ' % dauth )
2011-04-15 10:28:14 +02:00
props = self . doc . DocumentProperties . getUserDefinedProperties ( )
2011-01-27 15:03:58 +01:00
post_url = props . getPropertyValue ( ' documentUrl ' )
2013-11-07 13:11:25 +01:00
if not post_url :
parentwin = self . doc . CurrentController . Frame . ContainerWindow
2015-04-25 19:08:04 +02:00
error = " Métadonnée documentUrl absente du document, enregistrement impossible "
2013-11-07 13:11:25 +01:00
return MessageBox ( parentwin , error , ' Alerte ' , ' errorbox ' )
2015-04-25 19:08:04 +02:00
href = urllib . parse . urlunsplit ( urllib . parse . urlsplit ( post_url ) [ : 2 ] + (
2011-04-15 10:28:14 +02:00
' /xmldispatcher ' , ' ' , ' ' ) )
2011-01-27 15:03:58 +01:00
try :
get_url_opener ( self . ctx ) . open ( href , data = data )
2015-04-25 19:08:04 +02:00
except ( urllib . error . HTTPError , urllib . error . URLError ) as e :
2011-01-27 15:03:58 +01:00
if hasattr ( e , ' code ' ) and e . code == 510 :
s = e . fp . read ( )
if s . startswith ( ' <error> ' ) :
dom = xml . dom . minidom . parseString ( s )
2011-06-03 11:32:12 +02:00
error = get_text_node_content (
dom . childNodes [ 0 ] . getElementsByTagName ( ' description ' ) [ 0 ] )
2011-01-27 15:03:58 +01:00
elif hasattr ( e , ' code ' ) :
2015-04-25 19:08:04 +02:00
error = " Erreur %s à l ' authentification " % e . code
2011-01-27 15:03:58 +01:00
elif hasattr ( e , ' reason ' ) :
2015-04-25 19:08:04 +02:00
error = " Erreur à l ' authentification ( %s ) " % e . reason
2011-01-27 15:03:58 +01:00
else :
2015-04-25 19:08:04 +02:00
error = " Erreur à l ' authentification "
2011-04-15 10:28:14 +02:00
parentwin = self . doc . CurrentController . Frame . ContainerWindow
2011-01-27 15:03:58 +01:00
return MessageBox ( parentwin , error , ' Alerte ' , ' errorbox ' )
self . logon_callback ( self . doc )
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2011-01-27 15:03:58 +01:00
2010-10-18 10:37:08 +02:00
class UploadLegi ( unohelper . Base , XJobExecutor ) :
2011-01-27 15:03:58 +01:00
'''
Job to upload current file as legi to the server
'''
2010-10-18 10:37:08 +02:00
def __init__ ( self , ctx ) :
self . ctx = ctx
def trigger ( self , args ) :
try :
2011-01-27 15:03:58 +01:00
desktop = self . ctx . ServiceManager . createInstanceWithContext (
2010-10-18 10:37:08 +02:00
' com.sun.star.frame.Desktop ' , self . ctx )
doc = desktop . getCurrentComponent ( )
2011-01-27 15:03:58 +01:00
try :
props = doc . DocumentProperties . getUserDefinedProperties ( )
post_url = props . getPropertyValue ( ' documentUrl ' )
except : # com.sun.star.beans.UnknownPropertyException
parentwin = doc . CurrentController . Frame . ContainerWindow
return MessageBox ( parentwin , " Pas d ' adresse pour ce document. " ,
' Alerte ' , ' errorbox ' )
2010-10-18 10:37:08 +02:00
errors = check_structure ( doc )
if errors :
dialog = StructureCheckDialog ( self . ctx , doc , errors ,
2011-01-27 15:03:58 +01:00
continue_action = self . do_check_auth , continue_label = ' Continuer ' )
2010-10-18 10:37:08 +02:00
dialog . show ( )
else :
2011-01-27 15:03:58 +01:00
self . do_check_auth ( doc )
2010-10-18 10:37:08 +02:00
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2010-10-18 10:37:08 +02:00
2011-01-27 15:03:58 +01:00
def do_check_auth ( self , doc ) :
if get_mode ( self . ctx ) == ' PCF ' :
dlg = PcfLogonDlg ( self . ctx , doc , self . do_upload )
dlg . display ( )
else :
self . do_upload ( doc )
2010-10-18 10:37:08 +02:00
def do_upload ( self , doc ) :
parentwin = doc . CurrentController . Frame . ContainerWindow
2011-03-17 17:34:01 +01:00
try :
# saving odt to local file
temp_file = os . path . join ( tempfile . gettempdir ( ) , ' preview.odt ' )
doc . storeToURL ( unohelper . systemPathToFileUrl ( temp_file ) , ( ) )
2010-10-18 10:37:08 +02:00
2011-03-17 17:34:01 +01:00
oConfigAccess = getConfigAccess ( self . ctx ,
' /org.entrouvert.openoffice.tabellio.Configuration ' , False )
href = oConfigAccess . getByName ( ' PreviewServerURL ' ) + ' legi '
2010-10-26 13:28:51 +02:00
2011-03-17 17:34:01 +01:00
try :
2015-04-25 19:08:04 +02:00
url = get_url_opener ( self . ctx ) . open ( href , data = open ( temp_file , ' rb ' ) . read ( ) )
2011-03-17 17:34:01 +01:00
as_legi_string = url . read ( )
2015-04-25 19:08:04 +02:00
except socket . timeout as e :
2011-03-17 17:34:01 +01:00
return MessageBox ( parentwin , ' Timeout sur le serveur ' , ' Alerte ' , ' errorbox ' )
2010-10-26 13:28:51 +02:00
2011-03-17 17:34:01 +01:00
if url . headers [ ' Content-type ' ] == ' text/plain ' :
# error
2011-06-03 13:33:26 +02:00
return MessageBox ( parentwin , as_legi_string , ' Alerte ' , ' errorbox ' )
2010-10-26 13:28:51 +02:00
2011-03-17 17:34:01 +01:00
props = doc . DocumentProperties . getUserDefinedProperties ( )
post_url = props . getPropertyValue ( ' documentUrl ' )
2010-10-18 10:37:08 +02:00
2011-03-17 17:34:01 +01:00
urlopener = get_url_opener ( self . ctx )
2015-04-25 19:08:04 +02:00
request = urllib . request . Request ( post_url , data = as_legi_string )
2013-06-14 15:27:48 +02:00
request . add_header ( ' Content-Type ' , ' text/pcf-legi ' )
2011-03-17 17:34:01 +01:00
request . get_method = lambda : ' PUT '
try :
url = urlopener . open ( request )
s = url . read ( )
2015-04-25 19:08:04 +02:00
except socket . timeout as e :
2011-03-17 17:34:01 +01:00
return MessageBox ( parentwin , ' Timeout sur le serveur ' , ' Alerte ' , ' errorbox ' )
2015-04-25 19:08:04 +02:00
except urllib . error . URLError as e :
href = urllib . parse . urlsplit ( post_url ) [ 1 ]
error = " L ' authentification sur le serveur ( %s ) a échoué. " % href
2011-04-15 10:28:14 +02:00
return MessageBox ( parentwin , error , ' Alerte ' , ' errorbox ' )
2011-03-17 17:34:01 +01:00
return MessageBox ( parentwin ,
2015-04-25 19:08:04 +02:00
' Document sauvegardé sur le serveur ' ,
2011-03-17 17:34:01 +01:00
' Tabellio ' , ' infobox ' )
except :
2011-06-03 13:34:16 +02:00
display_exception ( self . ctx )
2010-10-18 10:37:08 +02:00
2009-04-30 10:51:14 +02:00
class NewTabellioDocument ( unohelper . Base , XJobExecutor ) :
2010-03-04 10:27:55 +01:00
'''
Job to create a new document based on the tabellio model
'''
2009-04-30 10:51:14 +02:00
def __init__ ( self , ctx ) :
self . ctx = ctx
def trigger ( self , args ) :
ctx = self . ctx
try :
smgr = self . ctx . ServiceManager
desktop = smgr . createInstanceWithContext ( ' com.sun.star.frame.Desktop ' , self . ctx )
oConfigAccess = getConfigAccess ( self . ctx ,
' /org.entrouvert.openoffice.tabellio.Configuration ' , False )
inserts_base_url = oConfigAccess . getByName ( ' InsertsRootURL ' )
document_url = inserts_base_url + ' tabellio.ott '
2012-02-22 13:36:58 +01:00
filename = download ( ctx , document_url )
url = unohelper . systemPathToFileUrl ( os . path . abspath ( filename ) )
desktop . loadComponentFromURL ( url , ' _default ' , 0 , ( ) )
2009-04-30 10:51:14 +02:00
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2009-04-30 10:51:14 +02:00
2009-03-11 11:54:29 +01:00
2010-05-03 10:27:37 +02:00
class SwitchReviewNoteMode ( unohelper . Base , XJobExecutor ) :
2011-06-03 11:32:12 +02:00
'''
Job to switch back and to review mode ( a simple highlighting )
'''
2010-05-03 10:27:37 +02:00
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 ( )
cursor = doc . getCurrentController ( ) . getViewCursor ( )
current_bg = cursor . getPropertyValue ( ' CharBackColor ' )
if current_bg == - 1 :
# 16776960 is yellow (red:255 << 16 | green:255 << 8 | blue:0)
cursor . setPropertyValue ( ' CharBackColor ' , 16776960 )
else :
cursor . setPropertyValue ( ' CharBackColor ' , - 1 )
2010-02-21 20:27:21 +01:00
2013-02-06 16:32:50 +01:00
class InsertFootnote ( unohelper . Base , XJobExecutor ) :
'''
Job to insert a footnote
'''
def __init__ ( self , ctx ) :
self . ctx = ctx
def trigger ( self , args ) :
try :
desktop = self . ctx . ServiceManager . createInstanceWithContext (
' com.sun.star.frame.Desktop ' , self . ctx )
doc = desktop . getCurrentComponent ( )
dispatchHelper = self . ctx . ServiceManager . createInstanceWithContext (
' com.sun.star.frame.DispatchHelper ' , self . ctx )
dispatchHelper . executeDispatch (
doc . getCurrentController ( ) . getFrame ( ) ,
' .uno:InsertFootnote ' ,
' ' , 0 , ( ) )
except :
display_exception ( self . ctx )
2008-07-08 21:45:03 +02:00
class DoNothing ( unohelper . Base , XJobExecutor ) :
def __init__ ( self , ctx ) :
pass
def trigger ( self , args ) :
pass
2008-03-02 16:56:46 +01:00
class Dispatcher ( unohelper . Base , XDispatch , XControlNotificationListener , XJobExecutor ,
XActionListener ) :
2010-03-04 10:27:55 +01:00
'''
Dispatcher necessary to handle complex controls in toolbars
'''
2008-03-02 15:31:41 +01:00
def __init__ ( self , ctx ) :
self . listeners = [ ]
self . ctx = ctx
def addStatusListener ( self , control , url ) :
if control not in self . listeners :
# keep track of listeners, for proper removal afterwards
self . listeners . append ( control )
def removeStatusListener ( self , control , url ) :
if control in self . listeners :
i = self . listeners . index ( control )
del self . listeners [ i ]
def dispatch ( self , url , args ) :
2008-03-02 17:36:35 +01:00
try :
2008-11-26 16:48:01 +01:00
debug_print ( ' received dispatch instruction on ' , url . Path )
debug_print ( ' args: ' , args )
2008-03-02 17:36:35 +01:00
pass
except :
2011-06-03 11:32:12 +02:00
display_exception ( )
2008-03-02 15:31:41 +01:00
def controlEvent ( self , event ) :
pass
def sendCommand ( self , control , aUrl , command = None , args = None , enable = True ) :
try :
aEvent = FeatureStateEvent ( )
aEvent . FeatureURL = aUrl
aEvent . Source = self
aEvent . IsEnabled = enable
aEvent . Requery = False
if command :
aCtrlCmd = ControlCommand ( )
aCtrlCmd . Command = command
aCtrlCmd . Arguments = args
aEvent . State = aCtrlCmd
control . statusChanged ( aEvent )
except :
2011-06-03 11:32:12 +02:00
display_exception ( )
2008-03-02 15:31:41 +01:00
2008-03-02 16:56:46 +01:00
class InsertDispatcher ( Dispatcher ) :
2010-03-04 10:27:55 +01:00
'''
Dispatcher handling the insert deputy / minitre / . . . dropdowns in toolbars
'''
2008-03-02 17:36:35 +01:00
def __init__ ( self , ctx ) :
Dispatcher . __init__ ( self , ctx )
self . has_just_changed = False
2008-03-05 08:58:48 +01:00
self . lists = { }
2008-07-09 16:06:38 +02:00
self . deputy_letters = { }
self . controls = { }
2009-01-14 12:25:25 +01:00
self . ctx = ctx
2008-03-02 17:36:35 +01:00
2008-03-02 16:56:46 +01:00
def addStatusListener ( self , control , url ) :
Dispatcher . addStatusListener ( self , control , url )
try :
2008-07-09 16:06:38 +02:00
self . controls [ url . Path ] = control
2008-07-08 14:29:18 +02:00
if url . Path . startswith ( ' depute ' ) :
PARTS = 4 # four dropdown boxes
part = url . Path . split ( ' _ ' ) [ 1 ]
2009-01-14 12:25:25 +01:00
parls = Deputy . values ( self . ctx )
2010-10-13 15:02:05 +02:00
if not parls :
return
2008-07-08 22:17:44 +02:00
list_content = [ x . get_name ( ) for x in parls ]
2011-05-04 18:22:11 +02:00
list_content . sort ( lambda x , y : cmp ( x . lower ( ) , y . lower ( ) ) )
2008-07-08 14:29:18 +02:00
naive_part_len = len ( list_content ) / PARTS
for i in range ( PARTS ) :
if i == 0 :
start_letter = ' a '
else :
start_letter = string . lowercase [
string . lowercase . index ( list_content [ i * naive_part_len ] [ 0 ] . lower ( ) ) + 1 ]
2008-10-03 10:53:47 +02:00
start_letter = chr ( ord ( start_letter ) - 1 )
2008-07-08 14:29:18 +02:00
if i == ( PARTS - 1 ) :
end_letter = ' z '
else :
end_letter = string . lowercase [
string . lowercase . index ( list_content [ ( i + 1 ) * naive_part_len ] [ 0 ] . lower ( ) ) ]
2008-10-03 10:53:47 +02:00
end_letter = chr ( ord ( end_letter ) - 1 )
2008-07-08 14:29:18 +02:00
if int ( part ) == i + 1 :
break
list_content = [ x for x in list_content if x [ 0 ] . lower ( ) > = start_letter and
x [ 0 ] . lower ( ) < = end_letter ]
2008-07-09 16:06:38 +02:00
self . deputy_letters [ part ] = ' %s -> %s ' % ( start_letter , end_letter )
2008-03-02 16:56:46 +01:00
values = makeNamedList ( tuple ( list_content ) )
self . sendCommand ( control , url , ' SetList ' , values )
2008-07-08 22:17:44 +02:00
2008-07-09 16:06:38 +02:00
self . set_dropdown_label ( control , self . deputy_letters [ part ] )
2008-07-08 22:17:44 +02:00
elif url . Path == ' ministres ' :
2010-06-21 11:27:42 +02:00
minsts = get_min_pres_menu_items ( self . ctx )
2008-07-08 22:17:44 +02:00
list_content = [ x . get_name ( ) for x in minsts ]
values = makeNamedList ( tuple ( list_content ) )
self . sendCommand ( control , url , ' SetList ' , values )
2015-04-25 19:08:04 +02:00
self . set_dropdown_label ( control , ' Ministres et Présidents ' )
2008-07-14 14:55:53 +02:00
elif url . Path == ' commissions ' :
2009-01-14 12:25:25 +01:00
elems = Commission . values ( self . ctx )
2008-07-14 14:55:53 +02:00
list_content = [ x . get_name ( ) for x in elems ]
values = makeNamedList ( tuple ( list_content ) )
self . sendCommand ( control , url , ' SetList ' , values )
2015-04-25 19:08:04 +02:00
self . set_dropdown_label ( control , ' Commissions ' )
2008-03-02 16:56:46 +01:00
else :
2008-11-26 16:48:01 +01:00
debug_print ( ' Unknown Path: ' , url . Path )
2008-03-02 16:56:46 +01:00
except :
2011-06-03 11:32:12 +02:00
display_exception ( )
2008-03-02 16:56:46 +01:00
2008-07-09 16:06:38 +02:00
def set_dropdown_label ( self , control , str ) :
aEvent = FeatureStateEvent ( )
aEvent . Source = self
aEvent . IsEnabled = True
aEvent . State = str
control . statusChanged ( aEvent )
2008-03-02 16:56:46 +01:00
def dispatch ( self , url , args ) :
2008-03-02 17:36:35 +01:00
try :
2008-07-08 22:17:44 +02:00
desktop = self . ctx . ServiceManager . createInstanceWithContext (
" com.sun.star.frame.Desktop " , self . ctx )
doc = desktop . getCurrentComponent ( )
cursor = doc . getCurrentController ( ) . getViewCursor ( )
string = args [ 1 ] . Value
2009-10-07 10:38:16 +02:00
if url . Path . startswith ( ' depute ' ) or url . Path == ' ministres ' :
text = doc . Text
text_cursor = text . createTextCursor ( )
text_cursor . gotoRange ( cursor , False )
is_start_of_paragraph = text_cursor . isStartOfParagraph ( )
2008-12-22 14:19:40 +01:00
2008-07-08 22:17:44 +02:00
if url . Path . startswith ( ' depute ' ) :
2009-01-14 12:25:25 +01:00
parls = Deputy . values ( self . ctx )
2008-07-08 22:17:44 +02:00
t = [ x for x in parls if x . get_name ( ) == string ]
if not t :
raise Exception ( ' Unknown Deputy ' )
parl = t [ 0 ]
2008-12-22 14:19:40 +01:00
if is_start_of_paragraph :
parl . insert_as_speaker ( self . ctx , doc , cursor )
else :
parl . insert ( self . ctx , doc , cursor )
2008-03-02 17:36:35 +01:00
2008-07-08 22:17:44 +02:00
elif url . Path == ' ministres ' :
2010-06-21 11:27:42 +02:00
minsts = get_min_pres_menu_items ( self . ctx )
2008-07-08 22:17:44 +02:00
t = [ x for x in minsts if x . get_name ( ) == string ]
if not t :
raise Exception ( ' Unknown Ministres ' )
minist = t [ 0 ]
2008-12-22 14:19:40 +01:00
if is_start_of_paragraph :
minist . insert_as_speaker ( self . ctx , doc , cursor )
else :
minist . insert ( self . ctx , doc , cursor )
2008-07-08 22:17:44 +02:00
2008-07-14 14:55:53 +02:00
elif url . Path == ' commissions ' :
2009-01-14 12:25:25 +01:00
commissions = Commission . values ( self . ctx )
2008-07-14 14:55:53 +02:00
t = [ x for x in commissions if x . get_name ( ) == string ]
if not t :
raise Exception ( ' Unknown Commission ' )
commis = t [ 0 ]
2010-11-23 15:14:44 +01:00
commis . insert ( self . ctx , cursor )
2015-04-25 19:08:04 +02:00
self . set_dropdown_label ( self . controls [ url . Path ] , ' Commissions ' )
2009-10-07 10:26:44 +02:00
except :
2011-06-03 11:32:12 +02:00
display_exception ( )
2009-10-07 10:26:44 +02:00
finally :
if url . Path . startswith ( ' depute ' ) :
part = url . Path . split ( ' _ ' ) [ 1 ]
self . set_dropdown_label ( self . controls [ url . Path ] , self . deputy_letters [ part ] )
elif url . Path == ' ministres ' :
2015-04-25 19:08:04 +02:00
self . set_dropdown_label ( self . controls [ url . Path ] , ' Ministres et Présidents ' )
2009-10-07 10:26:44 +02:00
elif url . Path == ' commissions ' :
2015-04-25 19:08:04 +02:00
self . set_dropdown_label ( self . controls [ url . Path ] , ' Commissions ' )
2008-07-08 22:17:44 +02:00
# set focus to document
current_frame = desktop . getCurrentFrame ( )
current_frame . getComponentWindow ( ) . setFocus ( )
2008-03-02 16:56:46 +01:00
class Inserts ( unohelper . Base , XJobExecutor , XDispatchProvider , XActionListener ) :
def __init__ ( self , ctx ) :
self . ctx = ctx
def queryDispatch ( self , url , target , flags ) :
return InsertDispatcher ( self . ctx )
2008-06-25 01:31:56 +02:00
class OnLoadEvent ( unohelper . Base , XJob ) :
2010-03-04 10:27:55 +01:00
'''
Job executed when a document is loaded
'''
2008-06-25 01:31:56 +02:00
def __init__ ( self , ctx ) :
self . ctx = ctx
def execute ( self , args ) :
try :
desktop = self . ctx . ServiceManager . createInstanceWithContext (
' com.sun.star.frame.Desktop ' , self . ctx )
document = desktop . getCurrentComponent ( )
2009-01-14 17:19:45 +01:00
if document and document . supportsService ( ' com.sun.star.text.TextDocument ' ) :
2008-06-25 01:31:56 +02:00
layout_manager = document . CurrentController . Frame . LayoutManager
2015-04-25 19:08:04 +02:00
if ' Tabellio ' in ( document . DocumentProperties . Keywords or ' ' ) :
2008-06-25 01:31:56 +02:00
set_toolbar_visibility ( self . ctx , True )
else :
set_toolbar_visibility ( self . ctx , False )
2009-01-14 17:19:45 +01:00
else :
set_toolbar_visibility ( self . ctx , False )
2008-06-25 01:31:56 +02:00
except :
2011-06-03 11:32:12 +02:00
display_exception ( self . ctx )
2008-06-25 01:31:56 +02:00
2010-03-04 10:27:55 +01:00
# register everything to OpenOffice.org
2007-11-14 21:30:36 +01:00
g_ImplementationHelper = unohelper . ImplementationHelper ( )
2008-07-14 16:08:00 +02:00
g_ImplementationHelper . addImplementation (
SpeakerDialog ,
" org.entrouvert.openoffice.SpeakerDialog " ,
( " com.sun.star.task.Job " , ) , )
2007-11-14 21:30:36 +01:00
g_ImplementationHelper . addImplementation (
2008-07-14 15:55:05 +02:00
ManualSpeakerDialog ,
" org.entrouvert.openoffice.ManualSpeakerDialog " ,
2007-11-14 21:30:36 +01:00
( " com.sun.star.task.Job " , ) , )
g_ImplementationHelper . addImplementation (
StyleApply ,
" org.entrouvert.openoffice.StyleApply " ,
( " com.sun.star.task.Job " , ) )
2008-07-14 14:03:23 +02:00
g_ImplementationHelper . addImplementation (
ListStyleApply ,
" org.entrouvert.openoffice.ListStyleApply " ,
( " com.sun.star.task.Job " , ) )
2007-11-14 21:30:36 +01:00
g_ImplementationHelper . addImplementation (
2008-02-18 11:16:31 +01:00
StructureCheck ,
" org.entrouvert.openoffice.StructureCheck " ,
2007-11-14 21:30:36 +01:00
( " com.sun.star.task.Job " , ) )
2007-11-26 14:39:00 +01:00
g_ImplementationHelper . addImplementation (
ShowHideToolbars ,
" org.entrouvert.openoffice.ShowHideToolbars " ,
( " com.sun.star.task.Job " , ) )
2007-11-27 21:53:00 +01:00
g_ImplementationHelper . addImplementation (
AboutDialog ,
" org.entrouvert.openoffice.AboutDialog " ,
( " com.sun.star.task.Job " , ) )
2007-11-29 11:42:39 +01:00
g_ImplementationHelper . addImplementation (
ConfigurationDialog ,
" org.entrouvert.openoffice.ConfigurationDialog " ,
( " com.sun.star.task.Job " , ) )
2007-11-30 22:12:50 +01:00
g_ImplementationHelper . addImplementation (
Preview ,
" org.entrouvert.openoffice.Preview " ,
( " com.sun.star.task.Job " , ) )
2009-03-11 11:54:29 +01:00
g_ImplementationHelper . addImplementation (
ExportAsLegi ,
" org.entrouvert.openoffice.ExportAsLegi " ,
( " com.sun.star.task.Job " , ) )
2010-10-18 10:37:08 +02:00
g_ImplementationHelper . addImplementation (
UploadLegi ,
" org.entrouvert.openoffice.UploadLegi " ,
( " com.sun.star.task.Job " , ) )
2009-04-30 10:51:14 +02:00
g_ImplementationHelper . addImplementation (
NewTabellioDocument ,
" org.entrouvert.openoffice.NewTabellioDocument " ,
( " com.sun.star.task.Job " , ) )
2009-03-11 11:54:29 +01:00
g_ImplementationHelper . addImplementation (
InsertVote ,
" org.entrouvert.openoffice.InsertVote " ,
( " com.sun.star.task.Job " , ) )
2009-03-12 14:13:48 +01:00
g_ImplementationHelper . addImplementation (
InsertStandardText ,
" org.entrouvert.openoffice.InsertStandardText " ,
( " com.sun.star.task.Job " , ) )
2009-04-24 10:43:44 +02:00
g_ImplementationHelper . addImplementation (
ImportDalet ,
" org.entrouvert.openoffice.ImportDalet " ,
( " com.sun.star.task.Job " , ) )
2010-05-03 10:27:37 +02:00
g_ImplementationHelper . addImplementation (
SwitchReviewNoteMode ,
" org.entrouvert.openoffice.SwitchReviewNoteMode " ,
( " com.sun.star.task.Job " , ) )
2013-02-06 16:32:50 +01:00
g_ImplementationHelper . addImplementation (
InsertFootnote ,
" org.entrouvert.openoffice.InsertFootnote " ,
( " com.sun.star.task.Job " , ) )
2008-07-08 21:45:03 +02:00
g_ImplementationHelper . addImplementation (
DoNothing ,
" org.entrouvert.openoffice.DoNothing " ,
( " com.sun.star.task.Job " , ) )
2008-03-02 16:56:46 +01:00
g_ImplementationHelper . addImplementation (
Inserts ,
' org.entrouvert.openoffice.Inserts ' ,
( ' com.sun.star.frame.DispatchProvider ' , ' com.sun.star.task.Job ' , ) )
2008-06-25 01:31:56 +02:00
g_ImplementationHelper . addImplementation (
OnLoadEvent ,
' org.entrouvert.openoffice.OnLoadEvent ' ,
( ' com.sun.star.task.Job ' , ) )