How to fix blurry text in WxPython controls on Windows? - windows

We have a Python-based application written with WxPython 4 that we build for multiple operating systems, including Windows. In Windows 10, at least in my environment (inside a VM on a high resolution monitor), the text elements in the interface are blurry:
I can improve the situation somewhat by setting the Windows DPI-scaling override on the application. This is indirect and suboptimal, and it seems like there should be a way to do it from WxPython more directly. However, I have not found a way to do it.
Is there any way to set DPI scaling from WxPython, or otherwise fix blurry text on Windows in WxPython 4 directly from within the application?

According to a message from Python Issue Tracker and what I tried in the wxPython official Hello World, Part 2 example (helloworld2.py), adding following code to your program should work:
import ctypes
try:
ctypes.windll.shcore.SetProcessDpiAwareness(True)
except:
pass

Related

GUI Development for a ROBOT Compatible with ROS and WINDOWS

for a project i have been assigned, I have been given 2 robots...one has ROS and the other basically uses Windows. So my task is to develop one Graphic User Interface that can be used for both robots.
From the GUI , a user should be able to.
- Connect to the Robot
- Move and control the robot.
- Change speed...etc
I will like to ask for advice as i am about to start this project.
How can i go about this? and which has better support for my requirements?
From my research i have read people recommend QT...for cross platform developmens. Are there any other alternatives? any book recommendations?
The goal will be to have a GUI that is compatible for both systems. Any Recommendations or help is welcomed.
First you setup ROS On windows Using WSL (or any other ways to do it WSL is most stable).
after that you need achieve everything you want the GUI does on robot using ROS terminal.
after that your write the GUI. You can Choose any framework You want(You need C++ or Python for compatibility issues with ROS) but QT Framework is most used in multi platform Application and has a lot of support.
the compatibility with non-ROS is what You should Implement in your Application Like Choosing or something Like that.
PySimpleGUI is a framework built on top of tkinter that runs on the Pi. There are some example programs written to do robot remote control. There are GUI buttons designed specifically for "realtime" control of hardware that will provide immediate and constant feedback when a button is held.
It runs on Python 2.7 and 3 (recommend 3).
There is a Recipe in the Cookbook that matches your problem located here.
If you use PySimpleGUI in your project, post in the Issues area on GitHub if you have any questions and you'll get support.

Python - pythondiologue vs. tkinker vs. wxPython vs. pyQt

I made a really simple, pseudo GUI using pythondialogue (its a wrapper for whiptail for bash), I need it to be cross platform between linux and Mac OSX. The main issue is its really hard to find information on pythondialogue, the only documentation seems to be on their own site. I would just use whiptail, but I'm learning python so using this to hone my python skills.
What I like about pythondialogue (and whiptail) is that its not really a GUI, just a dialogue inside the CLI, so it can used purely through the command line such as if you SSH to the computer you want to run it on. Can tkinter do this too?
Either way, a big thing I'm wondering is what benefits tkinter would provide over regular pythondialogue. Obviously the difference is it lets you create proper GUI applications, but would it be wisest to only create a GUI application in cases where its absolutely necessary?
tkinter sounds like the easiest way to code GUIs in python. What disadvantages does it have to PyQt or wxPython. I wan't to start developing mobile apps as soon as possible and I see iOS and android apps can be written using python and Qt can be used to write both Android and iOS apps. So with this in mind, would learning PyQt mean I would also be developing the skills I'll need to create iOS and android apps? If so, this is most definitely what I'm going to do.
Learning PyQt will definitely help you learn to create IOS and Android apps. Even more, PyQt comes with QtDesinger which is a visual editor for creating apps with minimal coding. Tkinter in my perspective is for very light GUI programming. If you feel like you want to make money of these apps, I would highly advise you to check out Kivy.

Programmatically choose correct backend for Matplotlib on Mac OS X

