FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-151920: Add the ttk.Style.theme_styles() method by serhiy-storchaka · Pull Request #151921 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (3) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
10 changes: 10 additions & 0 deletions Doc/library/tkinter.ttk.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2016,6 +2016,16 @@ If you don't know the class name of a widget, use the method
Returns a tuple of all known themes.


.. method:: theme_styles(themename=None)

Returns a tuple of all styles in *themename*.
If *themename* is not given, the current theme is used.

.. versionadded:: next

Availability: Tk 9.0.


.. method:: theme_use(themename=None)

If *themename* is not given, returns the theme in use. Otherwise, sets
Expand Down
6 changes: 5 additions & 1 deletion Doc/whatsnew/3.16.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ tkinter
synchronization of the displayed view with the underlying text.
(Contributed by Serhiy Storchaka in :gh:`151675`.)

* Added the :meth:`ttk.Style.theme_styles
<tkinter.ttk.Style.theme_styles>` method which returns the list of styles
defined in a theme.
(Contributed by Serhiy Storchaka in :gh:`151920`.)

* Added new :class:`!tkinter.Canvas` methods :meth:`~tkinter.Canvas.rchars`
which replaces the text or coordinates of canvas items, and
:meth:`~tkinter.Canvas.rotate` which rotates the coordinates of canvas items.
Expand Down Expand Up @@ -205,7 +210,6 @@ tkinter
dithered image when its data was supplied in pieces.
(Contributed by Serhiy Storchaka in :gh:`151888`.)


xml
---

Expand Down
22 changes: 21 additions & 1 deletion Lib/test/test_ttk/test_style.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from test import support
from test.support import requires
from test.test_tkinter.support import setUpModule # noqa: F401
from test.test_tkinter.support import AbstractTkTest, get_tk_patchlevel
from test.test_tkinter.support import (AbstractTkTest, get_tk_patchlevel,
requires_tk)

requires('gui')

Expand Down Expand Up @@ -124,6 +125,25 @@ def test_theme_use(self):

self.style.theme_use(curr_theme)

@requires_tk(9, 0)
def test_theme_styles(self):
# The 'default' theme is always available and defines the base styles.
default_styles = self.style.theme_styles('default')
self.assertIsInstance(default_styles, tuple)
self.assertIn('.', default_styles)
self.assertIn('TButton', default_styles)

# Without an argument the current theme is used.
styles = self.style.theme_styles()
self.assertIsInstance(styles, tuple)
self.assertIn('.', styles)

for theme in self.style.theme_names():
self.assertIsInstance(self.style.theme_styles(theme), tuple)

self.assertRaises(tkinter.TclError,
self.style.theme_styles, 'nonexistingname')

def test_theme_settings(self):
style = self.style
theme = style.theme_use()
Expand Down
14 changes: 14 additions & 0 deletions Lib/tkinter/ttk.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,20 @@ def theme_names(self):
return self.tk.splitlist(self.tk.call(self._name, "theme", "names"))


def theme_styles(self, themename=None):
"""Returns a list of all styles in themename.

If themename is omitted, the current theme is used.

Availability: Tk 9.0.
"""
if themename is None:
return self.tk.splitlist(
self.tk.call(self._name, "theme", "styles"))
return self.tk.splitlist(
self.tk.call(self._name, "theme", "styles", themename))


def theme_use(self, themename=None):
"""If themename is None, returns the theme in use, otherwise, set
the current theme to themename, refreshes all widgets and emits
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Add the :meth:`ttk.Style.theme_styles <tkinter.ttk.Style.theme_styles>`
method, wrapping the Tk ``ttk::style theme styles`` subcommand, which
returns the list of styles defined in a theme.
Loading

Back | FazBrowse Home | New Git URL