Package Camelot :: Package camelot :: Package action :: Module utils
[frames] | no frames]

Source Code for Module Camelot.camelot.action.utils

 1  #  ============================================================================ 
 2  # 
 3  #  Copyright (C) 2007-2008 Conceptive Engineering bvba. All rights reserved. 
 4  #  www.conceptive.be / project-camelot@conceptive.be 
 5  # 
 6  #  This file is part of the Camelot Library. 
 7  # 
 8  #  This file may be used under the terms of the GNU General Public 
 9  #  License version 2.0 as published by the Free Software Foundation 
10  #  and appearing in the file LICENSE.GPL included in the packaging of 
11  #  this file.  Please review the following information to ensure GNU 
12  #  General Public Licensing requirements will be met: 
13  #  http://www.trolltech.com/products/qt/opensource.html 
14  # 
15  #  If you are unsure which license is appropriate for your use, please 
16  #  review the following information: 
17  #  http://www.trolltech.com/products/qt/licensing.html or contact 
18  #  project-camelot@conceptive.be. 
19  # 
20  #  This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 
21  #  WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 
22  # 
23  #  For use of this library in commercial applications, please contact 
24  #  project-camelot@conceptive.be 
25  # 
26  #  ============================================================================ 
27   
28  """Manage QAction objects""" 
29   
30  from PyQt4 import QtGui, QtCore 
31   
32 -def getAction(parent, widgetaction):
33 if widgetaction: 34 return QtGui.QWidgetAction(parent) 35 else: 36 return QtGui.QAction(parent)
37
38 -def createAction(*a, **kw):
39 """creates and returns a QAction object""" 40 41 # collect params 42 parent = kw['parent'] 43 text = kw['text'] 44 slot = kw.get('slot', None) 45 shortcut = kw.get('shortcut', '') 46 actionicon = kw.get('actionicon', '') 47 tip = kw.get('tip', '') 48 checkable = kw.get('checkable', False) 49 signal = kw.get('signal', 'triggered()') 50 widgetaction = kw.get('widgetaction', False) 51 52 action = getAction(parent, widgetaction) 53 54 action.setText(text) 55 56 if actionicon: 57 action.setIcon(QtGui.QIcon(actionicon)) 58 if shortcut: 59 action.setShortcut(shortcut) 60 if tip: 61 action.setToolTip(tip) 62 action.setStatusTip(tip) 63 if slot is not None: 64 parent.connect(action, QtCore.SIGNAL(signal), slot) 65 if checkable: 66 action.setCheckable(True) 67 return action
68
69 -def addActions(target, actions):
70 """add action objects to menus, menubars, and toolbars 71 if action is None, add a separator. 72 """ 73 for action in actions: 74 if action is None: 75 target.addSeparator() 76 else: 77 target.addAction(action)
78