summaryrefslogtreecommitdiffstats
path: root/python/pykde/templates/annotated/menuapp3.py
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commit90825e2392b2d70e43c7a25b8a3752299a933894 (patch)
treee33aa27f02b74604afbfd0ea4f1cfca8833d882a /python/pykde/templates/annotated/menuapp3.py
downloadtdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.tar.gz
tdebindings-90825e2392b2d70e43c7a25b8a3752299a933894.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdebindings@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'python/pykde/templates/annotated/menuapp3.py')
-rw-r--r--python/pykde/templates/annotated/menuapp3.py209
1 files changed, 209 insertions, 0 deletions
diff --git a/python/pykde/templates/annotated/menuapp3.py b/python/pykde/templates/annotated/menuapp3.py
new file mode 100644
index 00000000..1935ce59
--- /dev/null
+++ b/python/pykde/templates/annotated/menuapp3.py
@@ -0,0 +1,209 @@
+"""
+This template constructs an application with menus, toolbar and statusbar.
+It uses an XML file (menuapp3ui.rc) to specify the menu layout; all menu
+items have a corresponding action defined, but no menus are created
+explicitly in code. This app has the same menu layout as menuapp2.py
+"""
+
+"""
+Copyright 2003 Jim Bublitz
+
+Terms and Conditions
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to
+deal in the Software without restriction, including without limitation the
+rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+sell copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
+Except as contained in this notice, the name of the copyright holder shall
+not be used in advertising or otherwise to promote the sale, use or other
+dealings in this Software without prior written authorization from the
+copyright holder.
+"""
+
+
+False = 0
+True = not False
+
+
+import sys
+
+from qt import QPopupMenu, SIGNAL
+
+from kdecore import KApplication, KCmdLineArgs, KAboutData, i18n
+from kdeui import KMainWindow, KMessageBox, KStdAction, KAction, KActionCollection
+
+STATUSBAR_LEFT = 1
+STATUSBAR_MIDDLE = 2
+STATUSBAR_RIGHT = 3
+
+class MainWin (KMainWindow):
+ def __init__ (self, *args):
+ apply (KMainWindow.__init__, (self,) + args)
+
+ # Create actions that correspond to those in the XML file
+ self.initActions ()
+
+ # Parse the default XML file (<appName>ui.rc> and create
+ # the menus and toolbar. This single line (and the XML
+ # file it reads) replace initMenus and initToolBar from
+ # menuapp2.py. Otherwise, the menuapp2 and menuapp3
+ # are identical 'createGUI' expects to find 'menuapp3ui.rc'
+ # either in the directory menuapp3.py is run from, or
+ # in $KDEDIR/apps/menuapp3/
+ self.createGUI ()
+
+ # Create the status bar
+ self.initStatusBar ()
+
+ # Disable a couple of menu items using their actions
+ self.saveAction.setEnabled (False)
+ self.saveAsAction.setEnabled (False)
+
+ def initActions (self):
+ # Most of the functions selectable by menu are "standard"
+ # actions (open a file, cut, paste, etc) - you customize
+ # how they behave in your code, but menu, toolbar, and
+ # accelerator settings are the same across all programs.
+ # Standard actions also have tooltips already assigned
+
+ # To create most of the actions below, KStdAction is
+ # is used, since it takes care of everything with
+ # a single line of code.
+
+ # The standard actions only need to specify the slot
+ # where the code for the action is located
+
+ # Because the XMLGUI mechanism parses $KDEDIR/config/ui/ui_standards.rc
+ # before parsing and merging menuapp3ui.rc, it actually isn't
+ # necessary to list KStdAction actions in menuapp3.rc. THE XMLGUI
+ # code will create menu/toolbar items and place them *automatically*
+ # if you defined the KStdActions as below. In fact, you can't override
+ # this behavior using KStdActions - if you want menus to be "non-standard"
+ # KDE menus (eg 'Cut' in the 'File' menu), you'll need to create your
+ # actions from KAction instead of KStdAction. Obviously it makes more
+ # sense to use the mechanism provided to produce consistent menus and
+ # toolbars. You can "unplug" items if, for example, you don't want them
+ # in the toolBar.
+
+ # "File" menu items
+ self.newAction = KStdAction.openNew (self.slotNew, self.actionCollection ())
+ self.openAction = KStdAction.open (self.slotOpen, self.actionCollection ())
+ self.saveAction = KStdAction.save (self.slotSave, self.actionCollection ())
+ self.saveAsAction = KStdAction.saveAs (self.slotSaveAs, self.actionCollection ())
+ self.printAction = KStdAction.print_ (self.slotPrint, self.actionCollection ())
+ self.quitAction = KStdAction.quit (self.slotQuit, self.actionCollection ())
+
+
+ # "Edit" menu items
+ self.undoAction = KStdAction.undo (self.slotUndo, self.actionCollection ())
+ self.redoAction = KStdAction.redo (self.slotRedo, self.actionCollection ())
+ self.cutAction = KStdAction.cut (self.slotCut, self.actionCollection ())
+ self.copyAction = KStdAction.copy (self.slotCopy, self.actionCollection ())
+ self.pasteAction = KStdAction.paste (self.slotPaste, self.actionCollection ())
+ self.findAction = KStdAction.find (self.slotFind, self.actionCollection ())
+ self.findNextAction = KStdAction.findNext (self.slotFindNext, self.actionCollection ())
+ self.replaceAction = KStdAction.replace (self.slotReplace, self.actionCollection ())
+
+ # For ANYTHING constructed from KAction or its descendants (KActionMenu, KActionSeparator,
+ # KFontAction, etc) you MUST provide the self.actionCollection () parent and an object
+ # name ("specialActionName") or the XMLGUI mechanism will not be able to locate the
+ # action. XMLGUI finds the action via its member name value, NOT via its variable name.
+ self.specialAction = KAction (i18n ("Special"), 0, self.slotSpecial, self.actionCollection (), "specialActionName")
+
+ def initStatusBar (self):
+ self.statusBar ().insertItem ("", STATUSBAR_LEFT, 1000, True)
+ self.statusBar ().insertItem ("", STATUSBAR_MIDDLE, 1000, True)
+ self.statusBar ().insertItem ("", STATUSBAR_RIGHT, 1000, True)
+
+#-------------------- slots -----------------------------------------------
+
+ def slotNew (self, id = -1):
+ self.notImpl ("New")
+
+ def slotOpen(self, id = -1):
+ self.notImpl ("Open")
+
+ def slotSave (self, id = -1):
+ self.notImpl ("Save")
+
+ def slotSaveAs (self):
+ self.notImpl ("Save As")
+
+ def slotPrint (self):
+ self.notImpl ("Print")
+
+ def slotQuit (self):
+ self.notImpl ("Quit")
+
+ def slotUndo (self):
+ self.notImpl ("Undo")
+
+ def slotRedo (self):
+ self.notImpl ("Redo")
+
+ def slotCut (self, id = -1):
+ self.notImpl ("Cut")
+
+ def slotCopy (self, id = -1):
+ self.notImpl ("Copy")
+
+ def slotPaste (self, id = -1):
+ self.notImpl ("Paste")
+
+ def slotFind (self):
+ self.notImpl ("Find")
+
+ def slotFindNext (self):
+ self.notImpl ("Find Next")
+
+ def slotReplace (self):
+ self.notImpl ("Replace")
+
+ def slotSpecial (self):
+ self.notImpl ("Special")
+
+ def notImpl (self, item = "Feature"):
+ self.statusBar ().changeItem ("%s not implemented" % item, STATUSBAR_LEFT)
+ KMessageBox.error (self, "%s not implemented" % item, "Not Implemented")
+ self.statusBar ().changeItem ("", STATUSBAR_LEFT)
+
+
+#-------------------- main ------------------------------------------------
+
+description = "A basic application template"
+version = "1.0"
+
+# To use the XMLGUI mechanism, you MUST provide an appName
+# (the first argument to KAboutData below) - the XML spec
+# for the interface will be in <appName>ui.rc (don't forget
+# the "ui" suffix to the application name)
+aboutData = KAboutData ("menuapp3", "",\
+ version, description, KAboutData.License_GPL,\
+ "(C) 2003 whoever the author is")
+
+aboutData.addAuthor ("author1", "whatever they did", "email@somedomain")
+aboutData.addAuthor ("author2", "they did something else", "another@email.address")
+
+KCmdLineArgs.init (sys.argv, aboutData)
+
+KCmdLineArgs.addCmdLineOptions ([("+files", "File to open")])
+
+app = KApplication ()
+mainWindow = MainWin (None, "main window")
+mainWindow.show()
+app.exec_loop()
+