I started a project where you can "log in" on a terminal (basically a Raspberry Pi with a touchscreen attached) with a wireless token (for time tracking).
What will be the best and fastest solution to display the status (basically a background picture and 2-3 texts changing depending on the status of the token) on the screen (fullscreen)? I tried it web-based with chromium, which is -very- slow...
It has to be easy to do http request and en-/decoding JSON - and please no C/C++.
Maybe python + wxwidgets?
If you want easy/fast, and all you care about is http, JSON, and displaying an image, then I'd go with Tkinter and the standard library.
You have import json for JSON, and httplib or urrlib2 for http requests. And for a fullscreen Tkinter widget, check out effbot.
You could use Python for this easily with just the standard library (python 2.7.3).
For the GUI you can use Tkinter or Pygame (not standard library) which both support images and text placement (and full screen). It is notable that Tkinter is not thread safe, so that may be a problem if your planning on threading this program.
For the http request you can use httplib.
For the Json related things you can use the json library.
Kindly give QT a try. It has very good GUI tools and supports the C++ and nativeness it requires. We use QT to build interface and deploy it small terminals such as raspberry Pi. It will also allow you to boot straight in to the application as it starts.
Here is a link : http://qt-project.org/wiki/Qt-RaspberryPi
Related
I'm trying to implement numpad in PyQt5 and Windows 10. There are buttons 1, 2, ... 9, enter
I'd like to implement the following event:
When user clicks for example on button 1, the character '1' will be sent to background application (for example notepad).
I have done simple GUI. I only need to implement this event. What libraries, functions can I use to this purpose?
You should research how Inter-process communication works and APIs.
You did not specify which Operating System you target, each one has its own ways to do it.
You mention "sending characters to notepad" but which application do you plan to communicate with ? Because working with any application may be a very difficult problem.
For Notepad I found this question that uses the Windows API to communicate, but it was relatively easy because the source language was C# (which is well-integrated with Windows). According to this other question you should use PyWin32 to do that in Python.
But if you plan your NumPad application to work with many other applications, you should look how other Input sofwares work. It may have clues how to do it.
I wrote a script using pyautogui that should start an program (an IDE) and then start using it.
This is the script so far:
#! python3
# mouseNow.py - Displays the mouse cursor's current position.
import pyautogui, sys, subprocess
from time import sleep
x,y = 1100,550
subprocess.call([r'C:\...exe', arg1, arg2])
pyautogui.click(x,y)
sleep(5) # 2 sec should suffice but this is for safety
pyautogui.typewrite(my_string)
pyautogui.press('enter')
This works well but I want to be portable. The x,y values were determined by where the program prompt appears on screen after I start the program, but this is not portable, I think. Is there a way to point the mouse to the prompt without giving const parameters? something like move_mouse_to_window_of_this_process_after_starting_it()
Also, I use sleep() so I would write the data to the window after it appears, but I guess it's not a good way (some PC will run this much slower, I guess), so is there a way to know when the prompt appeared and then do the pyautogui.typewrite(my_string)?
EDIT: I found a simple solution for the move_mouse_to_window_of_this_process_after_starting_it()
:
>>> pyautogui.hotkey('alt', 'tab')
If you need portable and reliable solution, you have to find a library that supports accessibility technologies to access GUI elements by text. Basic technologies are:
Win32 API, MS UI Automation (Windows)
AT-SPI (Linux)
Apple Accessibility API (MacOS)
There are several open-source GUI automation libraries supporting some of these technologies (usually 1 or 2). Python solutions:
pywinauto on Windows (both Win32 API & MS UIA, see Getting Started Guide)
pyatspi2 on Linux
pyatom on MacOS
There is also a thread on StackOverflow regarding hard sleeps vs flexible waiting.
Enjoy! :)
The way you are interacting with the .exe excludes alternatives to coordinates or blind firing (Tab, Tab, Enter etc..).
If the application has an API, you could interact with it programatically.
If it doesn't you can only try to match the location for x screen resolutions, and this only if the GUI is used in Fullscreen/windowed Fullscreen.
I need to show a webpage (a complex page with script and stuff, no static html) in a frame or something. It's for a desktop application, I'm using python 2.6 + wxPython 2.8.10.1. I need to catch some events too (mostly about changing page). I've found some samples using the webview module in a gtk application, but I couldn't have it works on wx.
You can embed IE, but I think that's about it. wxWebKit is working on a wx add-on to use WebKit as an embedded browser in wx, but I think it's still a work in progress.
There is a commercial solution for this called wxWebConnect that uses Gecko (the Mozilla engine). I've never used it myself because i'm waiting for the wxWebKit project to be ready to use but it looks pretty good although perhaps a little overkill for your needs.
I'm desiging a pygtk GUI and want to embed an external application into it.
Does anyone have any idea how this can be done?
It depends on what application you are trying to embed into yours, but if the other app is a GTK app (or one that supports the XEMBED protocol), you should be able to do this with gtk.Plug and gtk.Socket. The PyGTK tutorial has a section explaining how to do this:
http://www.pygtk.org/pygtk2tutorial/sec-PlugsAndSockets.html
This one might help. Read the article 19.15. How do I embed something using Plugs and Sockets? (http://faq.pygtk.org/index.py?req=all#19.15) and find out how to embed arbitrary X Window application into (Py)GTK Socket.
You don't use an external program to get the gtk.Plug/gtk.Socket ID, they have their respective functions for that. See this tutorial for examples: link.
If you're trying to reparent an external window (that may not be a gtk window), you can use
w = gdk.window_foreign_new(window_id)
to get a gdk window object from an operating system window handle, and then use
w.reparent(parent_window, x, y)
to reparent it into an existing gtk container.
How can I detect, or be notified, when windows is logging out in python?
Edit:
Martin v. Löwis' answer is good, and works for a full logout but it does not work for a 'fast user switching' event like pressing win+L which is what I really need it for.
Edit: im not using a gui this is running as a service
You can detect fast user switching events using the Terminal Services API, which you can access from Python using the win32ts module from pywin32. In a GUI application, call WTSRegisterSessionNotification to receive notification messages, WTSUnRegisterSessionNotification to stop receiving notifications, and handle the WM_WTSSESSION_CHANGE message in your window procedure.
If you're writing a Windows service in Python, use the RegisterServiceCtrlHandlerEx function to detect fast user switching events. This is available in the pywin32 library as the RegisterServiceCtrlHandler function in the servicemanager module. In your handler function, look for the SERVICE_CONTROL_SESSIONCHANGE notification. See also the WM_WTSSESSION_CHANGE documentation for details of the specific notification codes.
There's some more detail in this thread from the python-win32 mailing list, which may be useful.
I hope this helps!
In a console application, you can use win32api.SetConsoleCtrlHandler and look for CTRL_LOGOFF_EVENT. In a GUI application, you need a window open and wait for the WM_QUERYENDSESSION message. How precisely that works (and if it works at all) depends on your GUI library.