LeenO computo metrico con LibreOffice  3.22.0
Il software libero per la gestione di computi metrici e contabilità lavori.
LeenoDialogs.py
Vai alla documentazione di questo file.
1 """
2  LeenO - modulo di gestione dialoghi
3 """
4 
5 import threading
6 
7 import LeenoUtils
8 import pyleeno as PL
9 import Dialogs
10 
11 from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK
12 # from com.sun.star.awt.MessageBoxButtons import BUTTONS_OK_CANCEL
13 from com.sun.star.awt.MessageBoxButtons import BUTTONS_YES_NO
14 # from com.sun.star.awt.MessageBoxButtons import BUTTONS_YES_NO_CANCEL
15 # from com.sun.star.awt.MessageBoxButtons import BUTTONS_RETRY_CANCEL
16 # from com.sun.star.awt.MessageBoxButtons import BUTTONS_ABORT_IGNORE_RETRY
17 
18 # from com.sun.star.awt.MessageBoxButtons import DEFAULT_BUTTON_OK
19 # from com.sun.star.awt.MessageBoxButtons import DEFAULT_BUTTON_CANCEL
20 # from com.sun.star.awt.MessageBoxButtons import DEFAULT_BUTTON_RETRY
21 # from com.sun.star.awt.MessageBoxButtons import DEFAULT_BUTTON_YES
22 from com.sun.star.awt.MessageBoxButtons import DEFAULT_BUTTON_NO
23 # from com.sun.star.awt.MessageBoxButtons import DEFAULT_BUTTON_IGNORE
24 
25 from com.sun.star.awt.MessageBoxType import MESSAGEBOX
26 # from com.sun.star.awt.MessageBoxType import INFOBOX
27 # from com.sun.star.awt.MessageBoxType import WARNINGBOX
28 # from com.sun.star.awt.MessageBoxType import ERRORBOX
29 from com.sun.star.awt.MessageBoxType import QUERYBOX
30 
31 # rif.: https://wiki.openoffice.org/wiki/PythonDialogBox
32 
33 def barra_di_stato(testo='', valore=0):
34  '''Informa l'utente sullo stato progressivo dell'elaborazione.'''
35  oDoc = LeenoUtils.getDocument()
36  oProgressBar = oDoc.CurrentController.Frame.createStatusIndicator()
37  oProgressBar.start('', 100)
38  oProgressBar.Value = valore
39  oProgressBar.Text = testo
40  oProgressBar.reset()
41  oProgressBar.end()
42 
43 
44 def chi(s): # s = oggetto
45  '''
46  s { object } : oggetto da interrogare
47  mostra un dialog che indica il tipo di oggetto ed i metodi ad esso applicabili
48  '''
50  parentwin = doc.CurrentController.Frame.ContainerWindow
51  s1 = str(s) + '\n\n' + str(dir(s).__str__())
52  MessageBox(parentwin, str(s1), str(type(s)), 'infobox')
53 
54 
55 def DlgSiNo(s, t='Titolo'): # s = messaggio | t = titolo
56  '''
57  Visualizza il menù di scelta sì/no
58  restituisce 2 per sì e 3 per no
59  '''
61  parentwin = doc.CurrentController.Frame.ContainerWindow
62  # s = 'This a message'
63  # t = 'Title of the box'
64  # MESSAGEBOX, INFOBOX, WARNINGBOX, ERRORBOX, QUERYBOX
65  return MessageBox(parentwin, s, t, QUERYBOX, BUTTONS_YES_NO + DEFAULT_BUTTON_NO)
66 
67 
68 def MsgBox(s, t=''): # s = messaggio | t = titolo
69  '''
70  Visualizza una message box
71  '''
73  parentwin = doc.CurrentController.Frame.ContainerWindow
74  # s = 'This a message'
75  # t = 'Title of the box'
76  # res = MessageBox(parentwin, s, t, QUERYBOX, BUTTONS_YES_NO_CANCEL + DEFAULT_BUTTON_NO)
77  # chi(res)
78  # return
79  # s = res
80  # t = 'Titolo'
81  if t is None:
82  t = 'messaggio'
83  MessageBox(parentwin, str(s), t, 'infobox')
84 
85 
86 def MessageBox(ParentWin, MsgText, MsgTitle, MsgType=MESSAGEBOX, MsgButtons=BUTTONS_OK):
87  '''
88  Show a message box with the UNO based toolkit
89  '''
91  sm = ctx.ServiceManager
92  sv = sm.createInstanceWithContext('com.sun.star.awt.Toolkit', ctx)
93  myBox = sv.createMessageBox(ParentWin, MsgType, MsgButtons, MsgTitle, MsgText)
94 
95  return myBox.execute()
96 # [ 入手元 ]
97 
98 
99 def mri(target):
100  '''
101  Inspector https://extensions.openoffice.org/project/MRI
102  '''
104  mrii = ctx.ServiceManager.createInstanceWithContext('mytools.Mri', ctx)
105  mrii.inspect(target)
106  MsgBox('MRI in corso...', 'avviso')
107 
108 
109 
110 def dlg_attesa(msg=''):
111  '''
112  definisce la variabile globale oDialogo_attesa
113  che va gestita così negli script:
114 
115  dlg_attesa()
116  attesa().start() #mostra il dialogo
117  ...
118  LeenoUtils.getGlobalVar('oDialogo_attesa').endExecute() #chiude il dialogo
119  '''
120  psm = LeenoUtils.getComponentContext().ServiceManager
121  dp = psm.createInstance("com.sun.star.awt.DialogProvider")
122  oDialogo_attesa = dp.createDialog(
123  "vnd.sun.star.script:UltimusFree2.DlgAttesa?language=Basic&location=application")
124 
125  # oDialog1Model = oDialogo_attesa.Model # oDialogo_attesa è una variabile generale
126 
127  sString = oDialogo_attesa.getControl("Label2")
128  sString.Text = msg # 'ATTENDI...'
129  oDialogo_attesa.Title = 'Operazione in corso...'
130  sUrl = PL.LeenO_path() + '/icons/attendi.png'
131  oDialogo_attesa.getModel().ImageControl1.ImageURL = sUrl
132  LeenoUtils.setGlobalVar('oDialogo_attesa', oDialogo_attesa)
133  return oDialogo_attesa
134 
135 
136 class attesa(threading.Thread):
137  '''
138  avvia il dialogo di attesa
139  http://bit.ly/2fzfsT7
140  '''
141  def __init__(self):
142  threading.Thread.__init__(self)
143 
144  def run(self):
145  LeenoUtils.getGlobalVar('oDialogo_attesa').endExecute() # chiude il dialogo
146  LeenoUtils.getGlobalVar('oDialogo_attesa').execute()
147 
148 
149 def ScegliElaborato(titolo):
150  '''
151  Permetta la scelta dell'elaborato da trattare e restituisce il suo nome
152  '''
153  oDoc = LeenoUtils.getDocument()
154  psm = LeenoUtils.getComponentContext().ServiceManager
155  dp = psm.createInstance("com.sun.star.awt.DialogProvider")
156  oDlgXLO = dp.createDialog(
157  "vnd.sun.star.script:UltimusFree2.Dialog_XLO?language=Basic&location=application"
158  )
159  # oDialog1Model = oDlgXLO.Model
160  oDlgXLO.Title = titolo # Menù import XPWE'
161 
162  for el in ("COMPUTO", "VARIANTE", "CONTABILITA"):
163  try:
164  importo = oDoc.getSheets().getByName(el).getCellRangeByName(
165  'A2').String
166  if el == 'COMPUTO':
167  oDlgXLO.getControl(
168  "CME_XLO").Label = '~Computo: € ' + importo
169  if el == 'VARIANTE':
170  oDlgXLO.getControl(
171  "VAR_XLO").Label = '~Variante: € ' + importo
172  if el == 'CONTABILITA':
173  oDlgXLO.getControl(
174  "CON_XLO").Label = 'C~ontabilità: € ' + importo
175  # else:
176  # oDlgXLO.getControl("CON_XLO").Label = 'Contabilità: €: 0,0'
177  except Exception:
178  pass
179 
180  if oDlgXLO.execute() == 1:
181  if oDlgXLO.getControl("CME_XLO").State:
182  elaborato = 'COMPUTO'
183  elif oDlgXLO.getControl("VAR_XLO").State:
184  elaborato = 'VARIANTE'
185  elif oDlgXLO.getControl("CON_XLO").State:
186  elaborato = 'CONTABILITA'
187  elif oDlgXLO.getControl("EP_XLO").State:
188  elaborato = 'Elenco'
189  return elaborato
190 
191 
192 def ScegliElabDest(*, Title='', AskTarget=False, AskSort=False, Sort=False, ValComputo=None, ValVariante=None, ValContabilita=None):
193 
194  # altezza radiobutton, per fare il testo con il valore uguale
195  # ed averli quindi allineati
197 
198  # dimensione dell'icona col punto di domanda
199  imgW = Dialogs.getBigIconSize()[0] * 2
200 
201  # i 3 valori totali
202  vCmp = '' if ValComputo is None else '{:9.2f} €'.format(ValComputo)
203  vVar = '' if ValVariante is None else '{:9.2f} €'.format(ValVariante)
204  vCon = '' if ValContabilita is None else '{:9.2f} €'.format(ValContabilita)
205 
206  # handler per il button di info
207  def infoHandler(owner, widgetId, widget, cmdStr):
208  if widgetId == 'sortInfo':
209  Dialogs.Info(Title="Note sull'ordinamento", Text=
210  "È possibile effettuare l'ordinamento delle voci di\n"
211  "computo in base alla struttura delle categorie.\n"
212  "Se il file in origine è particolarmente disordinato,\n"
213  "riceverai un messaggio che ti indica come intervenire.\n"
214  "Se il risultato finale non dovesse andar bene, puoi\n"
215  "ripetere l'importazione senza il riordino delle voci\n"
216  "de-selezionando la casella relativa"
217  )
218  return False
219 
220  # prima parte fissa del dialogo
221  dlg = Dialogs.Dialog(Title=Title, Handler=infoHandler, Items=[
222  Dialogs.HSizer(Items=[
223  Dialogs.VSizer(Items=[
224  Dialogs.Spacer(),
225  Dialogs.ImageControl(Id="img", Image="Icons-Big/question.png", MinWidth=imgW),
227  ]),
228  Dialogs.VSizer(Id="vsizer", Items=[
229  Dialogs.GroupBox(Label="Scegli elaborato", Items=[
230  Dialogs.HSizer(Items=[
231  Dialogs.RadioGroup(Id="elab", Items=[
232  "Computo",
233  "Variante",
234  "Contabilità",
235  "Elenco Prezzi"
236  ]),
237  Dialogs.Spacer(),
238  Dialogs.VSizer(Items=[
239  Dialogs.FixedText(Id="TotComputo", Text=vCmp, MinHeight=radioH),
240  Dialogs.FixedText(Id="TotVariante", Text=vVar, MinHeight=radioH),
241  Dialogs.FixedText(Id="TotContabilità", Text=vCon, MinHeight=radioH),
243  ])
244  ])
245  ])
246  ])
247  ])
248  ])
249  if AskTarget:
250  dlg["vsizer"].add(
251  Dialogs.Spacer(),
252  Dialogs.GroupBox(Label="Scegli destinazione", Items=[
253  Dialogs.RadioGroup(Id="dest", Items=[
254  "Documento corrente",
255  "Nuovo documento"
256  ])
257  ])
258  )
259 
260  if AskSort:
261  dlg["vsizer"].add(
262  Dialogs.Spacer(),
263  Dialogs.GroupBox(Label="Ordinamento computo", Items=[
264  Dialogs.CheckBox(Id="sort", Label="Ordina computo", State=Sort),
265  Dialogs.Spacer(),
266  Dialogs.Button(Id="sortInfo", Label="Info su ordinamento", Icon="Icons-24x24/info.png")
267  ])
268  )
269 
270  dlg["vsizer"].add(
271  Dialogs.Spacer(),
272  Dialogs.HSizer(Items=[
273  Dialogs.Button(Label="Ok", RetVal=1, Icon="Icons-24x24/ok.png"),
274  Dialogs.Spacer(),
275  Dialogs.Button(Label="Annulla", RetVal=-1, Icon="Icons-24x24/cancel.png"),
276  ])
277  )
278 
279  # check if we canceled the job
280  if dlg.run() == -1:
281  return None
282 
283  elab = ('COMPUTO', 'VARIANTE', 'CONTABILITA', 'Elenco')[dlg['elab'].getCurrent()]
284  dest = ('CORRENTE', 'NUOVO')[dlg['dest'].getCurrent() if AskTarget else 1]
285  sort = dlg['sort'].getState()
286 
287  return {'elaborato':elab, 'destinazione':dest, 'ordina':sort}
LeenoDialogs.ScegliElabDest
def ScegliElabDest(*Title='', AskTarget=False, AskSort=False, Sort=False, ValComputo=None, ValVariante=None, ValContabilita=None)
Definition: LeenoDialogs.py:192
LeenoUtils.getGlobalVar
def getGlobalVar(name)
Definition: LeenoUtils.py:123
LeenoUtils.getDocument
def getDocument()
Definition: LeenoUtils.py:67
Dialogs.Spacer
Definition: Dialogs.py:616
LeenoDialogs.mri
def mri(target)
Definition: LeenoDialogs.py:99
Dialogs.ImageControl
Definition: Dialogs.py:1387
LeenoDialogs.MessageBox
def MessageBox(ParentWin, MsgText, MsgTitle, MsgType=MESSAGEBOX, MsgButtons=BUTTONS_OK)
Definition: LeenoDialogs.py:86
LeenoDialogs.MsgBox
def MsgBox(s, t='')
Definition: LeenoDialogs.py:68
Dialogs.FixedText
Definition: Dialogs.py:989
Dialogs.RadioGroup
Definition: Dialogs.py:1931
Dialogs.getRadioButtonHeight
def getRadioButtonHeight()
Definition: Dialogs.py:199
LeenoUtils.getComponentContext
def getComponentContext()
Definition: LeenoUtils.py:47
Dialogs.Info
def Info(*Title='', Text='')
Definition: Dialogs.py:2539
LeenoUtils.setGlobalVar
def setGlobalVar(name, value)
Definition: LeenoUtils.py:131
LeenoDialogs.attesa.run
def run(self)
Definition: LeenoDialogs.py:144
Dialogs.HSizer
Definition: Dialogs.py:706
Dialogs.GroupBox
Definition: Dialogs.py:2088
Dialogs.Dialog
Definition: Dialogs.py:2189
Dialogs.Button
Definition: Dialogs.py:1527
Dialogs.VSizer
Definition: Dialogs.py:848
LeenoDialogs.ScegliElaborato
def ScegliElaborato(titolo)
Definition: LeenoDialogs.py:149
Dialogs.CheckBox
Definition: Dialogs.py:1605
LeenoDialogs.dlg_attesa
def dlg_attesa(msg='')
Definition: LeenoDialogs.py:110
LeenoDialogs.chi
def chi(s)
Definition: LeenoDialogs.py:44
Dialogs.getBigIconSize
def getBigIconSize()
Definition: Dialogs.py:103
LeenoDialogs.DlgSiNo
def DlgSiNo(s, t='Titolo')
Definition: LeenoDialogs.py:55
LeenoDialogs.attesa.__init__
def __init__(self)
Definition: LeenoDialogs.py:141
LeenoDialogs.attesa
Definition: LeenoDialogs.py:136
LeenoDialogs.barra_di_stato
def barra_di_stato(testo='', valore=0)
Definition: LeenoDialogs.py:33