All Projects → sirk390 → wxasync

sirk390 / wxasync

Licence: MIT license
asyncio support for wxpython

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to wxasync

Phoenix
wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before.
Stars: ✭ 1,698 (+2512.31%)
Mutual labels:  wxwidgets, wxpython
Pyface
pyface: traits-capable windowing framework
Stars: ✭ 71 (+9.23%)
Mutual labels:  wxwidgets, wxpython
Libtorch Yolov3 Deepsort
Stars: ✭ 165 (+153.85%)
Mutual labels:  wxwidgets
Lua2SC
Lua client for supercollider scsynth and supernova
Stars: ✭ 55 (-15.38%)
Mutual labels:  wxwidgets
wxsqliteplus
A simple SQLite database browser built with wxWidgets
Stars: ✭ 34 (-47.69%)
Mutual labels:  wxwidgets
wxEditor
微信编辑器,微信排版,微信公众号编辑器, 微信素材,前后端已搭建完整,原UEditor(百度编辑器,PHP1.4.3版) 二次开发 (微信编辑器,微信公众号,图文发布在线编辑器) 。
Stars: ✭ 86 (+32.31%)
Mutual labels:  wx
Videomass
Videomass is a free, open source and cross-platform GUI for FFmpeg and youtube-dl / yt-dlp
Stars: ✭ 451 (+593.85%)
Mutual labels:  wxpython
Multivnc
MultiVNC is a cross-platform Multicast-enabled VNC viewer using wxWidgets and libvncclient . It runs on Unix, Mac OS X and Windows. Features include support for most encodings, ZeroConf service discovery and a seamless edge control mode á la x2vnc. There also is a mobile (Android) version with a different feature set available.
Stars: ✭ 134 (+106.15%)
Mutual labels:  wxwidgets
PySimpleGUI
Launched in 2018. It's 2022 and PySimpleGUI is actively developed & supported. Create complex windows simply. Supports tkinter, Qt, WxPython, Remi (in browser). Create GUI applications trivially with a full set of widgets. Multi-Window applications are also simple. 3.4 to 3.11 supported. 325+ Demo programs & Cookbook for rapid start. Extensive d…
Stars: ✭ 10,846 (+16586.15%)
Mutual labels:  wxpython
flamerobin
FlameRobin is a database administration tool for Firebird RDBMS. Our goal is to build a tool that is: lightweight (small footprint, fast execution) cross-platform (Linux, Windows, Mac OS X, FreeBSD) dependent only on other Open Source software
Stars: ✭ 181 (+178.46%)
Mutual labels:  wxwidgets
ESP32-CAM-MJPEG-Stream-Decoder-and-Control-Library
The library is MJPEG stream decoder based on libcurl and OpenCV, and written in C/C++.
Stars: ✭ 40 (-38.46%)
Mutual labels:  wxwidgets
wxAutoExcel
wxAutoExcel is a wxWidgets library attempting to make Microsoft Excel automation with C++ a bit less painful.
Stars: ✭ 27 (-58.46%)
Mutual labels:  wxwidgets
Examples wxWidgets
Shows how to use wxWidgets controls only by programming code (c++17).
Stars: ✭ 116 (+78.46%)
Mutual labels:  wxwidgets
thotkeeper
ThotKeeper — cross-platform personal daily journaling
Stars: ✭ 28 (-56.92%)
Mutual labels:  wxpython
Trade Frame
c++ based application for testing options based automated trading ideas using DTN IQ real time data feed and Interactive Brokers (TWS API) for trade execution.
Stars: ✭ 187 (+187.69%)
Mutual labels:  wxwidgets
wxfortune
运势小程序,使用canvas绘画图片,并保存图片
Stars: ✭ 79 (+21.54%)
Mutual labels:  wx
wx-tool
微信小程序工具类
Stars: ✭ 31 (-52.31%)
Mutual labels:  wx
face-login-wx
人脸识别登录微信小程序
Stars: ✭ 77 (+18.46%)
Mutual labels:  wx
wxapp-storage
简单的微信小程序Storage相关的封装, 特点是安全的数据源, 有效的存储时间
Stars: ✭ 13 (-80%)
Mutual labels:  wx
haxeui-hxwidgets
The hxWidgets backend of the HaxeUI framework -
Stars: ✭ 20 (-69.23%)
Mutual labels:  wxwidgets

