[Python-checkins] r62613 - in sandbox/trunk/ttk-gsoc: Doc/library/ttk.rst Lib/lib-tk/Ttk.py

guilherme.polo python-checkins at python.org
Thu May 1 15:54:35 CEST 2008


Author: guilherme.polo
Date: Thu May  1 15:54:35 2008
New Revision: 62613

Log:
Documented Style configure and lookup.

Improved Style's lookup method a bit, it works like as expected now,
state is a sequence of one or more states and default is returned
correctly if option is not present in style.

Typo corrections.


Modified:
   sandbox/trunk/ttk-gsoc/Doc/library/ttk.rst
   sandbox/trunk/ttk-gsoc/Lib/lib-tk/Ttk.py

Modified: sandbox/trunk/ttk-gsoc/Doc/library/ttk.rst
==============================================================================
--- sandbox/trunk/ttk-gsoc/Doc/library/ttk.rst	(original)
+++ sandbox/trunk/ttk-gsoc/Doc/library/ttk.rst	Thu May  1 15:54:35 2008
@@ -58,8 +58,8 @@
 -----------
 
 Ttk comes with 16 widgets, where 10 of these already existed in Tkinter:
-:class:`Button`, :class:`Checkbutton`, :class:`Entry`, :class:`Frame`, :
-class:`Label`, :class:`LabelFrame`, :class:`Menubutton`, :class:`PanedWindow`, 
+:class:`Button`, :class:`Checkbutton`, :class:`Entry`, :class:`Frame`, 
+:class:`Label`, :class:`LabelFrame`, :class:`Menubutton`, :class:`PanedWindow`, 
 :class:`Radiobutton` and :class:`Scrollbar`. The others 6 are new:
 :class:`Combobox`, :class:`Notebook`, :class:`Progressbar`, :class:`Separator`,
 :class:`Sizegrip` and :class:`Treeview`. And all them are subclasses of 
@@ -73,6 +73,7 @@
    l1 = Tkinter.Label(text="Test", fg="black", bg="white")
    l2 = Tkinter.Label(text="Test", fg="black", bg="white")
 
+
 Ttk code::
 
    style = Ttk.Style()
@@ -82,6 +83,10 @@
    l2 = Ttk.Label(text="Test", style="BW.TLabel")
 
 
+Read the :class:`Style` class documentation for more information about 
+TtkStyling_.
+
+
 .. class:: Widget
 
    Accepts the following options:
@@ -112,7 +117,7 @@
 
    And the new methods:
 
-   .. method:: instate(statespec[, callback=None], *args]])
+   .. method:: instate(statespec[, callback=None[, *args]])
 
       Test the widget's state. If a callback is not specified, returns 1
       if the widget state matches *statespec* and 0 otherwise. If callback
@@ -124,7 +129,7 @@
 
       Modify or inquire widget state. If *statespec* is specified, sets the
       widget state according to it and return a new *statespec* indicating
-      which flags were changed. If *statespec* is not especified, returns
+      which flags were changed. If *statespec* is not specified, returns
       the currently-enabled state flags.
 
    Note that *statespec* is always expected to be a sequence.
@@ -178,12 +183,52 @@
 .. class:: Treeview
 
 
+.. _TtkStyling:
+
 Ttk Styling
 -----------
 
+Each widget is assigned a style, which especifies the set of elements making
+up the widget and how they are arranged, along with dynamic and default
+settings for element options. By default, the style name is the same as
+the widget's class prefixed by a "T", which may be overriden by the widget's 
+style option.
+
+.. seealso::
+
+   `Tcl'2004 conference presentation <http://tktable.sourceforge.net/tile/tile-tcl2004.pdf>`_
+      This document explains how the theme engine works
+
 
 .. class:: Style
 
+   This class is used to manipulate the style database.
+
+
+   .. method:: configure(style, **kw)
+
+      Sets the default value of the specified option(s) in *style*.
+
+      Each key in *kw* is an option and each value is a string identifying
+      the value for that option.
+
+      For example, to change every default button to be a flat button with
+      some padding and a different background color you could do::
+
+         import Ttk
+         import Tkinter
+
+         root = Tkinter.Tk()
+
+         Ttk.Style().configure("TButton", padding=6, relief="flat", 
+            background="#ccc")
+
+         btn = Ttk.Button(text="Sample")
+         btn.pack()
+
+         root.mainloop()
+
+
    .. method:: map(style, **kw)
 
       Sets dynamic values of the specified option(s) in *style*. 
