commotion_client.GUI.menu_bar.MenuBar Class Reference
Inheritance diagram for commotion_client.GUI.menu_bar.MenuBar:

Public Member Functions

def __init__
 
def request_viewport
 
def clear_layout
 
def populate_menu
 
def get_parents
 
def add_menu_item
 

Public Attributes

 layout
 
 log
 
 translate
 
 ext_mgr
 

Static Public Attributes

tuple viewport_requested = QtCore.pyqtSignal(str)
 

Member Function Documentation

def commotion_client.GUI.menu_bar.MenuBar.add_menu_item (   self,
  parent 
)
Creates and returns a single top level menu item with cascading sub-menu items.

Args:
parent (string): The "parent" the top level menu item that is being requested.

Returns:
A tuple containing a top level button and its hidden sub-menu items.        

References commotion_client.GUI.menu_bar.MenuBar.request_viewport(), commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, and commotion_client.commotion_client.CommotionClientApplication.translate.

Referenced by commotion_client.GUI.menu_bar.MenuBar.populate_menu().

126  def add_menu_item(self, parent):
127  """Creates and returns a single top level menu item with cascading sub-menu items.
128 
129  Args:
130  parent (string): The "parent" the top level menu item that is being requested.
131 
132  Returns:
133  A tuple containing a top level button and its hidden sub-menu items.
134  """
135  extensions = self.ext_mgr.get_extension_from_property('parent', parent)
136  if not extensions:
137  raise NameError(self.translate("logs", "No extensions found under the parent item {0}.".format(parent)))
138  #Create Top level item button
139  title_button = QtGui.QPushButton(QtCore.QCoreApplication.translate("Menu Item", parent))
140  title_button.setCheckable(True)
141  #Create sub-menu
142  sub_menu = QtGui.QFrame()
143  sub_menu_layout = QtGui.QVBoxLayout()
144  #populate the sub-menu item table.
145  for ext in extensions:
146  sub_menu_item = subMenuWidget(self)
147  try:
148  menu_item_title = self.ext_mgr.get_property(ext, 'menu_item')
149  except KeyError:
150  menu_item_title = ext
151  sub_menu_item.setText(QtCore.QCoreApplication.translate("Sub-Menu Item", menu_item_title))
152  #We use partial here to pass a variable along when we attach the "clicked()" signal to the MenuBars requestViewport function
153  sub_menu_item.clicked.connect(partial(self.request_viewport, ext))
154  sub_menu_layout.addWidget(sub_menu_item)
155  sub_menu.setLayout(sub_menu_layout)
156  sub_menu.hide()
157  #Connect toggle on out checkable title button to the visability of our subMenu
158  title_button.toggled.connect(sub_menu.setVisible)
159  #package and return top level item and its corresponding subMenu
160  section = (title_button, sub_menu)
161  return section
162 
translate
Definition: menu_bar.py:38
def request_viewport
Definition: menu_bar.py:47
def add_menu_item
Definition: menu_bar.py:125
def commotion_client.GUI.menu_bar.MenuBar.clear_layout (   self,
  layout 
)
Clears a layout of all widgets.
 
Args:
layout (QLayout): A QLayout object that needs to be cleared of all objects.

References commotion_client.GUI.menu_bar.MenuBar.clear_layout().

Referenced by commotion_client.GUI.menu_bar.MenuBar.clear_layout(), and commotion_client.GUI.menu_bar.MenuBar.populate_menu().

54 
55  def clear_layout(self, layout):
56  """Clears a layout of all widgets.
57 
58  Args:
59  layout (QLayout): A QLayout object that needs to be cleared of all objects.
60  """
61  if not layout.isEmpty():
62  while layout.count():
63  item = layout.takeAt(0)
64  widget = item.widget()
65  if widget is not None:
66  widget.deleteLater()
67  else:
68  self.clear_layout(item.layout())
def clear_layout
Definition: menu_bar.py:54
def commotion_client.GUI.menu_bar.MenuBar.get_parents (   self,
  extension_list 
)
Gets all unique parents from a list of extensions.

This function gets the "parent" menu items from a list of extensions and returns a list of the unique members.

Args:
  extension_list (list): A list containing a set of strings that list the names of extensions.

