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. Development
8. Dictionary
9. Event
10. Exception
11. File
12. Function
13. GUI Pmw
14. GUI Tk
15. Language Basics
16. List
17. Math
18. Network
19. String
20. System
21. Thread
22. Tuple
23. Utility
24. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
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
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
w_w_w__.___jav___a2__s_.__c__o___m___ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.