Android QPython3 可視化-輸出窗體:Output.py
#需要BaseWindow.py? https://www.bilibili.com/read/cv8680125
from BaseWindow import *
XML="""<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#9f5f00"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="20">
<ScrollView? ?
? ? ? ? android:layout_width="fill_parent"? ?
? ? ? ? android:layout_height="fill_parent" >?
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_weight="20">
? ? <EditText
android:id="@+id/editNew"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="8dp"
android:text=""
android:textColor="#0000ff"
android:layout_weight="1"
/>
<EditText
android:id="@+id/editOld"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textSize="8dp"
android:text=""
android:textColor="#ff0000"
android:layout_weight="1"
/>
</LinearLayout>
</ScrollView>
? ? </LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="100dp"
android:orientation="horizontal"
android:layout_weight="8">
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="繼續(xù)(保留)"
android:id="@+id/but_conf"
android:textSize="8dp"
android:background="#2f3f8f"
android:textColor="#ffffffff"
android:layout_weight="1"
android:gravity="center"/>
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="復(fù)制"
android:id="@+id/but_copy"
android:textSize="8dp"
android:background="#7f7f00"
android:textColor="#ffffffff"
android:layout_weight="1"
android:gravity="center"/>
<Button
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="繼續(xù)(清除)"
android:id="@+id/but_canc"
android:textSize="8dp"
android:background="#6f1f6f"
android:textColor="#ffffffff"
android:layout_weight="1"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>"""
class MainScreen(Layout):
? ? def on_show(self):
? ? ? ? self.views.but_conf.add_event(click_EventHandler(self.views.but_conf,self.conf))
? ? ? ? self.views.but_copy.add_event(click_EventHandler(self.views.but_copy,self.copy))
? ? ? ? self.views.but_canc.add_event(click_EventHandler(self.views.but_canc,self.canc))
? ? ? ? self.views.editNew.text=clbr(self.New)
? ? ? ? global First
? ? ? ? if First:
? ? ? ? ? ? self.views.editOld.text=First
? ? ? ? ? ? First=None
? ? ? ? else:
? ? ? ? ? ? self.views.editOld.text=clbr(self.Old)
? ? ? ? MainScreen.Old=self.Old+self.New
? ? ? ? MainScreen.New=''
? ? def on_close(self):
? ? ? ? pass
? ? def copy(self,view,dummy):
? ? ? ? droid.setClipboard(self.Old)
? ? ? ? droid.makeToast("文本已復(fù)制")
? ? def conf(self,view,dummy):
? ? ? ? FullScreenWrapper2App.close_layout()
? ? def canc(self,view,dummy):
? ? ? ? MainScreen.Old=''
? ? ? ? FullScreenWrapper2App.close_layout()
? ? Old='';New=''
def clbr(x):
#去掉頭尾空行
? ? t=True
? ? while t:
? ? ? ? t=False
? ? ? ? if x and x[0]=='\n':
? ? ? ? ? ? x=x[1:]
? ? ? ? ? ? t=True
? ? ? ? if x and x[-1]=='\n':
? ? ? ? ? ? x=x[:-1]
? ? ? ? ? ? t=True
? ? return x
First='上/藍(lán):最新輸出\n下/紅:歷史輸出\n這是標(biāo)準(zhǔn)輸出窗口\n此提示只顯示一次'
def Output(Content=''):#主函數(shù)
#輸出窗體(內(nèi)容str)
#不會(huì)自動(dòng)換行
#輸出:None
? ? MainScreen.New=Content
? ? FullScreenWrapper2App.show_layout(MainScreen(XML,'Output'))
? ? FullScreenWrapper2App.eventloop()
__all__=('Output','droid')

作者:乘著船@Bilibili
更多文章+下載鏈接:https://www.bilibili.com/read/readlist/rl321663