Package topo :: Package param :: Module tk
[hide private]
[frames] | no frames]

Module tk

source code

Classes linking Parameters to Tkinter.

TkParameterized allows flexible graphical representation and manipulation of the parameters of a Parameterized instance or class.

ParametersFrame and ParametersFrameWithApply extend TkParameterized, displaying all the Parameters together in a list. Both allow these Parameters to be edited; ParametersFrame applies changes immediately as they are made, whereas ParametersFrameWithApply makes no changes until a confirmation is given (by pressing the 'Apply' button).

Using these classes to display parameters has several benefits, including that, automatically:

Examples

  1. Display the parameters of an object inside an existing window

You want to display all parameters of a parameterized instance inside an existing containter (e.g. a window or a frame):

# existing Parameterized instance g from topo import pattern g = pattern.Gaussian()

# existing window t import Tkinter t = Tkinter.Toplevel()

# display all the parameters of g in t from topo.param.tk import ParametersFrame ParametersFrame(t,g) #should be ParametersFrame(t,g).pack(); see ALERT in ParametersFrame

  1. Display the parameters of an object in a standalone window

You want a new window displaying only the parameters of your object:

# existing Parameterized instance g from topo import pattern g = pattern.Gaussian()

# display all the parameters of g in a new window from topo.param.tk import edit_parameters edit_parameters(g)

  1. Flexible GUI layout using TkParameterized

You want to display only some of the parameters of one or more Parameterized instances:

## Existing, non-GUI code from topo import param

class Object1(param.Parameterized):
duration = param.Number(2.0,bounds=(0,None),doc='Duration of measurement') displacement = param.Number(0.0,bounds=(-1,1),doc='Displacement from point A')
class Object2(param.Parameterized):
active_today = param.Boolean(True,doc='Whether or not to count today') operator_name = param.String('A. Person',doc='Operator today')

o1 = Object1() o2 = Object2()

## Existing window import Tkinter t = Tkinter.Toplevel()

## Flexible GUI representation: display o1.duration, o1.displacement, ## and o2.active_today inside t, ignoring o2.operator_name from topo.param.tk import TkParameterized

t1 = TkParameterized(t,o1) t2 = TkParameterized(t,o2)

t1.pack_param('duration',side='left') t1.pack_param('displacement',side='bottom') t2.pack_param('active_today',side='right')

  1. ?

TkParameterized is itself a subclass of Parameterized, so a TkParameterized class can have its own parameters (in addition to representing those of an external parameterized instance or class).

## Existing class from topo import params

class X(param.Parameterized):
one = param.Boolean(True) two = param.Boolean(True)

## Panel to represent an instance of X from Tkinter import Frame from topo.param.tk import TkParameterized

class XPanel(TkParameterized,Frame):

dock = param.Boolean(False,doc='Whether to attach this Panel')

def __init__(self,master,x):
self.pack_param('dock',side='top',on_change=self.handle_dock) self.pack_param('one',side='left') self.pack_param('two',side='right')
def handle_dock(self):
if self.dock:
# dock the window
else:
# undock the window

## Running the code t = Tkinter.Toplevel() x = X() XPanel(t,x)

$Id: tk.py 9416 2008-10-08 19:36:54Z ceball $

Classes [hide private]
  Button
A GUI-specific parameter to display a button.
  TkParameterizedBase
A Parameterized subclass that maintains Tkinter.Variable shadows (proxies) of its Parameters.
  TkParameterized
Provide widgets for Parameters of itself and up to one additional Parameterized instance or class.
  Translator
Abstract class that
  DoNothingTranslator
Performs no translation.
  BoolTranslator
  Eval_ReprTranslator
Translates a string to an object by eval()ing the string in __main__.__dict__ (i.e.
  String_ObjectTranslator
  CSPTranslator
  ParametersFrame
Displays and allows instantaneous editing of the Parameters of a supplied Parameterized.
  ParametersFrameWithApply
Displays and allows editing of the Parameters of a supplied Parameterized.
  Balloon
  Menu
Tkinter Menu, but with a way to access entries by name.
  TaggedSlider
Widget for manipulating a numeric value using either a slider or a text-entry box, keeping the two values in sync.
  FocusTakingButton
A Tkinter Button that takes the focus when the mouse <Enter>s.
  ScrolledFrame
XXXX
  ScrolledWindow
  StatusBar
  AppWindow
A ScrolledWindow with extra features intended to be common to all windows of an application.
Functions [hide private]
 
resolve_path(path, search_paths=[])
Find the path to an existing file, searching in the specified search paths if the filename is not absolute, and converting a UNIX-style path to the current OS's format if necessary.
source code
 
inverse(dict_)
Return the inverse of dictionary dict_.
source code
 
lookup_by_class(dict_, class_)
Look for class_ or its superclasses in the keys of dict_; on finding a match, return the value (return None if no match found).
source code
 
keys_sorted_by_value(d)
Return the keys of dictionary d sorted by value.
source code
 
keys_sorted_by_value_unique(d, **sort_kwargs)
Return the keys of d, sorted by value.
source code
 
keys_sorted_by_value_unique_None_safe(d, **sort_kwargs)
None is handled separately: if present, it always comes out at the end of the list.
source code
 
is_button(widget)
Simple detection of Button-like widgets that are not Checkbuttons (i.e.
source code
 
askyesno(title=None, message=None, **options)
Ask a question; return true if the answer is yes
source code
 
param_is_dynamically_generated(param, po) source code
 
edit_parameters(parameterized, with_apply=True, **params)
Edit the Parameters of a supplied parameterized instance or class.
source code
Variables [hide private]
  application_path = '/home/jbednar/research/topographica'
  output_path = '/home/jbednar/research/topographica'
Function Details [hide private]

resolve_path(path, search_paths=[])

source code 

Find the path to an existing file, searching in the specified search paths if the filename is not absolute, and converting a UNIX-style path to the current OS's format if necessary.

To turn a supplied relative path into an absolute one, the path is appended to each path in (search_paths+the current working directory+the application's base path), in that order, until the file is found.

(Similar to Python's os.path.abspath(), except more search paths than just os.getcwd() can be used, and the file must exist.)

An IOError is raised if the file is not found anywhere.

inverse(dict_)

source code 

Return the inverse of dictionary dict_.

(I.e. return a dictionary with keys that are the values of dict_,
and values that are the corresponding keys from dict_.)

The values of dict_ must be unique.

lookup_by_class(dict_, class_)

source code 

Look for class_ or its superclasses in the keys of dict_; on
finding a match, return the value (return None if no match found).

Searches from the most immediate class to the most distant
(i.e. from class_ to the final superclass of class_).

keys_sorted_by_value_unique(d, **sort_kwargs)

source code 

Return the keys of d, sorted by value.

The values of d must be unique (see inverse)

keys_sorted_by_value_unique_None_safe(d, **sort_kwargs)

source code 
None is handled separately: if present, it always comes out at the end of the list. Allows callers to use any sort function without worrying that None will not match the other objects (e.g. for using an attribute present on all the other objects, such as precedence of sheets).

is_button(widget)

source code 
Simple detection of Button-like widgets that are not Checkbuttons (i.e. widgets that do not require a separate label).

edit_parameters(parameterized, with_apply=True, **params)

source code 

Edit the Parameters of a supplied parameterized instance or class.

Specify with_apply=False for a ParametersFrame (which immediately updates the object - no need to press the Apply button).

Extra params are passed to the ParametersFrame constructor.