Returns:
  A list of all the unique parents of the given extensions.

    ['parent item 01', 'parent item 02']

References commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, and commotion_client.commotion_client.CommotionClientApplication.translate.

Referenced by commotion_client.GUI.menu_bar.MenuBar.populate_menu().

101  def get_parents(self, extension_list):
102  """Gets all unique parents from a list of extensions.
103 
104  This function gets the "parent" menu items from a list of extensions and returns a list of the unique members.
105 
106  Args:
107  extension_list (list): A list containing a set of strings that list the names of extensions.
108 
109  Returns:
110  A list of all the unique parents of the given extensions.
111 
112  ['parent item 01', 'parent item 02']
113  """
114  parents = []
115  for ext in extension_list:
116  try:
117  parent = self.ext_mgr.get_property(ext, "parent")
118  except KeyError:
119  self.log.debug(self.translate("logs", "Config for {0} does not contain a {1} value. Setting {1} to default value.".format(ext, "parent")))
120  parent = "Extensions"
121  if parent not in parents:
122  parents.append(parent)
123  return parents
124 
translate
Definition: menu_bar.py:38
def get_parents
Definition: menu_bar.py:100
def commotion_client.GUI.menu_bar.MenuBar.populate_menu (   self)
Resets and populates the menu using loaded extensions.

References commotion_client.GUI.menu_bar.MenuBar.add_menu_item(), commotion_client.GUI.menu_bar.MenuBar.clear_layout(), commotion_client.GUI.menu_bar.MenuBar.get_parents(), commotion_client.GUI.menu_bar.MenuBar.layout, commotion_client.GUI.menu_bar.MenuBar.translate, commotion_client.extensions.config_editor.main.ViewPort.translate, commotion_client.GUI.main_window.MainWindow.translate, commotion_client.GUI.extension_toolbar.ExtensionToolBar.translate, commotion_client.GUI.extension_toolbar.MenuItem.translate, and commotion_client.commotion_client.CommotionClientApplication.translate.

69 
70  def populate_menu(self):
71  """Resets and populates the menu using loaded extensions."""
72  if not self.layout.isEmpty():
73  self.clear_layout(self.layout)
74  menu_items = {}
75  if not self.ext_mgr.check_installed():
76  self.ext_mgr.init_extension_libraries()
77  extensions = self.ext_mgr.get_installed().keys()
78  if extensions:
79  top_level = self.get_parents(extensions)
80  for top_level_item in top_level:
81  try:
82  current_item = self.add_menu_item(top_level_item)
83  except NameError as _excpt:
84  self.log.debug(self.translate("logs", "No extensions found under the parent item {0}. Parent item will not be added to the menu.".format(top_level_item)))
85  self.log.exception(_excpt)
86  else:
87  if current_item:
88  menu_items[top_level_item] = current_item
89  if menu_items:
90  for title, section in menu_items.items():
91  #Add top level menu item
92  self.layout.addWidget(section[0])
93  #Add sub-menu layout
94  self.layout.addWidget(section[1])
95  else:
96  raise AttributeError(QtCore.QCoreApplication.translate("exception", "No menu items could be created from the extensions found. Please re-run the commotion client with full verbosity to identify what went wrong."))
97  else:
98  raise NameError(QtCore.QCoreApplication.translate("exception", "No extensions found. Please re-run the commotion_client with full verbosity to find out what went wrong."))
99  self.setLayout(self.layout)
translate
Definition: menu_bar.py:38
def populate_menu
Definition: menu_bar.py:69
layout
Definition: menu_bar.py:34
def clear_layout
Definition: menu_bar.py:54
def add_menu_item
Definition: menu_bar.py:125
def get_parents
Definition: menu_bar.py:100
def commotion_client.GUI.menu_bar.MenuBar.request_viewport (   self,
  viewport 
)
When called will emit a request for a viewport change.

Referenced by commotion_client.GUI.menu_bar.MenuBar.add_menu_item().

47 
48  def request_viewport(self, viewport):
49  """
50  When called will emit a request for a viewport change.
51  """
52  self.log.debug(QtCore.QCoreApplication.translate("logs", "Request to change viewport sent"))
53  self.viewport_requested.emit(viewport)
def request_viewport
Definition: menu_bar.py:47

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