Spectrum.py :  » GUI » Pmw » Pmw.1.3.2 » src » Pmw » Pmw_1_3 » demos » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » GUI » Pmw 
Pmw » Pmw.1.3.2 » src » Pmw » Pmw_1_3 » demos » Spectrum.py
title = 'Color spectrum demonstration'

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

import string
import Tkinter
import Pmw

class Demo:
    def __init__(self, parent):
  parent = Tkinter.Frame(parent)
  parent.pack(padx=10, pady=10, fill='both', expand=1)
  self.width = 350
  self.height = 250
  self.canvas = Tkinter.Canvas(parent,
    width = self.width, height = self.height)
  self.canvas.grid(row = 0, column = 0, columnspan = 2, sticky = 'news')

  self.numColors = Pmw.EntryField(parent,
    labelpos = 'w',
    label_text = 'Number of colors:',
    entry_width = 5,
    validate = 'numeric',
    command = Pmw.busycallback(self.execute))
  self.numColors.grid(row = 1, column = 0, sticky = 'ew')

  self.correction = Pmw.EntryField(parent,
    labelpos = 'w',
    label_text = 'Correction:',
    validate = 'real',
    entry_width = 5,
    command = Pmw.busycallback(self.execute))
  self.correction.grid(row = 1, column = 1, sticky = 'ew')

  self.saturation = Pmw.EntryField(parent,
    labelpos = 'w',
    label_text = 'Saturation:',
    validate = 'real',
    entry_width = 5,
    command = Pmw.busycallback(self.execute))
  self.saturation.grid(row = 2, column = 0, sticky = 'ew')

  self.intensity = Pmw.EntryField(parent,
    labelpos = 'w',
    label_text = 'Intensity:',
    validate = 'real',
    entry_width = 5,
    command = Pmw.busycallback(self.execute))
  self.intensity.grid(row = 2, column = 1, sticky = 'ew')

  self.extraOrange = Pmw.EntryField(parent,
    labelpos = 'w',
    label_text = 'Emphasize orange (0 or 1):',
    validate = {'validator' : 'numeric', 'min' : 0, 'max' : 1},
    entry_width = 5,
    command = Pmw.busycallback(self.execute))
  self.extraOrange.grid(row = 3, column = 0, sticky = 'ew')

  self.text = Pmw.EntryField(parent,
    labelpos = 'w',
    label_text = 'Text:',
    entry_width = 20,
    command = Pmw.busycallback(self.execute))
  self.text.grid(row = 4, column = 0, sticky = 'ew')

  self.brightness = Pmw.EntryField(parent,
    labelpos = 'w',
    label_text = 'Brightness:',
    validate = 'real',
    entry_width = 5,
    command = Pmw.busycallback(self.execute))
  self.brightness.grid(row = 3, column = 1, sticky = 'ew')

  self.radiobuttons = Pmw.RadioSelect(parent,
    command = Pmw.busycallback(self.radio_cb),
  )
        self.radiobuttons.grid(row = 4, column = 1)
        self.radiobuttons.add('Use saturation\nand intensity')
        self.radiobuttons.add('Use\nbrightness')

  parent.grid_columnconfigure(0, weight = 1)
  parent.grid_columnconfigure(1, weight = 1)
  parent.grid_rowconfigure(0, weight = 1)

  Pmw.alignlabels((self.numColors, self.saturation, self.extraOrange))
  Pmw.alignlabels((self.correction, self.intensity, self.brightness))

  # Set initial values for all entries.
  self.numColors.setentry('64')
  self.correction.setentry('1.0')
  self.saturation.setentry('1.0')
  self.intensity.setentry('1.0')
  self.extraOrange.setentry('1')
  self.brightness.setentry('0.7')
  self.text.setentry('This is a test')
  self.radiobuttons.invoke('Use saturation\nand intensity')

  self.execute()

    def radio_cb(self, value):
  self.execute()

    def execute(self):
  try:
      numColors = string.atoi(self.numColors.get())
      correction = string.atof(self.correction.get())
      saturation = string.atof(self.saturation.get())
      intensity = string.atof(self.intensity.get())
      extraOrange = string.atof(self.extraOrange.get())
      brightness = string.atof(self.brightness.get())
  except ValueError:
      self.numColors.bell()
      return

  if numColors <= 0:
      self.numColors.bell()
      return

        self.canvas.delete('all')

  colorList = Pmw.Color.spectrum(
    numColors, correction, saturation, intensity, extraOrange)
  extent = 360.0 / numColors

        useBrightness = \
                (self.radiobuttons.getcurselection() == 'Use\nbrightness')

  if numColors == 1:
      # Special case circle, since create_arc does not work when
      # extent is 360.
      background = colorList[0]
            if useBrightness:
                background = Pmw.Color.changebrightness(
                        self.canvas, background, brightness)
      self.canvas.create_oval(10, 10, self.width - 10, self.height - 10,
    fill = background, outline = background)

  for index in range(numColors):
      start = index * extent - extent / 2
      background = colorList[index]
            if useBrightness:
                background = Pmw.Color.changebrightness(
                        self.canvas, background, brightness)
      self.canvas.create_arc(10, 10, self.width - 10, self.height - 10,
    start = start, extent = extent,
    fill = background, outline = background)

        text = self.text.get()
        self.canvas.create_text(self.width / 2, self.height / 3, text = text)
        self.canvas.create_text(self.width / 2, self.height / 2, text = text)
        self.canvas.create_text(self.width / 2, 2 * self.height / 3, text = text)

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

# 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()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.