2018年12月30日日曜日

開発環境

Kivyプログラミング ―Pythonで作るマルチタッチアプリ― (実践Pythonライブラリー) (原口 和也(著)、久保 幹雄(監修)、朝倉書店)の3(イベントとプロパティ)、3.4(演習問題)、演習3.1を取り組んでみる。

コード(Emacs)

Python 3

#!/usr/bin/env python3
from kivy.app import App
from kivy.clock import Clock
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.core.text import LabelBase, DEFAULT_FONT

LabelBase.register(DEFAULT_FONT, 'NotoSansCJKjp-Regular.otf')


class MyLabel(Label):
    colors = [('赤', (1, 0, 0, 1)),
              ('緑', (0, 1, 0, 1)),
              ('青', (0, 0, 1, 1)),
              ('黄色', (1, 1, 0, 1)),
              ('シアン', (0, 1, 1, 1)),
              ('マゼンダ', (1, 0, 1, 1))]

    def __init__(self, *args, **kwargs):
        Label.__init__(self, *args, **kwargs)
        self.color_index = 0
        self.event = Clock.schedule_interval(self.change_color, 0.5)

    def change_color(self, dt):
        name, color = MyLabel.colors[self.color_index]
        self.text = f'ラベル({name})'
        self.color = color
        self.color_index += 1
        self.color_index %= len(self.colors)


class SampleApp(App):
    def build(self):
        box_layout = BoxLayout(orientation='horizontal')
        label = MyLabel()
        box_layout.add_widget(label)
        return box_layout


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

入出力結果(Terminal, cmd(コマンドプロンプト), Jupyter(IPython))

$ ./sample1.py
[INFO   ] [Logger      ] Record log in /~/.kivy/logs/kivy_18-12-31_33.txt
[INFO   ] [Kivy        ] v1.10.1
[INFO   ] [Python      ] v3.7.1 (default, Oct 21 2018, 09:01:26) 
[Clang 10.0.0 (clang-1000.11.45.2)]
[INFO   ] [Factory     ] 194 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_imageio, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL ES 2" graphics system
[INFO   ] [GL          ] Backend used <gl>
[INFO   ] [GL          ] OpenGL version <b'2.1 INTEL-12.4.7'>
[INFO   ] [GL          ] OpenGL vendor <b'Intel Inc.'>
[INFO   ] [GL          ] OpenGL renderer <b'Intel(R) Iris(TM) Pro Graphics 6200'>
[INFO   ] [GL          ] OpenGL parsed version: 2, 1
[INFO   ] [GL          ] Shading version <b'1.20'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <16>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [Base        ] Start application main loop
[INFO   ] [GL          ] NPOT texture support is available
[INFO   ] [Base        ] Leaving application in progress...
$

0 コメント:

コメントを投稿

関連コンテンツ