QPython3H 制作简易GUI长文本框界面

乘着船

#QPython3H 制作简易GUI长文本框界面
#函数代码部分

import androidhelper as android
droid=android.Android()
from qsl4ahelper.fullscreenwrapper2 import *
XML="""<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
 android:layout_width="fill_parent"
 android:layout_height="fill_parent"
 android:background="#ff0E4200"
 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/editTitle"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:textSize="8dp"
  android:text=""
  android:textColor="#ff0000"
  android:layout_weight="1"
  android:gravity="center"
 />
 <EditText
  android:id="@+id/editText"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:textSize="8dp"
  android:text=""
  android:textColor="#0000ff"
  android:layout_weight="1"
  android:gravity="center"
 />
 </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="%s"
  android:id="@+id/but_conf"
  android:textSize="8dp"
  android:background="#007f7f"
  android:textColor="#ffffffff"
  android:layout_weight="1"
  android:gravity="center"/>
 <Button
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:text="%s"
  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="%s"
  android:id="@+id/but_canc"
  android:textSize="8dp"
  android:background="#7f007f"
  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.editText.text=self.Text
        self.views.editTitle.text=self.Title
    def on_close(self):
        pass
    def copy(self,view,dummy):
        droid.setClipboard(self.views.editText.text)
        droid.makeToast("文本已复制")
    def conf(self,view,dummy):
        MainScreen.Text=self.views.editText.text
        FullScreenWrapper2App.close_layout()
    def canc(self,view,dummy):
        MainScreen.Text=None
        FullScreenWrapper2App.close_layout()
CCC=('确认','复制','取消')#默认按钮
def LongText(Title='',Text='',button=CCC):#主函数
#长文本(标题,多行文本,(确认按钮文本,复制按钮文本,取消按钮文本))
#替代系统输入函数:input=LongText
    MainScreen.Title=Title
    MainScreen.Text=Text
    FullScreenWrapper2App.show_layout(MainScreen(XML%tuple(button),Title),FullScreenWrapper2App.SHOW_LAYOUT_REPLACING_CURRENT)
    FullScreenWrapper2App.eventloop()
    i=MainScreen.Text
    MainScreen.Title=MainScreen.Text=True
    return i
FullScreenWrapper2App.initialize(droid)
__all__=('LongText','droid')

#举个例子:

input('按回车键继续1:')
print(LongText('测试1','文字1'))
input('按回车键继续2:')
print(LongText('测试2','文字2'))

#最后修改:2021-1-9
#视频 https://www.bilibili.com/av97477124 part1
#文章 https://www.bilibili.com/read/cv5224168
#其他 https://www.bilibili.com/read/readlist/rl321663
LongText示例
LongText("测试1","文字1")
#按“确认”返回“文字1”或继续编辑后的内容,按“取消”返回None。

阅读 833
1 声望
2 粉丝
0 条评论
1 声望
2 粉丝
文章目录
宣传栏