Skip to content

Commit

Permalink
mainwindow: Create separators if requested
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-erjavec committed Oct 15, 2015
1 parent 95a4ab9 commit f6fbe25
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
20 changes: 12 additions & 8 deletions oasys/canvas/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,19 +578,23 @@ def set_menu_registry(self, menu_registry):
sub_menus = menu_instance.getSubMenuNamesList()

for index in range(0, len(sub_menus)):
custom_action = \
QAction(sub_menus[index], self,
objectName=sub_menus[index].lower() + "-action",
toolTip=self.tr(sub_menus[index]),
)
if menu_instance.isSeparator(sub_menus[index]):
custom_menu.addSeparator()
else:
custom_action = \
QAction(sub_menus[index], self,
objectName=sub_menus[index].lower() + "-action",
toolTip=self.tr(sub_menus[index]),
)

custom_action.triggered.connect(getattr(menu_instance, 'executeAction_' + str(index+1)))
custom_action.triggered.connect(getattr(menu_instance, 'executeAction_' + str(index+1)))

custom_menu.addAction(custom_action)
custom_menu.addAction(custom_action)

self.menuBar().addMenu(custom_menu)
except Exception:
except Exception as exception:
print("Error in creating Customized Menu: " + str(menu_instance))
print(str(exception.args[0]))
continue

def closeEvent(self, event):
Expand Down
9 changes: 9 additions & 0 deletions oasys/menus/menu.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
__author__ = 'labx'
__menu__="just for discovery"

SEPARATOR = "OMENU_SEPARATOR"

class OMenu():

canvas_main_window=None
name = None
sub_menu_names = []
Expand All @@ -15,6 +18,12 @@ def setCanvasMainWindow(self, canvas_main_window):
def addSubMenu(self, name):
self.sub_menu_names.append(name)

def addSeparator(self):
self.sub_menu_names.append(SEPARATOR)

def isSeparator(self, name):
return name == SEPARATOR

def getSubMenuNamesList(self):
return self.sub_menu_names

0 comments on commit f6fbe25

Please sign in to comment.