wxasync

asyncio support for wxpython

wxasync it a library for using python 3 asyncio (async/await) with wxpython. It does GUI message polling every 5ms and runs the asyncio message loop the rest of the time. The polling doesn't have a noticable effect on CPU usage (still 0% when idle).

You can install it using:

pip install wxasync

To use it, just create a WxAsyncApp instead of a wx.App

app = WxAsyncApp()

and use AsyncBind to bind an event to a coroutine.

async def async_callback():
    (...your code...)
    
AsyncBind(wx.EVT_BUTTON, async_callback, button1)

You can still use wx.Bind together with AsyncBind.

If you don't want to wait for an event, you just use StartCoroutine and it will be executed immediatly. It will return an asyncio.Task in case you need to cancel it.

task = StartCoroutine(update_clock_coroutine, frame)

If you need to stop it run:

task.cancel()

Any coroutine started using AsyncBind or using StartCoroutine is attached to a wx Window. It is automatically cancelled when the Window is destroyed. This makes it easier to use, as you don't need to take care of cancelling them yourselve.

To show a Dialog, use AsyncShowDialog or AsyncShowDialogModal. This allows to use 'await' to wait until the dialog completes. Don't use dlg.ShowModal() directly as it would block the event loop.

You start the application using:

await app.MainLoop()

Below is full example with AsyncBind, WxAsyncApp, and StartCoroutine:

import wx
from wxasync import AsyncBind, WxAsyncApp, StartCoroutine
import asyncio
from asyncio.events import get_event_loop
import time


class TestFrame(wx.Frame):
    def __init__(self, parent=None):
        super(TestFrame, self).__init__(parent)
        vbox = wx.BoxSizer(wx.VERTICAL)
        button1 =  wx.Button(self, label="Submit")
        self.edit =  wx.StaticText(self, style=wx.ALIGN_CENTRE_HORIZONTAL|wx.ST_NO_AUTORESIZE)
        self.edit_timer =  wx.StaticText(self, style=wx.ALIGN_CENTRE_HORIZONTAL|wx.ST_NO_AUTORESIZE)
        vbox.Add(button1, 2, wx.EXPAND|wx.ALL)
        vbox.AddStretchSpacer(1)
        vbox.Add(self.edit, 1, wx.EXPAND|wx.ALL)
        vbox.Add(self.edit_timer, 1, wx.EXPAND|wx.ALL)
        self.SetSizer(vbox)
        self.Layout()
        AsyncBind(wx.EVT_BUTTON, self.async_callback, button1)
        StartCoroutine(self.update_clock, self)
        
    async def async_callback(self, event):
        self.edit.SetLabel("Button clicked")
        await asyncio.sleep(1)
        self.edit.SetLabel("Working")
        await asyncio.sleep(1)
        self.edit.SetLabel("Completed")

    async def update_clock(self):
        while True:
            self.edit_timer.SetLabel(time.strftime('%H:%M:%S'))
            await asyncio.sleep(0.5)


async def main():            
    app = WxAsyncApp()
    frame = TestFrame()
    frame.Show()
    app.SetTopWindow(frame)
    await app.MainLoop()


asyncio.run(main())

Performance

Below is view of the performances (on windows Core I7-7700K 4.2Ghz):

Scenario Latency Latency (at max throughput) Max Throughput(msg/s)
asyncio only (for reference) 0ms 17ms 571 325
wx only (for reference) 0ms 19ms 94 591
wxasync (GUI) 5ms 19ms 52 304
wxasync (GUI+asyncio) 5ms GUI / 0ms asyncio 24ms GUI / 12ms asyncio 40 302 GUI + 134 000 asyncio

The performance tests are included in the 'test' directory.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].