วันพุธที่ 30 กันยายน พ.ศ. 2558

Kivy Project : Kivy: Interactive Applications in Python Chapter 4

Improving the User Experience

ใน chapter นี้ จะพูดถึงการนำความรู้ตั้งแต่บทแรก มาใช้

Screen manager – selecting colors for the figures

Screen manager เป็น class ที่ช่วยในการสร้างหน้าจอโปรแกรมอีกจอนึง ซึ่ง screen นี่จะอยู่บน canvas เดี๋ยวกัน มี size เท่ากันกับหน้าต่างวาดรูป โดยในหนังสือจะนำเป็น ColorPicker เป็นหน้าจอที่ใช้สำหรับเลือกสีของตัว Stickman

ColorPicker

ขั้นตอนแรกให้ทำการสร้างไฟล์ .kv ไฟล์ขึ้นมา

โค้ดของ comicscreenmanager.kv

# File name: comicscreenmanager.kv
#:kivy 1.7.0
#:import FadeTransition kivy.uix.screenmanager.FadeTransition
<ComicScreenManager>:
    transition: FadeTransition()
    color_picker: _color_picker
    ComicCreator:
    Screen:
        name: 'colorscreen'
        ColorPicker:
            id: _color_picker
            Button:
                text: "Select"
                pos_hint: {'center_x': .75, 'y': .05}
                size_hint: None, None
                size: 150, 50
                on_press: root.current = 'comicscreen'

จากนั้นให้ไปเปลี่ยน  ไฟล์ comiccreator.kv

# File name: comiccreator.kv
#:kivy 1.7.0
<ComicCreator@Screen>:
    name: 'comicscreen'
    AnchorLayout:
        anchor_x: 'left'
        anchor_y: 'top'
        ToolBox:
            id: _tool_box
            drawing_space: _drawing_space
            comic_creator: root
            size_hint: None,None
            width: 100
    AnchorLayout:
        anchor_x: 'right'
        anchor_y: 'top'
        DrawingSpace:
            id: _drawing_space
            status_bar: _status_bar
            general_options: _general_options
            tool_box: _tool_box
            size_hint: None,None
            width: root.width - _tool_box.width
            height: root.height - _general_options.height - _status_bar.height
    AnchorLayout:
        anchor_x: 'center'
        anchor_y: 'bottom'
        BoxLayout:
            orientation: 'vertical'
            GeneralOptions:
                id: _general_options
                drawing_space: _drawing_space
                comic_creator: root
                size_hint: 1,None
                height: 48
            StatusBar:
                id: _status_bar
                size_hint: 1,None
                height: 24

Color Control on the canvas – coloring figures

StencilView – limiting the drawing space

Scatter – multitouching to drag, rotate, and scale

Simple gestures – drawing with the finger

ไม่มีความคิดเห็น:

แสดงความคิดเห็น