@@ -221,11 +266,58 @@
          for the foreground, for example, you would get a blue foreground when 
          the widget were in active or pressed states. 
        * In the background option, (('pressed', '!disabled'), 'black') was 
-         especified for grouping the states 'pressed' and '!disabled', but it
+         specified for grouping the states 'pressed' and '!disabled', but it
          has no different effect than using just 'pressed' for this example, 
          this was done just to explain the documentation.
 
 
+   .. method:: lookup(style, option[, state=None[, default=None]])
+
+      Returns the value specified for *option* in *style*.
+
+      If *state* is specified, it is expected to be a sequence of one or more
+      states. If the *default* argument is set, it is used as a fallback value
+      in case no specification for option is found.
+
+      To check what font a Button uses by default, you would do::
+
+         import Ttk
+
+         print Ttk.Style().lookup("TButton", "font")
+
+
+   .. method:: layout TBD
+
+
+   .. method:: element_create TBD
+
+   
+   .. method:: element_names()
+
+      Returns the list of elements defined in the current theme
+
+
+   .. method:: element_options(element)
+
+      Returns the list of element's options
+
+
+   .. method:: theme_create TBD
+
+
+   .. method:: theme_settings TBD
+
+
+   .. method:: theme_names()
+
+      Returns a list of all known themes
+       
+
+   .. method:: theme_use(themename)
+
+      Sets the current theme to themename and refreshes all wigets
+    
+
 Others new features
 -------------------
 

Modified: sandbox/trunk/ttk-gsoc/Lib/lib-tk/Ttk.py
==============================================================================
--- sandbox/trunk/ttk-gsoc/Lib/lib-tk/Ttk.py	(original)
+++ sandbox/trunk/ttk-gsoc/Lib/lib-tk/Ttk.py	Thu May  1 15:54:35 2008
@@ -56,7 +56,7 @@
         self.tk = master.tk
 
     def configure(self, style, **kw):
-        """Sets the default value of the especified option(s) in style."""
+        """Sets the default value of the specified option(s) in style."""
         opts = [("-%s" % opt, value) for opt, value in kw.iteritems()]
         opts = Tkinter._flatten(opts)
 
@@ -89,15 +89,17 @@
 
 
     def lookup(self, style, option, state=None, default=None):
-        """Returns the value specified for option for given style in
-        state, using the standard lookup rules for element options.
-        state is a list of state names; if omitted, it defaults to
-        "normal". If the default argument is present, it is used as a
-        fallback value in case no specification for option is
-        found."""
-        # XXX Re-write this docstring
-        return self.tk.call(self._name, "lookup", style, option, state, 
-                            default)
+        """Returns the value specified for option in style.
+
+        If state is specified it is expected to be a sequence of one 
+        or more states. If the default argument is set, it is used as 
+        a fallback value in case no specification for option is found."""
+        state = ' '.join(state) if state else ''
+
+        if not option.startswith('-'):
+            option = '-' + option
+
+        return self.tk.call(self._name, "lookup", style, option, state, default)
 
 
     def layout(self, style, layoutspec=None):
@@ -167,7 +169,7 @@
 
 
     def theme_use(self, themename):
-        """Sets the current theme to themename, and refreshes all widgets."""
+        """Sets the current theme to themename and refreshes all widgets."""
         self.tk.call(self._name, "theme", "use", themename)
 
 
@@ -200,7 +202,7 @@
     def instate(self, statespec, callback=None, *args):
         """Test the widget's state. 
         
-        If callback is not especified, returns 1 if the widget state 
+        If callback is not specified, returns 1 if the widget state 
         matches statespec and 0 otherwise. If callback is specified, 
         then it will be invoked with *args if the widget state matches 
         statespec. statespec is expected to be a sequence."""


More information about the Python-checkins mailing list