Krita Source Code Documentation
Loading...
Searching...
No Matches
scripter_hooks.MenuHooks Class Reference
+ Inheritance diagram for scripter_hooks.MenuHooks:

Public Member Functions

 __init__ (self, window=None)
 
 actionForMenu (self, menu)
 
 appendItem (self, menu, item, *extra_args)
 
 appendMenu (self, menu)
 
 appendSeparator (self, menu)
 
 createMenu (self, title)
 
 findMenu (self, title)
 
 insertMenuAfter (self, after_menu, new_menu)
 
 insertMenuBefore (self, before_menu, new_menu)
 
 iter_inner_menus (self, menu)
 
 iter_menus (self)
 
 menuAfter (self, menu)
 

Public Attributes

 menubar
 
 menus
 
 window
 

Detailed Description

This class lets extension-scripts hook into the main menu of Scribus.

Definition at line 22 of file scripter_hooks.py.

Constructor & Destructor Documentation

◆ __init__()

scripter_hooks.MenuHooks.__init__ ( self,
window = None )

Definition at line 28 of file scripter_hooks.py.

28 def __init__(self, window=None):
29 self.window = window or Scripter.dialogs.mainWindow.qt
30 self.menubar = self.window.menuBar()
31 self.menus = []
32

Member Function Documentation

◆ actionForMenu()

scripter_hooks.MenuHooks.actionForMenu ( self,
menu )

Definition at line 69 of file scripter_hooks.py.

69 def actionForMenu(self, menu):
70 for action in self.menubar.actions():
71 if action.menu() == menu:
72 return action
73

References scripter_hooks.MenuHooks.menubar, and krita.sceditor.mainwindow_ui.Ui_ScriptEditor.menubar.

◆ appendItem()

scripter_hooks.MenuHooks.appendItem ( self,
menu,
item,
* extra_args )

Definition at line 120 of file scripter_hooks.py.

120 def appendItem(self, menu, item, *extra_args):
121 if isinstance(menu, basestring):
122 title = menu
123 menu = self.findMenu(title)
124 if not menu:
125 raise ValueError("Menu %r not found" % title)
126 if isinstance(item, QMenu):
127 action = menu.addMenu(item)
128 else:
129 action = menu.addAction(item, *extra_args)
130 return action
131

References scripter_hooks.MenuHooks.findMenu().

◆ appendMenu()

scripter_hooks.MenuHooks.appendMenu ( self,
menu )
  Probably not that useful
  because it will add a menu after the help menu

Definition at line 100 of file scripter_hooks.py.

100 def appendMenu(self, menu):
101 """
102 Probably not that useful
103 because it will add a menu after the help menu
104 """
105 action = self.menubar.addMenu(menu)
106 return action
107

References scripter_hooks.MenuHooks.menubar, and krita.sceditor.mainwindow_ui.Ui_ScriptEditor.menubar.

◆ appendSeparator()

scripter_hooks.MenuHooks.appendSeparator ( self,
menu )

Definition at line 132 of file scripter_hooks.py.

132 def appendSeparator(self, menu):
133 if isinstance(menu, basestring):
134 menu = self.findMenu(menu)
135 menu.addSeparator()

References scripter_hooks.MenuHooks.findMenu().

◆ createMenu()

scripter_hooks.MenuHooks.createMenu ( self,
title )

Definition at line 33 of file scripter_hooks.py.

33 def createMenu(self, title):
34 m = QMenu(title)
35 self.menus.append(m)
36 self.menubar.addMenu(m)
37 return m
38

References scripter_hooks.MenuHooks.menubar, krita.sceditor.mainwindow_ui.Ui_ScriptEditor.menubar, and scripter_hooks.MenuHooks.menus.

◆ findMenu()

scripter_hooks.MenuHooks.findMenu ( self,
title )
find a menu with a given title

@type  title: string
@param title: English title of the menu
@rtype:       QMenu
@return:      None if no menu was found, else the menu with title

Definition at line 51 of file scripter_hooks.py.

51 def findMenu(self, title):
52 """
53 find a menu with a given title
54
55 @type title: string
56 @param title: English title of the menu
57 @rtype: QMenu
58 @return: None if no menu was found, else the menu with title
59 """
60 # See also http://pyqt.sourceforge.net/Docs/PyQt5/i18n.html#differences-between-pyqt5-and-qt
61 title = QApplication.translate(mikro.classname(self.window), title)
62 for menu in self.iter_menus():
63 if menu.title() == title:
64 return menu
65 for innerMenu in self.iter_inner_menus(menu):
66 if innerMenu.title() == title:
67 return innerMenu
68

