19 from _ost_gui
import *
25 def _close_event_override_(event):
27 def _set_data_override_(data):
34 sip_viewer=viewer.qobject
35 sip_viewer.closeEvent=_close_event_override_
36 sip_viewer.setData=_set_data_override_
40 gosty=GostyApp.Instance()
41 gosty.message_widget.Clear()
50 Pops up a color chooser that lets' the user pick a color and returns the
51 selected color. If the user cancels the color chooser, None is returned.
53 :rtype: :class:`~ost.gfx.Color`
56 qt_color=QColor(int(min(255,default.Red()*256)),
57 int(min(255,default.Green()*256)),
58 int(min(255,default.Blue()*256)))
59 qt_color=dialog.getColor(qt_color)
60 if not qt_color.isValid():
62 return gfx.RGBb(qt_color.red(), qt_color.green(),qt_color.blue())
65 persp=GostyApp.Instance().perspective
66 if isinstance(menu_name[0], QAction):
69 node=persp.GetMenu(menu_name[0])
70 for name
in menu_name[1:]:
72 for action
in node.actions():
73 if str(action.text())==str(name):
79 node=node.addMenu(name)
81 raise ValueError(
"Menu '%s' doesn't exist" %
', '.join(menu_name))
88 Add menu action to main menu.
90 This function lets you conveniently add actions to the main menu. To add a new
91 new action "Background Color" to the "Scene" menu, simply use
93 .. code-block:: python
95 def SetBackgroundColor():
96 scene.bg=gfx.PickColor(scene.bg)
98 AddMenuAction('Scene', "Background Color", SetBackgroundColor)
100 This will add the menu "Scene" if it does not exist yet, register the action
101 "Background Color" and execute the function SetBackgroundColor whenever the
104 To assign a keyboard shortcut to the action, you can use the shortcut
107 .. code-block:: python
109 AddMenuAction('Scene', 'Background Color', SetBackgroundColor,
112 Whenever you press Ctrl+B (Cmd+B on MacOS X), the action will be executed.
114 Very often menu actions are coupled to the current selected objects in the
115 scene menu. These menu actions are either enabled or disabled depending on the
116 type of the selected objects. To easily support this scenario, the "enable"
117 state of the menu action can be tightly coupled to the scene menu by providing
118 a callable to the enabled argument. As an example, the following menu action
119 is only enabled when exactly one gfx.Entity is selected.
121 .. code-block:: python
123 AddMenuAction('Scene', 'PrintAtomCount', PrintAtomCount,
124 enabled=OneOf(gfx.Entity))
126 OneOf is a simple function object that takes any number of classes and returns
127 true when the selected object is an instance. Alterantively, you might want to
128 use ManyOf or supply a custom function that evaluates the state of the menu
129 action to suit your needs.
131 class MenuActionEnabler(QObject):
132 def __init__(self, predicate, action):
133 QObject.__init__(self, action)
134 self.predicate=predicate
136 app=GostyApp.Instance()
137 QObject.connect(app.scene_win.qobject, SIGNAL(
'ActiveNodesChanged()'),
141 def TestEnable(self):
142 self.action.setEnabled(self.predicate())
143 persp=GostyApp.Instance().perspective
146 if isinstance(menu_name[0], QMenu):
149 node=persp.GetMenu(args[0])
150 for name
in menu_name[1:-1]:
152 for action
in node.actions():
153 if str(action.text())==str(name):
157 node=node.addMenu(name)
158 action=node.addAction(str(menu_name[-1]))
159 if 'shortcut' in kwargs:
160 action.setShortcut(QKeySequence(kwargs[
'shortcut']))
161 if 'checkable' in kwargs:
162 action.setCheckable(kwargs[
'checkable'])
163 if 'checked' in kwargs:
164 action.setChecked(kwargs[
'checked'])
165 if 'enabled' in kwargs:
166 if callable(kwargs[
'enabled']):
167 enabler=MenuActionEnabler(kwargs[
'enabled'], action)
169 action.setEnabled(kwargs[
'enabled'])
170 QObject.connect(action, SIGNAL(
'triggered()'), function)
178 sel=SceneSelection.Instance()
179 if sel.GetActiveNodeCount()!=1:
181 node=sel.GetActiveNode(0)
183 if isinstance(node, cl):
191 sel=SceneSelection.Instance()
192 act_count=sel.GetActiveNodeCount()
196 for i
in range(0, act_count):
197 node=sel.GetActiveNode(i)
199 if isinstance(node, cl):
211 sel=SceneSelection.Instance()
212 if sel.GetActiveNodeCount()==0:
214 for i
in range(sel.GetActiveNodeCount()):
215 node=sel.GetActiveNode(i)
218 if isinstance(node, cl):
225 from ost
import PushVerbosityLevel
as _PushVerbosityLevel
226 from ost
import PopVerbosityLevel
as _PopVerbosityLevel
227 from ost
import GetVerbosityLevel
as _GetVerbosityLevel
231 GostyApp.Instance().perspective.ChangeVerbositySlider(value)
235 GostyApp.Instance().perspective.ChangeVerbositySlider(_GetVerbosityLevel())