LeenO computo metrico con LibreOffice  3.22.0
Il software libero per la gestione di computi metrici e contabilità lavori.
Dialogs.py
Vai alla documentazione di questo file.
1 """
2 Module for generating dynamic dialogs
3 i.e. dialogs that auto-adjust their layout based on contents and
4 external constraints
5 
6 Copyright 2020 by Massimo Del Fedele
7 """
8 import os
9 import inspect
10 from datetime import date
11 import uno
12 import unohelper
13 
14 from com.sun.star.style.VerticalAlignment import MIDDLE as VA_MIDDLE
15 
16 from com.sun.star.awt import Size
17 from com.sun.star.awt import XActionListener, XTextListener
18 from com.sun.star.task import XJobExecutor
19 
20 from com.sun.star.awt import XTopWindowListener
21 
22 from com.sun.star.util import MeasureUnit
23 
24 from LeenoConfig import Config
25 import LeenoUtils
26 
27 
29  ''' get current script's path '''
30  return os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
31 
32 
34  '''
35  Get Size of parent window in order to
36  be able to create a dialog on center of it
37  '''
39  serviceManager = ctx.ServiceManager
40  toolkit = serviceManager.createInstanceWithContext(
41  "com.sun.star.awt.Toolkit", ctx)
42 
43  oWindow = toolkit.getActiveTopWindow()
44  if oWindow is None:
45  oDesktop = ctx.ServiceManager.createInstanceWithContext(
46  "com.sun.star.frame.Desktop", ctx)
47  oDoc = oDesktop.getCurrentComponent()
48 
49  oView = oDoc.getCurrentController()
50  oWindow = oView.getFrame().getComponentWindow()
51  rect = oWindow.getPosSize()
52  return rect.Width, rect.Height
53 
54 
56  '''
57  Get screen size
58  '''
60  oToolkit = ctx.ServiceManager.createInstanceWithContext(
61  "com.sun.star.awt.Toolkit", ctx)
62  aWorkArea = oToolkit.WorkArea
63  nWidht = aWorkArea.Width
64  nHeight = aWorkArea.Height
65 
66  return nWidht, nHeight
67 
68 
70  '''
71  Dialog positions are scaled by weird factors
72  so we need to figure them out before proceeding
73  pix = appfont / scale
74  appfont = pix * scale
75 
76  '''
78  docframe = doc.getCurrentController().getFrame()
79  docwindow = docframe.getContainerWindow()
80 
81  sc = docwindow.convertSizeToPixel(Size(1000, 1000), MeasureUnit.APPFONT)
82 
83  return 1000.0 / float(sc.Width), 1000.0 / float(sc.Height)
84 
85 def getImageSize(Image):
86  '''
87  gets the size of a given image
88  BEWARE : SIZE IN PIXEL !
89  '''
91  serviceManager = ctx.ServiceManager
92 
93  imageModel = serviceManager.createInstance(
94  "com.sun.star.awt.UnoControlImageControlModel")
95  image = serviceManager.createInstance(
96  "com.sun.star.awt.UnoControlImageControl")
97  image.setModel(imageModel)
98  imageModel.ImageURL = uno.systemPathToFileUrl(os.path.join(getCurrentPath(), Image))
99  size = imageModel.Graphic.SizePixel
100  imageModel.dispose()
101  return size.Width, size.Height
102 
104  '''
105  Get 'best' size for a big dialog icon
106  (like the one of alert and ok dialogs)
107  '''
108  scWidth, scHeight = getScreenInfo()
109  siz = min(scWidth, scHeight)
110  siz = int(siz / 20)
111 
112  return siz, siz
113 
114 
115 def getTextBox(txt):
116  '''
117  Get the size needed to display a multiline text box
118  BEWARE : SIZE IN PIXEL !
119  '''
121  serviceManager = ctx.ServiceManager
122 
123  textModel = serviceManager.createInstance(
124  "com.sun.star.awt.UnoControlFixedTextModel")
125  text = serviceManager.createInstance(
126  "com.sun.star.awt.UnoControlFixedText")
127  text.setModel(textModel)
128  text.setText(txt)
129  size = text.getMinimumSize()
130  textModel.dispose()
131  return size.Width, size.Height
132 
133 
134 def getEditBox(txt):
135  '''
136  Get the size needed to display a multiline edit field
137  BEWARE : SIZE IN PIXEL !
138  '''
140  serviceManager = ctx.ServiceManager
141 
142  editModel = serviceManager.createInstance(
143  "com.sun.star.awt.UnoControlEditModel")
144  edit = serviceManager.createInstance(
145  "com.sun.star.awt.UnoControlEdit")
146  edit.setModel(editModel)
147  edit.setText(txt)
148  size = edit.getMinimumSize()
149  editModel.dispose()
150  return size.Width, size.Height
151 
152 
153 def getListBoxSize(items):
154  '''
155  Get the size needed to display a list box
156  BEWARE : SIZE IN PIXEL !
157  '''
159  serviceManager = ctx.ServiceManager
160 
161  textModel = serviceManager.createInstance(
162  "com.sun.star.awt.UnoControlFixedTextModel")
163  text = serviceManager.createInstance(
164  "com.sun.star.awt.UnoControlFixedText")
165  text.setModel(textModel)
166  maxW = 0
167  maxH = 0
168  for item in items:
169  text.setText(item)
170  size = text.getMinimumSize()
171  maxW = max(maxW, size.Width)
172  maxH = max(maxH, size.Height)
173  if maxH == 0:
174  text.setText('X')
175  maxH = text.getMinimumSize().Height
176  textModel.dispose()
177  return maxW, maxH
178 
179 
181  '''
182  Get the size needed to display a radio button
183  BEWARE : SIZE IN PIXEL !
184  '''
186  serviceManager = ctx.ServiceManager
187 
188  rbModel = serviceManager.createInstance(
189  "com.sun.star.awt.UnoControlRadioButtonModel")
190  rb = serviceManager.createInstance(
191  "com.sun.star.awt.UnoControlRadioButton")
192  rb.setModel(rbModel)
193  rb.setLabel(label)
194  size = rb.getMinimumSize()
195  rbModel.dispose()
196  return size.Width, size.Height
197 
198 
200  '''
201  Get the height needed to display a radio button
202  BEWARE : SIZE IN PIXEL !
203  '''
204  return getRadioButtonSize("X")[1]
205 
206 
207 def getCheckBoxSize(label):
208  '''
209  Get the size needed to display a checkbox
210  BEWARE : SIZE IN PIXEL !
211  '''
213  serviceManager = ctx.ServiceManager
214 
215  cbModel = serviceManager.createInstance(
216  "com.sun.star.awt.UnoControlCheckBoxModel")
217  cb = serviceManager.createInstance(
218  "com.sun.star.awt.UnoControlCheckBox")
219  cb.setModel(cbModel)
220  cb.setLabel(label)
221  size = cb.getMinimumSize()
222  cbModel.dispose()
223  return size.Width, size.Height
224 
225 
227  '''
228  Get the height needed to display a checkbox
229  BEWARE : SIZE IN PIXEL !
230  '''
231  return getCheckBoxSize("X")[1]
232 
233 
234 def getButtonSize(txt, Icon=None):
235  '''
236  Get 'best' button size in a dialog
237  based on text
238  '''
239  width, height = getTextBox(txt)
240  if Icon is not None:
241  width += 32
242  height = max(height, 24)
243  return width + 15, height + 15
244 
245 
247  '''
248  returns stored last used path, if any
249  otherwise returns calling document base path
250  '''
251  oPath = Config().read('Generale', 'ultimo_percorso')
252  if oPath is None:
253  oDoc = LeenoUtils.getDocument()
254  oPath = oDoc.getURL()
255  if oPath is not None and oPath != '':
256  oPath = uno.fileUrlToSystemPath(oPath)
257 
258  # be sure that we return a path
259  return os.path.join(oPath, '')
260 
261 
262 def storeLastPath(oPath):
263  '''
264  store the folder of given path item to config
265  if a file path is given, we strip the file part
266  '''
267  oPath = os.path.dirname(oPath)
268  oPath = os.path.join(oPath, '')
269  Config().write('Generale', 'ultimo_percorso', oPath)
270 
271 
272 def shortenPath(pth, width):
273  '''
274  short a path adding ... in front
275  baset on a maximum allowed field width
276  '''
277  if pth is None:
278  return pth
279 
280  # check if no need to shorten
281  #w, h = getTextBox(pth)
282  w, h = getEditBox(pth)
283  if w <= width:
284  return pth
285  n = len(pth) - 3
286  while n > 0:
287  s = '...' + pth[-n:]
288  #w, h = getTextBox(s)
289  w, h = getEditBox(s)
290  if w <= width:
291  return s
292  n -= 1
293  return '...'
294 
295 
296 MINBTNWIDTH = 100
297 
298 class DialogException(Exception):
299 
300  '''
301  Base class for all dialog exceptions
302  '''
303  pass
304 
305 
306 class AbstractError(DialogException):
307  '''
308  Try to instantiate base class DialogItem
309  '''
310  def __init__(self):
311  ''' constructor '''
312  self.message = "Can't instantiate abstract class"
313 
314 
316  ''' Error during layout calculation in dialogs '''
317 
318  def __init__(self):
319  ''' constructor '''
320  self.message = 'Layout error'
321 
322 
323 '''
324 Dialog items alignment when size is bigger than mininum one
325 '''
326 HORZ_ALIGN_LEFT = 1
327 HORZ_ALIGN_CENTER = 2
328 HORZ_ALIGN_RIGHT = 4
329 
330 VERT_ALIGN_TOP = 8
331 VERT_ALIGN_CENTER = 16
332 VERT_ALIGN_BOTTOM = 32
333 
334 MIN_SPACER_SIZE = 10
335 
336 DIALOG_BORDERS = 10
337 
338 GROUPBOX_TOP_BORDER = 25
339 GROUPBOX_BOTTOM_BORDER = 10
340 GROUPBOX_LEFT_BORDER = 10
341 GROUPBOX_RIGHT_BORDER = 10
342 
343 
344 class DialogItem(unohelper.Base, XTextListener, XActionListener):
345  '''
346  Base class for every dialog item
347  '''
348  def __init__(
349  self, Id=None,
350  MinWidth=None, MinHeight=None,
351  MaxWidth=None, MaxHeight=None,
352  FixedWidth=None, FixedHeight=None,
353  InternalHandler=None
354  ):
355  ''' constructor '''
356 
357  self._minWidth = MinWidth
358  self._minHeight = MinHeight
359 
360  self._maxWidth = MaxWidth
361  self._maxHeight = MaxHeight
362 
363  self._fixedWidth = FixedWidth
364  self._fixedHeight = FixedHeight
365 
366  self._x = 0
367  self._y = 0
368 
369  self._width = 0
370  self._height = 0
371 
372  self.align = HORZ_ALIGN_LEFT | VERT_ALIGN_TOP
373  self._id = Id
374 
375  # we support "internal" handlers for events
376  # if a control has an internal handler, it gets called when there's
377  # an interaction with the control. If the handler returns true the
378  # event is NOT propagated to main handler, otherwise it is
379  # This is done to allow to build combined widgets
380  # the handler prototype is:
381  # internalHandler(self, owner, cmdStr)
382  # where owner is the owning dialog and cmdStr is the command string
383  self._internalHandler = InternalHandler
384 
385  # we need both owning dialog and UNO widget pointers
386  # so we can act on running dialogs
387  self._owner = None
388  self._UNOControl = None
389  self._UNOControlModel = None
390 
391  def _fixup(self):
392  '''
393  to be redefined if widget needs to adapt to size changes
394  '''
395  pass
396 
397  def _adjustSize(self):
398  ''' calculate min size and adjust considering minimum, maximum and fixed ones '''
399 
400  # calculate minimum size (depending on object)
401  self._width, self._height = self.calcMinSize()
402 
403  # adjust it
404 
405  # fixed size takes precedence
406  if self._fixedWidth is not None:
407  self._width = self._fixedWidth
408  else:
409  if self._minWidth is not None:
410  self._width = max(self._width, self._minWidth)
411  if self._maxWidth is not None:
412  self._width = min(self._width, self._maxWidth)
413 
414  if self._fixedHeight is not None:
415  self._height = self._fixedHeight
416  else:
417  if self._minHeight is not None:
418  self._height = max(self._height, self._minHeight)
419  if self._maxHeight is not None:
420  self._height = min(self._height, self._maxHeight)
421 
422  return self._width, self._height
423 
424  def calcMinSize(self):
425  '''
426  gets minimum control size (from content / type)
427  MUST be defined in derived classes
428  '''
429  raise AbstractError
430 
431  def _equalizeElements(self):
432  '''
433  This one is meant for grouping controls
434  like Sizers or GroupBox
435  '''
436  pass
437 
438  def _adjustLayout(self):
439  '''
440  This one is meant for grouping controls
441  like Sizers or GroupBox
442  '''
443  pass
444 
445  def dump(self, indent):
446  '''
447  bring a string representation of object
448  '''
449  res = 4 * indent * ' ' + type(self).__name__ + ': {'
450  res += f'Id:{self._id}'
451  res += f', X:{self._x}, Y:{self._y}'
452  res += f', Width:{self._width}, Height:{self._height}'
453  if self._fixedWidth is not None:
454  res += f', fixedWidth:{self._fixedWidth}'
455  else:
456  if self._minWidth is not None:
457  res += f', minWidth:{self._minWidth}'
458  if self._maxWidth is not None:
459  res += f', maxWidth:{self._maxWidth}'
460 
461  if self._fixedHeight is not None:
462  res += f', fixedHeight:{self._fixedHeight}'
463  else:
464  if self._minHeight is not None:
465  res += f', minHeight:{self._minHeight}'
466  if self._maxHeight is not None:
467  res += f', maxHeight:{self._maxHeight}'
468 
469  return res
470 
471  def __repr__(self):
472  '''
473  convert object to string
474  '''
475  return self.dump(0)
476 
477  def getProps(self):
478  '''
479  Get control's properties (name+value)
480  to be set in UNO
481  MUST be redefined on each visible control
482  '''
483  return {}
484 
485  def _initControl(self, oControl):
486  '''
487  do some special initialization
488  (needed, for example, for droplists...)
489  '''
490  pass
491 
492  def _getModelName(self):
493  '''
494  this MUST be redefined for classes that don't use
495  the standard model naming
496  '''
497  clsName = type(self).__name__
498  return "com.sun.star.awt.UnoControl" + clsName + "Model"
499 
500  def _addUnoItems(self, owner):
501  '''
502  Add uno item(s) to owning UNO dialog
503  '''
504  dialogModel = owner._dialogModel
505  dialogContainer = owner._dialogContainer
506 
507  # create the control
508  modelName = self._getModelName()
509  oControlModel = dialogModel.createInstance(modelName)
510 
511  # still dont' know why, but we've got to scale items coordinates
512  # so get the factors
513  xScale, yScale = getScaleFactors()
514 
515  # set base properties (position, size)
516  uno.invoke(oControlModel, "setPropertyValue", ("PositionX", int(self._x * xScale)))
517  uno.invoke(oControlModel, "setPropertyValue", ("PositionY", int(self._y * yScale)))
518  uno.invoke(oControlModel, "setPropertyValue", ("Width", int(self._width * xScale)))
519  uno.invoke(oControlModel, "setPropertyValue", ("Height", int(self._height * yScale)))
520 
521  # set control's specific properties
522  props = self.getProps()
523  for key, val in props.items():
524  if val is not None:
525  uno.invoke(oControlModel, "setPropertyValue", (key, val))
526 
527  if self._id is None:
528  self._id = owner._getNextId()
529  oControlModel.Name = self._id
530 
531  # insert the control into dialog
532  dialogModel.insertByName(self._id, oControlModel)
533 
534  # store the control model and the control for running usage
535  self._UNOControlModel = oControlModel
536  self._UNOControl = dialogContainer.getControl(self._id)
537 
538  # if needed, do some special initialization
539  self._initControl(self._UNOControl)
540 
541  # store owner pointer too
542  self._owner = owner
543 
544  # setup event handlers
545  # if control doesn't accept them, just do nothing
546  try:
547  self._UNOControl.addActionListener(self)
548  except AttributeError:
549  pass
550 
551  try:
552  self._UNOControl.addTextListener(self)
553  except AttributeError:
554  pass
555 
556  def _destruct(self):
557  '''
558  removes all reference to owner and UNO widget
559  so we know that dialog is not in running state
560  '''
561  self._UNOControlModel = None
562  self._UNOControl = None
563  self._owner = None
564 
565  def actionPerformed(self, oActionEvent):
566  '''
567  EVENT HANDLER
568  an action on underlying widget happened
569  '''
570  param = self.widgetEvent(oActionEvent)
571 
572  # check if widget has an internal handler attached
573  # if it does, call the handler and stop processing if
574  # it returns True
575  if self._internalHandler is not None:
576  if self._internalHandler(self, param):
577  return
578 
579  # do the dialog level event processing
580  self._owner.actionPerformed(self, self._id, param)
581 
582  def textChanged(self, textEvent):
583  '''
584  EVENT HANDLER
585  an action on underlying widget happened
586  '''
587  param = self.widgetEvent(textEvent)
588  self.owner.actionPerformed(self, self._id, param)
589 
590  def _presetWidgets(self):
591  '''
592  NEEDED ONLY FOR LISTBOX/DROPDOWN
593  used to pre-set the dropdown content
594  must be done with dialog visible
595  '''
596  pass
597 
598  def widgetEvent(self, evt):
599  '''
600  widget event handler
601  shall do widget-dependent process for each control
602  and return a 'parameter' to send to dialog event handler
603  MUST BE REDEFINED FOR WIDGETS HANDLING EVENTS
604  '''
605  return ''
606 
607  def getData(self):
608  ''' be redefined '''
609  return None
610 
611  def setData(self, d):
612  ''' be redefined '''
613  pass
614 
615 
616 class Spacer(DialogItem):
617  ''' A virtual widget used to leave space among other widgets'''
618 
619  def __init__(self, MinSize=None):
620  ''' constructor '''
621  if MinSize is None:
622  MinSize = MIN_SPACER_SIZE
623  super().__init__(MinWidth=MinSize, MinHeight=MinSize)
624 
625  def calcMinSize(self):
626  '''
627  Calculate widget's minimum size
628  '''
629  return self._minWidth, self._minHeight
630 
631  def _addUnoItems(self, owner):
632  ''' DO NOTHING'''
633  pass
634 
635 
636 class Sizer(DialogItem):
637  '''
638  Base class for horizontal and vertical sizers
639  Every dialog MUST contain exactly one sizer
640  '''
641  def __init__(self, *, Id=None, Items):
642  ''' constructor '''
643  super().__init__(Id=Id)
644  if Items is None:
645  Items = []
646  self._items = Items
647  self._x = 0
648  self._y = 0
649  self._width = 0
650  self._height = 0
651 
652  def dump(self, indent):
653  '''
654  bring a string representation of object
655  '''
656  res = super().dump(indent) + '\n'
657  for item in self._items:
658  res += item.dump(indent + 1) + '\n'
659  res += 4 * indent * ' ' + '}'
660  return res
661 
662  def add(self, *items):
663  '''
664  Add widgets to sizer
665  '''
666  for item in items:
667  self._items.append(item)
668 
669  def _addUnoItems(self, owner):
670  '''
671  fill UNO dialog with items
672  '''
673  for item in self._items:
674  item._addUnoItems(owner)
675 
676  def _destruct(self):
677  '''
678  removes all reference to owner and UNO widget
679  so we know that dialog is not in running state
680  '''
681  for item in self._items:
682  item._destruct()
683 
684  def _presetWidgets(self):
685  for item in self._items:
686  item._presetWidgets()
687 
688  def getWidget(self, wId):
689  ''' get widget by ID'''
690  if self._id == wId:
691  return self
692  for item in self._items:
693  if hasattr(item, 'getWidget'):
694  widget = item.getWidget(wId)
695  if widget is not None:
696  return widget
697  else:
698  if wId == item._id:
699  return item
700  return None
701 
702  def __getitem__(self, key):
703  return self.getWidget(key)
704 
705 
706 class HSizer(Sizer):
707  '''
708  Horizontal sizer
709  Used to arrange controls horizontally
710  '''
711  def __init__(self, *, Id=None, Items=None):
712  ''' constructor '''
713  super().__init__(Id=Id, Items=Items)
714 
715  def calcMinSize(self):
716  '''
717  Calculate widget's minimum size
718  '''
719  w = 0
720  h = 0
721  for item in self._items:
722  # calculate min size for item
723  itemMinWidth, itemMinHeight = item._adjustSize()
724 
725  # store it to item, we'll need later on
726  item._width, item._height = itemMinWidth, itemMinHeight
727 
728  # update our size
729  w += itemMinWidth
730  h = max(h, itemMinHeight)
731  return w, h
732 
733  def _equalizeElements(self):
734  '''
735  equalize elements inside container
736  for hSizer, that means to put all of them at max height
737  '''
738  maxH = 0
739  for item in self._items:
740  maxH = max(maxH, item._height)
741  for item in self._items:
742  item._height = maxH
743  item._equalizeElements()
744  self.height = maxH
745 
746  def _adjustLayout(self):
747  u"""
748  based on requested size and (previously calculated) minimum size
749  layout contained items
750  WARNING : we need a PREVIOUS call to calcMinSize and _equalizeElements ¯on widget three
751  """
752  xOrg, yOrg = self._x, self._y
753 
754  # store previous origin, we need it later
755  curXOrg, curYOrg = xOrg, yOrg
756 
757  # get total of contained elements size
758  totW = 0
759  for item in self._items:
760  totW += item._width
761 
762  # this is an hSizer, so we shall divide horizontal spare space
763  # between items somehow. if there's some Spacer inside, divide
764  # the space among them. Oterwise divide the space among contained
765  # items based on their sizes. Not an easy task...
766  dW = self._width - totW
767  if dW > 0:
768  # count spacer items
769  nSpacers = 0
770  for item in self._items:
771  if isinstance(item, Spacer):
772  nSpacers += 1
773 
774  # it we've got spacers, divide tspaces among them
775  if nSpacers > 0:
776  # the size must contain spacer's minimum size
777  # so se add it BEFORE dividing
778  dW += nSpacers * MIN_SPACER_SIZE
779 
780  space = int(dW / nSpacers)
781  lastSpace = dW - space * (nSpacers - 1)
782  n = 0
783  for item in self._items:
784  if isinstance(item, Spacer):
785  n += 1
786  if n == nSpacers:
787  sp = lastSpace
788  else:
789  sp = space
790  item._width = sp
791  # set item position
792  item._x, item._y = curXOrg, curYOrg
793  # move to next item
794  curXOrg += sp
795  else:
796  # set item position
797  item._x, item._y = curXOrg, curYOrg
798  # move to next item
799  curXOrg += item._width
800  else:
801  # no spacers inside, we shall divide space between items
802  # but NOT for items with fixed size
803 
804  # calculate at first the ratio of items space / total space
805  widths = []
806  totw = 0
807  for item in self._items:
808  if item._fixedWidth is None:
809  totw += item._width
810  widths.append(item._width)
811  ratios = []
812  for item in widths:
813  ratios.append(item / totw)
814 
815  # now divide the space between items
816  # last space gets the remainder
817  spaceRemainder = dW
818  iItem = 0
819  for item in self._items:
820  if item._fixedWidth is None:
821  itemSpace = int(dW * ratios[iItem])
822  if iItem < len(ratios) - 1:
823  item._width += itemSpace
824  spaceRemainder -= itemSpace
825  else:
826  item._width += spaceRemainder
827  iItem += 1
828 
829  # set item position
830  item._x, item._y = curXOrg, curYOrg
831  # move to next item
832  curXOrg += item._width
833  else:
834  # no space to divide, requested size identical to minimum
835  for item in self._items:
836  # set item position
837  item._x, item._y = curXOrg, curYOrg
838  # move to next item
839  curXOrg += item._width
840 
841  # run _adjustLayout on all contained containers
842  # and fixup contents, if needed
843  for item in self._items:
844  item._adjustLayout()
845  item._fixup()
846 
847 
848 class VSizer(Sizer):
849  '''
850  Vertical sizer
851  Used to arrange controls vertically
852  '''
853  def __init__(self, *, Id=None, Items=None):
854  ''' constructor '''
855  super().__init__(Id=Id, Items=Items)
856 
857  def calcMinSize(self):
858  '''
859  Calculate widget's minimum size
860  '''
861  w = 0
862  h = 0
863  for item in self._items:
864  # calculate min size for item
865  itemMinWidth, itemMinHeight = item._adjustSize()
866 
867  # store it to item, we'll need later on
868  item._width, item._height = itemMinWidth, itemMinHeight
869 
870  # update our size
871  w = max(w, itemMinWidth)
872  h += itemMinHeight
873  return w, h
874 
875  def _equalizeElements(self):
876  '''
877  equalize elements inside container
878  for hSizer, that means to put all of them at max height
879  '''
880  maxW = 0
881  for item in self._items:
882  maxW = max(maxW, item._width)
883  for item in self._items:
884  item._width = maxW
885  item._equalizeElements()
886  self._width = maxW
887 
888  def _adjustLayout(self):
889  u"""
890  based on requested size and (previously calculated) minimum size
891  layout contained items
892  WARNING : we need a PREVIOUS call to calcMinSize and _equalizeElements ¯on widget three
893  """
894  xOrg, yOrg = self._x, self._y
895 
896  # store previous origin, we need it later
897  curXOrg, curYOrg = xOrg, yOrg
898 
899  # get total of contained elements size
900  totH = 0
901  for item in self._items:
902  totH += item._height
903 
904  # this is an hSizer, so we shall divide horizontal spare space
905  # between items somehow. if there's some Spacer inside, divide
906  # the space among them. Oterwise divide the space among contained
907  # items based on their sizes. Not an easy task...
908  dH = self._height - totH
909  if dH > 0:
910  # count spacer items
911  nSpacers = 0
912  for item in self._items:
913  if isinstance(item, Spacer):
914  nSpacers += 1
915 
916  # it we've got spacers, divide tspaces among them
917  if nSpacers > 0:
918  # the size must contain spacer's minimum size
919  # so we add it BEFORE dividing
920  dH += nSpacers * MIN_SPACER_SIZE
921 
922  space = int(dH / nSpacers)
923  lastSpace = dH - space * (nSpacers - 1)
924  n = 0
925  for item in self._items:
926  if isinstance(item, Spacer):
927  n += 1
928  if n == nSpacers:
929  sp = lastSpace
930  else:
931  sp = space
932  item._height = sp
933  # set item position
934  item._x, item._y = curXOrg, curYOrg
935  # move to next item
936  curYOrg += sp
937  else:
938  # set item position
939  item._x, item._y = curXOrg, curYOrg
940  # move to next item
941  curYOrg += item._height
942  else:
943  # no spacers inside, we shall divide space between items
944  # but NOT for items with fixed size
945 
946  # calculate at first the ratio of items space / total space
947  heights = []
948  toth = 0
949  for item in self._items:
950  if item._fixedHeight is None:
951  toth += item._height
952  heights.append(item._height)
953  ratios = []
954  for item in heights:
955  ratios.append(item / toth)
956 
957  # now divide the space between items
958  # last space gets the remainder
959  spaceRemainder = dH
960  iItem = 0
961  for item in self._items:
962  if item._fixedHeight is None:
963  itemSpace = int(dH * ratios[iItem])
964  if iItem < len(ratios) - 1:
965  item._height += itemSpace
966  spaceRemainder -= itemSpace
967  else:
968  item._height += spaceRemainder
969  iItem += 1
970 
971  # set item position
972  item._x, item._y = curXOrg, curYOrg
973  # move to next item
974  curYOrg += item._height
975  else:
976  # no space to divide, requested size identical to minimum
977  for item in self._items:
978  # set item position
979  item._x, item._y = curXOrg, curYOrg
980  # move to next item
981  curYOrg += item._height
982 
983  # run _adjustLayout on all contained containers
984  for item in self._items:
985  item._adjustLayout()
986  item._fixup()
987 
988 
990  '''
991  Fixed text box
992  Display a box of text
993  '''
994  def __init__(self, *, Id=None, Text='',
995  MinWidth=None, MinHeight=None,
996  MaxWidth=None, MaxHeight=None,
997  FixedWidth=None, FixedHeight=None,
998  Align=0,
999  TextColor=None, BackgroundColor=None,
1000  Border=0, BorderColor=None):
1001  ''' constructor '''
1002  super().__init__(Id=Id,
1003  MinWidth=MinWidth, MinHeight=MinHeight,
1004  MaxWidth=MaxWidth, MaxHeight=MaxHeight,
1005  FixedWidth=FixedWidth, FixedHeight=FixedHeight)
1006  self._text = Text
1007  self._align = Align
1008  self._textColor = TextColor
1009  self._backgroundColor = BackgroundColor
1010  self._border = Border
1011  self._borderColor = BorderColor
1012 
1013  def calcMinSize(self):
1014  '''
1015  Calculate widget's minimum size
1016  '''
1017  return getTextBox(self._text)
1018 
1019  def getProps(self):
1020  '''
1021  Get control's properties (name+value)
1022  to be set in UNO
1023  MUST be redefined on each visible control
1024  '''
1025  return {
1026  'Label': self._text,
1027  'Align': self._align,
1028  'VerticalAlign': VA_MIDDLE,
1029  'TextColor': self._textColor,
1030  'BackgroundColor': self._backgroundColor,
1031  'Border': self._border,
1032  'BorderColor': self._borderColor,
1033  }
1034 
1035  def dump(self, indent):
1036  '''
1037  convert object to string
1038  '''
1039  txt = self._text.replace("\n", "\\n")
1040  return super().dump(indent) + f", Text: '{txt}'" + '}'
1041 
1042  def setText(self, txt):
1043  self._text = txt
1044  if self._UNOControlModel is not None:
1045  self._UNOControlModel.Label = txt
1046 
1047  def getText(self):
1048  return self._text
1049 
1050  def setAlign(self, align):
1051  self._align = align
1052  if self._UNOControlModel is not None:
1053  self._UNOControlModel.Align = align
1054 
1055  def getAlign(self):
1056  return self._align
1057 
1058  def getData(self):
1059  return self.getText()
1060 
1061  def setData(self, d):
1062  self.setText(d)
1063 
1064 
1066  '''
1067  Editable text field
1068  '''
1069  def __init__(self, *, Id=None, Text='',
1070  ReadOnly=False,
1071  Align=0,
1072  MinWidth=None, MinHeight=None,
1073  MaxWidth=None, MaxHeight=None,
1074  FixedWidth=None, FixedHeight=None):
1075  ''' constructor '''
1076  super().__init__(Id=Id,
1077  MinWidth=MinWidth, MinHeight=MinHeight,
1078  MaxWidth=MaxWidth, MaxHeight=MaxHeight,
1079  FixedWidth=FixedWidth, FixedHeight=FixedHeight)
1080  self._text = Text
1081  self._readOnly = ReadOnly
1082  self._align = Align
1083 
1084  def calcMinSize(self):
1085  '''
1086  Calculate widget's minimum size
1087  '''
1088  if self._text != '':
1089  return getTextBox(self._text)
1090  else:
1091  return getTextBox('MMMMMMMMMM')
1092 
1093  def getProps(self):
1094  '''
1095  Get control's properties (name+value)
1096  to be set in UNO
1097  MUST be redefined on each visible control
1098  '''
1099  return {
1100  'Text': self._text,
1101  'Align': self._align,
1102  'VerticalAlign': VA_MIDDLE,
1103  'ReadOnly': self._readOnly,
1104  }
1105 
1106  def widgetEvent(self, evt):
1107  self._text = self._UNOControlModel.Text
1108  return self._text
1109 
1110  def dump(self, indent):
1111  '''
1112  convert object to string
1113  '''
1114  txt = self._text.replace("\n", "\\n")
1115  return super().dump(indent) + f", Text: '{txt}'" + '}'
1116 
1117  def setText(self, txt):
1118  self._text = txt
1119  if self._UNOControlModel is not None:
1120  self._UNOControlModel.Text = txt
1121 
1122  def getText(self):
1123  return self._text
1124 
1125  def getData(self):
1126  return self.getText()
1127 
1128  def setData(self, d):
1129  self.setText(d)
1130 
1132  '''
1133  Editable date field
1134  '''
1135  def __init__(self, *, Id=None, Date=date(2000, 1, 1),
1136  MinWidth=None, MinHeight=None,
1137  MaxWidth=None, MaxHeight=None,
1138  FixedWidth=None, FixedHeight=None):
1139  ''' constructor '''
1140  super().__init__(Id=Id,
1141  MinWidth=MinWidth, MinHeight=MinHeight,
1142  MaxWidth=MaxWidth, MaxHeight=MaxHeight,
1143  FixedWidth=FixedWidth, FixedHeight=FixedHeight)
1144  self.setDate(Date)
1145 
1146  def calcMinSize(self):
1147  '''
1148  Calculate widget's minimum size
1149  '''
1150  return getTextBox('99/99/9999')
1151 
1152  def getProps(self):
1153  '''
1154  Get control's properties (name+value)
1155  to be set in UNO
1156  MUST be redefined on each visible control
1157  '''
1158  return {
1159  'Date': LeenoUtils.date2UnoDate(self._date),
1160  'Align': 0,
1161  'VerticalAlign': VA_MIDDLE,
1162  }
1163 
1164  def dump(self, indent):
1165  '''
1166  convert object to string
1167  '''
1168  return super().dump(indent) + f", Date: '{self._date}'" + '}'
1169 
1170  def setDate(self, dat):
1171  self._date = dat
1172  if self._UNOControlModel is not None:
1173  d = LeenoUtils.date2UnoDate(self._date)
1174  self._UNOControlModel.Date = d
1175 
1176  def getDate(self):
1177  return self._date
1178 
1179  def getData(self):
1180  return self.getDate()
1181 
1182  def setData(self, d):
1183  self.setDate(d)
1184 
1185 
1187  '''
1188  A text field with a button
1189  used to select a file
1190  '''
1191  def __init__(self, *, Id=None, Path=None, Types="*.*",
1192  MinWidth=None, MinHeight=None,
1193  MaxWidth=None, MaxHeight=None,
1194  FixedWidth=None, FixedHeight=None,
1195  InternalHandler=None):
1196  ''' constructor '''
1197  super().__init__(Id=Id)
1198  btnIcon = 'Icons-16x16/file.png'
1199  btnWidth, btnHeight = getEditBox(' ')
1200  if Path is None or Path == '':
1201  Path = getDefaultPath()
1202  #self.add(FixedText(Text=Path))
1203  self.add(Edit(Text='', ReadOnly=True))
1204  #self.add(Button(Id='select', Icon=btnIcon, FixedWidth=btnWidth, InternalHandler=self.pathHandler))
1205  self.add(Button(Id='select', Icon=btnIcon, FixedWidth=btnWidth, FixedHeight=btnHeight, InternalHandler=self.pathHandler))
1206  self._path = Path
1207  self._types = Types
1208 
1209  def _fixup(self):
1210  txtBox = self._items[0]
1211  w = txtBox._width
1212  txtBox.setText(shortenPath(self._path, w))
1213 
1214  def getProps(self):
1215  '''
1216  Get control's properties (name+value)
1217  to be set in UNO
1218  MUST be redefined on each visible control
1219  '''
1220  return {'Text': self._path}
1221 
1222  def dump(self, indent):
1223  '''
1224  convert object to string
1225  '''
1226  pth = self._path
1227  return super().dump(indent) + f", Path: '{pth}'" + '}'
1228 
1229  # handler per il button di selezione path
1230  def pathHandler(self, owner, cmdStr):
1231  file = FileSelect(est = self._types)
1232  if file is not None:
1233  self._path = file
1234  self._fixup()
1235  # stop event processing
1236  return True
1237 
1238  def setFileTypes(self, fTypes):
1239  self._types = fTypes
1240 
1241  def setPath(self, pth):
1242  self._path = pth
1243  if self._UNOControlModel is not None:
1244  self._UNOControlModel.Text = pth
1245 
1246  def getPath(self):
1247  return self._path
1248 
1249  def getData(self):
1250  return self.getPath()
1251 
1252  def setData(self, d):
1253  self.setPath(d)
1254 
1255 
1257  '''
1258  A text field with a button
1259  used to select a path
1260  '''
1261  def __init__(self, *, Id=None, Path=None,
1262  MinWidth=None, MinHeight=None,
1263  MaxWidth=None, MaxHeight=None,
1264  FixedWidth=None, FixedHeight=None,
1265  InternalHandler=None):
1266  ''' constructor '''
1267  super().__init__(Id=Id)
1268  btnIcon = 'Icons-16x16/folder.png'
1269  btnWidth, btnHeight = getEditBox(' ')
1270  if Path is None or Path == '':
1271  Path = getDefaultPath()
1272  self.add(Edit(Text='', ReadOnly=True))
1273  # self.add(Spacer())
1274  self.add(Button(Id='select', Icon=btnIcon, FixedWidth=btnWidth, FixedHeight=btnHeight, InternalHandler=self.pathHandler))
1275  self._path = Path
1276 
1277  def _fixup(self):
1278  txtBox = self._items[0]
1279  w = txtBox._width
1280  txtBox.setText(shortenPath(self._path, w))
1281 
1282  def getProps(self):
1283  '''
1284  Get control's properties (name+value)
1285  to be set in UNO
1286  MUST be redefined on each visible control
1287  '''
1288  return {'Text': self._path}
1289 
1290  def dump(self, indent):
1291  '''
1292  convert object to string
1293  '''
1294  pth = self._path
1295  return super().dump(indent) + f", Path: '{pth}'" + '}'
1296 
1297  # handler per il button di selezione path
1298  def pathHandler(self, owner, cmdStr):
1299  folder = FolderSelect()
1300  if folder is not None:
1301  folder = os.path.join(folder, '')
1302  self._path = folder
1303  self._fixup()
1304  # stop event processing
1305  return True
1306 
1307  def setPath(self, pth):
1308  self._path = pth
1309  if self._UNOControlModel is not None:
1310  self._UNOControlModel.Text = pth
1311 
1312  def getPath(self):
1313  return self._path
1314 
1315  def getData(self):
1316  return self.getPath()
1317 
1318  def setData(self, d):
1319  self.setPath(d)
1320 
1321 
1323  '''
1324  A text field with a button
1325  used to select a date
1326  '''
1327  def __init__(self, *, Id=None, Date=None,
1328  MinWidth=None, MinHeight=None,
1329  MaxWidth=None, MaxHeight=None,
1330  FixedWidth=None, FixedHeight=None,
1331  InternalHandler=None):
1332  ''' constructor '''
1333  super().__init__(Id=Id)
1334  btnIcon = 'Icons-24x24/calendar.png'
1335  btnWidth, btnHeight = getButtonSize('', Icon=btnIcon)
1336  dateWidth, dummy = getTextBox('88 SETTEMBRE 9999XX')
1337  if Date is None:
1338  Date = date.today()
1339  self.add(Edit(Text='', ReadOnly=True, FixedWidth=dateWidth))
1340  # self.add(Spacer())
1341  self.add(Button(Id=self._id +'.select', Icon=btnIcon, FixedWidth=btnWidth, InternalHandler=self.dateHandler))
1342  self._date = Date
1343 
1344  def _fixup(self):
1345  txtBox = self._items[0]
1346  txtBox.setText(LeenoUtils.date2String(self._date))
1347 
1348  def getProps(self):
1349  '''
1350  Get control's properties (name+value)
1351  to be set in UNO
1352  MUST be redefined on each visible control
1353  '''
1354  return {'Text': LeenoUtils.date2String(self._date)}
1355 
1356  def dump(self, indent):
1357  '''
1358  convert object to string
1359  '''
1360  dat = self._date
1361  return super().dump(indent) + f", Date: '{LeenoUtils.date2String(dat)}'" + '}'
1362 
1363  # handler per il button di selezione data
1364  def dateHandler(self, owner, cmdStr):
1365  nDate = pickDate(self._date)
1366  if nDate is not None:
1367  self._date = nDate
1368  self._fixup()
1369  # stop event processing
1370  return True
1371 
1372  def setDate(self, dat):
1373  self._date = dat
1374  if self._UNOControlModel is not None:
1376 
1377  def getDate(self):
1378  return self._date
1379 
1380  def getData(self):
1381  return self.getDate()
1382 
1383  def setData(self, d):
1384  self.setDate(d)
1385 
1386 
1388  '''
1389  Fixed image
1390  Display an image
1391  '''
1392  def __init__(self, *, Id=None, Image,
1393  MinWidth=None, MinHeight=None,
1394  MaxWidth=None, MaxHeight=None,
1395  FixedWidth=None, FixedHeight=None,
1396  InternalHandler=None):
1397  ''' constructor '''
1398 
1399  # for images we do some smart sizing here...
1400  iW, iH = getImageSize(Image)
1401  ratio = iH / iW
1402 
1403  # take minimum sizes as the "true" minimum
1404  if MinWidth is not None:
1405  minH = int(MinWidth * ratio)
1406  if MinHeight is None or MinHeight < minH:
1407  MinHeight = minH
1408  elif MinHeight is not None:
1409  MinWidth = int(MinHeight / ratio)
1410 
1411  # take maximum sizes as the "true" maximum
1412  if MaxWidth is not None:
1413  maxH = int(MaxWidth * ratio)
1414  if MaxHeight is None or MaxHeight > maxH:
1415  MaxHeight = maxH
1416  elif MaxHeight is not None:
1417  MaxWidth = int(MaxHeight / ratio)
1418 
1419  super().__init__(Id=Id,
1420  MinWidth=MinWidth, MinHeight=MinHeight,
1421  MaxWidth=MaxWidth, MaxHeight=MaxHeight,
1422  FixedWidth=FixedWidth, FixedHeight=FixedHeight,
1423  InternalHandler = InternalHandler)
1424  self._image = Image
1425 
1426 
1427  def calcMinSize(self):
1428  '''
1429  Calculate widget's minimum size
1430  '''
1431  return getBigIconSize()
1432 
1433  def getProps(self):
1434  '''
1435  Get control's properties (name+value)
1436  to be set in UNO
1437  MUST be redefined on each visible control
1438  '''
1439  return {
1440  "Border": 0,
1441  "ImageURL": uno.systemPathToFileUrl(os.path.join(getCurrentPath(), self._image)),
1442  "ScaleImage": True,
1443  "ScaleMode": 1
1444  }
1445 
1446  def dump(self, indent):
1447  '''
1448  convert object to string
1449  '''
1450  return super().dump(indent) + f", Image: '{self._image}'" + '}'
1451 
1452 
1454  '''
1455  ProgressBar
1456  Display a ProgressBar
1457  '''
1458  def __init__(self, *, Id=None, MinVal=0, MaxVal=100, Value=0,
1459  MinWidth=None, MinHeight=None,
1460  MaxWidth=None, MaxHeight=None,
1461  FixedWidth=None, FixedHeight=None,
1462  InternalHandler=None):
1463  ''' constructor '''
1464  super().__init__(Id=Id,
1465  MinWidth=MinWidth, MinHeight=MinHeight,
1466  MaxWidth=MaxWidth, MaxHeight=MaxHeight,
1467  FixedWidth=FixedWidth, FixedHeight=FixedHeight,
1468  InternalHandler = InternalHandler)
1469  self._minVal = MinVal
1470  self._maxVal = MaxVal
1471  self._value = Value
1472 
1473  def calcMinSize(self):
1474  '''
1475  Calculate widget's minimum size
1476  '''
1477  # try to get an "optimal" size from current window
1478  pW, pH = getParentWindowSize()
1479  Width = int(2 * pW / 3)
1480 
1481  # correct the width just to be not too small nor too big
1482  ws, hs = getScreenInfo()
1483  if Width < ws / 8:
1484  Width = int(ws / 8)
1485  elif Width > ws / 4:
1486  Width = int(ws / 4)
1487 
1488  return Width, 20
1489 
1490  def getProps(self):
1491  '''
1492  Get control's properties (name+value)
1493  to be set in UNO
1494  MUST be redefined on each visible control
1495  '''
1496  res = {
1497  "ProgressValueMin": self._minVal,
1498  "ProgressValueMax": self._maxVal,
1499  "ProgressValue": self._value}
1500  return res
1501 
1502  def dump(self, indent):
1503  '''
1504  convert object to string
1505  '''
1506  return super().dump(indent) + '}'
1507 
1508  def setLimits(self, minVal, maxVal):
1509  self._minVal = minVal
1510  self._maxVal = maxVal
1511  if self._UNOControlModel is not None:
1512  self._UNOControlModel.ProgressValueMin = minVal
1513  self._UNOControlModel.ProgressValueMax = maxVal
1514 
1515  def getLimits(self):
1516  return self._minVal, self._maxVal
1517 
1518  def setValue(self, val):
1519  self._value = val
1520  if self._UNOControlModel is not None:
1521  self._UNOControlModel.ProgressValue = val
1522 
1523  def getValue(self):
1524  return self._value
1525 
1526 
1528  '''
1529  Push button
1530  Display a push button which reacts to presses
1531  If 'RetVal' is given, button closes the dialog and returns this value
1532  If 'RetVal' is None, button DOESN'T close the dialog, but external handler is called
1533  '''
1534  def __init__(self, *, Id=None, Label='', RetVal=None, Icon=None,
1535  MinWidth=None, MinHeight=None,
1536  MaxWidth=None, MaxHeight=None,
1537  FixedWidth=None, FixedHeight=None,
1538  Align=0,
1539  TextColor=None, BackgroundColor=None,
1540  InternalHandler=None):
1541  ''' constructor '''
1542  if Id is None:
1543  Id = Label
1544  super().__init__(Id=Id,
1545  MinWidth=MinWidth, MinHeight=MinHeight,
1546  MaxWidth=MaxWidth, MaxHeight=MaxHeight,
1547  FixedWidth=FixedWidth, FixedHeight=FixedHeight,
1548  InternalHandler = InternalHandler)
1549  self._label = Label
1550  self._retVal = RetVal
1551  self._icon = Icon
1552  self._textColor = TextColor
1553  self._backgroundColor = BackgroundColor
1554 
1555  def calcMinSize(self):
1556  '''
1557  Calculate widget's minimum size
1558  '''
1559  return getButtonSize(self._label, self._icon)
1560 
1561  def getProps(self):
1562  '''
1563  Get control's properties (name+value)
1564  to be set in UNO
1565  MUST be redefined on each visible control
1566  '''
1567  res = {'Label': self._label}
1568  if self._icon is not None:
1569  res['ImageAlign'] = 0
1570  res['ImageURL'] = uno.systemPathToFileUrl(os.path.join(getCurrentPath(), self._icon))
1571 
1572  if self._textColor is not None:
1573  res['TextColor'] = self._textColor
1574  if self._backgroundColor is not None:
1575  res['BackgroundColor'] = self._backgroundColor
1576  return res
1577 
1578  def widgetEvent(self, evt):
1579  return 'OnClick'
1580 
1581  def dump(self, indent):
1582  '''
1583  convert object to string
1584  '''
1585  res = super().dump(indent)
1586  res += f", Label: '{self._label}'"
1587  res += f", Icon: '{self._icon}'" + '}'
1588  return res
1589 
1590  def setLabel(self, lbl):
1591  self._label = lbl
1592  if self._UNOControlModel is not None:
1593  self._UNOControlModel.Label = lbl
1594 
1595  def getLabel(self):
1596  return self._label
1597 
1598  def getData(self):
1599  return self.getLabel()
1600 
1601  def setData(self, d):
1602  self.setLabel(d)
1603 
1604 
1606  '''
1607  Checkbox
1608  Display a check box (aka option)
1609  '''
1610  def __init__(self, *, Id=None, Label='aLabel', State=False,
1611  MinWidth=None, MinHeight=None,
1612  MaxWidth=None, MaxHeight=None,
1613  FixedWidth=None, FixedHeight=None,
1614  InternalHandler=None):
1615  ''' constructor '''
1616  super().__init__(Id=Id,
1617  MinWidth=MinWidth, MinHeight=MinHeight,
1618  MaxWidth=MaxWidth, MaxHeight=MaxHeight,
1619  FixedWidth=FixedWidth, FixedHeight=FixedHeight,
1620  InternalHandler = InternalHandler)
1621  self._label = Label
1622  self._state = State
1623 
1624  def calcMinSize(self):
1625  '''
1626  Calculate widget's minimum size
1627  '''
1628  return getCheckBoxSize(self._label)
1629 
1630  def getProps(self):
1631  '''
1632  Get control's properties (name+value)
1633  to be set in UNO
1634  MUST be redefined on each visible control
1635  '''
1636  return {
1637  'Label': self._label,
1638  'State': int(self._state),
1639  'VerticalAlign': VA_MIDDLE,
1640  }
1641 
1642  def widgetEvent(self, evt):
1643  self._state = True if self._UNOControlModel.State else False
1644  return "OnChange"
1645 
1646  def setState(self, state):
1647  self._state = state
1648  if self._UNOControlModel:
1649  self._UNOControlModel.State = self._state
1650 
1651  def getState(self):
1652  return self._state
1653 
1654  def dump(self, indent):
1655  '''
1656  convert object to string
1657  '''
1658  res = super().dump(indent)
1659  res += f", Label: '{self._label}'"
1660  res += f", State: '{self._state}'"
1661  return res
1662 
1663  def getData(self):
1664  return self.getState()
1665 
1666  def setData(self, d):
1667  self.setState(d)
1668 
1669 
1671  '''
1672  ListBox
1673  Display a list of strings
1674  '''
1675  def __init__(self, *, Id=None, List=None, Current=None,
1676  MinWidth=None, MinHeight=None,
1677  MaxWidth=None, MaxHeight=None,
1678  FixedWidth=None, FixedHeight=None,
1679  InternalHandler=None):
1680  ''' constructor '''
1681  super().__init__(Id=Id,
1682  MinWidth=MinWidth, MinHeight=MinHeight,
1683  MaxWidth=MaxWidth, MaxHeight=MaxHeight,
1684  FixedWidth=FixedWidth, FixedHeight=FixedHeight,
1685  InternalHandler = InternalHandler)
1686  self._current = Current
1687  self.setList(List)
1688 
1689  def calcMinSize(self):
1690  '''
1691  Calculate widget's minimum size
1692  '''
1693  return getListBoxSize(self._list)
1694 
1695  def getProps(self):
1696  '''
1697  Get control's properties (name+value)
1698  to be set in UNO
1699  MUST be redefined on each visible control
1700  '''
1701  return {
1702  'Dropdown': True, # lista a cascata
1703  'Border': 2,
1704  }
1705 
1706  def _initControl(self, oControl):
1707  '''
1708  do some special initialization
1709  (needed, for example, for droplists...)
1710  '''
1711  oControl.DropDownLineCount = 10
1712  oControl.MultipleMode = False # selezione multipla
1713  self.setList(self._list)
1714 
1715  def _presetWidgets(self):
1716  '''
1717  NEEDED ONLY FOR LISTBOX/DROPDOWN
1718  used to pre-set the dropdown content
1719  must be done with dialog visible
1720  '''
1721  self.setCurrent(self._current)
1722 
1723 
1724  def widgetEvent(self, evt):
1725  ''' an action on underlying widget happened '''
1726  self._current = evt.ActionCommand
1727  return self._current
1728 
1729  def setCurrent(self, curr):
1730  self._current= curr
1731  if self._UNOControl:
1732  self._UNOControl.selectItem(self._current, True)
1733 
1734  def getCurrent(self):
1735  return self._current
1736 
1737  def dump(self, indent):
1738  '''
1739  convert object to string
1740  '''
1741  res = super().dump(indent)
1742  res += f", Items: '{self._list}'"
1743  res += f", Current: '{self._current}'"
1744  return res
1745 
1746  def setList(self, list):
1747  if list is None:
1748  list = ()
1749  if type(list) == set:
1750  self._list = tuple(list)
1751  else:
1752  self._list = list
1753  if self._current not in list:
1754  if len(list) > 0:
1755  self._current = list[0]
1756  else:
1757  self._current = ''
1758  if self._current in list:
1759  itemIndex = list.index(self._current)
1760  else:
1761  itemIndex = -1
1762  if self._UNOControl is not None:
1763  count = self._UNOControl.getItemCount()
1764  if count > 0:
1765  self._UNOControl.removeItems(0, count)
1766  pos = 0
1767  for item in self._list:
1768  self._UNOControl.addItem(item, pos)
1769  pos += 1
1770  self._UNOControl.selectItem(self._current, True)
1771  self._UNOControl.makeVisible(itemIndex)
1772 
1773  def getList(self):
1774  return self._list
1775 
1776  def getData(self):
1777  return self.getCurrent()
1778 
1779  def setData(self, d):
1780  self.setCurrent(d)
1781 
1782 
1784  '''
1785  ListBox
1786  Display a list of strings
1787  '''
1788  def __init__(self, *, Id=None, List=None, Current=None,
1789  MinWidth=None, MinHeight=None,
1790  MaxWidth=None, MaxHeight=None,
1791  FixedWidth=None, FixedHeight=None,
1792  InternalHandler=None):
1793  ''' constructor '''
1794  super().__init__(Id=Id,
1795  MinWidth=MinWidth, MinHeight=MinHeight,
1796  MaxWidth=MaxWidth, MaxHeight=MaxHeight,
1797  FixedWidth=FixedWidth, FixedHeight=FixedHeight,
1798  InternalHandler = InternalHandler)
1799  self._current = Current
1800  self.setList(List)
1801 
1802  def calcMinSize(self):
1803  '''
1804  Calculate widget's minimum size
1805  '''
1806  return getListBoxSize(self._list)
1807 
1808  def getProps(self):
1809  '''
1810  Get control's properties (name+value)
1811  to be set in UNO
1812  MUST be redefined on each visible control
1813  '''
1814  return {
1815  'Dropdown': True,
1816  'Border': 2,
1817  }
1818 
1819  def _initControl(self, oControl):
1820  '''
1821  do some special initialization
1822  (needed, for example, for droplists...)
1823  '''
1824  oControl.DropDownLineCount = 10
1825  self.setList(self._list)
1826 
1827  def widgetEvent(self, evt):
1828  ''' an action on underlying widget happened '''
1829  self._current = self._UNOControlModel.Text
1830  return self._current
1831 
1832  def setCurrent(self, curr):
1833  self._current= curr
1834  if self._UNOControlModel:
1835  self._UNOControlModel.setText(curr)
1836 
1837  def getCurrent(self):
1838  return self._current
1839 
1840  def dump(self, indent):
1841  '''
1842  convert object to string
1843  '''
1844  res = super().dump(indent)
1845  res += f", Items: '{self._list}'"
1846  res += f", Current: '{self._current}'"
1847  return res
1848 
1849  def setList(self, list):
1850  if list is None:
1851  list = ()
1852  if type(list) == set:
1853  self._list = tuple(list)
1854  else:
1855  self._list = list
1856  if self._UNOControl is not None:
1857  count = self._UNOControl.getItemCount()
1858  if count > 0:
1859  self._UNOControl.removeItems(0, count)
1860  pos = 0
1861  for item in self._list:
1862  self._UNOControl.addItem(item, pos)
1863  pos += 1
1864  self._UNOControl.setText(self._current)
1865 
1866  def getList(self):
1867  return self._list
1868 
1869  def getData(self):
1870  return self.getCurrent()
1871 
1872  def setData(self, d):
1873  self.setCurrent(d)
1874 
1875 
1877  '''
1878  Radio button
1879  Display a radio button connected with others
1880  '''
1881  def __init__(self, *, Id=None, Label='aLabel',
1882  MinWidth=None, MinHeight=None,
1883  MaxWidth=None, MaxHeight=None,
1884  FixedWidth=None, FixedHeight=None,
1885  InternalHandler=None):
1886  ''' constructor '''
1887  super().__init__(Id=Id,
1888  MinWidth=MinWidth, MinHeight=MinHeight,
1889  MaxWidth=MaxWidth, MaxHeight=MaxHeight,
1890  FixedWidth=FixedWidth, FixedHeight=FixedHeight,
1891  InternalHandler = InternalHandler)
1892  self._label = Label
1893 
1894  def calcMinSize(self):
1895  '''
1896  Calculate widget's minimum size
1897  '''
1898  return getRadioButtonSize(self._label)
1899 
1900  def getProps(self):
1901  '''
1902  Get control's properties (name+value)
1903  to be set in UNO
1904  MUST be redefined on each visible control
1905  '''
1906  return {
1907  'Label': self._label
1908  }
1909 
1910  def widgetEvent(self, evt):
1911  ''' an action on underlying widget happened '''
1912  # our id should be in form of 'RadioButton_radiogroupID_buttonNumber
1913  # so we split it
1914  dest = self._id.split('_')
1915  if len(dest) != 3 or dest[0] != 'RadioGroup':
1916  return ''
1917  groupId = dest[1]
1918  radioItem = int(dest[2])
1919  group = self._owner.getWidget(groupId)
1920  return group.widgetEvent(radioItem)
1921 
1922  def dump(self, indent):
1923  '''
1924  convert object to string
1925  '''
1926  res = super().dump(indent)
1927  res += f", Label: '{self._label}'"
1928  return res
1929 
1930 
1932  '''
1933  Radio group
1934  Groups a sequence of radio buttons
1935  It has no label not border, if those are required
1936  you shall insert it into a GroupBox item
1937  '''
1938  def __init__(self, *, Id=None, Horz=False, Items=None, Default=0):
1939  ''' constructor '''
1940  super().__init__(Id=Id)
1941  if Items is None:
1942  Items = []
1943  self._items = Items
1944  if Default is None:
1945  Default = 0
1946  elif Default >= len(Items):
1947  Default = len(Items) - 1
1948  if Default < 0:
1949  Default = 0
1950  self._default = Default
1951  self._current = Default
1952  if Horz:
1953  self._sizer = HSizer()
1954  else:
1955  self._sizer = VSizer()
1956 
1957  # as Id can be None now, and we dont' have a reference to Dialog object
1958  # we can't setup the buttons ids, which are composed
1959  # by box id + '_' + button index.
1960  # We'll do it later when constructing the UNO dialog
1961  for item in self._items:
1962  self._sizer.add(RadioButton(Label=item))
1963  self._sizer._x, self._sizer._y = 0, 0
1964  self._x, self._y = 0, 0
1965  self._width, self._height = 0, 0
1966 
1967  def calcMinSize(self):
1968  '''
1969  Calculate widget's minimum size
1970  '''
1971  return self._sizer.calcMinSize()
1972 
1973  def _equalizeElements(self):
1974  '''
1975  Equalize all elements sizes in Sizer
1976  '''
1977  self._sizer._equalizeElements()
1978 
1979  def _adjustLayout(self):
1980  '''
1981  Adjust layout of contained Sizer
1982  '''
1983  self._sizer._x = self._x
1984  self._sizer._y = self._y
1985  self._sizer._adjustLayout()
1986 
1987  def add(self, *items):
1988  ''' add elements to group '''
1989  for item in items:
1990  self._items.append(item)
1991 
1992  def _addUnoItems(self, owner):
1993  '''
1994  fill UNO dialog with items
1995  '''
1996  self._owner = owner
1997 
1998  # fix Id, if it's None
1999  # we need it to handle buttons
2000  if self._id is None:
2001  self._id = owner._getNextId()
2002  # adjust buttons ids - they must follow
2003  # the schema "RadioGroup_rgID_buttonIdx
2004  # so we can handle the events
2005  curId = 0
2006  for item in self._sizer._items:
2007  item._id = 'RadioGroup_' + self._id + '_' + str(curId)
2008  curId += 1
2009 
2010  # now add the radio buttons
2011  self._sizer._addUnoItems(owner)
2012 
2013  # select current item
2014  self.setCurrent(self._current)
2015 
2016  def _destruct(self):
2017  '''
2018  removes all reference to owner and UNO widget
2019  so we know that dialog is not in running state
2020  '''
2021  self._sizer._destruct()
2022 
2023  def widgetEvent(self, param):
2024 
2025  # param is the button number, here
2026  # already extracted by button handler
2027  self._current = param
2028 
2029  return param
2030 
2031  def getWidget(self, wId):
2032  ''' gets widget by Id '''
2033  if self._id == wId:
2034  return self
2035  return self._sizer.getWidget(wId)
2036 
2037  def __getitem__(self, key):
2038  return self.getWidget(key)
2039 
2040  def getProps(self):
2041  '''
2042  Get control's properties (name+value)
2043  to be set in UNO
2044  MUST be redefined on each visible control
2045  '''
2046  return None
2047 
2048  def getCount(self):
2049  ''' get number of radio buttons '''
2050  return len(self._sizer._items)
2051 
2052  def getCurrent(self):
2053  '''
2054  gets the currently active radio button index
2055  starting from 0
2056  '''
2057  return self._current
2058 
2059  def setCurrent(self, current):
2060  '''
2061  sets the currently active radio button index
2062  if dialog is displaying, set also the widget on it
2063  '''
2064  self._current = current
2065  if self._owner is not None:
2066  idx = 0
2067  for item in self._sizer._items:
2068  item._UNOControlModel.State = idx == current
2069  idx += 1
2070 
2071  def dump(self, indent):
2072  '''
2073  bring a string representation of object
2074  '''
2075  res = super().dump(indent) + '\n'
2076  for item in self._sizer._items:
2077  res += item.dump(indent + 1) + '\n'
2078  res += 4 * indent * ' ' + '}'
2079  return res
2080 
2081  def getData(self):
2082  return self.getCurrent()
2083 
2084  def setData(self, d):
2085  self.setCurrent(d)
2086 
2087 
2089  '''
2090  Group box
2091  Display a box with optional border and label
2092  Used mostly to group items
2093  In behaviour is similar to Dialog
2094  '''
2095  def __init__(self, *, Id=None, Label='aLabel', Horz=False, Items=None):
2096  ''' constructor '''
2097  super().__init__(Id=Id)
2098  self._label = Label
2099  if Horz:
2100  self._sizer = HSizer(Items=Items)
2101  else:
2102  self._sizer = VSizer(Items=Items)
2103  self._sizer._x, self._sizer._y = GROUPBOX_LEFT_BORDER, GROUPBOX_TOP_BORDER
2104  self._x, self._y = 0, 0
2105  self._width, self._height = 0, 0
2106 
2107  def calcMinSize(self):
2108  '''
2109  Calculate widget's minimum size
2110  '''
2111  wl, hl = getTextBox(self._label)
2112  ws, hs = self._sizer.calcMinSize()
2113  return (
2114  max(wl, ws + GROUPBOX_LEFT_BORDER + GROUPBOX_RIGHT_BORDER),
2115  max(hl, hs + GROUPBOX_TOP_BORDER + GROUPBOX_BOTTOM_BORDER))
2116 
2117  def _equalizeElements(self):
2118  '''
2119  Equalize all elements sizes in Sizer
2120  '''
2121  self._sizer._equalizeElements()
2122 
2123  def _adjustLayout(self):
2124  '''
2125  Adjust layout of contained Sizer
2126  '''
2127  self._sizer._x = self._x + GROUPBOX_LEFT_BORDER
2128  self._sizer._y = self._y + GROUPBOX_TOP_BORDER
2129  self._sizer._adjustLayout()
2130 
2131  def add(self, *items):
2132  ''' add elements to group '''
2133  for item in items:
2134  self._sizer._items.append(item)
2135 
2136  def _addUnoItems(self, owner):
2137  '''
2138  fill UNO dialog with items
2139  '''
2140  super()._addUnoItems(owner)
2141  self._sizer._addUnoItems(owner)
2142 
2143  def _destruct(self):
2144  '''
2145  removes all reference to owner and UNO widget
2146  so we know that dialog is not in running state
2147  '''
2148  super()._destruct()
2149  self._sizer._destruct()
2150 
2151  def getWidget(self, wId):
2152  ''' gets widget by Id '''
2153  if self._id == wId:
2154  return self
2155  return self._sizer.getWidget(wId)
2156 
2157  def __getitem__(self, key):
2158  return self.getWidget(key)
2159 
2160  def getProps(self):
2161  '''
2162  Get control's properties (name+value)
2163  to be set in UNO
2164  MUST be redefined on each visible control
2165  '''
2166  return {
2167  'Label': self._label
2168  }
2169 
2170  def getAction(self):
2171  '''
2172  Gets a string representing the action on the control
2173  This string will be sent to event handler along with control name
2174  If the value returned is None or an empty string, no action will be performed
2175  '''
2176  return None
2177 
2178  def dump(self, indent):
2179  '''
2180  bring a string representation of object
2181  '''
2182  res = super().dump(indent) + '\n'
2183  for item in self._sizer._items:
2184  res += item.dump(indent + 1) + '\n'
2185  res += 4 * indent * ' ' + '}'
2186  return res
2187 
2188 
2189 class Dialog(unohelper.Base, XJobExecutor, XTopWindowListener):
2190  '''
2191  Main dialog class
2192  '''
2193  def __init__(self, *, Title='', Horz=False, Handler=None, CanClose=True, Items=None):
2194  ''' constructor '''
2195  unohelper.Base.__init__(self)
2196  self._title = Title
2197  if Horz:
2198  self._sizer = HSizer(Items=Items)
2199  else:
2200  self._sizer = VSizer(Items=Items)
2201  self._sizer._x, self._sizer._y = DIALOG_BORDERS, DIALOG_BORDERS
2202  self._x, self._y = 0, 0
2203  self._width, self._height = 0, 0
2204  self._handler = Handler
2205  self._canClose = CanClose
2206  self._showing = False
2207  self._retVal = None
2208 
2209  self._nextId = 0
2210 
2211  def _layout(self):
2212  '''
2213  Optimize widget's placement inside dialog based on
2214  constraints, sizers and spacers
2215  '''
2216  # first, calculate minimum size for ALL widgets on widget tree
2217  # and adjust it on constraints
2218  self._sizer._adjustSize()
2219 
2220  # equalize all container's elements
2221  self._sizer._equalizeElements()
2222 
2223  self._sizer._adjustLayout()
2224  self._width = self._sizer._width + 2 * DIALOG_BORDERS
2225  self._height = self._sizer._height + 2 * DIALOG_BORDERS
2226 
2227  def add(self, *items):
2228  ''' add elements to dialog '''
2229  for item in items:
2230  self._sizer._items.append(item)
2231 
2232  def dump(self):
2233  '''
2234  convert object to string
2235  '''
2236  res = f'Dialog: {{X:{self._x}, Y:{self._y}'
2237  res += f' , Width:{self._width}, Height:{self._height}\n'
2238  res += self._sizer.dump(1) + "\n"
2239  res += "}"
2240  return res
2241 
2242  def __repr__(self):
2243  '''
2244  convert object to string
2245  '''
2246  return self.dump()
2247 
2248  def _getNextId(self):
2249  ''' gets next free Id '''
2250  self._nextId += 1
2251  return str(self._nextId)
2252 
2253  def _construct(self):
2254  '''
2255  build internal dialog's UNO structures
2256  '''
2257  self._nextId = 0
2258 
2259  # Optimize widget's placement inside dialog based on
2260  # constraints, sizers and spacers
2261  self._layout()
2262 
2263  # we try to place the dialog bar at center of parent window
2264  pW, pH = getParentWindowSize()
2265  self._x = int((pW - self._width) / 2)
2266  self._y = int((pH - self._height) / 2)
2267 
2268  # create UNO dialog
2270  self._serviceManager = self._localContext.ServiceManager
2271  self._toolkit = self._serviceManager.createInstanceWithContext(
2272  "com.sun.star.awt.Toolkit", self._localContext)
2273 
2274  # create dialog model and set its properties properties
2275  self._dialogModel = self._serviceManager.createInstance(
2276  "com.sun.star.awt.UnoControlDialogModel")
2277 
2278  xScale, yScale = getScaleFactors()
2279  self._dialogModel.PositionX = int(self._x * xScale)
2280  self._dialogModel.PositionY = int(self._y * yScale)
2281  self._dialogModel.Width = int(self._width * xScale)
2282  self._dialogModel.Height = int(self._height * yScale)
2283 
2284  self._dialogModel.Name = "Default"
2285  self._dialogModel.Moveable = True
2286  self._dialogModel.Title = self._title
2287  self._dialogModel.DesktopAsParent = False
2288 
2289  # setup the Closeable flag to False
2290  # this makes the dialog impossible to close clicking on X
2291  # on top bar or pressing escape; this MUST be done in
2292  # windowClosing handler
2293  self._dialogModel.Closeable = False
2294 
2295  # create the dialog container and set our dialog model into it
2296  self._dialogContainer = self._serviceManager.createInstanceWithContext(
2297  "com.sun.star.awt.UnoControlDialog", self._localContext)
2298 
2299  self._dialogContainer.setModel(self._dialogModel)
2300 
2301  self._showing = False
2302 
2303  # fill UNO dialog with items
2304  self._sizer._addUnoItems(self)
2305 
2306  # add close listener
2307  self._dialogContainer.addTopWindowListener(self)
2308 
2309  def _destruct(self):
2310  '''
2311  Resets internal pointers to UNO objects
2312  so we'll be able to know if dialog is running or not
2313  '''
2314  self._sizer._destruct()
2315 
2316  # fondamentale per poter recuperare correttamente
2317  # il parent quando il dialogo viene chiuso...
2318  self._dialogContainer.dispose()
2319 
2320  def _presetWidgets(self):
2321  self._sizer._presetWidgets()
2322 
2323  def windowClosing(self, evt):
2324  '''
2325  We didn't find a way to stop closing here, so we use the
2326  Closeable property of DialogModel to disallow closing
2327  Here we just catch the closing op to set return value
2328  Even if Closeable is set to False, this hook gets called
2329  '''
2330  if self._canClose:
2331  self._dialogContainer.endDialog(-1)
2332  self._retVal = -1
2333  self._showing = False
2334 
2335  def actionPerformed(self, widget, widgetId, param):
2336  '''
2337  internal event handler
2338  will call a provided external event handler
2339  '''
2340  # if we've got an handler, we process the command inside it
2341  # and if returning True we close the dialog
2342  # if no handler or returning false, we process the event from here
2343  if self._handler is not None:
2344  if self._handler(self, widgetId, widget, param):
2345  return
2346 
2347  if widget is None:
2348  return
2349 
2350  if hasattr(widget, '_retVal') and widget._retVal is not None:
2351  self.stop(widget._retVal)
2352 
2353  def run(self):
2354  '''
2355  Runs the dialog and wait for completion
2356  '''
2357  # constructs the dialog
2358  self._construct()
2359 
2360  # execute it
2361  # signal that we showed the dialog
2362  self._showing = True
2363 
2364  self._dialogContainer.setVisible(True)
2365  self._dialogContainer.createPeer(self._toolkit, None)
2366 
2367  # some widgets, in my case ListBox, can't be preset with the dialog
2368  # still not constructed. So we do a sort of finalization here
2369  # awful, but no other way found
2370  self._presetWidgets()
2371 
2372  self._dialogContainer.execute()
2373 
2374  self._showing = False
2375 
2376  self._destruct()
2377 
2378  return self._retVal
2379 
2380  def stop(self, RetVal=None):
2381  '''
2382  Stops the dialog
2383  Shall be called from inside an handler
2384  '''
2385  if RetVal is not None:
2386  self._retVal = RetVal
2387  self._showing = False
2388  self._dialogContainer.endExecute()
2389 
2390  def show(self):
2391  '''
2392  Shows the dialog without waiting for completion
2393  '''
2394  # constructs the dialog
2395  self._construct()
2396 
2397  self._showing = True
2398  self._dialogContainer.setVisible(True)
2399 
2400  def hide(self):
2401  '''
2402  Hide the dialog
2403  '''
2404  self._dialogContainer.setVisible(False)
2405  self._showing = False
2406 
2407  self._destruct()
2408 
2409  def getWidget(self, wId):
2410  ''' get widget by ID'''
2411  return self._sizer.getWidget(wId)
2412 
2413  def __getitem__(self, key):
2414  return self.getWidget(key)
2415 
2416  def showing(self):
2417  return self._showing
2418 
2419  def getValue(self):
2420  return self._retVal
2421 
2422  def setData(self, data):
2423  ''' use a dictionary to fillup dialog data '''
2424  for key, val in data.items():
2425  widget = self.getWidget(key)
2426  if widget is not None:
2427  widget.setData(val)
2428  else:
2429  print(f"Widget with Id='{key}' not found")
2430 
2431  def getData(self, fields):
2432  '''
2433  retrieve all data fields with names in 'fields'
2434  return a dictionary
2435  '''
2436  res = {}
2437  for key in fields:
2438  widget = self.getWidget(key)
2439  val = widget.getData()
2440  res[key] = val
2441  return res
2442 
2443 
2444 
2447 
2448 def FileSelect(titolo='Scegli il file...', est='*.*', mode=0, startPath=None):
2449  """
2450  titolo { string } : titolo del FilePicker
2451  est { string } : filtro di visualizzazione file
2452  mode { integer } : modalità di gestione del file
2453 
2454  Apri file: `mode in(0, 6, 7, 8, 9)`
2455  Salva file: `mode in(1, 2, 3, 4, 5, 10)`
2456  see:('''http://api.libreoffice.org/docs/idl/ref/
2457  namespacecom_1_1sun_1_1star_1_1ui_1_1
2458  dialogs_1_1TemplateDescription.html''' )
2459  see:('''http://stackoverflow.com/questions/30840736/
2460  libreoffice-how-to-create-a-file-dialog-via-python-macro''')
2461  """
2462  estensioni = {'*.*': 'Tutti i file(*.*)',
2463  '*.odt': 'Writer(*.odt)',
2464  '*.ods': 'Calc(*.ods)',
2465  '*.odb': 'Base(*.odb)',
2466  '*.odg': 'Draw(*.odg)',
2467  '*.odp': 'Impress(*.odp)',
2468  '*.odf': 'Math(*.odf)',
2469  '*.xpwe': 'Primus(*.xpwe)',
2470  '*.xml': 'XML(*.xml)',
2471  '*.dat': 'dat(*.dat)', }
2472  oFilePicker = LeenoUtils.createUnoService("com.sun.star.ui.dialogs.FilePicker")
2473  oFilePicker.initialize((mode, ))
2474 
2475  # try to get path from current document, if any
2476  # if not, look into config to fetch last used one
2477  if startPath is None:
2478  oPath = getDefaultPath()
2479  else:
2480  oPath = startPath
2481  oPath = os.path.join(oPath, '')
2482  oPath = uno.systemPathToFileUrl(oPath)
2483  oFilePicker.setDisplayDirectory(oPath)
2484 
2485  oFilePicker.Title = titolo
2486  app = estensioni.get(est)
2487  oFilePicker.appendFilter(app, est)
2488  if oFilePicker.execute():
2489  oPath = uno.fileUrlToSystemPath(oFilePicker.getFiles()[0])
2490  storeLastPath(oPath)
2491  return oPath
2492  return None
2493 
2494 
2495 def FolderSelect(titolo='Scegli la cartella...', startPath=None):
2496  """
2497  titolo { string } : titolo del FolderPicker
2498  """
2499  oFolderPicker = LeenoUtils.createUnoService("com.sun.star.ui.dialogs.FolderPicker")
2500 
2501  # try to get path from current document, if any
2502  # if not, look into config to fetch last used one
2503  if startPath is None:
2504  oPath = getDefaultPath()
2505  else:
2506  oPath = startPath
2507  oPath = os.path.join(oPath, '')
2508  oPath = uno.systemPathToFileUrl(oPath)
2509  oFolderPicker.setDisplayDirectory(oPath)
2510 
2511  oFolderPicker.Title = titolo
2512  if oFolderPicker.execute():
2513  oPath = uno.fileUrlToSystemPath(oFolderPicker.getDirectory())
2514  oPath = os.path.join(oPath, '')
2515  storeLastPath(oPath)
2516  return oPath
2517  return None
2518 
2519 
2520 def NotifyDialog(*, Image, Title, Text):
2521  dlg = Dialog(Title=Title, Horz=False, CanClose=True, Items=[
2522  HSizer(Items=[
2523  ImageControl(Image=Image),
2524  Spacer(),
2525  FixedText(Text=Text)
2526  ]),
2527  Spacer(),
2528  HSizer(Items=[
2529  Spacer(),
2530  Button(Label='Ok', Icon='Icons-24x24/ok.png', MinWidth=MINBTNWIDTH, RetVal=1),
2531  Spacer()
2532  ])
2533  ])
2534  return dlg.run()
2535 
2536 def Exclamation(*, Title='', Text=''):
2537  return NotifyDialog(Image='Icons-Big/exclamation.png', Title=Title, Text=Text)
2538 
2539 def Info(*, Title='', Text=''):
2540  return NotifyDialog(Image='Icons-Big/info.png', Title=Title, Text=Text)
2541 
2542 def Ok(*, Title='', Text=''):
2543  return NotifyDialog(Image='Icons-Big/ok.png', Title=Title, Text=Text)
2544 
2545 def YesNoDialog(*, Title, Text):
2546  dlg = Dialog(Title=Title, Horz=False, CanClose=False, Items=[
2547  HSizer(Items=[
2548  ImageControl(Image='Icons-Big/question.png'),
2549  Spacer(),
2550  FixedText(Text=Text)
2551  ]),
2552  Spacer(),
2553  HSizer(Items=[
2554  Spacer(),
2555  Button(Label='Si', Icon='Icons-24x24/ok.png', MinWidth=MINBTNWIDTH, RetVal=1),
2556  Spacer(),
2557  Button(Label='No', MinWidth=MINBTNWIDTH, RetVal=0),
2558  Spacer()
2559  ])
2560  ])
2561  return dlg.run()
2562 
2563 def YesNoCancelDialog(*, Title, Text):
2564  dlg = Dialog(Title=Title, Horz=False, CanClose=True, Items=[
2565  HSizer(Items=[
2566  ImageControl(Image='Icons-Big/question.png'),
2567  Spacer(),
2568  FixedText(Text=Text)
2569  ]),
2570  Spacer(),
2571  HSizer(Items=[
2572  Spacer(),
2573  Button(Label='Si', Icon='Icons-24x24/ok.png', MinWidth=MINBTNWIDTH, RetVal=1),
2574  Spacer(),
2575  Button(Label='No', MinWidth=MINBTNWIDTH, RetVal=0),
2576  Spacer(),
2577  Button(Label='Annulla', Icon='Icons-24x24/cancel.png', MinWidth=MINBTNWIDTH, RetVal=-1),
2578  Spacer()
2579  ])
2580  ])
2581  return dlg.run()
2582 
2583 class Progress:
2584  '''
2585  Display a progress bar with some options
2586  '''
2587  def __init__(self, *, Title='', Closeable=False, MinVal=0, MaxVal=100, Value=0, Text=''):
2588  ''' constructor '''
2589  self._dlg = Dialog(
2590  Title=Title, Horz=False, CanClose=Closeable,
2591  Handler=lambda dialog, widgetId, widget, cmdStr :
2592  self._dlgHandler(dialog, widgetId, widget, cmdStr)
2593  )
2594  self._progress = ProgressBar(MinVal=MinVal, MaxVal=MaxVal, Value=Value)
2595  self._dlg.add(self._progress)
2596  self._text = Text
2597  if Text is not None:
2598  self._textWidget = FixedText(Text=Text)
2599  self._dlg.add(self._textWidget)
2600 
2601  if Closeable:
2602  self._dlg.add(Spacer())
2603  self._dlg.add(
2604  HSizer(Items=[
2605  Spacer(),
2606  Button(Label='Annulla', MinWidth=MINBTNWIDTH, RetVal=-1),
2607  Spacer()
2608  ])
2609  )
2610 
2611  def _dlgHandler(self, dialog, widgetId, widget, cmdStr):
2612  self._dlg.hide()
2613 
2614  def show(self):
2615  self._dlg.show()
2616 
2617  def hide(self):
2618  self._dlg.hide()
2619 
2620  def showing(self):
2621  return self._dlg.showing()
2622 
2623  def setLimits(self, pMin, pMax):
2624  self._progress.setLimits(pMin, pMax)
2625 
2626  def getLimits(self):
2627  return self._progress.getLimits()
2628 
2629  def setValue(self, val):
2630  self._progress.setValue(val)
2631  if self._text is not None and self._textWidget is not None:
2632  minVal, maxVal = self.getLimits()
2633  percent = '{:.0f}%'.format(100 * (val - minVal) / (maxVal - minVal))
2634  txt = self._text + ' (' + percent + ')'
2635  self._textWidget.setText(txt)
2636 
2637  def getValue(self):
2638  return self._progress.getValue()
2639 
2640  def setText(self, txt):
2641  self._text = txt
2642  if self._text is not None and self._textWidget is not None:
2643  minVal, maxVal = self.getLimits()
2644  val = self.getValue()
2645  percent = '{:.0f}%'.format(100 * (val - minVal) / (maxVal - minVal))
2646  txt = self._text + ' (' + percent + ')'
2647  self._textWidget.setText(txt)
2648 
2649 def MultiButton(*, Icon=None, Title='', Text='', Buttons=None):
2650  if Buttons is None:
2651  return None
2652  top = HSizer()
2653  if Icon is not None:
2654  top.add(ImageControl(Image=Icon))
2655  top.add(Spacer())
2656  top.add(FixedText(Text=Text))
2657  bottom = HSizer()
2658  idx = 0
2659  for label, value in Buttons.items():
2660  bottom.add(Button(Label=label, MinWidth=MINBTNWIDTH, RetVal=value))
2661  if idx < len(Buttons) - 1:
2662  bottom.add(Spacer())
2663  idx += 1
2664  dlg = Dialog(Title=Title, Items=[top, Spacer(), bottom])
2665  return dlg.run()
2666 
2667 
2668 def YesNo(*, Title='', Text='', CanClose=True):
2669  '''
2670  Yes/No dialog
2671  by default (CanClose=True) dialog may be dismissed
2672  closing it on topbar or pressing escape, with result 'No'
2673  '''
2674  res = MultiButton(
2675  Icon="Icons-Big/question.png",
2676  Title=Title, Text=Text, CanClose=CanClose,
2677  Buttons={'Si':'si', 'No':'no'}
2678  )
2679  if res == -1:
2680  res = 'no'
2681  return res
2682 
2683 def YesNoCancel(*, Title='', Text=''):
2684  '''
2685  Yes/No/Cancel dialog
2686  by default (CanClose=True) dialog may be dismissed
2687  closing it on topbar or pressing escape, with result 'No'
2688  '''
2689  res = MultiButton(
2690  Icon="Icons-Big/question.png",
2691  Title=Title, Text=Text, CanClose=True,
2692  Buttons={'Si':'si', 'No':'no', 'Annulla':-1}
2693  )
2694  if res == -1:
2695  res = 'annulla'
2696  return res
2697 
2698 
2699 def pickDate(curDate=None):
2700  '''
2701  Allow to pick a date from a calendar
2702  '''
2703  if curDate is None:
2704  curDate = date.today()
2705 
2706  def rgb(r, g, b):
2707  return 256*256*r + 256*g + b
2708 
2709 
2710  btnWidth, btnHeight = getButtonSize('<<')
2711  dateWidth, dummy = getTextBox('88 SETTEMBRE 8888XX')
2712 
2713  workdaysBkColor = rgb(38, 153, 153)
2714  workdaysFgColor = rgb(255, 255, 255)
2715  holydaysBkColor = rgb(27, 248, 250)
2716  holydaysFgColor = rgb(0, 0, 0)
2717 
2718  # create daynames list with spacers
2719  dayNamesLabels = [FixedText(
2720  Text=LeenoUtils.DAYNAMES[0], Align=1,
2721  BackgroundColor=rgb(38, 153, 153),
2722  TextColor=rgb(255, 255, 255),
2723  FixedWidth=btnWidth, FixedHeight=btnHeight
2724  )]
2725  for day in LeenoUtils.DAYNAMES[1:]:
2726  dayNamesLabels.append(Spacer())
2727  dayNamesLabels.append(
2728  FixedText(Text=day, Align=1,
2729  BackgroundColor=workdaysBkColor if day not in ('Sab', 'Dom') else holydaysBkColor,
2730  TextColor=workdaysFgColor if day not in ('Sab', 'Dom') else holydaysFgColor,
2731  FixedWidth=btnWidth, FixedHeight=btnHeight
2732  )
2733  )
2734 
2735  def mkDayLabels():
2736  monthDay = 1
2737  weeks = []
2738  for week in range(0, 5):
2739  items = []
2740  id = str(week) + '.0'
2741  items.append(Button(
2742  Id=id, Label=str(monthDay),
2743  BackgroundColor=workdaysBkColor,
2744  TextColor=workdaysFgColor,
2745  FixedWidth=btnWidth, FixedHeight=btnHeight
2746  ))
2747  monthDay += 1
2748  for day in range(1, 7):
2749  items.append(Spacer())
2750  id = str(week) + '.' + str(day)
2751  items.append(Button(
2752  Id=id, Label=str(monthDay),
2753  BackgroundColor=workdaysBkColor if day not in (5, 6) else holydaysBkColor,
2754  TextColor=workdaysFgColor if day not in (5, 6) else holydaysFgColor,
2755  FixedWidth=btnWidth, FixedHeight=btnHeight
2756  ))
2757  monthDay += 1
2758  weeks.append(HSizer(Items=items))
2759  weeks.append(Spacer())
2760  return weeks
2761 
2762  def loadDate(dlg, dat):
2763  day = - LeenoUtils.firstWeekDay(dat) + 1
2764  days = LeenoUtils.daysInMonth(dat)
2765  for week in range(0, 5):
2766  for wDay in range(0, 7):
2767  id = str(week) + '.' + str(wDay)
2768  if day <= 0 or day > days:
2769  dlg[id].setLabel('')
2770  else:
2771  dlg[id].setLabel(str(day))
2772  day += 1
2773 
2774  dlg['date'].setText(LeenoUtils.date2String(dat))
2775 
2776  def handler(dlg, widgetId, widget, cmdStr):
2777  nonlocal curDate
2778  if widgetId == 'prevYear':
2779  curDate = date(year=curDate.year-1, month=curDate.month, day=curDate.day)
2780  elif widgetId == 'prevMonth':
2781  month = curDate.month - 1
2782  if month < 1:
2783  month = 12
2784  year = curDate.year - 1
2785  else:
2786  year = curDate.year
2787  curDate = date(year=year, month=month, day=curDate.day)
2788  elif widgetId == 'nextMonth':
2789  month = curDate.month + 1
2790  if month > 12:
2791  month = 1
2792  year = curDate.year + 1
2793  else:
2794  year = curDate.year
2795  curDate = date(year=year, month=month, day=curDate.day)
2796  elif widgetId == 'nextYear':
2797  curDate = date(year=curDate.year+1, month=curDate.month, day=curDate.day)
2798  elif widgetId == 'today':
2799  curDate = date.today()
2800  elif '.' in widgetId:
2801  txt = widget.getLabel()
2802  if txt == '':
2803  return
2804  day = int(txt)
2805  curDate = date(year=curDate.year, month=curDate.month, day=day)
2806  else:
2807  return
2808  loadDate(dlg, curDate)
2809 
2810  dlg = Dialog(Title='Selezionare la data', Horz=False, CanClose=True, Handler=handler, Items=[
2811  HSizer(Items=[
2812  Button(Id='prevYear', Icon='Icons-24x24/leftdbl.png'),
2813  Spacer(),
2814  Button(Id='prevMonth', Icon='Icons-24x24/leftsng.png'),
2815  Spacer(),
2816  FixedText(Id='date', Text='99 Settembre 9999', Align=1, FixedWidth=dateWidth),
2817  Spacer(),
2818  Button(Id='nextMonth', Icon='Icons-24x24/rightsng.png'),
2819  Spacer(),
2820  Button(Id='nextYear', Icon='Icons-24x24/rightdbl.png'),
2821  ]),
2822  Spacer(),
2823  HSizer(Items=dayNamesLabels),
2824  Spacer()
2825  ] + mkDayLabels() + [
2826  Spacer(),
2827  HSizer(Items=[
2828  Spacer(),
2829  Button(Label='Ok', MinWidth=MINBTNWIDTH, Icon='Icons-24x24/ok.png', RetVal=1),
2830  Spacer(),
2831  Button(Id='today', Label='Oggi', MinWidth=MINBTNWIDTH),
2832  Spacer(),
2833  Button(Label='Annulla', MinWidth=MINBTNWIDTH, Icon='Icons-24x24/cancel.png', RetVal=-1),
2834  Spacer()
2835  ])
2836  ])
2837 
2838  loadDate(dlg, curDate)
2839  if dlg.run() < 0:
2840  return None
2841  return curDate
Dialogs.ImageControl.__init__
def __init__(self, *Id=None, Image, MinWidth=None, MinHeight=None, MaxWidth=None, MaxHeight=None, FixedWidth=None, FixedHeight=None, InternalHandler=None)
Definition: Dialogs.py:1392
Dialogs.Dialog.getData
def getData(self, fields)
Definition: Dialogs.py:2431
Dialogs.GroupBox._label
_label
Definition: Dialogs.py:2098
Dialogs.CheckBox._label
_label
Definition: Dialogs.py:1617
Dialogs.GroupBox.getAction
def getAction(self)
Definition: Dialogs.py:2170
Dialogs.Edit.dump
def dump(self, indent)
Definition: Dialogs.py:1110
Dialogs.Sizer.dump
def dump(self, indent)
Definition: Dialogs.py:652
Dialogs.Sizer.add
def add(self, *items)
Definition: Dialogs.py:662
Dialogs.Button._icon
_icon
Definition: Dialogs.py:1545
Dialogs.Progress._progress
_progress
Definition: Dialogs.py:2594
Dialogs.Progress._text
_text
Definition: Dialogs.py:2596
Dialogs.DialogItem.setData
def setData(self, d)
Definition: Dialogs.py:611
Dialogs.PathControl.getData
def getData(self)
Definition: Dialogs.py:1315
Dialogs.Dialog.add
def add(self, *items)
Definition: Dialogs.py:2227
Dialogs.ProgressBar
Definition: Dialogs.py:1453
Dialogs.Edit._align
_align
Definition: Dialogs.py:1077
Dialogs.AbstractError.message
message
Definition: Dialogs.py:312
Dialogs.DateField.getData
def getData(self)
Definition: Dialogs.py:1179
Dialogs.DialogItem.calcMinSize
def calcMinSize(self)
Definition: Dialogs.py:424
Dialogs.CheckBox.dump
def dump(self, indent)
Definition: Dialogs.py:1654
Dialogs.DateField._date
_date
Definition: Dialogs.py:1171
Dialogs.Button.setLabel
def setLabel(self, lbl)
Definition: Dialogs.py:1590
Dialogs.FixedText._backgroundColor
_backgroundColor
Definition: Dialogs.py:1003
Dialogs.Dialog._serviceManager
_serviceManager
Definition: Dialogs.py:2270
Dialogs.DialogItem._minWidth
_minWidth
Definition: Dialogs.py:351
Dialogs.FixedText._borderColor
_borderColor
Definition: Dialogs.py:1005
Dialogs.DateField
Definition: Dialogs.py:1131
Dialogs.RadioGroup._items
_items
Definition: Dialogs.py:1943
Dialogs.Button._backgroundColor
_backgroundColor
Definition: Dialogs.py:1547
Dialogs.ComboBox.dump
def dump(self, indent)
Definition: Dialogs.py:1840
Dialogs.ImageControl._image
_image
Definition: Dialogs.py:1420
Dialogs.FolderSelect
def FolderSelect(titolo='Scegli la cartella...', startPath=None)
Definition: Dialogs.py:2495
Dialogs.RadioGroup.dump
def dump(self, indent)
Definition: Dialogs.py:2071
Dialogs.Ok
def Ok(*Title='', Text='')
Definition: Dialogs.py:2542
Dialogs.Button.getData
def getData(self)
Definition: Dialogs.py:1598
Dialogs.FixedText._align
_align
Definition: Dialogs.py:1001
Dialogs.DialogItem.__init__
def __init__(self, Id=None, MinWidth=None, MinHeight=None, MaxWidth=None, MaxHeight=None, FixedWidth=None, FixedHeight=None, InternalHandler=None)
Definition: Dialogs.py:348
Dialogs.FileControl.getProps
def getProps(self)
Definition: Dialogs.py:1214
Dialogs.ComboBox.getCurrent
def getCurrent(self)
Definition: Dialogs.py:1837
Dialogs.Dialog.dump
def dump(self)
Definition: Dialogs.py:2232
Dialogs.getRadioButtonSize
def getRadioButtonSize(label)
Definition: Dialogs.py:180
Dialogs.RadioGroup.getCount
def getCount(self)
Definition: Dialogs.py:2048
Dialogs.DialogItem.getProps
def getProps(self)
Definition: Dialogs.py:477
Dialogs.Button.calcMinSize
def calcMinSize(self)
Definition: Dialogs.py:1555
Dialogs.FixedText._border
_border
Definition: Dialogs.py:1004
Dialogs.FileControl.setData
def setData(self, d)
Definition: Dialogs.py:1252
Dialogs.FixedText.setText
def setText(self, txt)
Definition: Dialogs.py:1042
Dialogs.Dialog.showing
def showing(self)
Definition: Dialogs.py:2416
Dialogs.ComboBox.calcMinSize
def calcMinSize(self)
Definition: Dialogs.py:1802
Dialogs.Spacer.__init__
def __init__(self, MinSize=None)
Definition: Dialogs.py:619
LeenoUtils.getDocument
def getDocument()
Definition: LeenoUtils.py:67
Dialogs.Spacer
Definition: Dialogs.py:616
Dialogs.LayoutError.message
message
Definition: Dialogs.py:320
Dialogs.Sizer._items
_items
Definition: Dialogs.py:646
Dialogs.PathControl
Definition: Dialogs.py:1256
Dialogs.Progress.__init__
def __init__(self, *Title='', Closeable=False, MinVal=0, MaxVal=100, Value=0, Text='')
Definition: Dialogs.py:2587
Dialogs.Dialog._localContext
_localContext
Definition: Dialogs.py:2269
Dialogs.Dialog._handler
_handler
Definition: Dialogs.py:2204
Dialogs.PathControl.setPath
def setPath(self, pth)
Definition: Dialogs.py:1307
Dialogs.LayoutError
Definition: Dialogs.py:315
Dialogs.PathControl.dump
def dump(self, indent)
Definition: Dialogs.py:1290
Dialogs.RadioButton.dump
def dump(self, indent)
Definition: Dialogs.py:1922
Dialogs.Dialog.windowClosing
def windowClosing(self, evt)
Definition: Dialogs.py:2323
Dialogs.getCheckBoxSize
def getCheckBoxSize(label)
Definition: Dialogs.py:207
Dialogs.DialogItem._UNOControlModel
_UNOControlModel
Definition: Dialogs.py:383
Dialogs.FileControl.setFileTypes
def setFileTypes(self, fTypes)
Definition: Dialogs.py:1238
Dialogs.RadioGroup.setData
def setData(self, d)
Definition: Dialogs.py:2084
Dialogs.RadioGroup.getCurrent
def getCurrent(self)
Definition: Dialogs.py:2052
Dialogs.PathControl.__init__
def __init__(self, *Id=None, Path=None, MinWidth=None, MinHeight=None, MaxWidth=None, MaxHeight=None, FixedWidth=None, FixedHeight=None, InternalHandler=None)
Definition: Dialogs.py:1261
Dialogs.YesNo
def YesNo(*Title='', Text='', CanClose=True)
Definition: Dialogs.py:2668
Dialogs.DateControl.getDate
def getDate(self)
Definition: Dialogs.py:1377
Dialogs.ComboBox
Definition: Dialogs.py:1783
Dialogs.Dialog._retVal
_retVal
Definition: Dialogs.py:2207
Dialogs.Dialog.__init__
def __init__(self, *Title='', Horz=False, Handler=None, CanClose=True, Items=None)
Definition: Dialogs.py:2193
Dialogs.FileControl.getData
def getData(self)
Definition: Dialogs.py:1249
Dialogs.DialogItem._height
_height
Definition: Dialogs.py:364
Dialogs.ComboBox._list
_list
Definition: Dialogs.py:1853
Dialogs.DialogItem._fixup
def _fixup(self)
Definition: Dialogs.py:391
Dialogs.ImageControl
Definition: Dialogs.py:1387
Dialogs.Dialog._construct
def _construct(self)
Definition: Dialogs.py:2253
Dialogs.DialogItem._x
_x
Definition: Dialogs.py:360
Dialogs.RadioGroup._current
_current
Definition: Dialogs.py:1951
Dialogs.DialogItem._minHeight
_minHeight
Definition: Dialogs.py:352
Dialogs.ListBox.setList
def setList(self, list)
Definition: Dialogs.py:1746
Dialogs.getScaleFactors
def getScaleFactors()
Definition: Dialogs.py:69
Dialogs.Dialog._width
_width
Definition: Dialogs.py:2224
Dialogs.Dialog.run
def run(self)
Definition: Dialogs.py:2353
Dialogs.Edit
Definition: Dialogs.py:1065
Dialogs.DialogException
Definition: Dialogs.py:298
Dialogs.ComboBox.getProps
def getProps(self)
Definition: Dialogs.py:1808
Dialogs.ProgressBar.dump
def dump(self, indent)
Definition: Dialogs.py:1502
Dialogs.ProgressBar.__init__
def __init__(self, *Id=None, MinVal=0, MaxVal=100, Value=0, MinWidth=None, MinHeight=None, MaxWidth=None, MaxHeight=None, FixedWidth=None, FixedHeight=None, InternalHandler=None)
Definition: Dialogs.py:1458
Dialogs.Button.getLabel
def getLabel(self)
Definition: Dialogs.py:1595
Dialogs.DateControl.dateHandler
def dateHandler(self, owner, cmdStr)
Definition: Dialogs.py:1364
Dialogs.Dialog._title
_title
Definition: Dialogs.py:2196
Dialogs.DateField.calcMinSize
def calcMinSize(self)
Definition: Dialogs.py:1146
Dialogs.Dialog._nextId
_nextId
Definition: Dialogs.py:2209
Dialogs.Button._textColor
_textColor
Definition: Dialogs.py:1546
Dialogs.RadioGroup.getData
def getData(self)
Definition: Dialogs.py:2081
Dialogs.RadioGroup.calcMinSize
def calcMinSize(self)
Definition: Dialogs.py:1967
Dialogs.FixedText.dump
def dump(self, indent)
Definition: Dialogs.py:1035
Dialogs.FixedText
Definition: Dialogs.py:989
Dialogs.ListBox.dump
def dump(self, indent)
Definition: Dialogs.py:1737
Dialogs.HSizer.calcMinSize
def calcMinSize(self)
Definition: Dialogs.py:715
Dialogs.RadioButton.calcMinSize
def calcMinSize(self)
Definition: Dialogs.py:1894
Dialogs.Dialog.__getitem__
def __getitem__(self, key)
Definition: Dialogs.py:2413
Dialogs.GroupBox.dump
def dump(self, indent)
Definition: Dialogs.py:2178
Dialogs.ListBox.__init__
def __init__(self, *Id=None, List=None, Current=None, MinWidth=None, MinHeight=None, MaxWidth=None, MaxHeight=None, FixedWidth=None, FixedHeight=None, InternalHandler=None)
Definition: Dialogs.py:1675
Dialogs.DateControl.getData
def getData(self)
Definition: Dialogs.py:1380
Dialogs.ListBox.setCurrent
def setCurrent(self, curr)
Definition: Dialogs.py:1729
Dialogs.getListBoxSize
def getListBoxSize(items)
Definition: Dialogs.py:153
Dialogs.DialogItem._internalHandler
_internalHandler
Definition: Dialogs.py:377
Dialogs.Progress.setValue
def setValue(self, val)
Definition: Dialogs.py:2629
Dialogs.CheckBox.widgetEvent
def widgetEvent(self, evt)
Definition: Dialogs.py:1642
Dialogs.ListBox.getProps
def getProps(self)
Definition: Dialogs.py:1695
Dialogs.ImageControl.dump
def dump(self, indent)
Definition: Dialogs.py:1446
Dialogs.YesNoCancel
def YesNoCancel(*Title='', Text='')
Definition: Dialogs.py:2683
Dialogs.Dialog.hide
def hide(self)
Definition: Dialogs.py:2400
Dialogs.ListBox._list
_list
Definition: Dialogs.py:1750
Dialogs.RadioGroup
Definition: Dialogs.py:1931
Dialogs.RadioGroup.__init__
def __init__(self, *Id=None, Horz=False, Items=None, Default=0)
Definition: Dialogs.py:1938
Dialogs.DialogItem.__repr__
def __repr__(self)
Definition: Dialogs.py:471
Dialogs.LayoutError.__init__
def __init__(self)
Definition: Dialogs.py:318
Dialogs.getRadioButtonHeight
def getRadioButtonHeight()
Definition: Dialogs.py:199
Dialogs.CheckBox._state
_state
Definition: Dialogs.py:1618
Dialogs.CheckBox.setData
def setData(self, d)
Definition: Dialogs.py:1666
Dialogs.FileControl.pathHandler
def pathHandler(self, owner, cmdStr)
Definition: Dialogs.py:1230
Dialogs.Sizer.getWidget
def getWidget(self, wId)
Definition: Dialogs.py:688
LeenoUtils.getComponentContext
def getComponentContext()
Definition: LeenoUtils.py:47
Dialogs.AbstractError.__init__
def __init__(self)
Definition: Dialogs.py:310
Dialogs.ComboBox.widgetEvent
def widgetEvent(self, evt)
Definition: Dialogs.py:1827
Dialogs.PathControl.pathHandler
def pathHandler(self, owner, cmdStr)
Definition: Dialogs.py:1298
Dialogs.YesNoDialog
def YesNoDialog(*Title, Text)
Definition: Dialogs.py:2545
Dialogs.Edit.getText
def getText(self)
Definition: Dialogs.py:1122
Dialogs.ListBox
Definition: Dialogs.py:1670
Dialogs.Button._retVal
_retVal
Definition: Dialogs.py:1544
Dialogs.CheckBox.__init__
def __init__(self, *Id=None, Label='aLabel', State=False, MinWidth=None, MinHeight=None, MaxWidth=None, MaxHeight=None, FixedWidth=None, FixedHeight=None, InternalHandler=None)
Definition: Dialogs.py:1610
Dialogs.Info
def Info(*Title='', Text='')
Definition: Dialogs.py:2539
Dialogs.ComboBox.setData
def setData(self, d)
Definition: Dialogs.py:1872
Dialogs.DateField.__init__
def __init__(self, *Id=None, Date=date(2000, 1, 1), MinWidth=None, MinHeight=None, MaxWidth=None, MaxHeight=None, FixedWidth=None, FixedHeight=None)
Definition: Dialogs.py:1135
Dialogs.shortenPath
def shortenPath(pth, width)
Definition: Dialogs.py:272
Dialogs.ProgressBar.getLimits
def getLimits(self)
Definition: Dialogs.py:1515
Dialogs.Exclamation
def Exclamation(*Title='', Text='')
Definition: Dialogs.py:2536
Dialogs.RadioButton.getProps
def getProps(self)
Definition: Dialogs.py:1900
Dialogs.FileControl.setPath
def setPath(self, pth)
Definition: Dialogs.py:1241
Dialogs.Dialog._canClose
_canClose
Definition: Dialogs.py:2205
Dialogs.DateControl.setDate
def setDate(self, dat)
Definition: Dialogs.py:1372
Dialogs.CheckBox.calcMinSize
def calcMinSize(self)
Definition: Dialogs.py:1624
Dialogs.Progress.setText
def setText(self, txt)
Definition: Dialogs.py:2640
LeenoUtils.firstWeekDay
def firstWeekDay(dat)
Definition: LeenoUtils.py:174
Dialogs.getTextBox
def getTextBox(txt)
Definition: Dialogs.py:115
Dialogs.Progress.showing
def showing(self)
Definition: Dialogs.py:2620
Dialogs.Button._label
_label
Definition: Dialogs.py:1543
Dialogs.DialogItem.getData
def getData(self)
Definition: Dialogs.py:607
Dialogs.Button.widgetEvent
def widgetEvent(self, evt)
Definition: Dialogs.py:1578
Dialogs.DialogItem._width
_width
Definition: Dialogs.py:363
Dialogs.FixedText.calcMinSize
def calcMinSize(self)
Definition: Dialogs.py:1013
LeenoUtils.daysInMonth
def daysInMonth(dat)
Definition: LeenoUtils.py:160
Dialogs.FileSelect
def FileSelect(titolo='Scegli il file...', est=' *.*', mode=0, startPath=None)
SOME COMMON DIALOGS.
Definition: Dialogs.py:2448
Dialogs.Dialog._showing
_showing
Definition: Dialogs.py:2206
Dialogs.ListBox.setData
def setData(self, d)
Definition: Dialogs.py:1779
Dialogs.FixedText.setData
def setData(self, d)
Definition: Dialogs.py:1061
Dialogs.Edit.__init__
def __init__(self, *Id=None, Text='', ReadOnly=False, Align=0, MinWidth=None, MinHeight=None, MaxWidth=None, MaxHeight=None, FixedWidth=None, FixedHeight=None)
Definition: Dialogs.py:1069
Dialogs.FileControl._types
_types
Definition: Dialogs.py:1203
Dialogs.PathControl._path
_path
Definition: Dialogs.py:1271
Dialogs.RadioGroup._sizer
_sizer
Definition: Dialogs.py:1953
Dialogs.Progress._dlgHandler
def _dlgHandler(self, dialog, widgetId, widget, cmdStr)
Definition: Dialogs.py:2611
Dialogs.Spacer.calcMinSize
def calcMinSize(self)
Definition: Dialogs.py:625
Dialogs.FileControl
Definition: Dialogs.py:1186
Dialogs.ComboBox._current
_current
Definition: Dialogs.py:1795
Dialogs.Progress
Definition: Dialogs.py:2583
Dialogs.GroupBox._sizer
_sizer
Definition: Dialogs.py:2100
Dialogs.HSizer
Definition: Dialogs.py:706
Dialogs.Sizer.__init__
def __init__(self, *Id=None, Items)
Definition: Dialogs.py:641
Dialogs.RadioButton.widgetEvent
def widgetEvent(self, evt)
Definition: Dialogs.py:1910
Dialogs.ProgressBar.setValue
def setValue(self, val)
Definition: Dialogs.py:1518
Dialogs.DialogItem.dump
def dump(self, indent)
Definition: Dialogs.py:445
Dialogs.RadioGroup.__getitem__
def __getitem__(self, key)
Definition: Dialogs.py:2037
Dialogs.PathControl.getProps
def getProps(self)
Definition: Dialogs.py:1282
Dialogs.CheckBox.getState
def getState(self)
Definition: Dialogs.py:1651
Dialogs.ProgressBar.calcMinSize
def calcMinSize(self)
Definition: Dialogs.py:1473
Dialogs.RadioButton._label
_label
Definition: Dialogs.py:1888
Dialogs.DateControl._date
_date
Definition: Dialogs.py:1338
Dialogs.GroupBox.getProps
def getProps(self)
Definition: Dialogs.py:2160
Dialogs.FileControl.dump
def dump(self, indent)
Definition: Dialogs.py:1222
Dialogs.getDefaultPath
def getDefaultPath()
Definition: Dialogs.py:246
Dialogs.DialogItem.align
align
Definition: Dialogs.py:366
Dialogs.Dialog.actionPerformed
def actionPerformed(self, widget, widgetId, param)
Definition: Dialogs.py:2335
Dialogs.Dialog._dialogContainer
_dialogContainer
Definition: Dialogs.py:2296
Dialogs.GroupBox
Definition: Dialogs.py:2088
Dialogs.RadioGroup.widgetEvent
def widgetEvent(self, param)
Definition: Dialogs.py:2023
Dialogs.Dialog.getWidget
def getWidget(self, wId)
Definition: Dialogs.py:2409
Dialogs.Edit._readOnly
_readOnly
Definition: Dialogs.py:1076
Dialogs.Dialog._x
_x
Definition: Dialogs.py:2265
Dialogs.GroupBox.__init__
def __init__(self, *Id=None, Label='aLabel', Horz=False, Items=None)
Definition: Dialogs.py:2095
Dialogs.CheckBox.getProps
def getProps(self)
Definition: Dialogs.py:1630
Dialogs.Dialog
Definition: Dialogs.py:2189
Dialogs.Dialog.setData
def setData(self, data)
Definition: Dialogs.py:2422
Dialogs.Button.getProps
def getProps(self)
Definition: Dialogs.py:1561
Dialogs.CheckBox.setState
def setState(self, state)
Definition: Dialogs.py:1646
Dialogs.Edit.getProps
def getProps(self)
Definition: Dialogs.py:1093
Dialogs.Button
Definition: Dialogs.py:1527
Dialogs.storeLastPath
def storeLastPath(oPath)
Definition: Dialogs.py:262
Dialogs.Dialog._destruct
def _destruct(self)
Definition: Dialogs.py:2309
LeenoUtils.createUnoService
def createUnoService(serv)
Definition: LeenoUtils.py:91
Dialogs.PathControl.getPath
def getPath(self)
Definition: Dialogs.py:1312
Dialogs.ProgressBar._maxVal
_maxVal
Definition: Dialogs.py:1466
Dialogs.DateControl
Definition: Dialogs.py:1322
LeenoConfig.Config
Definition: LeenoConfig.py:26
Dialogs.FixedText._textColor
_textColor
Definition: Dialogs.py:1002
Dialogs.Sizer
Definition: Dialogs.py:636
Dialogs.VSizer
Definition: Dialogs.py:848
Dialogs.ComboBox.setList
def setList(self, list)
Definition: Dialogs.py:1849
LeenoUtils.date2String
def date2String(dat, fmt=0)
Definition: LeenoUtils.py:189
Dialogs.ProgressBar._minVal
_minVal
Definition: Dialogs.py:1465
Dialogs.DateField.setData
def setData(self, d)
Definition: Dialogs.py:1182
Dialogs.getScreenInfo
def getScreenInfo()
Definition: Dialogs.py:55
Dialogs.Dialog.__repr__
def __repr__(self)
Definition: Dialogs.py:2242
Dialogs.ListBox.getData
def getData(self)
Definition: Dialogs.py:1776
Dialogs.CheckBox
Definition: Dialogs.py:1605
Dialogs.Button.__init__
def __init__(self, *Id=None, Label='', RetVal=None, Icon=None, MinWidth=None, MinHeight=None, MaxWidth=None, MaxHeight=None, FixedWidth=None, FixedHeight=None, Align=0, TextColor=None, BackgroundColor=None, InternalHandler=None)
Definition: Dialogs.py:1534
Dialogs.Edit.widgetEvent
def widgetEvent(self, evt)
Definition: Dialogs.py:1106
Dialogs.Button.dump
def dump(self, indent)
Definition: Dialogs.py:1581
Dialogs.DialogItem._UNOControl
_UNOControl
Definition: Dialogs.py:382
Dialogs.VSizer.__init__
def __init__(self, *Id=None, Items=None)
Definition: Dialogs.py:853
Dialogs.GroupBox.calcMinSize
def calcMinSize(self)
Definition: Dialogs.py:2107
Dialogs.Edit._text
_text
Definition: Dialogs.py:1075
Dialogs.RadioGroup._default
_default
Definition: Dialogs.py:1950
Dialogs.Edit.setText
def setText(self, txt)
Definition: Dialogs.py:1117
Dialogs.RadioGroup.getWidget
def getWidget(self, wId)
Definition: Dialogs.py:2031
Dialogs.getCurrentPath
def getCurrentPath()
Definition: Dialogs.py:28
Dialogs.ListBox.calcMinSize
def calcMinSize(self)
Definition: Dialogs.py:1689
Dialogs.PathControl.setData
def setData(self, d)
Definition: Dialogs.py:1318
Dialogs.CheckBox.getData
def getData(self)
Definition: Dialogs.py:1663
Dialogs.FixedText.getAlign
def getAlign(self)
Definition: Dialogs.py:1055
Dialogs.DialogItem._y
_y
Definition: Dialogs.py:361
Dialogs.getCheckBoxHeight
def getCheckBoxHeight()
Definition: Dialogs.py:226
Dialogs.Dialog.stop
def stop(self, RetVal=None)
Definition: Dialogs.py:2380
Dialogs.ComboBox.getList
def getList(self)
Definition: Dialogs.py:1866
Dialogs.getButtonSize
def getButtonSize(txt, Icon=None)
Definition: Dialogs.py:234
Dialogs.getBigIconSize
def getBigIconSize()
Definition: Dialogs.py:103
Dialogs.DialogItem._fixedHeight
_fixedHeight
Definition: Dialogs.py:358
Dialogs.DateField.getDate
def getDate(self)
Definition: Dialogs.py:1176
Dialogs.Dialog._height
_height
Definition: Dialogs.py:2203
Dialogs.ListBox.widgetEvent
def widgetEvent(self, evt)
Definition: Dialogs.py:1724
Dialogs.FileControl.__init__
def __init__(self, *Id=None, Path=None, Types="*.*", MinWidth=None, MinHeight=None, MaxWidth=None, MaxHeight=None, FixedWidth=None, FixedHeight=None, InternalHandler=None)
Definition: Dialogs.py:1191
Dialogs.ComboBox.setCurrent
def setCurrent(self, curr)
Definition: Dialogs.py:1832
Dialogs.ListBox._current
_current
Definition: Dialogs.py:1682
Dialogs.HSizer.__init__
def __init__(self, *Id=None, Items=None)
Definition: Dialogs.py:711
Dialogs.getParentWindowSize
def getParentWindowSize()
Definition: Dialogs.py:33
Dialogs.FileControl._path
_path
Definition: Dialogs.py:1202
Dialogs.ProgressBar.setLimits
def setLimits(self, minVal, maxVal)
Definition: Dialogs.py:1508
Dialogs.GroupBox.add
def add(self, *items)
Definition: Dialogs.py:2131
Dialogs.DialogItem._maxWidth
_maxWidth
Definition: Dialogs.py:354
Dialogs.Dialog._toolkit
_toolkit
Definition: Dialogs.py:2271
Dialogs.ImageControl.calcMinSize
def calcMinSize(self)
Definition: Dialogs.py:1427
Dialogs.RadioGroup.setCurrent
def setCurrent(self, current)
Definition: Dialogs.py:2059
Dialogs.ListBox.getCurrent
def getCurrent(self)
Definition: Dialogs.py:1734
Dialogs.DateField.setDate
def setDate(self, dat)
Definition: Dialogs.py:1170
Dialogs.FixedText.getText
def getText(self)
Definition: Dialogs.py:1047
Dialogs.Dialog.show
def show(self)
Definition: Dialogs.py:2390
Dialogs.Progress.setLimits
def setLimits(self, pMin, pMax)
Definition: Dialogs.py:2623
Dialogs.Progress.show
def show(self)
Definition: Dialogs.py:2614
Dialogs.DialogItem.actionPerformed
def actionPerformed(self, oActionEvent)
Definition: Dialogs.py:565
Dialogs.YesNoCancelDialog
def YesNoCancelDialog(*Title, Text)
Definition: Dialogs.py:2563
Dialogs.VSizer.calcMinSize
def calcMinSize(self)
Definition: Dialogs.py:857
Dialogs.Edit.setData
def setData(self, d)
Definition: Dialogs.py:1128
Dialogs.DialogItem._maxHeight
_maxHeight
Definition: Dialogs.py:355
Dialogs.ComboBox.__init__
def __init__(self, *Id=None, List=None, Current=None, MinWidth=None, MinHeight=None, MaxWidth=None, MaxHeight=None, FixedWidth=None, FixedHeight=None, InternalHandler=None)
Definition: Dialogs.py:1788
Dialogs.pickDate
def pickDate(curDate=None)
Definition: Dialogs.py:2699
Dialogs.Dialog.getValue
def getValue(self)
Definition: Dialogs.py:2419
Dialogs.Sizer.__getitem__
def __getitem__(self, key)
Definition: Dialogs.py:702
Dialogs.ImageControl.getProps
def getProps(self)
Definition: Dialogs.py:1433
Dialogs.FixedText.setAlign
def setAlign(self, align)
Definition: Dialogs.py:1050
Dialogs.GroupBox.__getitem__
def __getitem__(self, key)
Definition: Dialogs.py:2157
Dialogs.Dialog._layout
def _layout(self)
Definition: Dialogs.py:2211
Dialogs.DialogItem._id
_id
Definition: Dialogs.py:367
Dialogs.Button.setData
def setData(self, d)
Definition: Dialogs.py:1601
Dialogs.Progress._textWidget
_textWidget
Definition: Dialogs.py:2598
Dialogs.MultiButton
def MultiButton(*Icon=None, Title='', Text='', Buttons=None)
Definition: Dialogs.py:2649
Dialogs.getEditBox
def getEditBox(txt)
Definition: Dialogs.py:134
Dialogs.NotifyDialog
def NotifyDialog(*Image, Title, Text)
Definition: Dialogs.py:2520
Dialogs.Edit.getData
def getData(self)
Definition: Dialogs.py:1125
Dialogs.Dialog._y
_y
Definition: Dialogs.py:2202
Dialogs.DateField.dump
def dump(self, indent)
Definition: Dialogs.py:1164
Dialogs.DateControl.setData
def setData(self, d)
Definition: Dialogs.py:1383
Dialogs.ListBox.getList
def getList(self)
Definition: Dialogs.py:1773
Dialogs.RadioButton.__init__
def __init__(self, *Id=None, Label='aLabel', MinWidth=None, MinHeight=None, MaxWidth=None, MaxHeight=None, FixedWidth=None, FixedHeight=None, InternalHandler=None)
Definition: Dialogs.py:1881
Dialogs.Progress._dlg
_dlg
Definition: Dialogs.py:2589
Dialogs.Dialog._presetWidgets
def _presetWidgets(self)
Definition: Dialogs.py:2320
Dialogs.FixedText.getData
def getData(self)
Definition: Dialogs.py:1058
Dialogs.DialogItem.textChanged
def textChanged(self, textEvent)
Definition: Dialogs.py:582
Dialogs.DateField.getProps
def getProps(self)
Definition: Dialogs.py:1152
Dialogs.Edit.calcMinSize
def calcMinSize(self)
Definition: Dialogs.py:1084
Dialogs.DateControl.dump
def dump(self, indent)
Definition: Dialogs.py:1356
Dialogs.DialogItem
Definition: Dialogs.py:344
Dialogs.FixedText.getProps
def getProps(self)
Definition: Dialogs.py:1019
Dialogs.ProgressBar._value
_value
Definition: Dialogs.py:1467
Dialogs.Dialog._dialogModel
_dialogModel
Definition: Dialogs.py:2275
Dialogs.FileControl.getPath
def getPath(self)
Definition: Dialogs.py:1246
Dialogs.ProgressBar.getProps
def getProps(self)
Definition: Dialogs.py:1490
Dialogs.Progress.hide
def hide(self)
Definition: Dialogs.py:2617
Dialogs.GroupBox.getWidget
def getWidget(self, wId)
Definition: Dialogs.py:2151
Dialogs.getImageSize
def getImageSize(Image)
Definition: Dialogs.py:85
Dialogs.DialogItem._owner
_owner
Definition: Dialogs.py:381
Dialogs.RadioGroup.add
def add(self, *items)
Definition: Dialogs.py:1987
Dialogs.DialogItem.widgetEvent
def widgetEvent(self, evt)
Definition: Dialogs.py:598
Dialogs.DialogItem._fixedWidth
_fixedWidth
Definition: Dialogs.py:357
Dialogs.ProgressBar.getValue
def getValue(self)
Definition: Dialogs.py:1523
Dialogs.RadioButton
Definition: Dialogs.py:1876
Dialogs.HSizer.height
height
Definition: Dialogs.py:744
Dialogs.DateControl.getProps
def getProps(self)
Definition: Dialogs.py:1348
Dialogs.RadioGroup.getProps
def getProps(self)
Definition: Dialogs.py:2040
Dialogs.ComboBox.getData
def getData(self)
Definition: Dialogs.py:1869
Dialogs.Progress.getValue
def getValue(self)
Definition: Dialogs.py:2637
Dialogs.Dialog._sizer
_sizer
Definition: Dialogs.py:2198
Dialogs.FixedText._text
_text
Definition: Dialogs.py:1000
Dialogs.FixedText.__init__
def __init__(self, *Id=None, Text='', MinWidth=None, MinHeight=None, MaxWidth=None, MaxHeight=None, FixedWidth=None, FixedHeight=None, Align=0, TextColor=None, BackgroundColor=None, Border=0, BorderColor=None)
Definition: Dialogs.py:994
Dialogs.Progress.getLimits
def getLimits(self)
Definition: Dialogs.py:2626
Dialogs.DateControl.__init__
def __init__(self, *Id=None, Date=None, MinWidth=None, MinHeight=None, MaxWidth=None, MaxHeight=None, FixedWidth=None, FixedHeight=None, InternalHandler=None)
Definition: Dialogs.py:1327