RadioDataAware.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 .CommonListener import ItemListenerProcAdapter
  19. from .DataAware import DataAware
  20. class RadioDataAware(DataAware):
  21. def __init__(self, data, value, radioButtons):
  22. super(RadioDataAware,self).__init__(data, value)
  23. self.radioButtons = radioButtons
  24. def setToUI(self, value):
  25. selected = int(value)
  26. if selected == -1:
  27. for i in self.radioButtons:
  28. i.State = False
  29. else:
  30. self.radioButtons[selected].State = True
  31. def getFromUI(self):
  32. for index, workwith in enumerate(self.radioButtons):
  33. if workwith.State:
  34. return index
  35. return -1
  36. @classmethod
  37. def attachRadioButtons(self, data, prop, buttons, field):
  38. da = RadioDataAware(data, prop, buttons)
  39. method = getattr(da,"updateData")
  40. for i in da.radioButtons:
  41. i.addItemListener(ItemListenerProcAdapter(method))
  42. return da