More examples of subclassing of Pmw EntryField : Subclassing Pmw « GUI Pmw « Python

Python
1. 2D
2. Application
3. Buildin Function
4. Class
5. Data Structure
6. Data Type
7. Database
8. Development
9. Dictionary
10. Event
11. Exception
12. File
13. Function
14. GUI Pmw
15. GUI Tk
16. Language Basics
17. List
18. Math
19. Network
20. String
21. System
22. Thread
23. Tuple
24. Utility
25. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Python » GUI Pmw » Subclassing PmwScreenshots 
More examples of subclassing of Pmw EntryField
More examples of subclassing of Pmw EntryField

title = 'More examples of subclassing'

# Import Pmw from this directory tree.
import sys
sys.path[:0['../../..']

import Tkinter
import Pmw

class ExtraMethods(Pmw.EntryField):

    # How to subclass a Pmw megawidget when you only want to add or
    # override methods.

    def doubletext(self):
  self.setvalue(self.getvalue() ' ' + self.getvalue())

class OverrideInit(Pmw.EntryField):

    # How to subclass a Pmw megawidget when you want to define
    # a new __init__ method.

    def __init__(self, textToAdd, parent = None, **kw):
        self._textToAdd = textToAdd
  apply(Pmw.EntryField.__init__, (self, parent), kw)

    def addtext(self):
  self.setvalue(self.getvalue() ' ' + self._textToAdd)

class DefaultOptions(Pmw.EntryField):

    # How to subclass a Pmw megawidget when you only want to set
    # existing options to new default values.

    def __init__(self, parent = None, **kw):
        kw['label_foreground'] 'blue'
        kw['entry_background'] 'white'
  apply(Pmw.EntryField.__init__, (self, parent), kw)

class NewOptions(Pmw.EntryField):

    # How to subclass a Pmw megawidget when you want to add new options.

    def __init__(self, parent=None , **kw):

  # Define the megawidget options.
  optiondefs = (
            ('backgrounds',              None,     self._backgrounds),
  )
  self.defineoptions(kw, optiondefs)

  # Initialise the base class (after defining the options).
  Pmw.EntryField.__init__(self, parent)

  # Check keywords and initialise options.
  self.initialiseoptions()

    def _backgrounds(self):
  background = self['backgrounds']
        Pmw.Color.changecolor(self.component('hull'), background)

class Demo:
    def __init__(self, parent):
  # Create and pack the megawidgets.
  self._extraMethod = ExtraMethods(parent,
    labelpos = 'w',
    label_text = 'Suclass with extra method:',
                value = 'Hello'
        )
  self._overrideInit = OverrideInit('Again', parent,
    labelpos = 'w',
    label_text = 'Suclass with new __init__ method:',
                value = 'Hello'
        )
  self._defaultOptions = DefaultOptions(parent,
    labelpos = 'w',
    label_text = 'Suclass with new default options:',
                value = 'Hello'
        )

  self._newOptions = NewOptions(parent,
    labelpos = 'w',
    label_text = 'Suclass with new option:',
                value = 'Hello',
                backgrounds = 'white',
        )

  entries = (self._extraMethod, self._overrideInit,
                self._defaultOptions, self._newOptions)

  for entry in entries:
      entry.pack(fill='x', expand=1, padx=10, pady=5)
  Pmw.alignlabels(entries)

        bb = Pmw.ButtonBox(parent)
        bb.add('Double text', command = self._doubleText)
        bb.pack()
        bb.add('Add text', command = self._addText)
        bb.pack()
        bb.add('White', command = self._changeColorWhite)
        bb.pack()
        bb.add('Green', command = self._changeColorGreen)
        bb.pack()

    def _doubleText(self):
        self._extraMethod.doubletext()

    def _addText(self):
        self._overrideInit.addtext()

    def _changeColorWhite(self):
        self._newOptions.configure(backgrounds = 'white')

    def _changeColorGreen(self):
        self._newOptions.configure(backgrounds = 'green')

######################################################################

# Create demo in root window for testing.
if __name__ == '__main__':
    root = Tkinter.Tk()
    Pmw.initialise(root)
    root.title(title)

    exitButton = Tkinter.Button(root, text = 'Exit', command = root.destroy)
    exitButton.pack(side = 'bottom')
    widget = Demo(root)
    root.mainloop()


           
       
Related examples in the same category
1. Subclassing Pmw EntryField: data format: any data and int valueSubclassing Pmw EntryField: data format: any data and int value
2. Subclassing Pmw EntryField: real number and dateSubclassing Pmw EntryField: real number and date
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.