File: progress_dialog.py

package info (click to toggle)
python-pyface 8.0.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,944 kB
  • sloc: python: 54,107; makefile: 82
file content (70 lines) | stat: -rw-r--r-- 1,495 bytes parent folder | download | duplicates (2)
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
#
# simple example of its use
#


import time
from pyface.api import GUI, ApplicationWindow, ProgressDialog
from pyface.action.api import Action, MenuManager, MenuBarManager


def task_func(t):
    progress = ProgressDialog(
        title="progress",
        message="counting to %d" % t,
        max=t,
        show_time=True,
        can_cancel=True,
    )
    progress.open()

    for i in range(0, t + 1):
        time.sleep(1)
        print(i)
        (cont, skip) = progress.update(i)
        if not cont or skip:
            break

    progress.update(t)


def _main():
    task_func(10)


class MainWindow(ApplicationWindow):
    """ The main application window. """

    # --------------------------------------------------------------------
    # 'object' interface.
    # --------------------------------------------------------------------

    def __init__(self, **traits):
        """ Creates a new application window. """

        # Base class constructor.
        super().__init__(**traits)

        # Add a menu bar.
        self.menu_bar_manager = MenuBarManager(
            MenuManager(
                Action(name="E&xit", on_perform=self.close),
                Action(name="DoIt", on_perform=_main),
                name="&File",
            )
        )

        return


if __name__ == "__main__":
    gui = GUI()

    # Create and open the main window.
    window = MainWindow()
    window.open()

    _main()

    # Start the GUI event loop!
    gui.start_event_loop()