DirectGuiGlobals.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. """
  2. Global definitions used by Direct Gui Classes and handy constants
  3. that can be used during widget construction
  4. """
  5. __all__ = []
  6. from panda3d.core import (
  7. KeyboardButton,
  8. MouseButton,
  9. PGButton,
  10. PGEntry,
  11. PGFrameStyle,
  12. PGSliderBar,
  13. TextNode,
  14. )
  15. defaultFont = None
  16. defaultFontFunc = TextNode.getDefaultFont
  17. defaultClickSound = None
  18. defaultRolloverSound = None
  19. defaultDialogGeom = None
  20. defaultDialogRelief = PGFrameStyle.TBevelOut
  21. drawOrder = 100
  22. panel = None
  23. # USEFUL GUI CONSTANTS
  24. #: Constant used to indicate that an option can only be set by a call
  25. #: to the constructor.
  26. INITOPT = ['initopt']
  27. # Mouse buttons
  28. LMB = 0
  29. MMB = 1
  30. RMB = 2
  31. # Widget state
  32. NORMAL = 'normal'
  33. DISABLED = 'disabled'
  34. # Frame style
  35. FLAT = PGFrameStyle.TFlat
  36. RAISED = PGFrameStyle.TBevelOut
  37. SUNKEN = PGFrameStyle.TBevelIn
  38. GROOVE = PGFrameStyle.TGroove
  39. RIDGE = PGFrameStyle.TRidge
  40. TEXTUREBORDER = PGFrameStyle.TTextureBorder
  41. FrameStyleDict = {'flat': FLAT, 'raised': RAISED, 'sunken': SUNKEN,
  42. 'groove': GROOVE, 'ridge': RIDGE,
  43. 'texture_border': TEXTUREBORDER,
  44. }
  45. # Orientation of DirectSlider and DirectScrollBar
  46. HORIZONTAL = 'horizontal'
  47. VERTICAL = 'vertical'
  48. VERTICAL_INVERTED = 'vertical_inverted'
  49. # Dialog button values
  50. DIALOG_NO = 0
  51. DIALOG_OK = DIALOG_YES = DIALOG_RETRY = 1
  52. DIALOG_CANCEL = -1
  53. # User can bind commands to these gui events
  54. DESTROY = 'destroy-'
  55. PRINT = 'print-'
  56. ENTER = PGButton.getEnterPrefix()
  57. EXIT = PGButton.getExitPrefix()
  58. WITHIN = PGButton.getWithinPrefix()
  59. WITHOUT = PGButton.getWithoutPrefix()
  60. B1CLICK = PGButton.getClickPrefix() + MouseButton.one().getName() + '-'
  61. B2CLICK = PGButton.getClickPrefix() + MouseButton.two().getName() + '-'
  62. B3CLICK = PGButton.getClickPrefix() + MouseButton.three().getName() + '-'
  63. B1PRESS = PGButton.getPressPrefix() + MouseButton.one().getName() + '-'
  64. B2PRESS = PGButton.getPressPrefix() + MouseButton.two().getName() + '-'
  65. B3PRESS = PGButton.getPressPrefix() + MouseButton.three().getName() + '-'
  66. B1RELEASE = PGButton.getReleasePrefix() + MouseButton.one().getName() + '-'
  67. B2RELEASE = PGButton.getReleasePrefix() + MouseButton.two().getName() + '-'
  68. B3RELEASE = PGButton.getReleasePrefix() + MouseButton.three().getName() + '-'
  69. WHEELUP = PGButton.getReleasePrefix() + MouseButton.wheelUp().getName() + '-'
  70. WHEELDOWN = PGButton.getReleasePrefix() + MouseButton.wheelDown().getName() + '-'
  71. # For DirectEntry widgets
  72. OVERFLOW = PGEntry.getOverflowPrefix()
  73. ACCEPT = PGEntry.getAcceptPrefix() + KeyboardButton.enter().getName() + '-'
  74. ACCEPTFAILED = PGEntry.getAcceptFailedPrefix() + KeyboardButton.enter().getName() + '-'
  75. TYPE = PGEntry.getTypePrefix()
  76. ERASE = PGEntry.getErasePrefix()
  77. CURSORMOVE = PGEntry.getCursormovePrefix()
  78. # For DirectSlider and DirectScrollBar widgets
  79. ADJUST = PGSliderBar.getAdjustPrefix()
  80. # For setting the sorting order of a widget's visible components
  81. IMAGE_SORT_INDEX = 10
  82. GEOM_SORT_INDEX = 20
  83. TEXT_SORT_INDEX = 30
  84. FADE_SORT_INDEX = 1000
  85. NO_FADE_SORT_INDEX = 2000
  86. # Handy conventions for organizing top-level gui objects in loose buckets.
  87. BACKGROUND_SORT_INDEX = -100
  88. MIDGROUND_SORT_INDEX = 0
  89. FOREGROUND_SORT_INDEX = 100
  90. # Symbolic constants for the indexes into an optionInfo list.
  91. _OPT_DEFAULT = 0
  92. _OPT_VALUE = 1
  93. _OPT_FUNCTION = 2
  94. # DirectButton States:
  95. BUTTON_READY_STATE = PGButton.SReady # 0
  96. BUTTON_DEPRESSED_STATE = PGButton.SDepressed # 1
  97. BUTTON_ROLLOVER_STATE = PGButton.SRollover # 2
  98. BUTTON_INACTIVE_STATE = PGButton.SInactive # 3
  99. def getDefaultRolloverSound():
  100. return defaultRolloverSound
  101. def setDefaultRolloverSound(newSound):
  102. global defaultRolloverSound
  103. defaultRolloverSound = newSound
  104. def getDefaultClickSound():
  105. return defaultClickSound
  106. def setDefaultClickSound(newSound):
  107. global defaultClickSound
  108. defaultClickSound = newSound
  109. def getDefaultFont():
  110. global defaultFont
  111. if defaultFont is None:
  112. defaultFont = defaultFontFunc()
  113. return defaultFont
  114. def setDefaultFont(newFont):
  115. """Changes the default font for DirectGUI items. To change the default
  116. font across the board, see :meth:`.TextNode.setDefaultFont`. """
  117. global defaultFont
  118. defaultFont = newFont
  119. def setDefaultFontFunc(newFontFunc):
  120. global defaultFontFunc
  121. defaultFontFunc = newFontFunc
  122. def getDefaultDialogGeom():
  123. return defaultDialogGeom
  124. def getDefaultDialogRelief():
  125. return defaultDialogRelief
  126. def setDefaultDialogGeom(newDialogGeom, relief=None):
  127. global defaultDialogGeom, defaultDialogRelief
  128. defaultDialogGeom = newDialogGeom
  129. defaultDialogRelief = relief
  130. def getDefaultDrawOrder():
  131. return drawOrder
  132. def setDefaultDrawOrder(newDrawOrder):
  133. global drawOrder
  134. drawOrder = newDrawOrder
  135. def getDefaultPanel():
  136. return panel
  137. def setDefaultPanel(newPanel):
  138. global panel
  139. panel = newPanel
  140. get_default_rollover_sound = getDefaultRolloverSound
  141. set_default_rollover_sound = setDefaultRolloverSound
  142. get_default_click_sound = getDefaultClickSound
  143. set_default_click_sound = setDefaultClickSound
  144. get_default_font = getDefaultFont
  145. set_default_font = setDefaultFont
  146. get_default_dialog_geom = getDefaultDialogGeom
  147. get_default_dialog_relief = getDefaultDialogRelief
  148. set_default_dialog_geom = setDefaultDialogGeom
  149. get_default_draw_order = getDefaultDrawOrder
  150. set_default_draw_order = setDefaultDrawOrder
  151. get_default_panel = getDefaultPanel
  152. set_default_panel = setDefaultPanel