Commits

Aleš Erjavec  committed 58c976c

Added sphinx documentation for QuickMenu

  • Participants
  • Parent commits 719c8b4

Comments (0)

Files changed (3)

File Orange/OrangeCanvas/document/quickmenu.py

     """
     A menu page in a :class:`QuickMenu` widget, showing a list of actions.
     Shown actions can be disabled by setting a filtering function using the
-    :ref:`setFilterFunc`.
+    :func:`setFilterFunc`.
 
     """
     def __init__(self, parent=None, title=None, icon=None, **kwargs):
         """
         return self.__title
 
-    title_ = Property(unicode, fget=title, fset=setTitle)
+    title_ = Property(unicode, fget=title, fset=setTitle,
+                      doc="Title of the page.")
 
     def setIcon(self, icon):
         """
         """
         return self.__icon
 
-    icon_ = Property(QIcon, fget=icon, fset=setIcon)
+    icon_ = Property(QIcon, fget=icon, fset=setIcon,
+                     doc="Page icon")
 
     def setFilterFunc(self, func):
         """
 
     def setModel(self, model):
         """
-        Reimplemented from :ref:`ToolTree.setModel`.
+        Reimplemented from :func:`ToolTree.setModel`.
         """
         proxyModel = ItemDisableFilter(self)
         proxyModel.setSourceModel(model)
 
     def setRootIndex(self, index):
         """
-        Reimplemented from :ref:`ToolTree.setRootIndex`
+        Reimplemented from :func:`ToolTree.setRootIndex`
         """
         proxyModel = self.view().model()
         mappedIndex = proxyModel.mapFromSource(index)
 
     def rootIndex(self):
         """
-        Reimplemented from :ref:`ToolTree.rootIndex`
+        Reimplemented from :func:`ToolTree.rootIndex`
         """
         proxyModel = self.view().model()
         return proxyModel.mapToSource(ToolTree.rootIndex(self))
     """
     A quick menu popup for the widgets.
 
-    The widgets are set using :ref:`setModel` which must be a
-    model as returned by QtWidgetRegistry.model()
+    The widgets are set using :func:`QuickMenu.setModel` which must be a
+    model as returned by :func:`QtWidgetRegistry.model`
 
     """
 
+    #: An action has been triggered in the menu.
     triggered = Signal(QAction)
+
+    #: An action has been hovered in the menu
     hovered = Signal(QAction)
 
     def __init__(self, parent=None, **kwargs):
 
     def addPage(self, name, page):
         """
-        Add the page and return it's index.
+        Add the `page` (:class:`MenuPage`) with `name` and return it's index.
+        The `page.icon()` will be used as the icon in the tab bar.
+
         """
         icon = page.icon()
 
             tip = page.toolTip()
 
         index = self.__pages.addPage(page, name, icon, tip)
-        # TODO: get the background.
 
         # Route the page's signals
         page.triggered.connect(self.__onTriggered)
         page.hovered.connect(self.hovered)
 
-        # Install event filter to process key presses.
+        # Install event filter to intercept key presses.
         page.view().installEventFilter(self)
 
         return index
         self.show()
 
     def exec_(self, pos=None):
+        """
+        Execute the menu at position `pos` (in global screen coordinates).
+        Return the triggered :class:`QAction` or `None` if no action was
+        triggered.
+
+        """
         self.popup(pos)
         self.setFocus(Qt.PopupFocusReason)
 
         return action
 
     def hideEvent(self, event):
+        """
+        Reimplemented from :class:`QWidget`
+        """
         FramelessWindow.hideEvent(self, event)
         if self.__loop:
             self.__loop.exit()
 
 
 class ItemViewKeyNavigator(QObject):
+    """
+    A event filter class listening to key press events and responding
+    by moving 'currentItem` on a :class:`QListView`.
+
+    """
     def __init__(self, parent=None):
         QObject.__init__(self, parent)
         self.__view = None
 
     def setView(self, view):
+        """
+        Set the QListView.
+        """
         if self.__view != view:
             self.__view = view
 
     def view(self):
+        """
+        Return the view
+        """
         return self.__view
 
     def eventFilter(self, obj, event):
         if self.__view is not None:
             curr = self.__view.currentIndex()
             if curr.isValid():
-                # TODO: Does this work
+                # TODO: Does this work? We are emitting signals that are
+                # defined by a different class. This might break some things.
+                # Should we just send the keyPress events to the view, and let
+                # it handle them.
                 self.__view.activated.emit(curr)
 
     def ensureCurrent(self):
 class WindowSizeGrip(QSizeGrip):
     """
     Automatically positioning :class:`QSizeGrip`.
+    The widget automatically maintains its position in the window
+    corner during resize events.
+
     """
     def __init__(self, parent):
         QSizeGrip.__init__(self, parent)
 
     def setCorner(self, corner):
         """
-        Set the corner where the size grip should position itself.
+        Set the corner (:class:`Qt.Corner`) where the size grip should
+        position itself.
+
         """
         if corner not in [Qt.TopLeftCorner, Qt.TopRightCorner,
                           Qt.BottomLeftCorner, Qt.BottomRightCorner]:

File docs/canvas/document.quickmenu.rst

+=============================
+Quick Menu (:mod:`quickmenu`)
+=============================
+
+.. automodule:: Orange.OrangeCanvas.document.quickmenu
+
+
+.. autoclass:: QuickMenu
+   :members:
+   :exclude-members:
+      triggered,
+      hovered
+   :member-order: bysource
+   :show-inheritance:
+
+   .. automethod:: triggered(QAction)
+
+   .. automethod:: hovered(QAction)
+
+
+.. autoclass:: MenuPage
+   :members:
+   :exclude-members:
+      title_,
+      icon_
+   :member-order: bysource
+   :show-inheritance:

File docs/canvas/document.rst

 .. toctree::
 
    document.schemeedit
+   document.quickmenu