Synchronous comparison of Chinese version of beeware tutorial

Mobile phone code words are easy to make mistakes and leak. Some links are difficult to add. Go back and touch the computer and change it. Please forgive me for the time being

  • Product Name: Bee set
  • Ingredients: toga, briefcase, rubicon objectc, rubicon java 😂 Another fatal weakness is that all his files have to be downloaded from the network, and all of them will be stored under appdata. Be careful of the hard disk!
  • Reference parameters: Unicom Gigabit broadband, the cumulative time of downloading the first 7 steps is 50min, and the cumulative time of build ing is 70min

(haha, I almost can't hit the watch) if you want to run bee gear, your system disk needs

functionAccumulated space required for system disk
python running300M
Compiling and packaging for Windows500M
android virtual machine build7GB
android virtual machine run8GB

(link) konjaku's exclusive hard disk cleaning method

  • Main function: let your program code once and run everywhere!
    I doubt it
  • Applicable crowd: at present, the bee has supported windows, MAC, Linux, IOS, Android and web, but the web function is not mature
    (official start)

1.1 install a 3.7 or above python and a git, and then ensure that they can be run from the system command

If you don't want to find something for yourself, you'd better install 3.8. In addition, you don't need to manually check whether it is added to the environment variable. If you install it and it prompts you not to install it, it's not added. You only need to reinstall the (python/git) software once
1.2 create a virtual environment, and then all components will be isolated in it, so that even if your program breaks, it will not explode into the computer. This is optional
It does have a protective effect, but don't think it's done by deleting the virtual environment

md beeware-tutorial
cd beeware-tutorial
::You can also in the folder you want to create (preferably empty) Shift+Right click, equivalent to upper 2
py -m venv beeware-venv
::py yes python.exe,The premise is that you have to be in the environment variable
beeware-venv\Scripts\activate.bat
::script Is automatically generated

(there should be a dynamic virtual environment here)

First you need to install briefcase

python -m pip install briefcase

Then I'm all dealing with briefcase
briefcase step 1

briefcase new
cd helloworld
::Or your own appname,No spaces
briefcase dev

Explanation of the pop-up options of the new command

termWhat do you do?Default value (enter directly)
formal nameIt's no usehello world
app nameapp name, unique and usefulhello world
project nameIt's no usehello world
bundleDomain name, if you havecom.example
descriptionDescription, irrelevanthello world
authorauthorHow can there be a default value?
author's emailauthorHow can there be a default value?
urlYour websitehttps://example.com/helloworld
LicenseLicense, withBSD
GUI frameworkWhat format is the graphical user interface intoga

Then now a window will pop up bling ly, turn it off and continue

Now you have used up 300MB of system disk and 50MB of memory

The script of the program is HelloWorld / SRC / HelloWorld / APP Py, just look at the other two
Next, if you want to try, you can replace helloworld class with the following one, but don't move the content that doesn't belong to class

class HelloWorld(toga.App):
    def startup(self):
        main_box = toga.Box(style=Pack(direction=COLUMN))

        name_label = toga.Label(
            'Your name: ',
            style=Pack(padding=(0, 5))
        )
        self.name_input = toga.TextInput(style=Pack(flex=1))

        name_box = toga.Box(style=Pack(direction=ROW, padding=5))
        name_box.add(name_label)
        name_box.add(self.name_input)

        button = toga.Button(
            'Say Hello!',
            on_press=self.say_hello,
            style=Pack(padding=5)
        )

        main_box.add(name_box)
        main_box.add(button)

        self.main_window = toga.MainWindow(title=self.formal_name)
        self.main_window.content = main_box
        self.main_window.show()

    def say_hello(self, widget):
        print("Hello", self.name_input.value)
briefcase dev
briefcase run
::because briefcase It runs automatically, so you can call briefcase dev perhaps briefcase run -d

Turn your program into a windows installation package

briefcase create
::It will take a while
briefcase build
briefcase run
::Run your application,If you want to pack, this sentence can be ignored
briefcase package

4.1. How to update the application file after changing the source program

briefcase update
briefcase run
::Equivalent to briefcase run -u
  1. How to update the installation package after changing the source program
briefcase update
briefcase package
::Equivalent to briefcase package -u

Choose your mobile carrier (I did it according to Android)

Use these three commands to build android at one time

briefcase create android
briefcase build android
briefcase run android

(link again) konjaku exclusive tips for efficient hard disk cleaning

The first half of the part is talking with lungs. I told you to import the third-party package first. Why did you fry the duck? Oh, I didn't install it
But we can't blow up the user's computer, so we asked briefcase to install it for us first. Open HelloWorld / pyproject Toml, find requirements = [] and add the package name in the following format in brackets, one by one

requires = [
    "Package name>=edition",
    "Package name==edition",
    "git+https://github.com/encode/httpx"
]

After editing, run the following

briefcase update -d

Make him siiiiii slippery
In human terms, it is to replace synchronous loading with asynchronous loading (well, it doesn't seem to be human)
The students who used python and successfully reached this step were very lucky. I fainted when I did EventLoop in Android studio

So what's going on in python

async def say_hello(self, widget):#The keyword async is added
    if self.name_input.value:
        name = self.name_input.value
    else:
        name = 'stranger'

    async with httpx.AsyncClient() as client:#async with keyword and AsyncClient method are added
        response = await client.get("https://jsonplaceholder.typicode.com/posts/42 ") # through awaitclient, you can get the result when there is already a result in the response, although there is no result in the actual operation

    payload = response.json()

    self.main_window.info_dialog(
        "Hello, {}".format(name),
        payload["body"],
    )

Change your icon, publish it on the Internet, and then publish it (the author said: later) hh hhhhhhhg, can I also be better
Link other options
Link toga control

Keywords: Python Android

Added by funguse on Thu, 03 Feb 2022 20:40:18 +0200