File: button_demo.py

package info (click to toggle)
python-enable 4.3.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 7,280 kB
  • ctags: 13,899
  • sloc: cpp: 48,447; python: 28,502; ansic: 9,004; makefile: 315; sh: 44
file content (40 lines) | stat: -rw-r--r-- 1,408 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
from copy import copy
import os.path

from enable.savage.trait_defs.ui.svg_button import SVGButton
from traits.api import HasTraits, Str
from traitsui.api import Item, View, HGroup

button_size = (64, 64)

class ButtonDemo(HasTraits):

    copy_button = SVGButton(label='Copy',
                            filename=os.path.join(os.path.dirname(__file__),
                                                  'edit-copy.svg'),
                            width=button_size[0],
                            height=button_size[1])
    paste_button = SVGButton(label='Paste',
                             filename=os.path.join(os.path.dirname(__file__),
                                                   'edit-paste.svg'),
                             width=button_size[0],
                             height=button_size[1])
    text = Str
    clipboard = Str

    traits_view = View(HGroup(Item('copy_button', show_label=False),
                              Item('paste_button', show_label=False,
                                   enabled_when='len(clipboard)>0')),
                       Item('text', width=200),
                       title='SVG Button Demo')

    def _copy_button_fired(self, event):
        self.clipboard = copy(self.text)

    def _paste_button_fired(self, event):
        self.text += self.clipboard


if __name__ == "__main__":
    example = ButtonDemo()
    example.configure_traits()