Skip to content

Merge vnotebook into master to add VNotebook widget #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ This file contains a list of all the authors of widgets in this repository. Plea
* `Balloon`
* `ItemsCanvas`
* `TimeLine`
* `VNotebook`
- The Python Team
* `Calendar`, found [here](http://svn.python.org/projects/sandbox/trunk/ttk-gsoc/samples/ttkcalendar.py)
- Mitja Martini
Expand Down
1 change: 1 addition & 0 deletions docs/source/authors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ List of all the authors of widgets in this repository. Please note that this lis
* :class:`~ttkwidgets.frames.Balloon`
* :class:`~ttkwidgets.ItemsCanvas`
* :class:`~ttkwidgets.TimeLine`
* :class:`~ttkwidgets.VNotebook`

- The Python Team

Expand Down
1 change: 1 addition & 0 deletions docs/source/ttkwidgets/ttkwidgets.frames.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ ttkwidgets.frames
Balloon
ScrolledFrame
ToggledFrame
VNotebook
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
VNotebook
=========

.. currentmodule:: ttkwidgets.frames

.. autoclass:: VNotebook
:show-inheritance:
:members:

.. automethod:: __init__
19 changes: 19 additions & 0 deletions examples/example_vnotebook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from ttkwidgets import VNotebook
import tkinter.ttk as ttk
import tkinter as tk


def callback():
notebook.hide(id_)


root = tk.Tk()
notebook = VNotebook(root, compound=tk.RIGHT)
notebook.add(ttk.Scale(notebook), text="Scale")
notebook.add(ttk.Button(notebook, text="Destroy", command=root.destroy), text="Button")
frame = ttk.Frame(notebook)
id_ = notebook.add(frame, text="Hidden")
ttk.Button(frame, command=callback, text="Hide").grid()
notebook.enable_traversal()
notebook.grid(row=1)
root.mainloop()
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
License
-------

ttkwidgets: A collection of widgets for Tkinter's ttk extensions by various authors
ttkwidgets: A collection of widgets for Tkinter's ttk extensions by various authors
Copyright (C) RedFantom 2017
Copyright (C) The Python Team
Copyright (C) Mitja Martini 2008
Expand Down Expand Up @@ -47,15 +47,15 @@
.. |Codecov| image:: https://codecov.io/gh/RedFantom/ttkwidgets/branch/master/graph/badge.svg
:alt: Code Coverage
:target: https://codecov.io/gh/RedFantom/ttkwidgets

.. |Pypi| image:: https://badge.fury.io/py/ttkwidgets.svg
:alt: PyPI version
:target: https://badge.fury.io/py/ttkwidgets

.. |License| image:: https://img.shields.io/badge/License-GPL%20v3-blue.svg
:alt: License: GPL v3
:target: http://www.gnu.org/licenses/gpl-3.0

"""

setup(
Expand Down
71 changes: 71 additions & 0 deletions tests/test_vnotebook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""
Author: RedFantom
License: GNU GPLv3, as in LICENSE.md
Copyright (C) 2018 RedFantom
"""
from unittest import TestCase
# Basic UI imports
import tkinter as tk
from tkinter import ttk
# Module to test
from ttkwidgets.frames import VNotebook

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can add some more tests, like for the configure() method. I can write some.


class TestVNotebook(TestCase):
def setUp(self):
self.window = tk.Tk()

def tearDown(self):
self.window.destroy()

def test_init(self):
VNotebook(self.window).grid()
self.window.update()

def _add_test_frame(self, notebook, **kwargs):
notebook.grid()
frame = ttk.Frame(notebook)
ttk.Scale(frame).grid()
frame.grid()
return notebook.add(frame, text="Test", **kwargs)

def test_add(self):
notebook = VNotebook(self.window)
self._add_test_frame(notebook)
self.window.update()

def test_compound(self):
for compound in (tk.BOTTOM, tk.TOP, tk.RIGHT, tk.LEFT):
VNotebook(self.window, compound=compound).grid()
self.window.update()

def test_index(self):
notebook = VNotebook(self.window)
self._add_test_frame(notebook)
frame = ttk.Frame(notebook)
notebook.insert(0, frame)
self.assertEqual(notebook.tabs[0], notebook.get_id_for_tab(frame))
self.assertEqual(0, notebook.index(frame))

def test_enable_traversal(self):
notebook = VNotebook(self.window)
self._add_test_frame(notebook)
self._add_test_frame(notebook)
notebook.enable_traversal()
active = notebook.active
notebook._switch_tab(None)
self.assertNotEqual(active, notebook.active)

def test_tab_config(self):
notebook = VNotebook(self.window)
id = self._add_test_frame(notebook)
notebook.tab_configure(id, text="Hello")
self.assertEqual(notebook.tab_cget(id, "text"), "Hello")

def test_activate(self):
notebook = VNotebook(self.window)
self._add_test_frame(notebook)
self._add_test_frame(notebook)
self.assertEqual(notebook.tabs[0], notebook.active)
notebook.activate_index(1)
self.assertEqual(notebook.tabs[1], notebook.active)
3 changes: 3 additions & 0 deletions ttkwidgets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@
from ttkwidgets.scaleentry import ScaleEntry
from ttkwidgets.timeline import TimeLine
from ttkwidgets.tickscale import TickScale

from ttkwidgets.frames import VNotebook
from ttkwidgets.table import Table

8 changes: 4 additions & 4 deletions ttkwidgets/debugwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ class DebugWindow(tk.Toplevel):
"""
A Toplevel that shows sys.stdout and sys.stderr for Tkinter applications
"""
def __init__(self, master=None, title="Debug window", stdout=True,
def __init__(self, master=None, title="Debug window", stdout=True,
stderr=False, width=70, autohidescrollbar=True, **kwargs):
"""
Create a Debug window.

:param master: master widget
:type master: widget
:param stdout: whether to redirect stdout to the widget
Expand Down Expand Up @@ -61,7 +61,7 @@ def __init__(self, master=None, title="Debug window", stdout=True,
def save(self):
"""Save widget content."""
file_name = fd.asksaveasfilename()
if file_name is "" or file_name is None:
if file_name == "" or file_name is None:
return
with open(file_name, "w") as f:
f.write(self.text.get("1.0", tk.END))
Expand All @@ -73,7 +73,7 @@ def _grid_widgets(self):
def write(self, line):
"""
Write line at the end of the widget.

:param line: text to insert in the widget
:type line: str
"""
Expand Down
1 change: 1 addition & 0 deletions ttkwidgets/frames/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from .scrolledframe import ScrolledFrame
from .toggledframe import ToggledFrame
from .balloon import Balloon
from .vnotebook import VNotebook
Loading