LeenO computo metrico con LibreOffice  3.22.0
Il software libero per la gestione di computi metrici e contabilità lavori.
LeenoEvents.py
Vai alla documentazione di questo file.
1 """
2  LeenO - modulo di gestione eventi del documento e dei fogli
3 """
4 import uno
5 import sys
6 from com.sun.star.beans import PropertyValue
7 import LeenoUtils
8 import LeenoBasicBridge
9 
10 def macro_SHEET(nSheet, nEvento, miamacro):
11  '''
12  Attribuisce specifica macro ad evento di un foglio
13  '''
14  # ~nEvento:
15  # ~"OnFocus" entrando nel foglio
16  # ~"OnUnfocus" uscendo dal foglio
17  # ~"OnSelect" selezionando
18  # ~"OnDoubleClick" doppio click
19  # ~"OnRightClick" click destro
20  # ~"OnChange" modificando il contenuto
21  # ~"OnCalculate" mboh...
22  oProp = []
23  oProp0 = PropertyValue()
24  oProp0.Name = 'EventType'
25  oProp0.Value = 'Script'
26  oProp1 = PropertyValue()
27  oProp1.Name = 'Script'
28  oProp1.Value = miamacro
29 
30  oProp.append(oProp0)
31  oProp.append(oProp1)
32 
33  properties = tuple(oProp)
34  oDoc = LeenoUtils.getDocument()
35  oSheet = oDoc.getSheets().getByName(nSheet)
36  uno.invoke(
37  oSheet.Events, 'replaceByName',
38  (nEvento, uno.Any('[]com.sun.star.beans.PropertyValue', properties))
39  )
40  return
41 
42 
43 
44 def macro_DOC(nEvento, miamacro):
45  '''
46  Attribuisce specifica macro ad evento del documento
47  '''
48 # ~http://bit.ly/1EgROQt
49 # ~esempio: macro_DOC("OnUnfocus", "vnd.sun.star.script:UltimusFree2.Menu.SeeComponentsElements?language=Basic&location=application")
50 
51  oProp = []
52  oProp0 = PropertyValue()
53  oProp0.Name = 'EventType'
54  oProp0.Value = 'Script'
55  oProp1 = PropertyValue()
56  oProp1.Name = 'Script'
57  oProp1.Value = miamacro # persorso macro da assegnare
58 
59  oProp.append(oProp0)
60  oProp.append(oProp1)
61 
62  properties = tuple(oProp)
63  oDoc = LeenoUtils.getDocument()
64 
65  uno.invoke(
66  oDoc.Events, 'replaceByName',
67  (nEvento, uno.Any('[]com.sun.star.beans.PropertyValue', properties))
68  )
69  return
70 
71 
72 
73 def macro_URL (modulo, miamacro):
74  '''
75  Ricostruisce la URL della macro
76  '''
77  if sys.platform == 'linux' or sys.platform == 'darwin':
78  pmacro = LeenoBasicBridge.myPath.split('/')
79  elif sys.platform == 'win32':
80  pmacro = LeenoBasicBridge.myPath.split('\\')
81  return 'vnd.sun.star.script:' + '|'.join((pmacro[-3:])) + '|' + modulo + '.py$' + miamacro + '?language=Python&location=user:uno_packages'
82 
83 
84 
85 def assegna():
86  '''
87  Assegna le macro agli eventi del documento dei fogli
88  '''
89  # ~OnFocus
90  # ~OnUnfocus
91  # ~OnSelect
92  # ~OnDoubleClick
93  # ~OnRightClick
94  # ~OnChange
95  # ~OnCalculate
96  oDoc = LeenoUtils.getDocument()
97 
98  '''sotto Linux l'assegnazione delle macro agli eventi deve passare attraverso Basic, quindi:'''
99 
100  # ~ macro_SHEET ("Elenco Prezzi", "OnFocus", macro_URL("LeenoToolbars", "Vedi"))
101  macro_SHEET ("Elenco Prezzi", "OnFocus", 'vnd.sun.star.script:UltimusFree2.PY_bridge.Vedi?language=Basic&location=application')
102 
103  if oDoc.getSheets().hasByName('Analisi di Prezzo'):
104  # ~ macro_SHEET ("Analisi di Prezzo", "OnFocus", macro_URL("LeenoToolbars", "Vedi"))
105  macro_SHEET ("Analisi di Prezzo", "OnFocus", 'vnd.sun.star.script:UltimusFree2.PY_bridge.Vedi?language=Basic&location=application')
106 
107  # ~ macro_SHEET ("COMPUTO", "OnFocus", macro_URL("LeenoToolbars", "Vedi"))
108  macro_SHEET ("COMPUTO", "OnFocus", 'vnd.sun.star.script:UltimusFree2.PY_bridge.Vedi?language=Basic&location=application')
109 
110  if oDoc.getSheets().hasByName("VARIANTE"):
111  # ~ macro_SHEET ("VARIANTE", "OnFocus", macro_URL("LeenoToolbars", "Vedi"))
112  macro_SHEET ("VARIANTE", "OnFocus", 'vnd.sun.star.script:UltimusFree2.PY_bridge.Vedi?language=Basic&location=application')
113 
114  if oDoc.getSheets().hasByName("CONTABILITA"):
115  # ~ macro_SHEET ("CONTABILITA", "OnFocus", macro_URL("LeenoToolbars", "Vedi"))
116  macro_SHEET ("CONTABILITA", "OnFocus", 'vnd.sun.star.script:UltimusFree2.PY_bridge.Vedi?language=Basic&location=application')
117  macro_SHEET ("S2", "OnUnfocus", "vnd.sun.star.script:UltimusFree2.Header_Footer.set_header_auto?language=Basic&location=application")
118  # ~ macro_SHEET ("S1", "OnUnfocus", macro_URL("LeenoToolbars", "Vedi"))
119  macro_SHEET ("S1", "OnUnfocus", 'vnd.sun.star.script:UltimusFree2.PY_bridge.Vedi?language=Basic&location=application')
120  # ~OnStartApp
121  # ~OnCloseApp
122  # ~macro_DOC ("OnCreate", "vnd.sun.star.script:Standard.Controllo.Controlla_Esistenza_LibUltimus?language=Basic&location=document")
123  macro_DOC ("OnNew", "vnd.sun.star.script:Standard.Controllo.Controlla_Esistenza_LibUltimus?language=Basic&location=document")
124  # ~OnLoadFinished
125  macro_DOC ("OnLoad", "vnd.sun.star.script:Standard.Controllo.Controlla_Esistenza_LibUltimus?language=Basic&location=document")
126  macro_DOC ("OnPrepareUnload", "vnd.sun.star.script:UltimusFree2._variabili.autoexec_off?language=Basic&location=application")
127  macro_DOC ("OnUnload", "vnd.sun.star.script:UltimusFree2.Lupo_0.Svuota_Globale?language=Basic&location=application")
128  macro_DOC ("OnSave", macro_URL("LeenoBasicBridge", "bak0"))
129  # ~OnSaveDone
130  # ~OnSaveFailed
131  macro_DOC ("OnSaveAs", "vnd.sun.star.script:UltimusFree2.Lupo_0.Svuota_Globale?language=Basic&location=application")
132  # ~OnSaveAsDone
133  macro_DOC ("OnSaveAsFailed", "vnd.sun.star.script:UltimusFree2._variabili.autoexec?language=Basic&location=application")
134  # ~macro_DOC ("OnCopyTo", "vnd.sun.star.script:UltimusFree2.Lupo_0.Svuota_Globale?language=Basic&location=application")
135  # ~OnCopyToDone
136  # ~OnCopyToFailed
137  macro_DOC ("OnFocus", macro_URL("LeenoToolbars", "Vedi"))
138  # ~macro_DOC ("OnUnfocus", "vnd.sun.star.script:UltimusFree2.PY_bridge.ScriviNomeDocumentoPrincipale?language=Basic&location=application")
139  # ~OnPrint
140  # ~OnViewCreated
141  # ~OnPrepareViewClosing
142  # ~OnViewClosed
143  # ~OnModifyChanged
144  # ~OnTitleChanged
145  # ~OnVisAreaChanged
146  # ~OnModeChanged
147  # ~OnStorageChanged
148 
149 
150 
151 
152 def pulisci():
153  '''
154  Rimuove le macro dagli eventi del codumento e dei fogli.
155  Assegna al document le macro per il controllo dell'esistenza di LeenO
156  '''
157  oDoc = LeenoUtils.getDocument()
158  lista_fogli = oDoc.Sheets.ElementNames
159 
160  eventi = oDoc.CurrentController.ActiveSheet.Events.ElementNames
161  eventi_doc = oDoc.Events.ElementNames
162  for nome in lista_fogli:
163  for ev in eventi:
164 
165  macro_SHEET(nome, ev, '')
166  for ev in eventi_doc:
167  macro_DOC(ev, '')
168  macro_DOC ("OnNew", "vnd.sun.star.script:Standard.Controllo.Controlla_Esistenza_LibUltimus?language=Basic&location=document")
169  macro_DOC ("OnLoad", "vnd.sun.star.script:Standard.Controllo.Controlla_Esistenza_LibUltimus?language=Basic&location=document")
LeenoEvents.pulisci
def pulisci()
Definition: LeenoEvents.py:152
LeenoEvents.macro_SHEET
def macro_SHEET(nSheet, nEvento, miamacro)
Definition: LeenoEvents.py:10
LeenoUtils.getDocument
def getDocument()
Definition: LeenoUtils.py:67
LeenoEvents.macro_DOC
def macro_DOC(nEvento, miamacro)
Definition: LeenoEvents.py:44
LeenoEvents.macro_URL
def macro_URL(modulo, miamacro)
Definition: LeenoEvents.py:73
LeenoEvents.assegna
def assegna()
Definition: LeenoEvents.py:85