I have a program which integrates a tkinter GUI as well as a matplotlib plot (using pyplot). I'm running into endless troubles having this program work correctly across a variety of Mac platforms. The main problem seems to be the appropriate selection of the backend.
In some cases, the program runs fine no problem. In other cases, I run into a similar issue documented in this question. Implementing the solution outlined there solves that problem, but then other errors pop up for other systems. The solution to these other errors appears to be to use the Qt4Agg backend.
There has to be some standard way of getting a program using tkinter and matplotlib at the same time to play nice with Macs. How can I programmatically make sure the correct backend is being used such that the program won't crash for a Mac user?
Sorry if this is vague but it is a very broad problem.
See this answer: How to switch backends in matplotlib / Python
In essence, if you do not know which backend is available, the following code should load up the first backend that is available on the current machine. (I have only included 4 backends, there are quite a few others).
import matplotlib
gui_env = ['TKAgg','GTKAgg','Qt4Agg','WXAgg']
for gui in gui_env:
try:
print("testing", gui)
matplotlib.use(gui,warn=False, force=True)
from matplotlib import pyplot as plt
break
except:
continue
print("Using:",matplotlib.get_backend())
Using: GTKAgg
Update: I am lead to believe that there is a backend for OSX called MacOSX which could be added to that list, although I have no way of testing it myself.

GUIs inside Operating Systems

How do GUIs get built inside operating systems. Lets use two examples, say GTK+ in Ubuntu verses a Java JFrame. I thought that operating systems using some kind of graphical user interface would have to provide some system calls to be able to display windows. So for example, if I installed a version of Ubuntu on a machine, with out downloading any software I should be able to make a system call to display a window. It appears though that isn't the case. I have to install and download the SDK for GTK+ which allows me to create windows with buttons, etc. So then my question is with Java, how does Java then build it's JFrames? I understand that there is a Java Virtual Machine running ontop of the Linux system, but how does the Java virtual machine make calls to actually display the window? Along with GUIs comes the events that the user interacts with them. At the Java level, the JVM handles all the lower level calls, and you get OnClick() events etc. How does the JVM actually call and work with those calls? Same with GDK+? I understand this is a broad question with many different answers, but any help would be greatly appreciated.
Let's take Linux as an example. There are several layers:
Kernel (Linux) and operating system (GNU) - Knows how to work the hardware, including graphics.
Windowing system (X) - Uses graphics functions to draw windows.
Desktop (eg Gnome) - Applies global styles such as window borders.
(Usually) A toolkit such as GTK - Knows about widgets, how to draw them and how to style them.
Your application.
On Windows, the Kernel, OS, windowing system, desktop and widgets are all bundled together. In this case the toolkit probably doesn't draw its own widgets, but uses them directly from Windows.
In any case, the toolkit insulates your application from the platform-specific details and automatically does the right thing.

Console widget wxpython

I have forked an interpreter written in C (Picoc), and I want to create a GUI for that interpreter.
The GUI should have a textarea (TextView in pygtk) and a console in the bottom, that will show the output of the script that you just written, and also prompt the input if its needed.
I do create a PyGTK GUI that has VTE Console widget, but the problem is that i want to make PyGTK cross-platform, i'm using GTKSourceView and as i was looking on Google, its no so easy to port GTK to windows, so, i research about WxPython (which is the same window Manager of Code::Blocks), but the question is:
It DO exists a Console Widget on wxPython?
and most important, how portable it is? can i port it to windows easier than GTK?
It was my understanding that PyGTK is cross-platform. It just doesn't use native widgets. I've certainly used an application written in it on Windows anyway. Admittedly, I've never had much luck actually using it on Windows.
As for wxPython, no it doesn't have a console widget. You would have to use Python's subprocess to launch a console window and communicate with it. On the other hand, wxPython is quite portable. I've seen screenshots of apps on all 3 major platforms and I've written a couple of mine to work on Windows and Ubuntu.

Resources