File: shapedwindow.py

package info (click to toggle)
kivy 2.3.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 35,316 kB
  • sloc: python: 80,678; ansic: 5,326; javascript: 780; objc: 725; lisp: 195; sh: 173; makefile: 150
file content (98 lines) | stat: -rw-r--r-- 2,648 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
from kivy.config import Config
Config.set('graphics', 'shaped', 1)

from kivy.resources import resource_find
default_shape = Config.get('kivy', 'window_shape')
alpha_shape = resource_find('data/logo/kivy-icon-512.png')

from kivy.app import App
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout
from kivy.properties import (
    BooleanProperty,
    StringProperty,
    ListProperty,
)


Builder.load_string('''
#:import win kivy.core.window.Window

<Root>:
    orientation: 'vertical'
    BoxLayout:
        Button:
            text: 'default_shape'
            on_release: app.shape_image = app.default_shape
        Button:
            text: 'alpha_shape'
            on_release: app.shape_image = app.alpha_shape

    BoxLayout:
        ToggleButton:
            group: 'mode'
            text: 'default'
            state: 'down'
            on_release: win.shape_mode = 'default'
        ToggleButton:
            group: 'mode'
            text: 'binalpha'
            on_release: win.shape_mode = 'binalpha'
        ToggleButton:
            group: 'mode'
            text: 'reversebinalpha'
            on_release: win.shape_mode = 'reversebinalpha'
        ToggleButton:
            group: 'mode'
            text: 'colorkey'
            on_release: win.shape_mode = 'colorkey'

    BoxLayout:
        ToggleButton:
            group: 'cutoff'
            text: 'cutoff True'
            state: 'down'
            on_release: win.shape_cutoff = True
        ToggleButton:
            group: 'cutoff'
            text: 'cutoff False'
            on_release: win.shape_cutoff = False

    BoxLayout:
        ToggleButton:
            group: 'colorkey'
            text: '1, 1, 1, 1'
            state: 'down'
            on_release: win.shape_color_key = [1, 1, 1, 1]
        ToggleButton:
            group: 'colorkey'
            text: '0, 0, 0, 1'
            on_release: win.shape_color_key = [0, 0, 0, 1]
''')


class Root(BoxLayout):
    pass


class ShapedWindow(App):
    shape_image = StringProperty('', force_dispatch=True)

    def on_shape_image(self, instance, value):
        if 'kivy-icon' in value:
            Window.size = (512, 512)
            Window.shape_image = self.alpha_shape
        else:
            Window.size = (800, 600)
            Window.shape_image = self.default_shape

    def build(self):
        self.default_shape = default_shape
        self.alpha_shape = alpha_shape

        return Root()


if __name__ == '__main__':
    ShapedWindow().run()