Skip to content

Commit

Permalink
Update RibbonBar's parent to QMenuBar
Browse files Browse the repository at this point in the history
  • Loading branch information
Hailin Wang committed Jul 25, 2022
1 parent c47bd6f commit 7bc81bb
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 21 deletions.
2 changes: 1 addition & 1 deletion docs/source/tutorial-ribbonbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

# Ribbon bar
ribbonbar = RibbonBar()
window.setMenuBar(ribbonbar)
category = ribbonbar.addCategory("Category 1")
panel = category.addPanel("Panel 1")
panel.addLargeButton("A Large Button", QIcon(data_file_path("icons/python.png")))
Expand All @@ -35,7 +36,6 @@
label.setAlignment(Qt.AlignCenter)

# Add the ribbon bar and label to the layout
layout.addWidget(ribbonbar, 0)
layout.addWidget(label, 1)

# Show the window
Expand Down
6 changes: 2 additions & 4 deletions docs/source/user.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@ Instantiating a Ribbon Bar

To begin with, you have to initialize your PyQt application.

Using the RibbonBar
~~~~~~~~~~~~~~~~~~~

:py:class:`~ribbon.ribbonbar.RibbonBar` is a class that implements a ribbon bar, you can use it to create a ribbon bar.
:py:class:`~ribbon.ribbonbar.RibbonBar` is inherited from :py:class:`~PyQt5.QtWidgets.QMenuBar`,
you can use the `setMenuBar` method of :py:class:`~PyQt5.QtWidgets.QMainWindow` to set the ribbon bar as the main menu bar.

.. literalinclude:: tutorial-ribbonbar.py
:language: python
Expand Down
20 changes: 13 additions & 7 deletions examples/word.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@

from qtpy import QtWidgets, QtGui
from qtpy.QtGui import QIcon
from ribbon import RibbonMainWindow
from ribbon import RibbonBar

if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
app.setFont(QtGui.QFont("Times New Roman", 8))

window = RibbonMainWindow()
window = QtWidgets.QMainWindow()
window.setWindowTitle("Microsoft Word")
window.setWindowIcon(QIcon("word.png"))
window.layout().addWidget(QtWidgets.QTextEdit(), 1)
window.ribbonBar().setApplicationIcon(QIcon("word.png"))
window.ribbonBar().applicationOptionButton().setToolTip("Microsoft Word")
centralWidget = QtWidgets.QWidget()
window.setCentralWidget(centralWidget)
layout = QtWidgets.QVBoxLayout(centralWidget)
ribbonbar = RibbonBar()
window.setMenuBar(ribbonbar)

layout.addWidget(QtWidgets.QTextEdit(), 1)
ribbonbar.setApplicationIcon(QIcon("word.png"))
ribbonbar.applicationOptionButton().setToolTip("Microsoft Word")

# Home category
homeCategory = window.ribbonBar().addCategory("Home")
homeCategory = ribbonbar.addCategory("Home")
undoPanel = homeCategory.addPanel("Undo")
undoPanel.addMediumButton("Undo", icon=QIcon("undo.png"))
undoPanel.addMediumButton("Redo", icon=QIcon("redo.png"))
Expand Down
13 changes: 8 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
from qtpy import QtWidgets, QtGui, QtCore
from qtpy.QtGui import QIcon

from ribbon import RibbonMainWindow
from ribbon import RibbonBar

if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
app.setFont(QtGui.QFont("Times New Roman", 8))
app.setStyle("Windows")

window = RibbonMainWindow()
window = QtWidgets.QMainWindow()
ribbon = RibbonBar()
window.setMenuBar(ribbon)
window.setWindowTitle("Ribbon Test")
window.setWindowIcon(QIcon("icons/python.png"))

ribbon = window.ribbonBar()

window.setCentralWidget(QtWidgets.QWidget(window))
layout = QtWidgets.QVBoxLayout(window.centralWidget())

