File: test_editing.py

package info (click to toggle)
wxglade 1%3A1.1.1%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,592 kB
  • sloc: python: 30,644; javascript: 740; makefile: 169; cpp: 99; perl: 90; lisp: 62; xml: 61; sh: 3
file content (150 lines) | stat: -rw-r--r-- 6,254 bytes parent folder | download | duplicates (3)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
"""
@copyright: 2019-2020 Dietmar Schwertberger

@license: MIT (see LICENSE.txt) - THIS PROGRAM COMES WITH NO WARRANTY
"""


from testsupport_new import WXGladeGUITest

import common, clipboard
import unittest, wx, time


class TestEditing(WXGladeGUITest):
    "Test for e.g. cut/paste; to be extended..."

    def test_crash_on_cut_paste(self):
        "with NEW_STRUCTURE at first there were crashes when cutting the static box sizer"
        basename = 'crash_on_cut_paste'
        infilename = self._get_casefile_path( '%s.wxg'%basename )
        common.main._open_app(infilename, use_progress_dialog=False, add_to_history=False)
        editor = common.root.find_widget_from_path( 'App/frame/sizer_limit/panel_3/sizer_8' )
        common.app_tree.show_toplevel( None, common.root.find_widget_from_path('App/frame') )
        self._process_wx_events()
        parent = editor.parent

        # cut
        data = clipboard.dump_widget(editor)
        editor.remove()
        self._process_wx_events()
        # paste again
        parent.clipboard_paste(data)
        self._process_wx_events()

        # save and check .wxg file
        generated_filename = self._get_outputfile_path(infilename)
        common.main._save_app(generated_filename)
        self._compare_files(infilename, generated_filename)

        # generate and check python code
        app = common.root

        expected_filename = self._get_casefile_path( '%s.py'%basename )
        generated_filename = self._get_outputfile_path( '%s.py'%basename )
        app.properties["output_path"].set(generated_filename)
        common.app_tree.root.generate_code()
        self._compare_files(expected_filename, generated_filename, check_mtime=True)

    def sleep(self, dt=1.0):
        end = time.time() + dt
        while time.time() < end:
            self._process_wx_events()

    def check_no_overlap(self, editor, rectangles=None):
        # recursively check that all widgets have been created and sizer children do not overlap
        if rectangles is None: rectangles = []
        for child in editor.get_all_children():
            if child.IS_SLOT and child.overlapped: continue
            if editor.IS_SIZER and not child.IS_SIZER:
                rect = child.widget.GetRect()
                for r in rectangles:
                    self.assertFalse( rect.Intersects(r) )
                rectangles.append(rect)
            elif editor.IS_SIZER and child.IS_SIZER:
                self.check_no_overlap(child, rectangles)
            self.check_no_overlap(child)

    def test_editing_1(self):
        basename = 'Test_Editing'
        infilename = self._get_casefile_path( '%s.wxg'%basename )
        common.main._open_app(infilename, use_progress_dialog=False, add_to_history=False)
        wx.SafeYield()
        app = common.root  # shortcut
        common.app_tree.show_toplevel( None, app.children[0] )
        # ensure that there's no overlap of elements
        self.check_no_overlap(app.children[0])

        # cut static box sizer
        widget = app.find_widget_from_path("app/frame/notebook_1/panel_1/sizer_2/sizer_1")
        parent = widget.parent
        index = widget.index
        data = self.simulate_cut(widget)
        # paste again
        self.simulate_paste(parent, index, data)

        # insert panel into splitter; change "Scrollable" to test re-creation
        widget = app.find_widget_from_path("app/frame/notebook_1/window_1/SLOT 1")
        import widgets.panel.panel
        panel = widgets.panel.panel.builder(widget.parent, widget.index)
        self.assertTrue(isinstance(panel.widget, wx.Panel))
        panel.properties["scrollable"].set(True, notify=True)
        self.assertTrue(isinstance(panel.widget, wx.ScrolledWindow))
        #panel.widget.GetSize()
        #wx.Size(404, 659)
        #self.sleep(1.0)

        # set span of button inside gridbag sizer
        widget = app.find_widget_from_path("app/frame/notebook_1/window_1/window_1_pane_1/grid_sizer_1/button_3")
        widget.properties["span"].set((2,2), notify=True)
        #self.sleep(1.0)

        # XXX test change_sizer

        ## save and check .wxg file
        #generated_filename = self._get_outputfile_path(infilename)
        #common.main._save_app(generated_filename)
        #self._compare_files(infilename, generated_filename)

    def test_editing_2(self):
        basename = 'Test_Editing2'
        infilename = self._get_casefile_path( '%s.wxg'%basename )
        common.main._open_app(infilename, use_progress_dialog=False, add_to_history=False)
        wx.SafeYield()
        app = common.root  # shortcut
        common.app_tree.show_toplevel( None, app.children[0] )
        # ensure that there's no overlap of elements
        self.check_no_overlap(app.children[0])
        
        # change font size for static text and asserts it's size change
        text = common.root.find_widget_from_path("app/frame/notebook_1/panel_1/sizer_2/static_text_1")
        rect1 = text.widget.GetRect()
        size1 = text.widget.GetSize()
        font_p = text.properties["font"]
        font_p.set( (42, 'default', 'normal', 'normal', 0, ''), notify=True)
        self.check_no_overlap(text.parent)
        return

        # cut static box sizer
        widget = app.find_widget_from_path("app/frame/notebook_1/panel_1/sizer_2/sizer_1")
        parent = widget.parent
        index = widget.index
        data = self.simulate_cut(widget)
        # paste again
        self.simulate_paste(parent, index, data)

        # insert panel into splitter; change "Scrollable" to test re-creation
        widget = app.find_widget_from_path("app/frame/notebook_1/window_1/SLOT 1")
        import widgets.panel.panel
        panel = widgets.panel.panel.builder(widget.parent, widget.index)
        self.assertTrue(isinstance(panel.widget, wx.Panel))
        panel.properties["scrollable"].set(True, notify=True)
        self.assertTrue(isinstance(panel.widget, wx.ScrolledWindow))

        # set span of button inside gridbag sizer
        widget = app.find_widget_from_path("app/frame/notebook_1/window_1/window_1_pane_1/grid_sizer_1/button_3")
        widget.properties["span"].set((2,2), notify=True)


if __name__ == '__main__':
    unittest.main(exit=False)