【鼎革‧革鼎】︰ Raspbian Stretch 《三‧癸》

一九七二年布萊恩‧柯林漢 Brian Wilson Kernighan  於貝爾實驗室撰寫《Introduction to the Language B》的內部技術文件時,寫了一個『hello, world』的範例程式。其後他與 丹尼斯‧里奇 Dennis M. Ritchie 合著的《The C Programming Language》也保留了這個範例程式。不知怎的這成了一個『傳統』,成了初學者所編寫的第一個程式。現今流行的寫法是『Hello, World!』,不知柯林漢會不會抱怨這是是那個嗎?它的原典是︰

hello, world

,裡頭所有字母全是小寫,『 , 』之後有一『空白』。

Thue 1

Thue 2

現在就讓我們用著 Colagioia 之 Thue 語言寫我們第一支中文的『打招呼』程式︰

打招呼::=~別來無恙
::=
打招呼

那要怎麽『跑』run 這個程式呢?網路雲端上有一個『Thue interpreter in Javascript』的網頁,你可以將這支『哈囉』程式,如左圖般地打入或拷貝,先按 Update 鍵載入程式,然後按 Run 鍵執行。你將見證『打招呼』被改寫成了『別來無恙』 !!

─── 《Thue 之改寫系統《三》

 

派生 Python 之圖形使用者界面 GUI 架構眾多,

GUI Programming in Python

Python has a huge number of GUI frameworks (or toolkits) available for it, from TkInter (traditionally bundled with Python, using Tk) to a number of other cross-platform solutions, as well as bindings to platform-specific (also known as “native”) technologies.

 

因是只需自己擇取所好者即可。

此處特舉

Kivy

Innovative user interfaces made easy.

Kivy is an open source, cross-platform Python framework for the development of applications that make use of innovative, multi-touch user interfaces. The aim is to allow for quick and easy interaction design and rapid prototyping whilst making your code reusable and deployable.

Kivy is written in Python and Cython, based on OpenGL ES 2, supports various input devices and has an extensive widget library. With the same codebase, you can target Windows, OS X, Linux, Android and iOS. All Kivy widgets are built with multitouch support.

Kivy is MIT licensed, actively developed by a great community and is supported by many projects managed by the Kivy Organization.

 

以其跨平台,可以用多點觸控裝置,而且新版 ver.1.10.0 支援派生三 Python3 ,中文編程或將更容易乎!

樹莓派上的安裝,請參考

User’s Guide » Installation on Raspberry Pi

還請讀者注意,目前觸控螢幕,除了官方 7″ HDMI 者,

 

早有多種多樣大小裝置。故而測試驗證,眼下恐難免矣!

比方說官方螢幕旋轉,觸控如何隨之協轉乙事,或反映在 kivy 之 hidinput.py

pi@raspberrypi:~ more /usr/local/lib/python3.5/dist-packages/kivy/input/providers/hidinput.py | grep invert * invert_x : 1 to invert X axis * invert_y : 1 to invert Y axis                    'invert_x', 'invert_y', 'rotation')             invert_x = int(bool(drs('invert_x', 0)))             invert_y = int(bool(drs('invert_y', 1)))             def assign_coord(point, value, invert, coords):                 if invert:             def assign_rel_coord(point, value, invert, coords):                 if invert:                         assign_coord(point, val, invert_x, 'xy')                         assign_coord(point, val, invert_y, 'yx')                             invert_x, 'xy')                             invert_y, 'yx')                         assign_coord(point, val, invert_x, 'xy')                         assign_coord(point, val, invert_y, 'yx') pi@raspberrypi:~ 

 

 invert_y = int(bool(drs(‘invert_y’, 1))) 的缺值 1 之預設中?它者務須知道如何設定耶!