saveButton = QtWidgets.QToolButton()
saveButton.setAutoRaise(True)
Expand Down Expand Up @@ -142,7 +145,7 @@
label = QtWidgets.QLabel("Ribbon Test Window")
label.setFont(QtGui.QFont("Arial", 20))
label.setAlignment(QtCore.Qt.AlignCenter)
window.layout().addWidget(label, 1)
layout.addWidget(label, 1)

window.resize(1800, 350)
window.show()
Expand Down
50 changes: 49 additions & 1 deletion ribbon/ribbonbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class RibbonStyle(IntEnum):
Debug = 1


class RibbonBar(QtWidgets.QFrame):
class RibbonBar(QtWidgets.QMenuBar):
"""The RibbonBar class is the top level widget that contains the ribbon.
"""
#: Signal, the help button was clicked.
Expand Down Expand Up @@ -76,6 +76,54 @@ def __init__(self, *args, **kwargs):
)
self.setRibbonStyle(RibbonStyle.Default)

def actionAt(self, QPoint):
raise NotImplementedError('RibbonBar.actionAt() is not implemented in the ribbon bar.')

def actionGeometry(self, QAction):
raise NotImplementedError('RibbonBar.actionGeometry() is not implemented in the ribbon bar.')

def activeAction(self):
raise NotImplementedError('RibbonBar.activeAction() is not implemented in the ribbon bar.')

def addMenu(self, *__args):
raise NotImplementedError('RibbonBar.addMenu() is not implemented in the ribbon bar.')

def addAction(self, *__args):
raise NotImplementedError('RibbonBar.addAction() is not implemented in the ribbon bar.')

def addSeparator(self):
raise NotImplementedError('RibbonBar.addSeparator() is not implemented in the ribbon bar.')

def clear(self):
raise NotImplementedError('RibbonBar.clear() is not implemented in the ribbon bar.')

def cornerWidget(self, corner=None):
raise NotImplementedError('RibbonBar.cornerWidget() is not implemented in the ribbon bar.')

def insertMenu(self, QAction, QMenu):
raise NotImplementedError('RibbonBar.insertMenu() is not implemented in the ribbon bar.')

def insertSeparator(self, QAction):
raise NotImplementedError('RibbonBar.insertSeparator() is not implemented in the ribbon bar.')

def isDefaultUp(self):
raise NotImplementedError('RibbonBar.isDefaultUp() is not implemented in the ribbon bar.')

def isNativeMenuBar(self):
raise NotImplementedError('RibbonBar.isNativeMenuBar() is not implemented in the ribbon bar.')

def setActiveAction(self, QAction):
raise NotImplementedError('RibbonBar.setActiveAction() is not implemented in the ribbon bar.')

def setCornerWidget(self, QWidget, corner=None):
raise NotImplementedError('RibbonBar.setCornerWidget() is not implemented in the ribbon bar.')

def setDefaultUp(self, up):
raise NotImplementedError('RibbonBar.setDefaultUp() is not implemented in the ribbon bar.')

def setNativeMenuBar(self, bar):
raise NotImplementedError('RibbonBar.setNativeMenuBar() is not implemented in the ribbon bar.')

def setRibbonStyle(self, style: RibbonStyle):
"""Set the style of the ribbon.
Expand Down
5 changes: 2 additions & 3 deletions tests/test_ribbonbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def test_ribbonbar():

# Ribbon bar
ribbonbar = RibbonBar()
window.setMenuBar(ribbonbar)
category = ribbonbar.addCategory("Category 1")
panel = category.addPanel("Panel 1")
panel.addLargeButton("A Large Button", QtGui.QIcon(data_file_path("icons/python.png")))
Expand All @@ -36,11 +37,9 @@ def test_ribbonbar():
label.setAlignment(QtCore.Qt.AlignCenter)

# Add the ribbon bar and label to the layout
layout.addWidget(ribbonbar, 0)
layout.addWidget(label, 1)
layout.addWidget(label)

# Show the window
window.resize(1800, 350)
window.show()
sys.exit(app.exec_())

0 comments on commit 7bc81bb

Please sign in to comment.