LeenO computo metrico con LibreOffice  3.22.0
Il software libero per la gestione di computi metrici e contabilità lavori.
TEST.py
Vai alla documentazione di questo file.
1 
2 def debug_link():
3  '''
4  @@ DA DOCUMENTARE
5  '''
7  window = oDoc.getCurrentController().getFrame().getContainerWindow()
9 
10  def create(name):
11  return ctx.getServiceManager().createInstanceWithContext(name, ctx)
12 
13  toolkit = create("com.sun.star.awt.Toolkit")
14  msgbox = toolkit.createMessageBox(window, 0, 1, "Message", 'foo')
15  link = create("com.sun.star.awt.UnoControlFixedHyperlink")
16  link_model = create("com.sun.star.awt.UnoControlFixedHyperlinkModel")
17  link.setModel(link_model)
18  link.createPeer(toolkit, msgbox)
19  link.setPosSize(35, 8, 100, 15, 15)
20  link.setText("Canale Telegram")
21  link.setURL("https://t.me/leeno_computometrico")
22  link.setVisible(True)
23  msgbox.execute()
24  msgbox.dispose()
25 
27  '''
28  @@ DA DOCUMENTARE
29  '''
30  # sStRange = LeenoComputo.circoscriveVoceComputo(oSheet, lrow)
31  # return
32 
33  try:
34  # sStRange = LeenoComputo.circoscriveVoceComputo(oSheet, lrow)
36 
37  except Exception as e:
38  # MsgBox ("CSV Import failure exception " + str(type(e)) +
39  # ". Messaggio: " + str(e) + " args " + str(e.args) +
40  # traceback.format_exc());
41  DLG.MsgBox("Eccezione " + str(type(e)) + "\nMessaggio: " + str(e.args) + '\n' + traceback.format_exc())
42 
57 
58 
59 # def debug_():
60 # oDoc = LeenoUtils.getDocument()
61 # oSheet = oDoc.CurrentController.ActiveSheet
62 # try:
63 # oRangeAddress = oDoc.getCurrentSelection().getRangeAddresses()
64 # except AttributeError:
65 # oRangeAddress = oDoc.getCurrentSelection().getRangeAddress()
66 # el_y = list()
67 # try:
68 # len(oRangeAddress)
69 # for el in oRangeAddress:
70 # el_y.append((el.StartRow, el.EndRow))
71 # except TypeError:
72 # el_y.append((oRangeAddress.StartRow, oRangeAddress.EndRow))
73 # lista = list()
74 # for y in el_y:
75 # for el in range(y[0], y[1] + 1):
76 # lista.append(el)
77 # for el in lista:
78 # oSheet.getCellByPosition(
79 # 7, el).Formula = '=' + oSheet.getCellByPosition(
80 # 6, el).Formula + '*' + oSheet.getCellByPosition(7, el).Formula
81 # oSheet.getCellByPosition(6, el).String = ''
82 
83 
84 
85 
87  '''
88  @@ DA DOCUMENTARE
89  '''
90  # ~pydevd.settrace()
91  # pathsstring = "paths \n"
92  somestring = ''
93  for i in sys.path:
94  somestring = somestring + i + "\n"
95  DLG.chi(somestring)
96 
109 import itertools
110 import operator
111 import functools
112 import LeenoImport as LI
113 
115  # ~import LeenoPdf
116  # ~LeenoPdf.MENU_Pdf()
117  # ~sistema_cose()
118  # ~MENU_nasconde_voci_azzerate()
119  # ~oDoc = LeenoUtils.getDocument()
120  # ~oSheet = oDoc.CurrentController.ActiveSheet
121  # ~lrow = LeggiPosizioneCorrente()[1]
122 
123  # ~raggruppa_righe_voce(lrow, 1)
124  return
125  oDoc = LeenoUtils.getDocument()
126  oSheet = oDoc.CurrentController.ActiveSheet
127  lr = SheetUtils.getLastUsedRow(oSheet) + 1
128  for el in reversed(range (1, lr)):
129  if oSheet.getCellByPosition(2, el).CellStyle == 'comp 1-a' and \
130  "'" in oSheet.getCellByPosition(2, el).Formula:
131  ff = oSheet.getCellByPosition(2, el).Formula.split("'")
132  oSheet.getCellByPosition(2, el).Formula = ff[0] + ff[-1][1:]
133 
134  return
135  # ~LeenoSheetUtils.setAdatta()
136  # ~sistema_cose()
137  # ~return
138  oDoc = LeenoUtils.getDocument()
139  oSheet = oDoc.CurrentController.ActiveSheet
140  usedArea = SheetUtils.getUsedArea(oSheet)
141  # ~oSheet.getCellRangeByPosition(0, 0, usedArea.EndColumn, usedArea.EndRow).Rows.OptimalHeight = False
142  oSheet.getCellRangeByPosition(0, 0, 1023, 1048575).Rows.OptimalHeight = False
143  oSheet.getCellRangeByPosition(0, 0, 1023, 1048575).Rows.Height = 1576
144  DLG.mri(oSheet.getCellRangeByPosition(0, 0, usedArea.EndColumn, usedArea.EndRow).Rows)
145  return
146  lr = SheetUtils.getLastUsedRow(oSheet) + 1
147  for el in reversed(range (1, lr)):
148  if oSheet.getCellByPosition(2, el).CellStyle == 'comp 1-a' and \
149  oSheet.getCellByPosition(2, el).String == '' and \
150  oSheet.getCellByPosition(9, el).String == '':
151  oSheet.getRows().removeByIndex(el, 1)
152  elif oSheet.getCellByPosition(2, el).Type.value == 'TEXT':
153  oSheet.getCellByPosition(2, el).String = '- ' + oSheet.getCellByPosition(2, el).String
154  return
155 
156 def MENU_debug():
157 
158  oDoc = LeenoUtils.getDocument()
159  oSheet = oDoc.CurrentController.ActiveSheet
160  oSheets = oDoc.Sheets.ElementNames
162  orig = oDoc.getURL()
163 
164  dest = '.'.join(os.path.basename(orig).split('.')[0:-1]) + '.pdf'
165  orig = uno.fileUrlToSystemPath(orig)
166  dir_bak = os.path.dirname(oDoc.getURL())
167  # ~DelPrintArea()
168  oDoc.storeToURL(dir_bak + '/' + dest, list())
169 
170  # ~DLG.chi(dir_bak)
171  return
172 
173 
174 def MENU_debug():
175  '''
176 
177  '''
178  DelPrintArea()
179  oDoc = LeenoUtils.getDocument()
180  # ~oProp = []
181  # ~oProp0 = PropertyValue()
182  # ~oProp0.Name = 'Overwrite'
183  # ~oProp0.Value = True
184  # ~oProp1 = PropertyValue()
185  # ~oProp1.Name = 'FilterName'
186  # ~oProp1.Value = 'calc_pdf_Export'
187  # ~oProp.append(oProp0)
188  # ~oProp.append(oProp1)
189  # ~properties = tuple(oProp)
190  # ~sUrl = "file:///W:/test.pdf"
191  # ~oDoc.storeToURL(sUrl, properties)
192 
193  # ~'crea proprietà e valori in filterData, che verranno passati a filterProps
194  filterData = []
195  filterData0 = PropertyValue()
196  filterData0.Name = "Selection"
197  filterData0.Value = oDoc.CurrentController.ActiveSheet
198  filterData1 = PropertyValue()
199  filterData1.Name = "IsAddStream"
200  filterData1.Value = True
201  filterData.append(filterData0)
202  filterData.append(filterData1)
203 
204  # ~'crea proprietà e valori in filterProps, che verranno passati alla funzione di esportazione storeToURL
205  filterProps = []
206  filterProps0 = PropertyValue()
207  filterProps0.Name = "FilterName"
208  filterProps0.Value = "calc_pdf_Export"
209  filterProps1 = PropertyValue()
210  filterProps1.Name = "FilterData"
211  filterProps1.Value = tuple(filterData)
212  filterProps.append(filterProps0)
213  filterProps.append(filterProps1)
214 
215  properties = tuple(filterProps)
216 
217  sUrl = "file:///W:/test.pdf"
218  oDoc.storeToURL(sUrl, properties)
219 def MENU_debug():
220 
221  # ~DlgPDF()
222  # ~return
223  oDoc = LeenoUtils.getDocument()
224  oSheet = oDoc.CurrentController.ActiveSheet
225  DLG.chi(len(oSheet.RowPageBreaks))
226  return
227  # ~testo = oSheet.getCellByPosition(0, 0).String
228  # ~txt = " ".join(testo.split())
229  # ~oSheet.getCellByPosition(0, 1).String = txt
230  # ~DLG.chi(txt)
231  import LeenoSettings
233  # ~LeenoSettings.MENU_JobSettings()
234  return
235  import LeenoPdf
236  # ~LeenoPdf.MENU_Pdf()
237  # ~return
238 
239  oDoc = LeenoUtils.getDocument()
240  es = LeenoPdf.loadExportSettings(oDoc)
241 
242  # ~DLG.chi(es)
243  # ~return
244 
245  # ~dlg = PdfDlg()
246  dlg = LeenoPdf.PdfDialog()
247  dlg.setData(es)
248 
249  # se premuto "annulla" non fa nulla
250  if dlg.run() < 0:
251  return
252 
253  es = dlg.getData(_EXPORTSETTINGSITEMS)
254  storeExportSettings(oDoc, es)
255 
256  # estrae la path
257  # ~destFolder = dlg['pathEdit'].getPath()
258  destFolder = 'W:\\_dwg\\ULTIMUSFREE\\_SRC'
259 
260  # ~import LeenoDialogs as DLG
261  # ~DLG.chi(destFolder)
262  # ~return
263 
264  # controlla se selezionato elenco prezzi
265  if dlg['cbElencoPrezzi'].getState():
266  PdfElencoPrezzi(destFolder, es['npElencoPrezzi'])
267 
268  # controlla se selezionato computo metrico
269  if dlg['cbComputoMetrico'].getState():
270  PdfComputoMetrico(destFolder, es['npComputoMetrico'])
271  return
272 
273  oDoc = LeenoUtils.getDocument()
274 
275  oSheets = list(oDoc.getSheets().getElementNames())
276  # ~DLG.chi(oSheets)
277  # ~DLG.chi(oSheets)
278  # ~nWidth, hItems = Dialogs.getEditBox('g')
279 
280  # ~Dialogs.FolderSelect()
281  # ~Dialogs.ListBox(Id=None, List=oSheets, Current=None)
282  # ~nWidth, hItems = Dialogs.getEditBox('aa')
283  Dialogs.ListBox.setList(self, oSheets)
284  return
285 
286  return
287  oDoc = LeenoUtils.getDocument()
288  oSheet = oDoc.CurrentController.ActiveSheet
289  lrow = LeggiPosizioneCorrente()[1]
290  rigenera_voce(lrow)
291  lrow = LeenoSheetUtils.prossimaVoce(oSheet, lrow, 1)
292 
293  # ~dispatchHelper.executeDispatch(oFrame, '.uno:DataSort', '', 0, properties)
294 
295  # ~For Each oSh In oSheets
296  # ~If oSh.Name <> "cP_Cop" and oSh.Name <> oActiveSheet Then ' and oSh.Name <> "copyright_LeenO" Then
297  # ~p = 0
298 
299  # ~' ThisComponent.CurrentController.Select(ThisComponent.Sheets.GetByName(oSh.Name).getCellByPosition(0,0))
300  # ~' oSh.IsVisible = False
301  # ~Else
302 
303  # ~Set_Area_Stampa_N("NO_messaggio")
304  # ~If oSh.Name = oActiveSheet Then
305  # ~ThisComponent.CurrentController.Select(oSh.getCellRangeByposition(0,0,getLastUsedCol(oSh),getLastUsedRow(oSh)))
306  # ~if msgbox (CHR$(10) &"Preferisci nascondere i colori?",36, "") = 6 Then ScriptPy("LeenoSheetUtils.py","SbiancaCellePrintArea")
307  # ~unSelect 'unselect ranges
308  # ~Else
309  # ~End If
310  # ~End If
311  # ~Next
312 # ~'parametri di esportazione
313  # ~dim dispatcher as Object
314  # ~dim document as Object
315  # ~document = ThisComponent.CurrentController.Frame
316  # ~dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
317 
318 
319  # ~rem ----------------------------------------------------------------------
320 import LeenoUtils
321 import LeenoEvents
322 import LeenoContab
323 
324 import LeenoImport
325 from com.sun.star.sheet.GeneralFunction import MAX
326 
327 
328 def MENU_debug():
329  testo = ''
330  suffisso = InputBox(
331  testo, t='Inserisci il suffisso per il Codice Articolo (es: "BAS22/1_").')
332  if suffisso in (None, '', ' '):
333  return
334  oDoc = LeenoUtils.getDocument()
335  oSheet = oDoc.CurrentController.ActiveSheet
336  lrow = SheetUtils.getLastUsedRow(oSheet)
337 
338  # attiva la progressbar
339  progress = Dialogs.Progress(Title='Operazione in corso...', Text="Progressione")
340  n = 0
341  progress.setLimits(n, lrow)
342  progress.show()
343  progress.setValue(0)
344  for y in range(0, lrow):
345  if oSheet.getCellByPosition(0, y).CellStyle == "EP-aS" and \
346  oSheet.getCellByPosition(0, y).String != "000":
347  oSheet.getCellByPosition(0, y).String = suffisso + oSheet.getCellByPosition(0, y).String
348  progress.setValue(y)
349  progress.hide()
350  # ~DLG.chi(oSheet.getCellByPosition(0, 3).CellBackColor)
351  return
352  oDoc = LeenoUtils.getDocument()
353  oStyleFam = oDoc.StyleFamilies
354  oTablePageStyles = oStyleFam.getByName("PageStyles")
355  oCpyStyle = oDoc.createInstance("com.sun.star.style.PageStyle")
356  # ~oTablePageStyles.insertByName('PageStyle_REGISTRO_A4', oCpyStyle)
357  stili = ("VARIANTE", "COMPUTO", "COMPUTO_print", 'Elenco Prezzi', 'CONTABILITA', 'Registro', 'SAL')
358  for el in stili:
359  try:
360  oTablePageStyles.insertByName(el, oCpyStyle)
361  except:
362  pass
363  return
364  oDoc = LeenoUtils.getDocument()
365  DLG.mri(oDoc.StyleFamilies.getByName('PageStyles')[1])
366  return
367  stili = oDoc.StyleFamilies.getByName('PageStyles').getElementNames()
368  oDoc.getStyleFamilies().loadStylesFromURL(filename, list())
369 
370  DLG.chi(stili)
371 
372  return
373 
374 
375  oColumn = oSheet.getColumns().getByIndex(23)
376  DLG.chi(int(oColumn.computeFunction(MAX)))
377  # ~i= LeenoSheetUtils.prossimaVoce(oSheet, i, saltaCat=True)
378 
379  return
380  lrow = LeggiPosizioneCorrente()[1]
381 
382  DLG.chi(oSheet.getCellRangeByName("A1").CellBackColor)
383  return
384  sistema_cose()
385  return
386 
387  return
388  oDoc = LeenoUtils.getDocument()
389  oRange = oDoc.NamedRanges.elenco_prezzi.ReferredCells.RangeAddress
390  SR = oRange.StartRow + 1
391  ER = oRange.EndRow
392  oSheet = oDoc.CurrentController.ActiveSheet
393 
394  oDoc.CurrentController.select(oSheet.getCellRangeByPosition(1, SR, 1, ER -1))
395  return
397  oSheet = oDoc.CurrentController.ActiveSheet
398  lrow = SheetUtils.getUsedArea(oSheet).EndRow + 1
399  lCol = SheetUtils.getUsedArea(oSheet).EndColumn
400  for y in reversed(range(1, lrow)):
401  if oSheet.getCellByPosition(1, y).String == "CAM":
402  oSheet.getCellByPosition(2, y).String = "CAM - " + oSheet.getCellByPosition(2, y).String
403  # ~oSheet.getRows().removeByIndex(y, 1)
404 
406 
407 
408  # ~ LeenoSheetUtils.elimina_righe_vuote()
409  # ~SheetUtils.MENU_unisci_fogli()
410  # ~DLG.chi(loVersion())
411  # ~LeenoEvents.assegna()
412 
413  return
414  # ~vista_terra_terra()
415  oDoc = LeenoUtils.getDocument()
416  oSheet = oDoc.CurrentController.ActiveSheet
417 
418  # ~DLG.mri(oSheet.getColumns().getCount())
419  DLG.mri(oSheet)
420  return
421  import LeenoPdf
422  # ~LeenoPdf.MENU_Pdf()
423 
424  dlg = LeenoPdf.PdfDialog()
425 
426  return
427  # ~LeenoSheetUtils.elimina_righe_vuote()
428  # ~sistema_cose()
429  # ~LI.MENU_emilia_romagna()
430  # ~return
431 
432 # ~'ACCODA PIù FILE DI CALC IN UNO SOLO
433  # ~Dim DocName as object, DocUlr as string, dummy()
434  # ~Doc = ThisComponent
435  # ~Sheet = Doc.Sheets(0)
436  # ~sPath ="W:/_dwg/ULTIMUSFREE/elenchi/Piemonte/2022_luglio/" ' cartella con i documenti da copiare (non ci deve essere il file destinazione con la macro
437  # ~sFileName = Dir(sPath & "*.ods", 0)
438 # ~' Barra_Apri_Chiudi_5(".......................Sto lavorando su "& sFileName, 0)
439  # ~Do While (sFileName <> "")
440  # ~c = Sheet.createCursor
441  # ~c.gotoEndOfUsedArea(false)
442  # ~LastRow = c.RangeAddress.EndRow + 1
443  # ~DocUrl = ConvertToURL(sPath & sFileName)
444 # ~'on error goto errore
445  # ~DocName = StarDesktop.loadComponentFromURL (DocUrl, "_blank",0, Dummy() )
446  # ~Sheet1 = DocName.Sheets(0) ' questo indica l'index del foglio da copiare
447  # ~c = Sheet1.createCursor
448  # ~c.gotoEndOfUsedArea(false)
449  # ~LastRow1 = c.RangeAddress.EndRow
450  # ~' oStart=uFindString("ATTENZIONE!", Sheet1)
451  # ~' Srow=oStart.RangeAddress.EndRow+1
452  # ~Srow = 2
453  # ~Range = Sheet1.getCellRangeByPosition(0, Srow, 12, LastRow1).getDataArray '(1^ colonna, 1^ riga, 10^ colonna, ultima riga)
454  # ~DocName.dispose
455  # ~dRange = Sheet.getCellRangeByPosition(0, LastRow, 12, LastRow1 + LastRow-Srow)
456  # ~dRange.setDataArray(Range)
457  # ~sFileName = Dir()
458  # ~Loop
459  # ~print "fatto!"
460  # ~errore:
461 # ~End Sub
pyleeno.sistema_cose
def sistema_cose()
Definition: pyleeno.py:8664
LeenoUtils.getDocument
def getDocument()
Definition: LeenoUtils.py:67
LeenoUtils.DocumentRefresh
def DocumentRefresh(boo)
Definition: LeenoUtils.py:109
TEST.debug_link
def debug_link()
Definition: TEST.py:2
LeenoPdf.PdfElencoPrezzi
def PdfElencoPrezzi(destFolder, nTavola)
Definition: LeenoPdf.py:174
pyleeno.set_area_stampa
def set_area_stampa()
Definition: pyleeno.py:8838
Dialogs.ListBox.setList
def setList(self, list)
Definition: Dialogs.py:1746
LeenoSheetUtils.prossimaVoce
def prossimaVoce(oSheet, lrow, n=1, saltaCat=False)
Definition: LeenoSheetUtils.py:281
LeenoPdf.PdfComputoMetrico
def PdfComputoMetrico(destFolder, nTavola)
Definition: LeenoPdf.py:199
TEST.MENU_debug
def MENU_debug()
Definition: TEST.py:114
SheetUtils.getUsedArea
def getUsedArea(oSheet)
Definition: SheetUtils.py:373
LeenoPdf.PdfDialog
def PdfDialog()
Definition: LeenoPdf.py:118
LeenoUtils.getComponentContext
def getComponentContext()
Definition: LeenoUtils.py:47
pyleeno.DelPrintArea
def DelPrintArea()
Definition: pyleeno.py:8819
Dialogs.Progress
Definition: Dialogs.py:2583
LeenoComputo.circoscriveVoceComputo
def circoscriveVoceComputo(oSheet, lrow)
Definition: LeenoComputo.py:65
pyleeno.InputBox
def InputBox(sCella='', t='')
Definition: pyleeno.py:8226
pyleeno.rigenera_voce
def rigenera_voce(lrow=None)
Definition: pyleeno.py:5644
LeenoPdf.storeExportSettings
def storeExportSettings(oDoc, es)
Definition: LeenoPdf.py:27
SheetUtils.getLastUsedRow
def getLastUsedRow(oSheet)
Definition: SheetUtils.py:392
LeenoSettings.MENU_PrintSettings
def MENU_PrintSettings()
Definition: LeenoSettings.py:277
TEST.debug_syspath
def debug_syspath()
def debug_(): ''' @ DA DOCUMENTARE ''' oDoc = LeenoUtils.getDocument() oSheet = oDoc....
Definition: TEST.py:86
LeenoPdf.loadExportSettings
def loadExportSettings(oDoc)
Definition: LeenoPdf.py:20
TEST.debug_errore
def debug_errore()
Definition: TEST.py:26
pyleeno.LeggiPosizioneCorrente
def LeggiPosizioneCorrente()
Definition: pyleeno.py:5389