20 from _ost_gui
import *
26 def _close_event_override_(event):
28 def _set_data_override_(data):
35 sip_viewer=viewer.qobject
36 sip_viewer.closeEvent=_close_event_override_
37 sip_viewer.setData=_set_data_override_
41 gosty=GostyApp.Instance()
42 gosty.message_widget.Clear()
51 Pops up a color chooser that lets' the user pick a color and returns the
52 selected color. If the user cancels the color chooser, None is returned.
54 :rtype: :class:`~ost.gfx.Color`
57 qt_color=QColor(int(min(255,default.Red()*256)),
58 int(min(255,default.Green()*256)),
59 int(min(255,default.Blue()*256)))
60 qt_color=dialog.getColor(qt_color)
61 if not qt_color.isValid():
63 return gfx.RGBb(qt_color.red(), qt_color.green(),qt_color.blue())
66 persp=GostyApp.Instance().perspective
67 if isinstance(menu_name[0], QAction):
70 node=persp.GetMenu(menu_name[0])
71 for name
in menu_name[1:]:
73 for action
in node.actions():
74 if str(action.text())==str(name):
80 node=node.addMenu(name)
82 raise ValueError(
"Menu '%s' doesn't exist" %
', '.join(menu_name))
89 Add menu action to main menu.
91 This function lets you conveniently add actions to the main menu. To add a new
92 new action "Background Color" to the "Scene" menu, simply use
94 .. code-block:: python
96 def SetBackgroundColor():
97 scene.bg=gfx.PickColor(scene.bg)
99 AddMenuAction('Scene', "Background Color", SetBackgroundColor)
101 This will add the menu "Scene" if it does not exist yet, register the action
102 "Background Color" and execute the function SetBackgroundColor whenever the
105 To assign a keyboard shortcut to the action, you can use the shortcut
108 .. code-block:: python
110 AddMenuAction('Scene', 'Background Color', SetBackgroundColor,
113 Whenever you press Ctrl+B (Cmd+B on MacOS X), the action will be executed.
115 Very often menu actions are coupled to the current selected objects in the
116 scene menu. These menu actions are either enabled or disabled depending on the
117 type of the selected objects. To easily support this scenario, the "enable"
118 state of the menu action can be tightly coupled to the scene menu by providing
119 a callable to the enabled argument. As an example, the following menu action
120 is only enabled when exactly one gfx.Entity is selected.
122 .. code-block:: python
124 AddMenuAction('Scene', 'PrintAtomCount', PrintAtomCount,
125 enabled=OneOf(gfx.Entity))
127 OneOf is a simple function object that takes any number of classes and returns
128 true when the selected object is an instance. Alterantively, you might want to
129 use ManyOf or supply a custom function that evaluates the state of the menu
130 action to suit your needs.
132 class MenuActionEnabler(QObject):
133 def __init__(self, predicate, action):
134 QObject.__init__(self, action)
135 self.predicate=predicate
137 app=GostyApp.Instance()
138 QObject.connect(app.scene_win.qobject, SIGNAL(
'ActiveNodesChanged()'),
142 def TestEnable(self):
143 self.action.setEnabled(self.predicate())
144 persp=GostyApp.Instance().perspective
147 if isinstance(menu_name[0], QMenu):
150 node=persp.GetMenu(args[0])
151 for name
in menu_name[1:-1]:
153 for action
in node.actions():
154 if str(action.text())==str(name):
158 node=node.addMenu(name)
159 action=node.addAction(str(menu_name[-1]))
160 if 'shortcut' in kwargs:
161 action.setShortcut(QKeySequence(kwargs[
'shortcut']))
162 if 'checkable' in kwargs:
163 action.setCheckable(kwargs[
'checkable'])
164 if 'checked' in kwargs:
165 action.setChecked(kwargs[
'checked'])
166 if 'enabled' in kwargs:
167 if callable(kwargs[
'enabled']):
168 enabler=MenuActionEnabler(kwargs[
'enabled'], action)
170 action.setEnabled(kwargs[
'enabled'])
171 QObject.connect(action, SIGNAL(
'triggered()'), function)
179 sel=SceneSelection.Instance()
180 if sel.GetActiveNodeCount()!=1:
182 node=sel.GetActiveNode(0)
184 if isinstance(node, cl):
192 sel=SceneSelection.Instance()
193 act_count=sel.GetActiveNodeCount()
197 for i
in range(0, act_count):
198 node=sel.GetActiveNode(i)
200 if isinstance(node, cl):
212 sel=SceneSelection.Instance()
213 if sel.GetActiveNodeCount()==0:
215 for i
in range(sel.GetActiveNodeCount()):
216 node=sel.GetActiveNode(i)
219 if isinstance(node, cl):
226 from ost
import PushVerbosityLevel
as _PushVerbosityLevel
227 from ost
import PopVerbosityLevel
as _PopVerbosityLevel
228 from ost
import GetVerbosityLevel
as _GetVerbosityLevel
232 GostyApp.Instance().perspective.ChangeVerbositySlider(value)
236 GostyApp.Instance().perspective.ChangeVerbositySlider(_GetVerbosityLevel())