References scripter_hooks.MenuHooks.iter_inner_menus(), scripter_hooks.MenuHooks.iter_menus(), KisMemoryWindow::MappingWindow.window, KisTheme.window(), View.window(), Window::Private.window, KoStorePrivate.window, and scripter_hooks.MenuHooks.window.

◆ insertMenuAfter()

scripter_hooks.MenuHooks.insertMenuAfter ( self,
after_menu,
new_menu )
Insert a menu before another menu in the menubar

Definition at line 108 of file scripter_hooks.py.

108 def insertMenuAfter(self, after_menu, new_menu):
109 """
110 Insert a menu before another menu in the menubar
111 """
112 if isinstance(after_menu, basestring):
113 after_menu = self.findMenu(after_menu)
114 after_after_menu = self.menuAfter(after_menu)
115 if after_after_menu:
116 return self.insertMenuBefore(after_after_menu, new_menu)
117 else:
118 return self.appendMenu(new_menu)
119

References scripter_hooks.MenuHooks.appendMenu(), scripter_hooks.MenuHooks.findMenu(), scripter_hooks.MenuHooks.insertMenuBefore(), and scripter_hooks.MenuHooks.menuAfter().

◆ insertMenuBefore()

scripter_hooks.MenuHooks.insertMenuBefore ( self,
before_menu,
new_menu )
Insert a menu after another menu in the menubar

@type: before_menu QMenu instance or title string of menu
@param before_menu: menu which should be after the newly inserted menu
@rtype: QAction instance
@return: action for inserted menu

Definition at line 74 of file scripter_hooks.py.

74 def insertMenuBefore(self, before_menu, new_menu):
75 """
76 Insert a menu after another menu in the menubar
77
78 @type: before_menu QMenu instance or title string of menu
79 @param before_menu: menu which should be after the newly inserted menu
80 @rtype: QAction instance
81 @return: action for inserted menu
82 """
83 if isinstance(before_menu, basestring):
84 before_menu = self.findMenu(before_menu)
85 before_action = self.actionForMenu(before_menu)
86 # I have no clue why QMenuBar::insertMenu only allows
87 # to insert before another menu and not after a menu...
88 new_action = self.menubar.insertMenu(before_action, new_menu)
89 return new_action
90

References scripter_hooks.MenuHooks.actionForMenu(), scripter_hooks.MenuHooks.findMenu(), scripter_hooks.MenuHooks.menubar, and krita.sceditor.mainwindow_ui.Ui_ScriptEditor.menubar.

◆ iter_inner_menus()

scripter_hooks.MenuHooks.iter_inner_menus ( self,
menu )

Definition at line 45 of file scripter_hooks.py.

45 def iter_inner_menus(self, menu):
46 for action in menu.actions():
47 menu = action.menu()
48 if menu:
49 yield menu
50

◆ iter_menus()

scripter_hooks.MenuHooks.iter_menus ( self)

Definition at line 39 of file scripter_hooks.py.

39 def iter_menus(self):
40 for action in self.menubar.actions():
41 menu = action.menu()
42 if menu:
43 yield menu
44

References scripter_hooks.MenuHooks.menubar, and krita.sceditor.mainwindow_ui.Ui_ScriptEditor.menubar.

◆ menuAfter()

scripter_hooks.MenuHooks.menuAfter ( self,
menu )

Definition at line 91 of file scripter_hooks.py.

91 def menuAfter(self, menu):
92 # This method is needed for insertMenuAfter because
93 # QMenuBar.insertMenu can only insert before another menu
94 previous = None
95 for m in self.iter_menus():
96 if previous and previous == menu:
97 return m
98 previous = m
99

References scripter_hooks.MenuHooks.iter_menus().

Member Data Documentation

◆ menubar

scripter_hooks.MenuHooks.menubar

Definition at line 30 of file scripter_hooks.py.

◆ menus

scripter_hooks.MenuHooks.menus

Definition at line 31 of file scripter_hooks.py.

◆ window

scripter_hooks.MenuHooks.window

Definition at line 29 of file scripter_hooks.py.


The documentation for this class was generated from the following file: