1
2 """
3 This module will be a collection of functions to hook into the GUI of Scribus.
4
5 Currently it only provides functions to add items to a menubar.
6 Support for the toolbar, statusbar and dockarea have still to be implemented.
7 I have to think about how to provide this stuff to QtScript.
8 """
9
10 from PyQt4.QtGui import QApplication, QMenu
11
12 import mikro
13
14
16 """
17 This class lets extension-scripts hook into the main menu of Scribus.
18 """
19
20
22 self.window = window or ScripterNG.dialogs.mainWindow.qt
23 self.menubar = self.window.menuBar()
24 self.menus = []
25
26
28 m = QMenu(title)
29 self.menus.append(m)
30 self.menubar.addAction(m)
31 return m
32
33
35 for action in self.menubar.actions():
36 menu = action.menu()
37 if menu:
38 yield menu
39
40
42 """
43 find a menu with a given title
44
45 @type title: string
46 @param title: English title of the menu
47 @rtype: QMenu
48 @return: None if no menu was found, else the menu with title
49 """
50
51 title = QApplication.translate(mikro.classname(self.window), title)
52 for menu in self.iter_menus():
53 if menu.title() == title:
54 return menu
55
56
61
62
64 """
65 Insert a menu after another menu in the menubar
66
67 @type: before_menu QMenu instance or title string of menu
68 @param before_menu: menu which should be after the newly inserted menu
69 @rtype: QAction instance
70 @return: action for inserted menu
71 """
72 if isinstance(before_menu, basestring):
73 before_menu = self.findMenu(before_menu)
74 before_action = self.actionForMenu(before_menu)
75
76
77 new_action = self.menubar.insertMenu(before_action, new_menu)
78 return new_action
79
80
82
83
84 previous = None
85 for m in self.iter_menus():
86 if previous and previous == menu:
87 return m
88 previous = m
89
90
92 """
93 Probably not that usefull
94 because it will add a menu after the help menu
95 """
96 action = self.menubar.addMenu(menu)
97 return action
98
99
101 """
102 Insert a menu before another menu in the menubar
103 """
104 if isinstance(after_menu, basestring):
105 after_menu = self.findMenu(after_menu)
106 after_after_menu = self.menuAfter(after_menu)
107 if after_after_menu:
108 return self.insertMenuBefore(after_after_menu, new_menu)
109 else:
110 return self.appendMenu(new_menu)
111
112
114 if isinstance(menu, basestring):
115 title = menu
116 menu = self.findMenu(title)
117 if not menu:
118 raise ValueError, "Menu %r not found" % title
119 if isinstance(item, QMenu):
120 action = menu.addMenu(item)
121 else:
122 action = menu.addAction(item, *extra_args)
123 return action
124
125
130