Application Example
import sys, os
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../shared")
from DevMachines import __pyside2__, __pyside6__
from DevMachines import QtitanBase
from DevMachines.QtitanBase import Qtitan, CommonStyle
from DevMachines.QtitanRibbon import (RibbonBar, RibbonSliderPane, RibbonGallery, RibbonGalleryGroup, RibbonLabelControl, RibbonDoubleSpinBoxControl,
RibbonGalleryControl, RibbonToolBarControl, RibbonControlSizeDefinition, PopupColorButton, OfficePopupMenu,
RibbonStatusBar, RibbonStatusBarSwitchGroup)
if __pyside2__:
from PySide2 import QtCore
from PySide2.QtCore import Qt, QTextStream, QSize, QFile, QFileInfo, QSettings, QByteArray, QBuffer, QIODevice
from PySide2.QtGui import QFontMetrics, QFontInfo, QIcon, QPixmap, QColor, QTextCharFormat, QKeySequence, QContextMenuEvent, QFontDatabase, QFont
from PySide2.QtWidgets import (QSizePolicy, QAction, QActionGroup, QApplication, QWidget, QMenu, QMessageBox,
QGroupBox, QVBoxLayout, QFontComboBox, QCheckBox, QDockWidget, QListWidget, QTextEdit, QListWidgetItem,
QComboBox, QToolButton, QWidgetAction)
if __pyside6__:
from PySide6 import QtCore
from PySide6.QtCore import Qt, QTextStream, QSize, QFile, QFileInfo, QSettings, QByteArray, QBuffer, QIODevice
from PySide6.QtGui import (QAction, QActionGroup, QFontMetrics, QFontInfo, QIcon, QPixmap, QColor, QTextCharFormat,
QKeySequence, QContextMenuEvent, QFontDatabase, QFont)
from PySide6.QtWidgets import (QWidgetAction, QSizePolicy, QApplication, QWidget, QMenu, QMessageBox,
QGroupBox, QVBoxLayout, QFontComboBox, QCheckBox, QDockWidget, QListWidget, QTextEdit, QListWidgetItem,
QComboBox, QToolButton)
from DemoRibbonWindow import DemoRibbonWindow
import Application_rc
from ribbonpopularpage import RibbonPopularPage
class MainWindow(DemoRibbonWindow):
categoryPopularCommands = "Popular Commands"
categoryAllCommands = "All Commands"
categoryMainPages = "Main Pages"
backgroundUrl = ""
def __init__(self):
DemoRibbonWindow.__init__(self)
self.setWindowTitle(self.tr("PyQtitanRibbon Office Sample"))
self.comboFont = None
self.setRibbonBackground(":/res/calligraphy.png")
self.createAction()
self.createMenuFile()
self.createQuickAccessBar()
self.createRibbonBar()
self.createStatusBar()
self.createDockWindows()
self.textEdit = QTextEdit(self)
self.connect(self.textEdit, QtCore.SIGNAL("currentCharFormatChanged(QTextCharFormat)"), self.currentCharFormatChanged)
self.connect(self.textEdit, QtCore.SIGNAL("cursorPositionChanged()"), self.cursorPositionChanged)
self.setCentralWidget(self.textEdit)
self.textEdit.setFocus()
self.fontChanged(self.textEdit.font())
self.colorChanged(self.textEdit.textColor())
self.alignmentChanged(self.textEdit.alignment())
self.connect(self.textEdit.document(), QtCore.SIGNAL("modificationChanged(bool)"), self.actionSaveFile, QtCore.SLOT("setEnabled(bool)"))
self.connect(self.textEdit.document(), QtCore.SIGNAL("modificationChanged(bool)"), self, QtCore.SLOT("setWindowModified(bool)"))
self.connect(self.textEdit.document(), QtCore.SIGNAL("undoAvailable(bool)"), self.actionUndo, QtCore.SLOT("setEnabled(bool)"))
self.connect(self.textEdit.document(), QtCore.SIGNAL("redoAvailable(bool)"), self.actionRedo, QtCore.SLOT("setEnabled(bool)"))
self.setWindowModified(self.textEdit.document().isModified())
self.actionSaveFile.setEnabled(self.textEdit.document().isModified())
self.actionUndo.setEnabled(self.textEdit.document().isUndoAvailable())
self.actionRedo.setEnabled(self.textEdit.document().isRedoAvailable())
self.connect(self.actionUndo, QtCore.SIGNAL("triggered()"), self.textEdit, QtCore.SLOT("undo()"))
self.connect(self.actionRedo, QtCore.SIGNAL("triggered()"), self.textEdit, QtCore.SLOT("redo()"))
self.actionCut.setEnabled(False)
self.actionCopy.setEnabled(False)
self.connect(self.actionCut, QtCore.SIGNAL("triggered()"), self.textEdit, QtCore.SLOT("cut()"))
self.connect(self.actionCopy, QtCore.SIGNAL("triggered()"), self.textEdit, QtCore.SLOT("copy()"))
self.connect(self.actionPaste1, QtCore.SIGNAL("triggered()"), self.textEdit, QtCore.SLOT("paste()"))
self.connect(self.actionPaste2, QtCore.SIGNAL("triggered()"), self.textEdit, QtCore.SLOT("paste()"))
self.connect(self.textEdit, QtCore.SIGNAL("copyAvailable(bool)"), self.actionCut, QtCore.SLOT("setEnabled(bool)"))
self.connect(self.textEdit, QtCore.SIGNAL("copyAvailable(bool)"), self.actionCopy, QtCore.SLOT("setEnabled(bool)"))
self.connect(QApplication.clipboard(), QtCore.SIGNAL("dataChanged()"), self, QtCore.SLOT("clipboardDataChanged()"))
self.connect(self.textEdit, QtCore.SIGNAL("selectionChanged()"), self, QtCore.SLOT("selectionChanged()"))
self.connect(self.ribbonBar(), QtCore.SIGNAL("showRibbonContextMenu(QMenu*, QContextMenuEvent*)"), self, QtCore.SLOT("showRibbonContextMenu(QMenu*, QContextMenuEvent*)"))
self.ribbonBar().setFrameThemeEnabled()
self.stateWindow = self.windowState()
initialFile = ":/res/example.html"
args = QApplication.arguments()
if len(args) == 2:
initialFile = args.at(1)
customizeManager = self.ribbonBar().customizeManager()
customizeManager.setDefaultState() # Make a default state-point for ribbon-ui elements.
self.customization()
if not self.load(initialFile):
self.fileNew()
self.readSettings()
def ribbonBackground(self):
return self.backgroundUrl
def setRibbonBackground(self, name):
if self.backgroundUrl != name:
self.backgroundUrl = name
self.updateRibbonBackground()
def closeEvent(self, event):
if self.maybeSave():
event.accept()
else:
event.ignore()
self.writeSettings()
def createAction(self):
self.actionFileNew = QAction(DemoRibbonWindow.createIcon(DemoRibbonWindow.Image_New), self.tr("&New"), self)
self.actionFileNew.setPriority(QAction.LowPriority)
self.actionFileNew.setShortcut(QKeySequence.New)
self.actionFileNew.setStatusTip(self.tr("Create a new document"))
self.actionFileNew.setToolTip(self.tr("New"))
self.connect(self.actionFileNew, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("fileNew()"))
self.actionOpenFile = QAction(DemoRibbonWindow.createIcon(DemoRibbonWindow.Image_Open), self.tr("&Open..."), self)
self.actionOpenFile.setShortcut(QKeySequence.Open)
self.actionOpenFile.setToolTip(self.tr("Open"))
self.actionOpenFile.setStatusTip(self.tr("Open an existing document"))
self.connect(self.actionOpenFile, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("fileOpen()"))
self.actionSaveFile = QAction(DemoRibbonWindow.createIcon(DemoRibbonWindow.Image_Save), self.tr("&Save"), self)
self.actionSaveFile.setShortcut(QKeySequence.Save)
self.actionSaveFile.setToolTip(self.tr("Save"))
self.actionSaveFile.setStatusTip(self.tr("Save the active document"))
self.actionSaveFile.setEnabled(False)
self.connect(self.actionSaveFile, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("fileSave()"))
self.actionPrint = QAction(DemoRibbonWindow.createIcon(DemoRibbonWindow.Image_Print), self.tr("&Print..."), self)
self.actionPrint.setPriority(QAction.LowPriority)
self.actionPrint.setShortcut(QKeySequence.Print)
self.actionPrint.setToolTip(self.tr("Select a printer, number of copies, and other printing options before printing"))
self.connect(self.actionPrint, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("filePrint()"))
self.actionPrintSetup = QAction(QIcon(":/res/largePrintSetup.png"), self.tr("P&rint Setup"), self)
self.actionPrintSetup.setToolTip(self.tr("Change the printer and printing options"))
self.actionPrintPreview = QAction(QIcon(":/res/largePrintPreview.png"), self.tr("Print Pre&view..."), self)
self.actionPrintPreview.setToolTip(self.tr("Preview and make changes to pages before printing"))
self.connect(self.actionPrintPreview, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("filePrintPreview()"))
def createMenuFile(self):
iconLogo = QIcon()
iconLogo.addPixmap(QPixmap(":/res/qtitanlogo32x32.png"))
actionFile = self.ribbonBar().addSystemButton(iconLogo, self.tr("&File"))
if actionFile:
actionFile.setToolTip(self.tr("Click here to see everything you can do with your document"))
systemMenu = self.ribbonBar().systemButton().systemMenu()
systemMenu.addAction(self.actionFileNew)
systemMenu.addAction(self.actionOpenFile)
systemMenu.addAction(self.actionSaveFile)
actionSaveAsFile = systemMenu.addAction(DemoRibbonWindow.createIcon(DemoRibbonWindow.Image_SaveAs), self.tr("Save &As..."))
actionSaveAsFile.setPriority(QAction.LowPriority)
actionSaveAsFile.setToolTip(self.tr("Save As"))
actionSaveAsFile.setStatusTip(self.tr("Save the active document with a new name"))
self.connect(actionSaveAsFile, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("fileSaveAs()"))
systemMenu.addSeparator()
actionPagePrint = QAction(self.actionPrint.icon(), self.actionPrint.text(), self)
systemMenu.addAction(actionPagePrint)
pageSystemPopup = systemMenu.addPageSystemPopup(self.tr("Preview and print the document"), actionPagePrint, True)
if pageSystemPopup:
self.connect(actionPagePrint, QtCore.SIGNAL("triggered()"), self.actionPrint, QtCore.SIGNAL("triggered()"))
pageSystemPopup.setMinimumWidth(296)
pageSystemPopup.addAction(self.actionPrint)
pageSystemPopup.addAction(self.actionPrintSetup)
pageSystemPopup.addAction(self.actionPrintPreview)
actionPrepare = systemMenu.addAction(QIcon(":/res/largePrepare.png"), self.tr("Pr&epare"))
systemMenu.addAction(actionPrepare)
actionSend = systemMenu.addAction(QIcon(":/res/largeSend.png"), self.tr("Sen&d"))
systemMenu.addAction(actionSend)
pageSystemPopup = systemMenu.addPageSystemPopup(self.tr("Preview and print the document"), actionSend, False)
if pageSystemPopup:
pageSystemPopup.setMinimumWidth(296)
actionMail = pageSystemPopup.addAction(QIcon(":/res/largeMail.png"), self.tr("E-Mail"))
actionMail.setToolTip(self.tr("Send the active document by e-mail"))
pageSystemPopup.addAction(actionMail)
actionIntenetFax = pageSystemPopup.addAction(QIcon(":/res/largeInternetfix.png"), self.tr("Intenet Fax"))
actionIntenetFax.setToolTip(self.tr("Use an Internet fax service to fax the document"))
pageSystemPopup.addAction(actionIntenetFax)
systemMenu.addSeparator()
actionClose = systemMenu.addAction(DemoRibbonWindow.createIcon(DemoRibbonWindow.Image_Close), self.tr("&Close"))
actionClose.setShortcut(self.tr("Ctrl+C"))
actionClose.setStatusTip(self.tr("Exit"))
actionClose.setEnabled(False)
actionExit = systemMenu.addPopupBarAction(self.tr("Exit Sample"))
self.connect(actionExit, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("close()"))
actionOption = systemMenu.addPopupBarAction(self.tr("Option"))
actionOption.setEnabled(False)
pageRecentFile = systemMenu.addPageRecentFile(self.tr("Recent Documents"))
def createQuickAccessBar(self):
quickAccessBar = self.ribbonBar().quickAccessBar()
if quickAccessBar:
action = quickAccessBar.actionCustomizeButton()
action.setToolTip(self.tr("Customize Quick Access Bar"))
quickAccessBar.addAction(self.actionFileNew)
quickAccessBar.setActionVisible(self.actionFileNew, False)
quickAccessBar.addAction(self.actionOpenFile)
quickAccessBar.setActionVisible(self.actionOpenFile, False)
quickAccessBar.addAction(self.actionSaveFile)
self.actionUndo = quickAccessBar.addAction(DemoRibbonWindow.createIcon(DemoRibbonWindow.Image_Undo), self.tr("&Undo"))
self.actionUndo.setShortcut(QKeySequence.Undo)
self.actionRedo = quickAccessBar.addAction(DemoRibbonWindow.createIcon(DemoRibbonWindow.Image_Redo), self.tr("&Redo"))
self.actionRedo.setShortcut(QKeySequence.Redo)
quickAccessBar.addAction(self.actionPrint)
quickAccessBar.setVisible(True)
def createRibbonBar(self):
self.pageHome = self.ribbonBar().addPage(self.tr("&Home"))
if self.pageHome:
self.createGroupClipboard(self.pageHome)
self.createGroupFont(self.pageHome)
self.createGroupParagraph(self.pageHome)
self.createGroupStyles(self.pageHome)
self.createGroupEditing(self.pageHome)
self.pageInsert = self.ribbonBar().addPage(self.tr("&Insert"))
if self.pageInsert:
self.createGroupPages(self.pageInsert)
self.createGroupTables(self.pageInsert)
self.createGroupIllustrations(self.pageInsert)
self.createGroupLinks(self.pageInsert)
self.createGroupHeaderFooter(self.pageInsert)
self.createGroupText(self.pageInsert)
self.createGroupSymbols(self.pageInsert)
self.pageLayout = self.ribbonBar().addPage(self.tr("&Page Layout"))
if self.pageLayout:
self.createGroupThemes(self.pageLayout.addGroup(self.tr("Themes")))
self.createGroupPageSetup(self.pageLayout.addGroup(self.tr("Page Setup")))
self.createGroupPageBackground(self.pageLayout.addGroup(self.tr("Page Background")))
self.createGroupParagraphLayout(self.pageLayout.addGroup(self.tr("Paragraph")))
self.pageRef = self.ribbonBar().addPage(self.tr("Reference&s"))
if self.pageRef:
self.createGroupTableOfContents(self.pageRef.addGroup(self.tr("Table of Contents")))
self.createGroupFootnotes(self.pageRef.addGroup(self.tr("&Footnotes")))
self.createGroupCaptions(self.pageRef.addGroup(self.tr("Captions")))
self.createGroupIndex(self.pageRef.addGroup(self.tr("Index")))
self.pageView = self.ribbonBar().addPage(self.tr("View"))
if self.pageView:
self.createGroupDocumentViews(self.pageView.addGroup(self.tr("Document Views")))
self.createGroupShow_Hide(self.pageView.addGroup(self.tr("Show/Hide")))
self.createGroupZoom(self.pageView.addGroup(self.tr("Zoom")))
self.pagePictureFormat = self.ribbonBar().addPage(self.tr("Picture Format"))
if self.pagePictureFormat:
self.pagePictureFormat.setContextTitle(self.tr("Picture Tools"))
self.pagePictureFormat.setContextColor(Qtitan.ContextColorRed)
self.pagePictureFormat.setVisible(False)
def createGroupClipboard(self, page):
groupClipboard = page.addGroup(DemoRibbonWindow.createIcon(DemoRibbonWindow.Image_Clipboard), self.tr("Clipboard"))
if groupClipboard:
groupClipboard.setOptionButtonVisible(True)
action = groupClipboard.optionButtonAction()
action.setText(self.tr("Clipboard"))
action.setIcon(QIcon(":/res/clipboardToolTip.png"))
action.setToolTip(self.tr("Show the Office clipboard Task Pane"))
action.setStatusTip(self.tr("Show the Office clipboard Task Pane"))
self.connect(action, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("optionClipboard()"))
editPaste = QMenu(self.ribbonBar())
self.actionPaste1 = editPaste.addAction(DemoRibbonWindow.createIcon(DemoRibbonWindow.Image_Clipboard), self.tr("Paste"))
self.actionPaste1.setPriority(QAction.LowPriority)
self.actionPaste1.setShortcut(QKeySequence.Paste)
editPaste.addAction(self.tr("Paste Special"))
self.actionPaste2 = groupClipboard.addAction(DemoRibbonWindow.createIcon(DemoRibbonWindow.Image_Clipboard), self.tr("&Paste"), Qt.ToolButtonTextUnderIcon, editPaste)
control = groupClipboard.controlByAction(self.actionPaste2)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setWordWrap(False)
self.actionPaste2.setPriority(QAction.LowPriority)
self.actionPaste2.setShortcut(QKeySequence.Paste)
self.actionPaste2.setToolTip(self.tr("Insert Clipboard contents"))
self.actionPaste1.setEnabled(QApplication.clipboard().text() != "")
self.actionPaste2.setEnabled(QApplication.clipboard().text() != "")
self.actionCut = groupClipboard.addAction(QIcon(":/res/smallcut.png"), self.tr("&Cut"), Qt.ToolButtonTextBesideIcon)
control = groupClipboard.controlByAction(self.actionCut)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageSmall)
self.actionCut.setShortcut(QKeySequence.Cut)
self.actionCut.setToolTip(self.tr("Cut the selection and put it on the Clipboard"))
self.actionCopy = groupClipboard.addAction(QIcon(":/res/smallcopy.png"), self.tr("&Copy"), Qt.ToolButtonTextBesideIcon)
control = groupClipboard.controlByAction(self.actionCopy)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageSmall)
self.actionCopy.setShortcut(QKeySequence.Copy)
self.actionFormatPointerAction = groupClipboard.addAction(QIcon(":/res/smallformatpainter.png"), self.tr("F&ormat Pointer"), Qt.ToolButtonTextBesideIcon)
control = groupClipboard.controlByAction(self.actionFormatPointerAction)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageSmall)
def createGroupFont(self, page):
groupFont = page.addGroup(QIcon(":/res/smallfontgrow.png"), self.tr("Font"))
if groupFont:
groupFont.setOptionButtonVisible(True)
action = groupFont.optionButtonAction()
action.setText(self.tr("F&ont"))
action.setIcon(QIcon(":/res/fontToolTip.png"))
action.setToolTip(self.tr("Show the Font dialog box"))
action.setStatusTip(self.tr("Show the Font dialog box"))
self.connect(action, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("optionFont()"))
toolBarControl = RibbonToolBarControl(groupFont)
self.comboFont = QFontComboBox()
self.comboFont.setMaximumWidth(130)
toolBarControl.addWidget(self.comboFont)
self.connect(self.comboFont, QtCore.SIGNAL("activated(str)"), self, QtCore.SLOT("textFamily(str)"))
self.comboSize = QComboBox()
self.comboSize.setMaximumWidth(45)
self.comboSize.setObjectName("self.comboSize")
toolBarControl.addWidget(self.comboSize)
self.comboSize.setEditable(False)
db = QFontDatabase()
for size in db.standardSizes():
self.comboSize.addItem(str(size))
self.connect(self.comboSize, QtCore.SIGNAL("activated(str)"), self, QtCore.SLOT("textSize(str)"))
self.comboSize.setCurrentIndex(self.comboSize.findText(str(QApplication.font().pointSize())))
toolBarControl.addSeparator()
toolBarControl.addAction(QIcon(":/res/smallfontgrow.png"), self.tr("Grow Font"))
toolBarControl.addAction(QIcon(":/res/smallfontshrink.png"), self.tr("Shrink Font"))
toolBarControl.addSeparator()
toolBarControl.addAction(QIcon(":/res/smallfontclear.png"), self.tr("&Clear Formatting"))
toolBarControl.addSeparator()
self.actionTextBold = toolBarControl.addAction(QIcon(":/res/smalltextbold.png"), self.tr("&Bold"))
self.actionTextBold.setShortcut(Qt.CTRL | Qt.Key_B)
self.actionTextBold.setPriority(QAction.LowPriority)
bold = QFont()
bold.setBold(True)
self.actionTextBold.setFont(bold)
self.connect(self.actionTextBold, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("textBold()"))
self.actionTextBold.setCheckable(True)
self.actionTextItalic = toolBarControl.addAction(QIcon(":/res/smalltextitalic.png"), self.tr("&Italic"))
self.actionTextItalic.setPriority(QAction.LowPriority)
self.actionTextItalic.setShortcut(Qt.CTRL | Qt.Key_I)
italic = QFont()
italic.setItalic(True)
self.actionTextItalic.setFont(italic)
self.connect(self.actionTextItalic, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("textItalic()"))
self.actionTextItalic.setCheckable(True)
self.actionTextUnderline = toolBarControl.addAction(QIcon(":/res/smalltextunder.png"), self.tr("&Underline"))
self.actionTextUnderline.setShortcut(Qt.CTRL | Qt.Key_U)
self.actionTextUnderline.setPriority(QAction.LowPriority)
underline = QFont()
underline.setUnderline(True)
self.actionTextUnderline.setFont(underline)
self.connect(self.actionTextUnderline, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("textUnderline()"))
self.actionTextUnderline.setCheckable(True)
charStrikethrough = toolBarControl.addAction(QIcon(":/res/smallstrikethrough.png"), self.tr("Strikethrough"))
charStrikethrough.setEnabled(False)
toolBarControl.addSeparator()
textSubscript = toolBarControl.addAction(QIcon(":/res/smallsubscript.png"), self.tr("Subscript"))
textSubscript.setEnabled(False)
textSuperscript = toolBarControl.addAction(QIcon(":/res/smallsuperscript.png"), self.tr("Superscript"))
textSuperscript.setEnabled(False)
textChangecase = toolBarControl.addAction(QIcon(":/res/smallchangecase.png"), self.tr("Change Case"))
textChangecase.setEnabled(False)
toolBarControl.addSeparator()
highlightColorButton = PopupColorButton()
textHighlightcolor = toolBarControl.addWidget(QIcon(":/res/smallcolor.png"), self.tr("Highlight Color"), highlightColorButton)
textHighlightcolor.setEnabled(False)
self.colorButton = PopupColorButton()
self.actionTextColor = toolBarControl.addWidget(QIcon(":/res/smallcolor.png"), self.tr("Color"), self.colorButton)
self.connect(self.colorButton, QtCore.SIGNAL("colorChanged(const QColor&)"), self, QtCore.SLOT("textColor(const QColor&)"))
self.connect(self.actionTextColor, QtCore.SIGNAL("triggered()"), self.setColorText)
groupFont.addControl(toolBarControl)
def createGroupParagraph(self, page):
groupParagraph = page.addGroup(QIcon(":/res/smallcenter.png"), self.tr("&Paragraph"))
if groupParagraph:
groupParagraph.setOptionButtonVisible(True)
action = groupParagraph.optionButtonAction()
action.setText(self.tr("Paragraph"))
action.setIcon(QIcon(":/res/paragraphToolTip.png"))
action.setToolTip(self.tr("Show the Paragraph dialog box"))
action.setStatusTip(self.tr("Show the Paragraph dialog box"))
self.connect(action, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("optionParagraph()"))
toolBarControl = RibbonToolBarControl(groupParagraph)
toolBarControl.addAction(QIcon(":/res/smallbullets.png"),
self.tr("Bullets"), Qt.ToolButtonIconOnly, QMenu(self.ribbonBar()), QToolButton.InstantPopup)
toolBarControl.addAction(QIcon(":/res/smallnumbering.png"),
self.tr("Numbering"), Qt.ToolButtonIconOnly, QMenu(self), QToolButton.InstantPopup)
toolBarControl.addAction(QIcon(":/res/smallmultilevellist.png"),
self.tr("Multilevel List"), Qt.ToolButtonIconOnly, QMenu(self.ribbonBar()), QToolButton.InstantPopup)
toolBarControl.addSeparator()
toolBarControl.addAction(QIcon(":/res/smalldecreaseindent.png"),
self.tr("Decrease Indent"), Qt.ToolButtonIconOnly)
toolBarControl.addAction(QIcon(":/res/smallincreaseindent.png"),
self.tr("Increase Indent"), Qt.ToolButtonIconOnly)
toolBarControl.addSeparator()
toolBarControl.addAction(QIcon(":/res/smallsort.png"),
self.tr("Sort"), Qt.ToolButtonIconOnly)
toolBarControl.addSeparator()
action = toolBarControl.addAction(QIcon(":/res/smallshow_hide_marks.png"),
self.tr("Show/Hide Marks"), Qt.ToolButtonIconOnly)
action.setCheckable(False)
self.connect(action, QtCore.SIGNAL("triggered()"), self, QtCore.SLOT("showHideMarks()"))
toolBarControl.addSeparator()
grp = QActionGroup(self)
self.connect(grp, QtCore.SIGNAL("triggered(QAction*)"), self, QtCore.SLOT("textAlign(QAction*)"))
self.actionAlignLeft = toolBarControl.addAction(QIcon(":/res/smallalignleft.png"),
self.tr("Align Left"), Qt.ToolButtonIconOnly)
self.actionAlignLeft.setActionGroup(grp)
self.actionAlignCenter = toolBarControl.addAction(QIcon(":/res/smallcenter.png"),
self.tr("Center"), Qt.ToolButtonIconOnly)
self.actionAlignCenter.setActionGroup(grp)
self.actionAlignRight = toolBarControl.addAction(QIcon(":/res/smallalignright.png"),
self.tr("Align Right"), Qt.ToolButtonIconOnly)
self.actionAlignRight.setActionGroup(grp)
self.actionAlignJustify = toolBarControl.addAction(QIcon(":/res/smalljustify.png"),
self.tr("Justify"), Qt.ToolButtonIconOnly)
self.actionAlignJustify.setActionGroup(grp)
self.actionAlignLeft.setShortcut(Qt.CTRL | Qt.Key_L)
self.actionAlignLeft.setCheckable(True)
self.actionAlignLeft.setPriority(QAction.LowPriority)
self.actionAlignCenter.setShortcut(Qt.CTRL | Qt.Key_E)
self.actionAlignCenter.setCheckable(True)
self.actionAlignCenter.setPriority(QAction.LowPriority)
self.actionAlignRight.setShortcut(Qt.CTRL | Qt.Key_R)
self.actionAlignRight.setCheckable(True)
self.actionAlignRight.setPriority(QAction.LowPriority)
self.actionAlignJustify.setShortcut(Qt.CTRL | Qt.Key_J)
self.actionAlignJustify.setCheckable(True)
self.actionAlignJustify.setPriority(QAction.LowPriority)
toolBarControl.addSeparator()
menuLineSpacing = QMenu(self.ribbonBar())
action = QAction("1.0", self)
action.setCheckable(True)
action.setChecked(True)
menuLineSpacing.addAction(action)
action = QAction("1.15", self)
action.setCheckable(True)
menuLineSpacing.addAction(action)
action = QAction("1.5", self)
action.setCheckable(True)
menuLineSpacing.addAction(action)
action = QAction("2.0", self)
action.setCheckable(True)
menuLineSpacing.addAction(action)
action = QAction("2.5", self)
action.setCheckable(True)
menuLineSpacing.addAction(action)
action = QAction("3.0", self)
action.setCheckable(True)
menuLineSpacing.addAction(action)
toolBarControl.addMenu(QIcon(":/res/smalllinespacing.png"), self.tr("Line spacing"), menuLineSpacing, QToolButton.InstantPopup)
toolBarControl.addSeparator()
toolBarControl.addAction(QIcon(":/res/smallshading.png"),
self.tr("Shading"), Qt.ToolButtonIconOnly, QMenu(self.ribbonBar()), QToolButton.InstantPopup)
toolBarControl.addSeparator()
toolBarControl.addAction(QIcon(":/res/smallnoborder.png"),
self.tr("No Border"), Qt.ToolButtonIconOnly, QMenu(self.ribbonBar()), QToolButton.InstantPopup)
groupParagraph.addControl(toolBarControl)
def createGroupStyles(self, page):
groupStyles = page.addGroup(QIcon(":/res/smallcenter.png"), self.tr("&Styles"))
if groupStyles:
galleryControl = RibbonGalleryControl()
galleryControl.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setMaximumItemCount(16)
galleryControl.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setMinimumItemCount(16)
galleryControl.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setMaximumItemCount(15)
galleryControl.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setMinimumItemCount(4)
galleryControl.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setMaximumItemCount(3)
galleryControl.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setMinimumItemCount(3)
galleryControl.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setMaximumItemCount(4)
galleryControl.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setMinimumItemCount(4)
groupStyles.addControl(galleryControl)
self.galleryGroup = RibbonGalleryGroup()
self.galleryGroup.setSize(QSize(72, 56))
px = QPixmap(":/res/galleryStyles.png")
for numStyle in range(0, 16):
item = self.galleryGroup.addItemFromMap("", numStyle, px, QSize(64, 48))
s = self.tr("Style") + " ," + str(numStyle + 1)
item.setToolTip(s)
widgetStyleFont = galleryControl.widget()
widgetStyleFont.setLabelsVisible(False)
widgetStyleFont.setBorderVisible(True)
widgetStyleFont.setGalleryGroup(self.galleryGroup)
widgetStyleFont.setCheckedIndex(0)
popup = OfficePopupMenu.createPopupMenu(self)
widgetStyleFont.setPopupMenu(popup).setText(self.tr("&Styles"))
popupStyleFont = RibbonGallery()
popup.setMinimumSize(QSize(307, 168))
popupStyleFont.resize(QSize(307, 168))
popupStyleFont.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
popupStyleFont.setGalleryGroup(self.galleryGroup)
popupStyleFont.setCheckedIndex(0)
# self.connect(popupStyleFont, SIGNAL(itemPressed(RibbonGalleryItem*)), self, SLOT(itemStyleFontPressed(RibbonGalleryItem*)))
popup.addWidget(popupStyleFont)
popup.addSeparator()
popup.addAction(self.tr("&Save Style"))
popup.addAction(self.tr("&Apply Style"))
def createGroupEditing(self, page):
groupEditing = page.addGroup(QIcon(":/res/smallfind.png"), self.tr("Editing"))
if groupEditing:
actionFind = QAction(QIcon(":/res/smallfind.png"), self.tr("Find"), self)
actionFind.setShortcut(Qt.CTRL | Qt.Key_F)
actionFind.setStatusTip(self.tr("Find the specified text"))
actionGoto = QAction(QIcon(":/res/smallgoto.png"), self.tr("Go To"), self)
actionGoto.setStatusTip(self.tr("Navigate to a specific page, line, numer, footnote, comment, or other object"))
actionGoto.setEnabled(False)
findMenu = QMenu(self.ribbonBar())
findMenu.addAction(actionFind)
findMenu.addAction(actionGoto)
control = groupEditing.controlByAction(groupEditing.addAction(actionFind, Qt.ToolButtonTextBesideIcon, findMenu))
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(True)
actionReplace = groupEditing.addAction(QIcon(":/res/smallreplace.png"), self.tr("Replace"), Qt.ToolButtonTextBesideIcon)
actionReplace.setShortcut(Qt.CTRL | Qt.Key_H)
actionReplace.setStatusTip(self.tr("Replace specific text with different text"))
actionReplace.setEnabled(False)
control = groupEditing.controlByAction(actionReplace)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(True)
selectMenu = groupEditing.addMenu(QIcon(":/res/smallselect.png"), self.tr("Select"), Qt.ToolButtonTextBesideIcon)
control = groupEditing.controlByAction(selectMenu.menuAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(True)
self.actionSelectAll = QAction(self.tr("Select All"), self)
self.actionSelectAll.setShortcut(Qt.CTRL | Qt.Key_A)
self.actionSelectAll.setStatusTip(self.tr("Select the entire document"))
selectMenu.addAction(self.actionSelectAll)
self.connect(self.actionSelectAll, QtCore.SIGNAL("triggered()"), self.selectAll)
actionSelectObjects = QAction(self.tr("Select Objects"), self)
actionSelectObjects.setEnabled(False)
selectMenu.addAction(actionSelectObjects)
pActionSelectMultipleObjects = QAction(self.tr("Select Multiple Objects"), self)
pActionSelectMultipleObjects.setEnabled(False)
selectMenu.addAction(pActionSelectMultipleObjects)
def createGroupPages(self, page):
groupPages = page.addGroup(QIcon(":/res/pagesgroup16x16.png"), self.tr("Pages"))
if groupPages:
menu = groupPages.addMenu(DemoRibbonWindow.createIconByFileName(":/res/coverpage16x16.png", ":/res/coverpage32x32.png"), self.tr("Cover Page"))
control = groupPages.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageLarge)
action = groupPages.addAction(DemoRibbonWindow.createIconByFileName(":/res/blankpage16x16.png",
":/res/blankpage32x32.png"), self.tr("Blank Page"),
Qt.ToolButtonTextBesideIcon)
control = groupPages.controlByAction(action)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageLarge)
action = groupPages.addAction(DemoRibbonWindow.createIconByFileName(":/res/pagebreak16x16.png",
":/res/pagebreak32x32.png"),
self.tr("Page Break"), Qt.ToolButtonTextBesideIcon)
control = groupPages.controlByAction(action)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageLarge)
def createGroupTables(self, page):
groupTables = page.addGroup(QIcon(":/res/tablegroup16x16.png"), self.tr("Tables"))
if groupTables:
menu = groupTables.addMenu(DemoRibbonWindow.createIconByFileName(":/res/table16x16.png",
":/res/table32x32.png"), self.tr("Table"))
control = groupTables.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageLarge)
def createGroupIllustrations(self, page):
groupIllustrations = page.addGroup(QIcon(":/res/illustrationsgroup16x16.png"), self.tr("Illustrations"))
if groupIllustrations:
action = groupIllustrations.addAction(DemoRibbonWindow.createIconByFileName(":/res/picture16x16.png",
":/res/picture32x32.png"),
self.tr("Picture"), Qt.ToolButtonTextBesideIcon)
control = groupIllustrations.controlByAction(action)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageLarge)
action = groupIllustrations.addAction(DemoRibbonWindow.createIconByFileName(":/res/clipart16x16.png",
":/res/clipart32x32.png"),
self.tr("Clip Art"), Qt.ToolButtonTextBesideIcon)
control = groupIllustrations.controlByAction(action)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageLarge)
menu = groupIllustrations.addMenu(DemoRibbonWindow.createIconByFileName(":/res/shapes16x16.png",
":/res/shapes32x32.png"), self.tr("Shapes"))
control = groupIllustrations.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageLarge)
action = groupIllustrations.addAction(DemoRibbonWindow.createIconByFileName(":/res/smartart16x16.png",
":/res/smartart32x32.png"),
self.tr("Smart Art"), Qt.ToolButtonTextBesideIcon)
control = groupIllustrations.controlByAction(action)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageLarge)
action = groupIllustrations.addAction(DemoRibbonWindow.createIconByFileName(":/res/chart16x16.png",
":/res/chart32x32.png"),
self.tr("Chart"), Qt.ToolButtonTextBesideIcon)
control = groupIllustrations.controlByAction(action)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageLarge)
def createGroupLinks(self, page):
groupLinks = page.addGroup(QIcon(":/res/linkgroup16x16.png"), self.tr("Links"))
if groupLinks:
action = groupLinks.addAction(DemoRibbonWindow.createIconByFileName(":/res/hyperlink16x16.png",
":/res/hyperlink32x32.png"),
self.tr("Hyperlink"), Qt.ToolButtonTextBesideIcon)
control = groupLinks.controlByAction(action)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageLarge)
action = groupLinks.addAction(DemoRibbonWindow.createIconByFileName(":/res/bookmark16x16.png",
":/res/bookmark32x32.png"),
self.tr("Bookmark"), Qt.ToolButtonTextBesideIcon)
control = groupLinks.controlByAction(action)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageLarge)
action = groupLinks.addAction(DemoRibbonWindow.createIconByFileName(":/res/crossref16x16.png",
":/res/crossref32x32.png"),
self.tr("Cross-reference"), Qt.ToolButtonTextBesideIcon)
control = groupLinks.controlByAction(action)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageLarge)
def createGroupHeaderFooter(self, page):
groupHeaderFooter = page.addGroup(QIcon(":/res/headerfootergroup16x16.png"), self.tr("Header/Footer"))
if groupHeaderFooter:
menu = groupHeaderFooter.addMenu(DemoRibbonWindow.createIconByFileName(":/res/header16x16.png",
":/res/header32x32.png"), self.tr("Header"))
control = groupHeaderFooter.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
menu = groupHeaderFooter.addMenu(DemoRibbonWindow.createIconByFileName(":/res/footer16x16.png",
":/res/footer32x32.png"), self.tr("Footer"))
control = groupHeaderFooter.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
menu = groupHeaderFooter.addMenu(DemoRibbonWindow.createIconByFileName(":/res/pagenumber16x16.png",
":/res/pagenumber32x32.png"), self.tr("Page Number"))
control = groupHeaderFooter.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
def createGroupText(self, page):
groupText = page.addGroup(QIcon(":/res/textgroup16x16.png"), self.tr("Text"))
if groupText:
menu = groupText.addMenu(DemoRibbonWindow.createIconByFileName(":/res/textbox16x16.png",
":/res/textbox32x32.png"), self.tr("Text Box"))
control = groupText.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageLarge)
menu = groupText.addMenu(DemoRibbonWindow.createIconByFileName(":/res/quickparts16x16.png",
":/res/quickparts32x32.png"), self.tr("Quick Parts"))
control = groupText.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageLarge)
menu = groupText.addMenu(DemoRibbonWindow.createIconByFileName(":/res/wordart16x16.png",
":/res/wordart32x32.png"), self.tr("WordArt"))
control = groupText.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageLarge)
menu = groupText.addMenu(DemoRibbonWindow.createIconByFileName(":/res/dropcap16x16.png",
":/res/dropcap32x32.png"), self.tr("Drop Cap"))
control = groupText.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageLarge)
menu = groupText.addMenu(DemoRibbonWindow.createIconByFileName(":/res/signatureline16x16.png",
""), self.tr("Signature line"))
control = groupText.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setLabelVisible(True)
action = groupText.addAction(DemoRibbonWindow.createIconByFileName(":/res/datatime16x16.png",
""), self.tr("Data / Time"), Qt.ToolButtonTextUnderIcon)
control = groupText.controlByAction(action)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setLabelVisible(True)
menu = groupText.addMenu(DemoRibbonWindow.createIconByFileName(":/res/object16x16.png", ""),
self.tr("Object"))
control = groupText.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setLabelVisible(True)
def createGroupSymbols(self, page):
groupSymbols = page.addGroup(QIcon(":/res/symbolsgroup16x16.png"), self.tr("Symbols"))
if groupSymbols:
action = groupSymbols.addAction(DemoRibbonWindow.createIconByFileName(":/res/equation16x16.png",
":/res/equation32x32.png"),
self.tr("Equation"), Qt.ToolButtonTextBesideIcon)
control = groupSymbols.controlByAction(action)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageLarge)
menu = groupSymbols.addMenu(DemoRibbonWindow.createIconByFileName(":/res/symbol16x16.png",
":/res/symbol32x32.png"), self.tr("Symbol"))
control = groupSymbols.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupPopup).setImageSize(RibbonControlSizeDefinition.ImageLarge)
def createGroupThemes(self, group):
themesMenu = QMenu(self.ribbonBar())
action = group.addAction(QIcon(":/res/largeThemes.png"), self.tr("Themes"),
Qt.ToolButtonTextUnderIcon, themesMenu)
control = group.controlByAction(action)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageLarge)
colors = QMenu(self.ribbonBar())
group.addAction(QIcon(":/res/smallcolors.png"), self.tr("Colors"), Qt.ToolButtonTextBesideIcon, colors).setEnabled(False)
fonts = QMenu(self.ribbonBar())
group.addAction(QIcon(":/res/smallfonts.png"), self.tr("Fonts"), Qt.ToolButtonTextBesideIcon, fonts)
effects = QMenu(self.ribbonBar())
group.addAction(QIcon(":/res/smalleffects.png"), self.tr("Effects"), Qt.ToolButtonTextBesideIcon, effects)
def createGroupPageSetup(self, group):
menu = group.addMenu(QIcon(":/res/largeMargins.png"), self.tr("Margins"))
control = group.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageLarge)
menu = group.addMenu(DemoRibbonWindow.createIconByFileName(":/res/orientation16x16.png",
":/res/orientation32x32.png"), self.tr("Orientation"))
control = group.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(True)
menu = group.addMenu(DemoRibbonWindow.createIconByFileName(":/res/size16x16.png",
":/res/size32x32.png"), self.tr("Size"))
control = group.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(True)
menu = group.addMenu(DemoRibbonWindow.createIconByFileName(":/res/columns16x16.png",
":/res/columns32x32.png"), self.tr("Columns"))
control = group.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(True)
menu = group.addMenu(QIcon(":/res/smallBreaks.png"), self.tr("Breaks"), Qt.ToolButtonTextBesideIcon)
control = group.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(False)
menu = group.addMenu(QIcon(":/res/smalllinenumbers.png"), self.tr("Line Numbers"), Qt.ToolButtonTextBesideIcon)
control = group.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(False)
menu = group.addMenu(QIcon(":/res/smallhyphenation.png"), self.tr("Hyphenation"), Qt.ToolButtonTextBesideIcon)
control = group.controlByAction(menu.defaultAction())
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setLabelVisible(True)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageSmall)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setLabelVisible(False)
def createGroupPageBackground(self, group):
group.addMenu(DemoRibbonWindow.createIconByFileName(":/res/watermark16x16.png", ":/res/watermark32x32.png"), self.tr("Watermark"))
group.addMenu(DemoRibbonWindow.createIconByFileName(":/res/pagecolor16x16.png", ":/res/pagecolor32x32.png"), self.tr("Page Color"))
group.addAction(DemoRibbonWindow.createIconByFileName(":/res/pageborders16x16.png", ":/res/pageborders32x32.png"), self.tr("Page Borders"), Qt.ToolButtonTextUnderIcon)
def createGroupParagraphLayout(self, group):
group.addControl(RibbonLabelControl(self.tr("Indent")))
spinBoxControl = RibbonDoubleSpinBoxControl()
spinBoxControl.setDefaultAction(QWidgetAction(self))
spinBoxControl.defaultAction().setIcon(QIcon(":/res/smallleft.png"))
spinBoxControl.defaultAction().setText(self.tr("Left:"))
group.addControl(spinBoxControl)
doubleSpinBox = spinBoxControl.widget()
doubleSpinBox.setValue(0.3)
doubleSpinBox.setDecimals(1)
doubleSpinBox.setSuffix(self.tr("\""))
doubleSpinBox.setRange(0.0, 22.0)
doubleSpinBox.setMinimumWidth(60)
doubleSpinBox.setMaximumWidth(60)
spinBoxControl = RibbonDoubleSpinBoxControl()
spinBoxControl.setDefaultAction(QWidgetAction(self))
spinBoxControl.defaultAction().setIcon(QIcon(":/res/smallright.png"))
spinBoxControl.defaultAction().setText(self.tr("Right:"))
group.addControl(spinBoxControl)
doubleSpinBox = spinBoxControl.widget()
doubleSpinBox.setValue(0.3)
doubleSpinBox.setDecimals(1)
doubleSpinBox.setSuffix(self.tr("\""))
doubleSpinBox.setRange(-11.0, 22.0)
doubleSpinBox.setMinimumWidth(60)
doubleSpinBox.setMaximumWidth(60)
group.addSeparator()
group.addControl(RibbonLabelControl(self.tr("Spacing")))
spinBoxControl = RibbonDoubleSpinBoxControl()
spinBoxControl.setDefaultAction(QWidgetAction(self))
spinBoxControl.defaultAction().setIcon(QIcon(":/res/smallbefore.png"))
spinBoxControl.defaultAction().setText(self.tr("Before:"))
group.addControl(spinBoxControl)
spinBox = spinBoxControl.widget()
spinBox.setValue(0)
spinBox.setSuffix(self.tr("pt"))
spinBox.setRange(0, 10000)
spinBox.setMinimumWidth(60)
spinBox.setMaximumWidth(60)
spinBoxControl = RibbonDoubleSpinBoxControl()
spinBoxControl.setDefaultAction(QWidgetAction(self))
spinBoxControl.defaultAction().setIcon(QIcon(":/res/smallafter.png"))
spinBoxControl.defaultAction().setText(self.tr("After:"))
group.addControl(spinBoxControl)
spinBox = spinBoxControl.widget()
spinBox.setValue(3)
spinBox.setSuffix(self.tr("pt"))
spinBox.setRange(0, 10000)
spinBox.setMinimumWidth(60)
spinBox.setMaximumWidth(60)
def createGroupTableOfContents(self, group):
editPaste = QMenu(self.ribbonBar())
action = group.addAction(QIcon(":/res/largetablecontents.png"), self.tr("Table of Contents"),
Qt.ToolButtonTextUnderIcon, editPaste)
control = group.controlByAction(action)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageLarge)
group.addAction(QIcon(":/res/smalladdtext.png"), self.tr("Add Text"), Qt.ToolButtonTextBesideIcon)
group.addAction(QIcon(":/res/smallupdatetable.png"), self.tr("Update Table"), Qt.ToolButtonTextBesideIcon)
def createGroupFootnotes(self, group):
action = group.addAction(QIcon(":/res/largeInsertFootnote.png"), self.tr("Insert Footnote"), Qt.ToolButtonTextUnderIcon)
control = group.controlByAction(action)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageLarge)
group.addAction(QIcon(":/res/smallinsertendnote.png"), self.tr("&Insert Endnote"), Qt.ToolButtonTextBesideIcon)
nextFootnote = QMenu(self.ribbonBar())
group.addAction(QIcon(":/res/smallnextfootnote.png"), self.tr("Next Footnote"), Qt.ToolButtonTextBesideIcon, nextFootnote)
group.addAction(QIcon(":/res/smallshownotes.png"), self.tr("Show Notes"), Qt.ToolButtonTextBesideIcon).setEnabled(False)
def createGroupCaptions(self, group):
action = group.addAction(QIcon(":/res/largeInsertCaption.png"), self.tr("Insert Caption"), Qt.ToolButtonTextUnderIcon)
control = group.controlByAction(action)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageLarge)
group.addAction(QIcon(":/res/smallinserttablefigures.png"), self.tr("Insert Table of Figures"), Qt.ToolButtonTextBesideIcon)
group.addAction(QIcon(":/res/smallupdatetable.png"), self.tr("Update Table"), Qt.ToolButtonTextBesideIcon)
group.addAction(QIcon(":/res/smallcrossreference.png"), self.tr("Cross-reference"), Qt.ToolButtonTextBesideIcon).setEnabled(False)
def createGroupIndex(self, group):
action = group.addAction(QIcon(":/res/largeMarkEntry.png"), self.tr("Mark Entry"), Qt.ToolButtonTextUnderIcon)
control = group.controlByAction(action)
control.sizeDefinition(RibbonControlSizeDefinition.GroupLarge).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupMedium).setImageSize(RibbonControlSizeDefinition.ImageLarge)
control.sizeDefinition(RibbonControlSizeDefinition.GroupSmall).setImageSize(RibbonControlSizeDefinition.ImageLarge)
group.addAction(QIcon(":/res/smallinserttablefigures.png"), self.tr("Insert Index"), Qt.ToolButtonTextBesideIcon)
group.addAction(QIcon(":/res/smallupdatetable.png"), self.tr("Update Index"), Qt.ToolButtonTextBesideIcon).setEnabled(False)
def createGroupDocumentViews(self, group):
self.actionPrintLayout = group.addAction(DemoRibbonWindow.createIconByFileName(":/res/printlayout16x16.png",
":/res/printlayout32x32.png"), self.tr("Print Layout"), Qt.ToolButtonTextUnderIcon)
self.actionPrintLayout.setCheckable(True)
self.actionPrintLayout.setChecked(True)
fullScreenIcons = QIcon()
fullScreenIcons.addPixmap(QPixmap(":/res/largefullscreen.png"))
fullScreenIcons.addPixmap(QPixmap(":/res/smallfullscreen.png"))
self.actionFullScreen = group.addAction(fullScreenIcons, self.tr("Full Screen Reading"), Qt.ToolButtonTextUnderIcon)
self.actionFullScreen.setCheckable(True)
self.actionFullScreen.setChecked(False)
self.connect(self.actionFullScreen, QtCore.SIGNAL("triggered(bool)"), self.fullScreen)
group.addAction(QIcon(":/res/largeweblayout.png"), self.tr("Web Layout"), Qt.ToolButtonTextUnderIcon)
group.addAction(QIcon(":/res/largeoutline.png"), self.tr("Outline"), Qt.ToolButtonTextUnderIcon)
group.addAction(QIcon(":/res/largedraft.png"), self.tr("Draft"), Qt.ToolButtonTextUnderIcon)
def createGroupShow_Hide(self, group):
ruler = QCheckBox(self.tr("Ruler"))
ruler.setToolTip(self.tr("Ruler"))
group.addWidget(ruler)
gridlines = QCheckBox(self.tr("Gridlines"))
gridlines.setToolTip(self.tr("Gridlines"))
group.addWidget(gridlines)
properties = QCheckBox(self.tr("Properties"))
properties.setToolTip(self.tr("Properties"))
group.addWidget(properties)
documentMap = QCheckBox(self.tr("Document Map"))
documentMap.setToolTip(self.tr("Document Map"))
group.addWidget(documentMap)
statusBar = QCheckBox(self.tr("Status Bar"))
statusBar.setCheckState(Qt.Checked)
statusBar.setToolTip(self.tr("Status Bar"))
statusBar.setStatusTip(self.tr("Show or hide the status bar"))
group.addWidget(statusBar)
self.connect(statusBar, QtCore.SIGNAL("stateChanged(int)"), self.stateStatusBar)
messageBar = QCheckBox(self.tr("Message Bar"))
messageBar.setToolTip(self.tr("Message Bar"))
group.addWidget(messageBar)
def createGroupZoom(self, group):
group.addAction(QIcon(":/res/largezoom.png"), self.tr("Zoom"), Qt.ToolButtonTextUnderIcon)
group.addAction(QIcon(":/res/smallonepage.png"), self.tr("One Page"), Qt.ToolButtonTextBesideIcon)
group.addAction(QIcon(":/res/smalltwopage.png"), self.tr("Two Page"), Qt.ToolButtonTextBesideIcon)
group.addAction(QIcon(":/res/smallpagewidth.png"), self.tr("Page Width"), Qt.ToolButtonTextBesideIcon)
def createStatusBar(self):
statusBar = RibbonStatusBar()
self.setStatusBar(statusBar)
statusBar.addAction(self.tr("Page 1 of 1"))
statusBar.addSeparator()
statusBar.addAction(self.tr("Words: 1"))
statusBar.addSeparator()
statusBar.addAction(self.tr("English (U.S.)"))
statusBar.addSeparator()
statusBar.addAction(self.tr("Track Changes: Off"))
statusBar.addSeparator()
statusBar.addAction(self.tr("Insert"))
switchGroup = RibbonStatusBarSwitchGroup()
actions = []
actions.append(self.actionPrintLayout)
actions.append(self.actionFullScreen)
actionWebLayout = QAction(QIcon(":/res/smallweblayout.png"), self.tr("Web Layout"), self)
actions.append(actionWebLayout)
actionOutLine = QAction(QIcon(":/res/smalloutline.png"), self.tr("Outline"), self)
actions.append(actionOutLine)
actionDraft = QAction(QIcon(":/res/smalldraft.png"), self.tr("Draft"), self)
actions.append(actionDraft)
switchGroup.addActions(actions)
statusBar.addPermanentWidget(switchGroup)
self.zoomPercentage = QToolButton(statusBar)
self.zoomPercentage.setText(self.tr("100%"))
self.zoomPercentage.setToolTip(self.tr("Zoom level. Click to open the Zoom dialog box."))
statusBar.addPermanentWidget(self.zoomPercentage)
fm = QFontMetrics(statusBar.font())
minimumWidth = fm.boundingRect(str("0000%")).width()
self.zoomPercentage.setMinimumWidth(minimumWidth)
sliderPane = RibbonSliderPane()
sliderPane.setScrollButtons(True)
sliderPane.setRange(0, 200) # range
sliderPane.setMaximumWidth(130)
sliderPane.setSingleStep(10)
sliderPane.setSliderPosition(100)
statusBar.addPermanentWidget(sliderPane, 1)
self.connect(sliderPane, QtCore.SIGNAL("valueChanged(int)"), self, QtCore.SLOT("zoomSliderScroll(int)"))
def createDockWindows(self):
dock = QDockWidget(self.tr("Styles"), self)
dock.setAllowedAreas(Qt.AllDockWidgetAreas)
styleWidget = QWidget()
styleGroup = QWidget()
listLayout = QVBoxLayout()
listLayout.setContentsMargins(0, 0, 0, 0)
customerList = QListWidget()
for i in range(0, 10):
customerList.insertItem(i, QListWidgetItem(self.tr("Item ") + str(i+1)))
listLayout.addWidget(customerList)
styleGroup.setLayout(listLayout)
optionsGroup = QGroupBox(self.tr("Preview"))
optionsLayout = QVBoxLayout()
showPreviewBox = QCheckBox(self.tr("Show Preview"))
showPreviewBox.setEnabled(False)
linkedStylesBox = QCheckBox(self.tr("Disable Linked Styles"))
optionsLayout.addWidget(showPreviewBox)
optionsLayout.addWidget(linkedStylesBox)
optionsGroup.setLayout(optionsLayout)
mainLayout = QVBoxLayout()
mainLayout.addWidget(styleGroup)
mainLayout.addWidget(optionsGroup)
styleWidget.setLayout(mainLayout)
dock.setWidget(styleWidget)
self.addDockWidget(Qt.LeftDockWidgetArea, dock)
docks = [dock]
sizes = [120]
self.resizeDocks(docks, sizes, Qt.Vertical)
def load(self, fileName):
if not QFile.exists(fileName):
return False
file = QFile(fileName)
if not file.open(QFile.ReadOnly):
return False
self.setCurrentFileName(fileName)
s = QTextStream(file).readAll()
if True: #Qt.mightBeRichText(s):
self.textEdit.setHtml(s)
else:
self.textEdit.setPlainText(s)
return True
def maybeSave(self):
if not self.textEdit.document().isModified():
return True
if self.fileName.startsWith(QLatin1String(":/")):
return True
ret = QMessageBox.warning(self, self.tr("Application"), self.tr("The document has been modified.\n"
"Do you want to save your changes?"), QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel)
if ret == QMessageBox.Save:
return self.fileSave()
elif ret == QMessageBox.Cancel:
return False
return True
def setCurrentFileName(self, fileName):
self.fileName = fileName;
self.textEdit.document().setModified(False)
if self.fileName == "":
shownName = "untitled.txt"
else:
shownName = QFileInfo(self.fileName).fileName()
self.setWindowTitle("[*] " + shownName + " - " + self.tr("Qtitan Ribbon Office"))
self.setWindowModified(False)
self.setWindowFilePath(shownName)
@QtCore.Slot()
def fileNew(self):
if maybeSave():
self.textEdit.clear()
self.setCurrentFileName("")
@QtCore.Slot()
def fileOpen(self):
fileName = QFileDialog.getOpenFileName(self, self.tr("Open File..."), "",
self.tr("HTML-Files (*.htm *.html);All Files (*)"))[0]
if not fileName:
return
load(fileName)
@QtCore.Slot()
def fileSave(self):
if self.fileName != "":
return self.fileSaveAs()
writer = QTextDocumentWriter(self.fileName)
success = writer.write(self.textEdit.document())
if success:
self.textEdit.document().setModified(False)
self.setWindowModified(False)
return success
@QtCore.Slot()
def fileSaveAs(self):
fileName = QFileDialog.getSaveFileName(self, self.tr("Save as..."), "",
self.tr("ODF files (*.odt);HTML-Files (*.htm *.html);All Files (*)"))[0]
if fileName == "":
return False
if not (fileName.endswith(".odt") or fileName.endswith(".htm") or fileName.endswith(".html")):
fileName += ".odt"
self.setCurrentFileName(fileName)
return self.fileSave()
@QtCore.Slot()
def filePrint(self):
printer = QPrinter(QPrinter.HighResolution)
dlg = QPrintDialog(printer, self)
if self.textEdit.textCursor().hasSelection():
dlg.addEnabledOption(QAbstractPrintDialog.PrintSelection)
dlg.setWindowTitle(self.tr("Print Document"))
if dlg.exec() == QDialog.Accepted:
self.textEdit.print(printer)
@QtCore.Slot()
def filePrintPreview(self):
printer = QPrinter(QPrinter.HighResolution)
preview = QPrintPreviewDialog(printer, self)
self.connect(preview, QtCore.SIGNAL("paintRequested(QPrinter*)"), self.printPreview)
preview.exec()
def printPreview(self, printer):
self.textEdit.print(printer)
@QtCore.Slot()
def filePrintPdf(self):
fileName = QFileDialog.getSaveFileName(self, "Export PDF", "", "*.pdf")[0]
if fileName != "":
if QFileInfo(fileName).suffix() == "":
fileName.append(".pdf")
printer = QPrinter(QPrinter.HighResolution)
printer.setOutputFormat(QPrinter.PdfFormat)
printer.setOutputFileName(fileName)
self.textEdit.document().print(printer)
@QtCore.Slot()
def textBold(self):
fmt = QTextCharFormat()
if self.actionTextBold.isChecked():
fmt.setFontWeight(QFont.Bold)
else:
fmt.setFontWeight(QFont.Normal)
self.mergeFormatOnWordOrSelection(fmt)
@QtCore.Slot()
def textUnderline(self):
fmt = QTextCharFormat()
fmt.setFontUnderline(self.actionTextUnderline.isChecked())
self.mergeFormatOnWordOrSelection(fmt)
@QtCore.Slot()
def textItalic(self):
fmt = QTextCharFormat()
fmt.setFontItalic(self.actionTextItalic.isChecked())
self.mergeFormatOnWordOrSelection(fmt)
@QtCore.Slot(str)
def textFamily(self, f):
fmt = QTextCharFormat()
fmt.setFontFamily(f)
self.mergeFormatOnWordOrSelection(fmt)
@QtCore.Slot(str)
def textSize(self, p):
pointSize = float(p)
if p.toFloat() > 0:
fmt = QTextCharFormat()
fmt.setFontPointSize(pointSize)
self.mergeFormatOnWordOrSelection(fmt)
@QtCore.Slot(int)
def textStyle(self, styleIndex):
cursor = self.textEdit.textCursor()
style = QTextListFormat.ListDisc
if styleIndex == 0:
bfmt = QTextBlockFormat()
bfmt.setObjectIndex(-1)
cursor.mergeBlockFormat(bfmt)
return
elif styleIndex == 1:
style = QTextListFormat.ListDisc
elif styleIndex == 2:
style = QTextListFormat.ListCircle
elif styleIndex == 3:
style = QTextListFormat.ListSquare
elif styleIndex == 4:
style = QTextListFormat.ListDecimal
elif styleIndex == 5:
style = QTextListFormat.ListLowerAlpha
elif styleIndex == 6:
style = QTextListFormat.ListUpperAlpha
elif styleIndex == 7:
style = QTextListFormat.ListLowerRoman
elif styleIndex == 8:
style = QTextListFormat.ListUpperRoman
cursor.beginEditBlock()
blockFmt = cursor.blockFormat()
listFmt = QTextListFormat()
if cursor.currentList():
listFmt = cursor.currentList().format()
else:
listFmt.setIndent(blockFmt.indent() + 1)
blockFmt.setIndent(0)
cursor.setBlockFormat(blockFmt)
listFmt.setStyle(style)
cursor.createList(listFmt)
cursor.endEditBlock()
@QtCore.Slot(QColor)
def textColor(self, color):
if not color.isValid():
return
fmt = QTextCharFormat()
fmt.setForeground(color)
self.mergeFormatOnWordOrSelection(fmt)
self.colorChanged(color)
@QtCore.Slot()
def setColorText(self):
self.textColor(self.colorButton.color())
@QtCore.Slot(QAction)
def textAlign(self, action):
if action == self.actionAlignLeft:
self.textEdit.setAlignment(Qt.AlignLeft | Qt.AlignAbsolute)
elif action == self.actionAlignCenter:
self.textEdit.setAlignment(Qt.AlignHCenter)
elif action == self.actionAlignRight:
self.textEdit.setAlignment(Qt.AlignRight | Qt.AlignAbsolute)
elif action == self.actionAlignJustify:
self.textEdit.setAlignment(Qt.AlignJustify)
@QtCore.Slot()
def selectAll(self):
self.textEdit.selectAll()
@QtCore.Slot()
def optionParagraph(self):
QMessageBox.information(self, self.windowTitle(), "Paragraph dialog.", QMessageBox.Ok)
@QtCore.Slot()
def optionClipboard(self):
QMessageBox.information(self, self.windowTitle(), "Clipboard dialog.", QMessageBox.Ok)
@QtCore.Slot()
def showHideMarks(self):
document = self.textEdit.document()
if document:
txtOption = document.defaultTextOption()
if txtOption.flags().testFlag(QTextOption.ShowLineAndParagraphSeparators):
txtOption.setFlags(QTextOption.IncludeTrailingSpaces)
else:
txtOption.setFlags(QTextOption.ShowLineAndParagraphSeparators)
document.setDefaultTextOption(txtOption)
@QtCore.Slot()
def optionFont(self):
font, ok = QFontDialog.getFont(self.textEdit.currentFont(), self)
if ok:
self.textEdit.setCurrentFont(font)
@QtCore.Slot(bool)
def fullScreen(self, checked):
if checked:
self.stateWindow = windowState()
self.actionFullScreen.setChecked(True)
self.ribbonBar().setVisible(False)
self.setWindowState(Qt.WindowFullScreen)
else:
self.ribbonBar().setVisible(True)
self.setWindowState(self.stateWindow)
self.actionFullScreen.setChecked(False)
@QtCore.Slot(int)
def stateStatusBar(self, state):
self.statusBar().setVisible(Qt.CheckState(state) == Qt.Checked)
@QtCore.Slot(QTextCharFormat)
def currentCharFormatChanged(self, format):
self.fontChanged(format.font())
#self.colorChanged(format.foreground().color())
@QtCore.Slot()
def cursorPositionChanged(self):
self.alignmentChanged(self.textEdit.alignment())
@QtCore.Slot()
def clipboardDataChanged(self):
self.actionPaste1.setEnabled(QApplication.clipboard().text() != "")
self.actionPaste2.setEnabled(QApplication.clipboard().text() != "")
@QtCore.Slot()
def selectionChanged(self):
if self.pagePictureFormat:
format = self.textEdit.textCursor().charFormat()
if format.isImageFormat():
self.pagePictureFormat.setVisible(True)
else:
self.pagePictureFormat.setVisible(False)
@QtCore.Slot(int)
def zoomSliderScroll(self, value):
s += str(value) + "%"
self.zoomPercentage.setText(s)
@QtCore.Slot(QMenu, QContextMenuEvent)
def showRibbonContextMenu(self, menu, event):
event.setAccepted(False)
@QtCore.Slot()
def showCompanyWebSite(self):
QDesktopServices.openUrl(QUrl("https://www.devmachines.com"))
def keyPressEvent(self, event):
super(RibbonMainWindow, self).keyPressEvent(event)
if event.key() == Qt.Key_Escape and self.actionFullScreen.isChecked():
fullScreen(False)
def mergeFormatOnWordOrSelection(self, format):
cursor = self.textEdit.textCursor()
if not cursor.hasSelection():
cursor.select(QTextCursor.WordUnderCursor)
cursor.mergeCharFormat(format)
self.textEdit.mergeCurrentCharFormat(format)
def fontChanged(self, font):
famaly = QFontInfo(font).family()
if famaly == "":
return
index = -1
if self.comboFont:
index = self.comboFont.findText(famaly)
if index == -1:
return
self.comboFont.setCurrentIndex(index)
self.comboSize.setCurrentIndex(self.comboSize.findText(str(font.pointSize())))
self.actionTextBold.setChecked(font.bold())
self.actionTextItalic.setChecked(font.italic())
self.actionTextUnderline.setChecked(font.underline())
def colorChanged(self, color):
self.colorButton.setColor(color)
def alignmentChanged(self, alignment):
if alignment & Qt.AlignLeft:
self.actionAlignLeft.setChecked(True)
elif alignment & Qt.AlignHCenter:
self.actionAlignCenter.setChecked(True)
elif alignment & Qt.AlignRight:
self.actionAlignRight.setChecked(True)
elif alignment & Qt.AlignJustify:
self.actionAlignJustify.setChecked(True)
def customization(self):
customizeManager = self.ribbonBar().customizeManager()
customizeManager.addAllActionsCategory(MainWindow.categoryAllCommands)
# customization for ribbonQuickAccessBar
customizeManager.addToCategory(MainWindow.categoryPopularCommands, self.actionFileNew)
customizeManager.addToCategory(MainWindow.categoryPopularCommands, self.actionOpenFile)
customizeManager.addToCategory(MainWindow.categoryPopularCommands, self.actionSaveFile)
customizeManager.addToCategory(MainWindow.categoryPopularCommands, self.actionPrint)
customizeManager.addToCategory(MainWindow.categoryPopularCommands, self.actionPrintPreview)
customizeManager.addToCategory(MainWindow.categoryPopularCommands, self.actionCut)
for i in range(0, self.pageHome.groupCount()):
customizeManager.addToCategory(self.pageHome.title(), self.pageHome.group(i))
for i in range(0, self.pageLayout.groupCount()):
customizeManager.addToCategory(self.pageLayout.title(), self.pageLayout.group(i))
for i in range(0, self.pageRef.groupCount()):
customizeManager.addToCategory(self.pageRef.title(), self.pageRef.group(i))
for i in range(0, self.pageView.groupCount()):
customizeManager.addToCategory(self.pageView.title(), self.pageView.group(i))
# customization for ribbon
customizeManager.addToCategory(MainWindow.categoryMainPages, self.pageHome)
customizeManager.addToCategory(MainWindow.categoryMainPages, self.pageLayout)
customizeManager.addToCategory(MainWindow.categoryMainPages, self.pageRef)
customizeManager.addToCategory(MainWindow.categoryMainPages, self.pageView)
# Adding custom page to the standard ribbon customization dialog.
dialog = self.ribbonBar().customizeDialog()
popularPage = RibbonPopularPage(self)
dialog.insertPage(0, popularPage)
customizeQuickAccessBarPage = dialog.pageByIndex(1)
if customizeQuickAccessBarPage:
customizeQuickAccessBarPage.addCustomCategory(MainWindow.categoryPopularCommands)
customizeQuickAccessBarPage.addCustomCategory(MainWindow.categoryAllCommands)
customizeQuickAccessBarPage.addSeparatorCategory()
customizeQuickAccessBarPage.addCustomCategory(self.pageHome.title())
customizeQuickAccessBarPage.addCustomCategory(self.pageLayout.title())
customizeQuickAccessBarPage.addCustomCategory(self.pageRef.title())
customizeQuickAccessBarPage.addCustomCategory(self.pageView.title())
customizeRibbonBar = dialog.pageByIndex(2)
if customizeRibbonBar:
customizeRibbonBar.addCustomCategory(MainWindow.categoryPopularCommands)
customizeRibbonBar.addCustomCategory(MainWindow.categoryAllCommands)
customizeRibbonBar.addCustomCategory(MainWindow.categoryMainPages)
def readSettings(self):
settings = QSettings(self)
styleName = str(settings.value("style", "Default"))
if styleName != "":
self.setStyle(styleName)
self.updateStyleActions(styleName)
data = settings.value("geometry")
if data != None:
self.restoreGeometry(data)
minimized = settings.value("ribbonMinimized", False) == "true"
self.ribbonBar().setMinimized(minimized)
onTop = settings.value("quickAccessToolbarOnTop", True)
if onTop:
self.ribbonBar().setQuickAccessBarPosition(RibbonBar.TopPosition)
else:
self.ribbonBar().setQuickAccessBarPosition(RibbonBar.BottomPosition)
strBackground = str(settings.value("titleBackground", self.ribbonBackground()))
self.setRibbonBackground(strBackground)
def writeSettings(self):
settings = QSettings(self)
byteArray = QByteArray()
buffer = QBuffer(byteArray)
if not buffer.open(QIODevice.WriteOnly):
assert False
self.ribbonBar().customizeManager().saveStateToDevice(buffer)
settings.setValue("stateRibbon", byteArray)
data = self.saveGeometry()
settings.setValue("geometry", data)
settings.setValue("style", self.styleName)
settings.setValue("ribbonMinimized", self.ribbonBar().isMinimized())
settings.setValue("quickAccessToolbarOnTop", self.ribbonBar().quickAccessBarPosition() == RibbonBar.TopPosition)
settings.setValue("titleBackground", self.ribbonBackground())
def updateStyleActions(self, styleName):
DemoRibbonWindow.updateStyleActions(self, styleName)
self.updateImageStyles()
self.updateRibbonBackground()
def updateRibbonBackground(self):
px = QPixmap(self.backgroundUrl)
#Office2013Style* officeStyle13 = qobject_cast<Office2013Style*>(style())
#if (officeStyle13 && officeStyle13.theme() == Office2013Style.Dark)
#{
# self.ribbonBar().setTitleBackground(QPixmap.fromImage(DrawHelpers.addaptColors(px.toImage(), qRgb(255, 255, 255), qRgb(230, 230, 230))))
# return;
#}
self.ribbonBar().setTitleBackground(px)
def updateImageStyles(self):
px = QPixmap(":/res/galleryStyles.png")
#Office2016Style* officeStyle16 = qobject_cast<Office2016Style*>(style())
#if (officeStyle16 && officeStyle16.theme() == Office2016Style.Black)
# px = QPixmap.fromImage(DrawHelpers.invertColors(px.toImage()))
sz = QSize(64, 48)
return
for i in range(0, self.galleryGroup.itemCount()):
item = self.galleryGroup.item(i)
rcImage = QRect(i * sz.width(), 0, sz.width(), sz.height())
copyPix = px.copy(rcImage.left(), rcImage.top(), rcImage.width(), rcImage.height())
item.setIcon(copyPix)
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setApplicationName("PyQtitanRibbon Office Sample");
app.setOrganizationName("Developer Machines");
w = MainWindow()
w.show()
sys.exit(app.exec_())