|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the project helper base for Mercurial extension interfaces. |
|
8 """ |
|
9 |
|
10 from PyQt5.QtCore import QObject |
|
11 from PyQt5.QtWidgets import QMenu |
|
12 |
|
13 |
|
14 class HgExtensionProjectHelper(QObject): |
|
15 """ |
|
16 Class implementing the project helper base for Mercurial extension |
|
17 interfaces. |
|
18 |
|
19 Note: The methods initActions(), initMenu(mainMenu) and menuTitle() have |
|
20 to be reimplemented by derived classes. |
|
21 """ |
|
22 def __init__(self): |
|
23 """ |
|
24 Constructor |
|
25 """ |
|
26 super().__init__() |
|
27 |
|
28 self.actions = [] |
|
29 |
|
30 self.initActions() |
|
31 |
|
32 def setObjects(self, vcsObject, projectObject): |
|
33 """ |
|
34 Public method to set references to the vcs and project objects. |
|
35 |
|
36 @param vcsObject reference to the vcs object |
|
37 @param projectObject reference to the project object |
|
38 """ |
|
39 self.vcs = vcsObject |
|
40 self.project = projectObject |
|
41 |
|
42 def getActions(self): |
|
43 """ |
|
44 Public method to get a list of all actions. |
|
45 |
|
46 @return list of all actions (list of E5Action) |
|
47 """ |
|
48 return self.actions[:] |
|
49 |
|
50 def initActions(self): |
|
51 """ |
|
52 Public method to generate the action objects. |
|
53 |
|
54 Note: Derived class must implement this method. |
|
55 |
|
56 @exception NotImplementedError raised if the class has not been |
|
57 reimplemented |
|
58 """ |
|
59 raise NotImplementedError |
|
60 |
|
61 def initMenu(self, mainMenu): |
|
62 """ |
|
63 Public method to generate the extension menu. |
|
64 |
|
65 Note: Derived class must implement this method. |
|
66 |
|
67 @param mainMenu reference to the main menu (QMenu) |
|
68 @return populated menu (QMenu) |
|
69 @exception NotImplementedError raised if the class has not been |
|
70 reimplemented |
|
71 """ |
|
72 raise NotImplementedError |
|
73 |
|
74 return QMenu() |
|
75 |
|
76 def menuTitle(self): |
|
77 """ |
|
78 Public method to get the menu title. |
|
79 |
|
80 Note: Derived class must implement this method. |
|
81 |
|
82 @return title of the menu (string) |
|
83 @exception NotImplementedError raised if the class has not been |
|
84 reimplemented |
|
85 """ |
|
86 raise NotImplementedError |
|
87 |
|
88 return "" |
|
89 |
|
90 def shutdown(self): |
|
91 """ |
|
92 Public method to perform shutdown actions. |
|
93 |
|
94 Note: Derived class may implement this method if needed. |
|
95 """ |
|
96 pass |