LeenO computo metrico con LibreOffice  3.22.0
Il software libero per la gestione di computi metrici e contabilità lavori.
LeenoSettings.py
Vai alla documentazione di questo file.
1 '''
2 Modulo per la modifica delle impostazioni di LeenO
3 '''
4 import Dialogs
5 import LeenoConfig
6 import LeenoUtils
7 import DocUtils
8 import SheetUtils
9 
10 _JOBSETTINGSITEMS = (
11  'progetto',
12  'committente',
13  'stazioneAppaltante',
14  'rup',
15  'progettista',
16  'data',
17  'revisione',
18  'dataRevisione',
19 )
20 
21 _PRINTSETTINGSITEMS = (
22  'fileCopertine',
23  'copertina',
24  'intSx',
25  'intCenter',
26  'intDx',
27  'ppSx',
28  'ppCenter',
29  'ppDx',
30 )
31 
33 _DOCSTRINGS = (
34  '[COMMITTENTE]',
35  '[DATA]',
36  '[DATA_REVISIONE]',
37  '[DATI_COMMITTENTE]',
38  '[DATI_PROGETTISTA]',
39  '[DIRETTORE_LAVORI]',
40  '[NUMERO_DOCUMENTO]',
41  '[OGGETTO]',
42  '[PAGINA]',
43  '[PAGINE]',
44  '[PROGETTISTA]',
45  '[PROGETTO]',
46  '[REVISIONE]',
47  '[RUP]',
48  '[STAZIONE_APPALTANTE]',
49 )
50 
51 def loadJobSettings(oDoc):
52  cfg = LeenoConfig.Config()
53  data = DocUtils.loadDataBlock(oDoc, 'Lavoro')
54  if data is None or len(data) == 0:
55  data = cfg.readBlock('Lavoro', True)
56  return data
57 
59  repl = loadJobSettings(oDoc)
60  res = {}
61  for key, val in repl.items():
62  nKey = '[' + key.upper() + ']'
63  if nKey in _DOCSTRINGS:
64  # if simple substitution works, do it
65  # so, just add [ and ] around and put to uppercase
66  res[nKey] = val
67  else:
68  # no simple way, try to look for similar string
69  # inside _DOCSTRINGS, just removing _ chars
70  for v in _DOCSTRINGS:
71  vr = v.replace('_', '')
72  if vr == nKey:
73  res[v] = val
74  break
75  return res
76 
77 def storeJobSettings(oDoc, js):
78  cfg = LeenoConfig.Config()
79 
80  DocUtils.storeDataBlock(oDoc, 'Lavoro', js)
81  cfg.writeBlock('Lavoro', js, True)
82 
84  # dimensione dell'icona col punto di domanda
85  imgW = Dialogs.getBigIconSize()[0] * 3
86  fieldW, dummy = Dialogs.getTextBox("W" * 30)
87 
88  return Dialogs.Dialog(Title='Impostazioni dati lavoro', Horz=False, CanClose=True, Items=[
89  Dialogs.HSizer(Items=[
90  Dialogs.VSizer(Items=[
92  Dialogs.ImageControl(Image='Icons-Big/books.png', MinWidth=imgW),
94  ]),
96  Dialogs.VSizer(Items=[
97  Dialogs.FixedText(Text='Progetto:'),
99  Dialogs.Edit(Id="progetto", FixedWidth=fieldW),
100  Dialogs.Spacer(),
101 
102  Dialogs.FixedText(Text='Committente:'),
103  Dialogs.Spacer(),
104  Dialogs.Edit(Id="committente", FixedWidth=fieldW),
105  Dialogs.Spacer(),
106 
107  Dialogs.FixedText(Text='Stazione appaltante'),
108  Dialogs.Spacer(),
109  Dialogs.Edit(Id="stazioneAppaltante"),
110  Dialogs.Spacer(),
111 
112  Dialogs.FixedText(Text='Responsabile del procedimento'),
113  Dialogs.Spacer(),
114  Dialogs.Edit(Id="rup"),
115  Dialogs.Spacer(),
116 
117  Dialogs.FixedText(Text='Progettista'),
118  Dialogs.Spacer(),
119  Dialogs.Edit(Id="progettista"),
120  Dialogs.Spacer(),
121 
122  Dialogs.FixedText(Text='Data'),
123  Dialogs.Spacer(),
124  Dialogs.DateControl(Id="data"),
125  Dialogs.Spacer(),
126 
127  Dialogs.FixedText(Text='Revisione'),
128  Dialogs.Spacer(),
129  Dialogs.Edit(Id="revisione"),
130  Dialogs.Spacer(),
131 
132  Dialogs.FixedText(Text='Data revisione'),
133  Dialogs.Spacer(),
134  Dialogs.DateControl(Id="dataRevisione"),
135  Dialogs.Spacer(),
136  ]),
137  ]),
138  Dialogs.Spacer(),
139  Dialogs.HSizer(Items=[
140  Dialogs.Spacer(),
141  Dialogs.Button(Label='Ok', MinWidth=Dialogs.MINBTNWIDTH, Icon='Icons-24x24/ok.png', RetVal=1),
142  Dialogs.Spacer(),
143  Dialogs.Button(Label='Annulla', MinWidth=Dialogs.MINBTNWIDTH, Icon='Icons-24x24/cancel.png', RetVal=-1),
145  ])
146  ])
147 
148 
150 
151  oDoc = LeenoUtils.getDocument()
152  js = loadJobSettings(oDoc)
153 
154  dlg = JobSettingsDialog()
155  dlg.setData(js)
156 
157  if dlg.run() >= 0:
158  js = dlg.getData(_JOBSETTINGSITEMS)
159  storeJobSettings(oDoc, js)
160 
161 def fixupCover(coversPath, coverName):
162  covers = ()
163  if coversPath is not None and coversPath != '':
164  covers = SheetUtils.getSheetNames(coversPath)
165 
166  # controlla che la copertina specificata sia tra quelle disponibili
167  # (uno potrebbe aver modificato il file...)
168  if coverName in covers:
169  return covers, coverName
170  if len(covers) > 0:
171  coverName = covers[0]
172  else:
173  coverName = ''
174  return covers, coverName
175 
177  cfg = LeenoConfig.Config()
178  data = DocUtils.loadDataBlock(oDoc, 'ImpostazioniStampa')
179  if data is None or len(data) == 0:
180  data = cfg.readBlock('ImpostazioniStampa', True)
181 
182  # legge i nomi delle copertine dal file fornito, se esistente
183  covers, copertina = fixupCover(data.get('fileCopertine', ''), data.get('copertina', ''))
184 
185  data['copertina'] = copertina
186 
187  return data, covers
188 
189 def storePrintSettings(oDoc, js):
190  cfg = LeenoConfig.Config()
191 
192  DocUtils.storeDataBlock(oDoc, 'ImpostazioniStampa', js)
193  cfg.writeBlock('ImpostazioniStampa', js, True)
194 
196  # dimensione dell'icona grande
197  imgW = Dialogs.getBigIconSize()[0] * 3
198  fieldW, dummy = Dialogs.getTextBox("W" * 30)
199  posW, dummy = Dialogs.getTextBox("SinistraXX")
200 
201  return Dialogs.Dialog(Title='Impostazioni stampa / PDF', Horz=False, CanClose=True, Items=[
202  Dialogs.VSizer(Items=[
203  Dialogs.FixedText(Text='Intestazione:'),
204  Dialogs.Spacer(),
205 
206  Dialogs.HSizer(Items=[
207  Dialogs.VSizer(Items=[
208  Dialogs.FixedText(Text='Sinistra: '),
209  Dialogs.ComboBox(Id="intSx", List=_DOCSTRINGS, FixedHeight=20, MaxWidth=200),
210  ]),
211  Dialogs.Spacer(),
212  Dialogs.VSizer(Items=[
213  Dialogs.FixedText(Text='Centro: '),
214  Dialogs.ComboBox(Id="intCenter", List=_DOCSTRINGS, FixedHeight=20, MaxWidth=200),
215  ]),
216  Dialogs.Spacer(),
217  Dialogs.VSizer(Items=[
218  Dialogs.FixedText(Text='Destra: '),
219  Dialogs.ComboBox(Id="intDx", List=_DOCSTRINGS, FixedHeight=20, MaxWidth=200),
220  ]),
221  ]),
222 
223  Dialogs.Spacer(MinSize = 10),
224  Dialogs.HSizer(Items=[
225  # ~Dialogs.Spacer(),
226  Dialogs.ImageControl(Image='Icons-Big/preview.png', MinWidth=imgW * 1.5),
227  # ~Dialogs.Spacer(),
228  ]),
229  Dialogs.Spacer(MinSize = 10),
230 
231  Dialogs.FixedText(Text='Piè di pagina:'),
232  Dialogs.Spacer(),
233  Dialogs.HSizer(Items=[
234  Dialogs.VSizer(Items=[
235  # ~Dialogs.FixedText(Text='Sinistra: ', FixedWidth=posW),
236  Dialogs.FixedText(Text='Sinistra: '),
237  Dialogs.ComboBox(Id="ppSx", List=_DOCSTRINGS, FixedHeight=20, MaxWidth=200),
238  ]),
239  Dialogs.Spacer(MinSize = 10),
240  Dialogs.VSizer(Items=[
241  Dialogs.FixedText(Text='Centro: '),
242  Dialogs.ComboBox(Id="ppCenter", List=_DOCSTRINGS, FixedHeight=20, MaxWidth=200),
243  ]),
244  Dialogs.Spacer(MinSize = 10),
245  Dialogs.VSizer(Items=[
246  Dialogs.FixedText(Text='Destra: '),
247  Dialogs.ComboBox(Id="ppDx", List=_DOCSTRINGS, FixedHeight=20, MaxWidth=200),
248  ]),
249  ]),
250  ]),
251  Dialogs.Spacer(),
252  Dialogs.HSizer(Items=[
253  ]),
254  Dialogs.Spacer(),
255  Dialogs.VSizer(Items=[
256  Dialogs.FixedText(Text='Documento con le copertine: '), #FixedWidth=fieldW),
257  # ~Dialogs.Spacer(),
258  Dialogs.FileControl(Id="fileCopertine", Types='*.ods'),
259  Dialogs.Spacer(),
260  Dialogs.FixedText(Text='Selezionare copertina in uso: ', FixedHeight=25),
261  # ~Dialogs.Spacer(),
262  Dialogs.ListBox(Id='copertina'),
263  Dialogs.Spacer(MinSize = 3),
264  ]),
265  Dialogs.Spacer(),
266  Dialogs.Spacer(),
267  Dialogs.HSizer(Items=[
268  Dialogs.Spacer(),
269  Dialogs.Button(Label='Ok', MinWidth=Dialogs.MINBTNWIDTH, Icon='Icons-24x24/ok.png', RetVal=1),
270  Dialogs.Spacer(),
271  Dialogs.Button(Label='Annulla', MinWidth=Dialogs.MINBTNWIDTH, Icon='Icons-24x24/cancel.png', RetVal=-1),
272  Dialogs.Spacer(),
273  ]),
274  ])
275 
276 
278 
279  oDoc = LeenoUtils.getDocument()
280  ps, covers = loadPrintSettings(oDoc)
281 
282  dlg = PrintSettingsDialog()
283  dlg.getWidget('copertina').setList(covers)
284  dlg.setData(ps)
285 
286  if dlg.run() >= 0:
287  ps = dlg.getData(_PRINTSETTINGSITEMS)
288  storePrintSettings(oDoc, ps)
LeenoSettings.fixupCover
def fixupCover(coversPath, coverName)
Definition: LeenoSettings.py:161
SheetUtils.getSheetNames
def getSheetNames(filePath)
Definition: SheetUtils.py:137
LeenoUtils.getDocument
def getDocument()
Definition: LeenoUtils.py:67
Dialogs.Spacer
Definition: Dialogs.py:616
Dialogs.ComboBox
Definition: Dialogs.py:1783
Dialogs.ImageControl
Definition: Dialogs.py:1387
Dialogs.Edit
Definition: Dialogs.py:1065
LeenoSettings.loadPrintSettings
def loadPrintSettings(oDoc)
Definition: LeenoSettings.py:176
LeenoSettings.storePrintSettings
def storePrintSettings(oDoc, js)
Definition: LeenoSettings.py:189
LeenoSettings.PrintSettingsDialog
def PrintSettingsDialog()
Definition: LeenoSettings.py:195
Dialogs.FixedText
Definition: Dialogs.py:989
DocUtils.storeDataBlock
def storeDataBlock(oDoc, baseName, data)
Definition: DocUtils.py:56
LeenoSettings.storeJobSettings
def storeJobSettings(oDoc, js)
Definition: LeenoSettings.py:77
LeenoSettings.MENU_JobSettings
def MENU_JobSettings()
Definition: LeenoSettings.py:149
Dialogs.ListBox
Definition: Dialogs.py:1670
Dialogs.getTextBox
def getTextBox(txt)
Definition: Dialogs.py:115
Dialogs.FileControl
Definition: Dialogs.py:1186
Dialogs.HSizer
Definition: Dialogs.py:706
LeenoSettings.loadJobSettings
def loadJobSettings(oDoc)
Definition: LeenoSettings.py:51
LeenoSettings.loadPageReplacements
def loadPageReplacements(oDoc)
Definition: LeenoSettings.py:58
Dialogs.Dialog
Definition: Dialogs.py:2189
Dialogs.Button
Definition: Dialogs.py:1527
Dialogs.DateControl
Definition: Dialogs.py:1322
LeenoConfig.Config
Definition: LeenoConfig.py:26
Dialogs.VSizer
Definition: Dialogs.py:848
Dialogs.getBigIconSize
def getBigIconSize()
Definition: Dialogs.py:103
LeenoSettings.MENU_PrintSettings
def MENU_PrintSettings()
Definition: LeenoSettings.py:277
LeenoSettings.JobSettingsDialog
def JobSettingsDialog()
Definition: LeenoSettings.py:83
DocUtils.loadDataBlock
def loadDataBlock(oDoc, baseName)
Definition: DocUtils.py:65