File: test_button_command.py

package info (click to toggle)
pygubu 0.37-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,768 kB
  • sloc: python: 22,345; sh: 55; makefile: 7
file content (83 lines) | stat: -rw-r--r-- 2,067 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# encoding: utf-8
import os
import sys
import unittest
import tkinter as tk
import tkinter.ttk as ttk

import fixpath
import pygubu
import support


class TestButtonCommand(unittest.TestCase):
    def setUp(self):
        support.root_deiconify()
        xmldata = "test_button_command.ui"
        self.builder = builder = pygubu.Builder()
        builder.add_from_file(xmldata)
        self.widget = builder.get_object("mainwindow")
        self.button1 = builder.get_object("button1")
        self.button2 = builder.get_object("button2")

    def tearDown(self):
        support.root_withdraw()

    def test_command_simple(self):
        success = []

        class AnObject:
            def button1_clicked(self):
                success.append(1)

            def on_button_clicked(self):
                pass

        cbobj = AnObject()
        self.builder.connect_callbacks(cbobj)
        self.button1.invoke()
        self.widget.update()

        self.assertTrue(success)
        self.widget.destroy()

    def test_command_with_widgetid(self):
        success = []
        received_id = []

        class AnObject:
            def button1_clicked(self):
                pass

            def on_button_clicked(self, widgetid):
                success.append(1)
                received_id.append(widgetid)

        cbobj = AnObject()
        self.builder.connect_callbacks(cbobj)
        self.button2.invoke()
        self.widget.update()

        self.assertTrue(success)
        self.assertEqual(received_id[0], "button2")
        self.widget.destroy()

    # def test_command_generate_event(self):
    # success = []

    # class AnObject:
    # def button1_clicked(self):
    # pass
    # def on_button_clicked(self):
    # pass
    # def catch_button_event(self, event):
    # success.append(1)

    # cbobj = AnObject()
    # self.button3.bind('<<MyButtonEvent>>', cbobj.catch_button_event)
    # self.builder.connect_callbacks(cbobj)
    # self.button3.invoke()
    # self.widget.update()

    # self.assertTrue(success)
    # self.widget.destroy()