UnoDialog2.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. #
  2. # This file is part of the LibreOffice project.
  3. #
  4. # This Source Code Form is subject to the terms of the Mozilla Public
  5. # License, v. 2.0. If a copy of the MPL was not distributed with this
  6. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  7. #
  8. # This file incorporates work covered by the following license notice:
  9. #
  10. # Licensed to the Apache Software Foundation (ASF) under one or more
  11. # contributor license agreements. See the NOTICE file distributed
  12. # with this work for additional information regarding copyright
  13. # ownership. The ASF licenses this file to you under the Apache
  14. # License, Version 2.0 (the "License"); you may not use this file
  15. # except in compliance with the License. You may obtain a copy of
  16. # the License at http://www.apache.org/licenses/LICENSE-2.0 .
  17. #
  18. from .UnoDialog import UnoDialog, UIConsts
  19. from ..common.Desktop import Desktop
  20. from ..common.PropertyNames import PropertyNames
  21. from ..common.SystemDialog import SystemDialog
  22. from .event.CommonListener import ItemListenerProcAdapter, \
  23. ActionListenerProcAdapter, TextListenerProcAdapter, \
  24. AdjustmentListenerProcAdapter
  25. '''
  26. This class contains convenience methods for inserting components to a dialog.
  27. It was created for use with the automatic conversion of Basic XML Dialog
  28. description files to a Java class which builds
  29. the same dialog through the UNO API.<br/>
  30. It uses an Event-Listener method, which calls a method through reflection
  31. when an event on a component is triggered.
  32. see the classes CommonListener for details
  33. '''
  34. class UnoDialog2(UnoDialog):
  35. '''
  36. Override this method to return another listener.
  37. @return
  38. '''
  39. def __init__(self, xmsf):
  40. super(UnoDialog2,self).__init__(xmsf,(), ())
  41. ControlList = {}
  42. def insertButton(
  43. self, sName, actionPerformed, sPropNames, oPropValues, listener):
  44. xButton = self.insertControlModel(
  45. "com.sun.star.awt.UnoControlButtonModel",
  46. sName, sPropNames, oPropValues)
  47. if actionPerformed is not None:
  48. actionPerformed = getattr(listener, actionPerformed)
  49. xButton.addActionListener(
  50. ActionListenerProcAdapter(actionPerformed))
  51. return xButton
  52. def insertCheckBox(
  53. self, sName, itemChanged, sPropNames, oPropValues, listener):
  54. xCheckBox = self.insertControlModel(
  55. "com.sun.star.awt.UnoControlCheckBoxModel",
  56. sName, sPropNames, oPropValues)
  57. if itemChanged is not None:
  58. itemChanged = getattr(listener, itemChanged)
  59. xCheckBox.addItemListener(ItemListenerProcAdapter(itemChanged))
  60. return xCheckBox
  61. def insertComboBox(
  62. self, sName, actionPerformed, itemChanged,
  63. textChanged, sPropNames, oPropValues, listener):
  64. xComboBox = self.insertControlModel(
  65. "com.sun.star.awt.UnoControlComboBoxModel",
  66. sName, sPropNames, oPropValues)
  67. if actionPerformed is not None:
  68. actionPerformed = getattr(listener, actionPerformed)
  69. xComboBox.addActionListener(
  70. ActionListenerProcAdapter(actionPerformed))
  71. if itemChanged is not None:
  72. itemChanged = getattr(listener, itemChanged)
  73. xComboBox.addItemListener(ItemListenerProcAdapter(itemChanged))
  74. if textChanged is not None:
  75. textChanged = getattr(listener, textChanged)
  76. xComboBox.addTextListener(TextListenerProcAdapter(textChanged))
  77. return xComboBox
  78. def insertListBox(
  79. self, sName, actionPerformed, itemChanged,
  80. sPropNames, oPropValues, listener):
  81. xListBox = self.insertControlModel(
  82. "com.sun.star.awt.UnoControlListBoxModel",
  83. sName, sPropNames, oPropValues)
  84. if itemChanged is not None:
  85. itemChanged = getattr(listener, itemChanged)
  86. xListBox.addItemListener(ItemListenerProcAdapter(itemChanged))
  87. return xListBox
  88. def insertRadioButton(
  89. self, sName, itemChanged, sPropNames, oPropValues, listener):
  90. xRadioButton = self.insertControlModel(
  91. "com.sun.star.awt.UnoControlRadioButtonModel",
  92. sName, sPropNames, oPropValues)
  93. if itemChanged is not None:
  94. itemChanged = getattr(listener, itemChanged)
  95. xRadioButton.addItemListener(
  96. ItemListenerProcAdapter(itemChanged))
  97. return xRadioButton
  98. def insertTextField(
  99. self, sName, sTextChanged, sPropNames, oPropValues, listener):
  100. return self.insertEditField(
  101. sName, sTextChanged, "com.sun.star.awt.UnoControlEditModel",
  102. sPropNames, oPropValues, listener)
  103. def insertImage(self, sName, sPropNames, oPropValues):
  104. return self.insertControlModel(
  105. "com.sun.star.awt.UnoControlImageControlModel",
  106. sName, sPropNames, oPropValues)
  107. def insertInfoImage(self, _posx, _posy, _iStep):
  108. xImgControl = self.insertImage(
  109. Desktop.getUniqueName(self.xDialogModel, "imgHint"),
  110. ("Border",
  111. PropertyNames.PROPERTY_HEIGHT,
  112. PropertyNames.PROPERTY_IMAGEURL,
  113. PropertyNames.PROPERTY_POSITION_X,
  114. PropertyNames.PROPERTY_POSITION_Y, "ScaleImage",
  115. PropertyNames.PROPERTY_STEP,
  116. PropertyNames.PROPERTY_WIDTH),
  117. (0, 10, UIConsts.INFOIMAGEURL, _posx, _posy, False, _iStep, 10))
  118. return xImgControl
  119. '''
  120. This method is used for creating Edit, Currency, Date, Formatted,
  121. Pattern, File and Time edit components.
  122. '''
  123. def insertEditField(
  124. self, sName, sTextChanged, sModelClass,
  125. sPropNames, oPropValues, listener):
  126. xField = self.insertControlModel(sModelClass,
  127. sName, sPropNames, oPropValues)
  128. if sTextChanged is not None:
  129. sTextChanged = getattr(listener, sTextChanged)
  130. xField.addTextListener(TextListenerProcAdapter(sTextChanged))
  131. return xField
  132. def insertDateField(
  133. self, sName, sTextChanged, sPropNames, oPropValues, listener):
  134. return self.insertEditField(
  135. sName, sTextChanged,
  136. "com.sun.star.awt.UnoControlDateFieldModel",
  137. sPropNames, oPropValues, listener)
  138. def insertNumericField(
  139. self, sName, sTextChanged, sPropNames, oPropValues, listener):
  140. return self.insertEditField(
  141. sName, sTextChanged,
  142. "com.sun.star.awt.UnoControlNumericFieldModel",
  143. sPropNames, oPropValues, listener)
  144. def insertTimeField(
  145. self, sName, sTextChanged, sPropNames, oPropValues, listener):
  146. return self.insertEditField(
  147. sName, sTextChanged,
  148. "com.sun.star.awt.UnoControlTimeFieldModel",
  149. sPropNames, oPropValues, listener)
  150. def insertFixedLine(self, sName, sPropNames, oPropValues):
  151. oLine = self.insertControlModel(
  152. "com.sun.star.awt.UnoControlFixedLineModel",
  153. sName, sPropNames, oPropValues)
  154. return oLine
  155. def insertLabel(self, sName, sPropNames, oPropValues):
  156. oFixedText = self.insertControlModel(
  157. "com.sun.star.awt.UnoControlFixedTextModel",
  158. sName, sPropNames, oPropValues)
  159. return oFixedText
  160. def insertScrollBar(self, sName, sPropNames, oPropValues,
  161. iControlKey, listener):
  162. oScrollBar = self.insertControlModel(
  163. "com.sun.star.awt.UnoControlScrollBarModel",
  164. sName, sPropNames, oPropValues)
  165. if listener is not None:
  166. method = getattr(listener, "scrollControls")
  167. oScrollBar.addAdjustmentListener(
  168. AdjustmentListenerProcAdapter(method))
  169. if self.ControlList is not None:
  170. self.ControlList[sName] = iControlKey
  171. return oScrollBar
  172. def showMessageBox(self, windowServiceName, windowAttribute, MessageText):
  173. return SystemDialog.showMessageBox(
  174. super().xMSF, self.xControl.Peer,
  175. windowServiceName, windowAttribute, MessageText)