pi@raspberrypi:~ more .kivy/config.ini  [input] mouse = mouse mtdev_%(name)s = probesysfs,provider=mtdev hid_%(name)s = probesysfs,provider=hidinput,param=invert_y=0 </pre>    <span style="color: #666699;">仍舊依循傳統向世界打聲招呼吧◎</span> <pre class="lang:default decode:true"># -*- coding: utf-8 -*-  import kivy  from kivy.app import App from kivy.uix.button import Button  import kivy.resources kivy.resources.resource_add_path('/usr/share/fonts/truetype/wqy/')  class 打招呼(App):     def build(self):         return Button(text=u'別來無恙',font_size=60,font_name=kivy.resources.resource_find('wqy-microhei.ttc'))  if __name__ == '__main__':     打招呼().run() </pre>   <pre class="lang:default decode:true ">pi@raspberrypi:~/test python3 打招呼.py 
[INFO   ] [Logger      ] Record log in /home/pi/.kivy/logs/kivy_17-10-17_8.txt
[INFO   ] [Kivy        ] v1.10.1.dev0, git-79bf5ef, 20171015
[INFO   ] [Python      ] v3.5.3 (default, Jan 19 2017, 14:11:04) 
[GCC 6.3.0 20170124]
[INFO   ] [Factory     ] 194 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Window      ] Provider: egl_rpi
[INFO   ] [GL          ] Using the "OpenGL ES 2" graphics system
[INFO   ] [GL          ] Backend used <gl>
[INFO   ] [GL          ] OpenGL version <b'OpenGL ES 2.0'>
[INFO   ] [GL          ] OpenGL vendor <b'Broadcom'>
[INFO   ] [GL          ] OpenGL renderer <b'VideoCore IV HW'>
[INFO   ] [GL          ] OpenGL parsed version: 2, 0
[INFO   ] [GL          ] Shading version <b'OpenGL ES GLSL ES 1.00'>
[INFO   ] [GL          ] Texture max size <2048>
[INFO   ] [GL          ] Texture max units <8>
[INFO   ] [Shader      ] fragment shader: <b'Compiled'>
[INFO   ] [Shader      ] vertex shader: <b'Compiled'>
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [OSC         ] using <multiprocessing> for socket
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event1
[INFO   ] [MTD         ] Read event from </dev/input/event1>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event2
[INFO   ] [MTD         ] Read event from </dev/input/event2>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event0
[INFO   ] [MTD         ] Read event from </dev/input/event0>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event1
[INFO   ] [HIDInput    ] Read event from </dev/input/event1>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event2
[INFO   ] [HIDInput    ] Read event from </dev/input/event2>
[INFO   ] [ProbeSysfs  ] device match: /dev/input/event0
[INFO   ] [HIDInput    ] Read event from </dev/input/event0>
[INFO   ] [Base        ] Start application main loop
[INFO   ] [MTD         ] </dev/input/event1> range position X is 0 - 0
[INFO   ] [MTD         ] </dev/input/event1> range position Y is 0 - 0
[INFO   ] [MTD         ] </dev/input/event1> range touch major is 0 - 0
[INFO   ] [MTD         ] </dev/input/event2> range position X is 0 - 0
[INFO   ] [MTD         ] </dev/input/event1> range touch minor is 0 - 0
[INFO   ] [MTD         ] </dev/input/event0> range position X is 0 - 10000
[INFO   ] [MTD         ] </dev/input/event2> range position Y is 0 - 0
[INFO   ] [MTD         ] </dev/input/event1> range pressure is 0 - 255
[INFO   ] [MTD         ] </dev/input/event0> range position Y is 0 - 10000
[INFO   ] [MTD         ] </dev/input/event2> range touch major is 0 - 0
[INFO   ] [HIDMotionEvent] using <b'Telink Wireless Receiver\x00                                                                                                                                                                                                                                       '>
[INFO   ] [HIDMotionEvent] using <b'Telink Wireless Receiver\x00                                                                                                                                                                                                                                       '>
[INFO   ] [MTD         ] </dev/input/event1> axes invertion: X is 0, Y is 0
[INFO   ] [MTD         ] </dev/input/event0> range touch major is 0 - 0
[INFO   ] [MTD         ] </dev/input/event2> range touch minor is 0 - 0
[INFO   ] [HIDMotionEvent] using <b'WWW.PowerMCU.COM Multi Media Development Board V1.0\x00                                                                                                                                                                                                            '>
[INFO   ] [MTD         ] </dev/input/event1> rotation set to 0
[INFO   ] [MTD         ] </dev/input/event0> range touch minor is 0 - 0
[INFO   ] [MTD         ] </dev/input/event2> range pressure is 0 - 255
[INFO   ] [GL          ] NPOT texture support is available
[INFO   ] [MTD         ] </dev/input/event0> range pressure is 0 - 255
[INFO   ] [HIDMotionEvent] <b'WWW.PowerMCU.COM Multi Media Development Board V1.0\x00                                                                                                                                                                                                            '> range ABS X position is 0 - 10000
[INFO   ] [MTD         ] </dev/input/event2> axes invertion: X is 0, Y is 0
[INFO   ] [MTD         ] </dev/input/event0> axes invertion: X is 0, Y is 0
[INFO   ] [HIDMotionEvent] <b'WWW.PowerMCU.COM Multi Media Development Board V1.0\x00                                                                                                                                                                                                            '> range ABS Y position is 0 - 10000
[INFO   ] [MTD         ] </dev/input/event2> rotation set to 0
[INFO   ] [MTD         ] </dev/input/event0> rotation set to 0