PyQT5 different view on OS and Linux - python-3.x

I created a python program that uses PyQT5, but looking at the displayed windows on Mac OS X and Linux then they differentiate quite a bit.
Here is the MAC OS X window
And here is the Linux version:
As you can see, the alignment of the tabs and the size/alignment of single lineedits is quite different. I understand that the rendering of the window depends on the underlying operating system, but is there any way to force the system to produce a similar output for all, e.g.:
Put the tabs to the very left
Make Lineedits be window width (or whatever size they were set to)

Qt5 has a platform-independent style plugin, fusion. Set the application to use this style, and it will look exactly the same on all platforms.
You can do this either by using Python code, calling QApplication.setStyle(), with an instance of QFusionStyle; or by setting the QT_STYLE_OVERRIDE environment variable to fusion; or by passing -style fusion as command line arguments to the application.
It is a decent style in my opinion, however, it doesn't feel entirely "native" anywhere.

Related

Mouse support with ncurses (for python) for large terminals

I'm using python3 with ncurses (curses) inside a docker container.
The problem is that mouse events are not accurately reporting x position in terminals that have more than 222 cells width. At first glance this is an obvious limitation because as far as i can see the position is sent in a single byte.
However Midnight Commander accurately handles large terminals. After some digging i could not find how to properly handle mouse with curses (this example does not work properly). Everything i tried with curses failed to work with large terminals. It seems that midnight commander is using gpm, but i could not find any way to use that in python.
q1: How can i handle mouse in large terminals in python3 directly, preferably with curses?
q2: Taking midnight commander as an example, will printing the escape sequences directly in stdout make the mouse work as expected ?
q3: Is there any other terminal gui library that handles mouse properly for python ?
It's not a direct limitation of the python interface to curses, but rather a feature of the underlying curses library, terminal description and the terminal:
For ncurses, that's the extended mouse feature which is standard in ncurses with ABI 6 (available since 2005, standard in ncurses 6 in 2015), noting that some distributions still provide ABI 5.
The terminal description has to use a feature which ncurses recognizes as implying the support for SGR 1006, and of course
The terminal itself has to support that feature (see note in ncurses database from January 2018 pointing out a few of the xterm imitators which do not).

How to get printer font names in X window?

I can get the list of available printer fonts by calling Delphi's TPrinter methods which I believe in turn calls Windows GDI (such as CreateFontA() ?). I do this in WINE running in Debian. I do not know why, but luckily this list contains true type font names, which I need most but are not shown by command xlsfonts. I am not sure if this is relevant to the technology under the hood, but package CUPS is installed.
This successful experience makes me to think that WINE must in turn call some Linux API (X, xfs, ...?) and then provide my program the results I want.
Now I would like to get the same list directly from Linux in C or C++. Which way should I take in order to achieve this goal? What API documentations should I study?
WINE font inspires me a lot, but I decide to stop researching the solution for my own question as the technology required to retrieve printer fonts in X window seems to be not trivial. I choose to use the font list given by Delphi's TPrinter running in WINE instead.
I close this question.

Keyboard layout switching in Qt, not Qt for embedded Linux

I am looking for a way to change the keyboard layout from within my Qt application. The application will run on a Linux kernel that doesn't support keyboard layout files, so Qt has to do everything concerning the mapping of the keyboard input.
In case of Qt for Embedded Linux I have found a good-looking solution here:
Qt Embedded for Linux. Keyboard layout switching
But unfortunately the QKbdDriverFactory class is not available for any other Qt versions, according to the documentation here: http://qt-project.org/doc/qt-4.8/qkbddriverfactory.html
I tried including it anyway (and astonishingly the class was there), but the compiler throws "undefined reference" errors whenever I invoke the create function.
Do I have to manually program huge QMap objects? Please tell me that there's a less tedious way. I don't want to believe that the qmap files can't be used outside of Qt for embedded Linux, because why would the kmap2qmap converter be available in practically any SDK if it's useless most of the time?
Alex
edit: Additional information:
I am using Qt 4.7.4 (32 Bit) and QtCreator 2.4.1.
I work on Ubuntu 12.04, 64 Bit on a Virtual Machine.
The target system is a hardware with a specialized minimal Linux kernel, so trying to use Qt Embedded would be very difficult.
There is no Xcb server, no frame buffer plugin (edit2: But we do use a frame buffer) and I couldn't find out what DE or eglfs means.
Seems like you should implement your own keyboard support layer.
You don't have dumpkeys program, so you can't generate keymap files on device. Use desktop version.
Keycodes generated on desktop PC might be different from keycode generated by your device, so you should adapt them.
After adapting keymap files you can write code to read these files.
Having a map of KEY_CODE=>UTF8_CHARACTER you can intercept key events and translate them to input symbols, according to currently used keymap.

Recognition of keyboard event in python

I'm a beginning programmer and i need a way to get python to recognize a keyboard event. So far i can only find these methods in vPython or tkinter, and i want to simply use the normal python shell. if anyone can help me with a module name/where i could download a module for free that would be very helpful. or simply the code if there is no need for a module.Thanks
There is no generic "keyboard event", they all depend on what your environment is.
In a terminal there are no keyboard events at all, you simply get sent text on stdin. In Windows you need to use the Win32, on Unix you need to use the X11 API and on Mac you have to use whatever OS X uses is it Cocoa?). wxPython and tkinter all work on all these platforms to provide an API that works on all of them. And the same goes for other GUI toolkits of the same sort like KDE and GTK. So you should use one of those. Which one is a matter of taste, but since tkinter is included in Python, that seems the obvious choice.
You can call the respective API's for the respective platforms directly, but it's generally not worth the trouble.

How can I make a single PyQt code to work in Windows and Linux?

PyQt experts: I developed the GUI in Windows and used setGeometry to position the widgets. When I tried to run the same code in Linux it looks cluttered.
And added to that in Windows the font size of 8 seems good. But in Linux, especially in Ubuntu, it doesn't appear well since the font size is 10 by default. Some among the differences are the border of the group box doesn't appear in Linux while it is visible in Windows..
Is there a way that I can make the same code to get the same look and feel in Windows and Linux irrespective of the font and size changes and other differences?
In future if I port my application to Mac will the same code work there too? Or should I have to maintain the separate code for each by checking with platform.system() equal to "windows" or "linux"?
The answer is simple: don't use setGeometry directly (to position your widgets).
Consider the following: what if the user wants to resize your application window?
Compose the user interface (you could do this from Designer or from code) within QSplitters (if you want a resize handle between two components) and/or within QVBoxLayouts / QHBoxLayouts (note that these can be nested).
This will make your UI components behave consistently.
I agree with #ChristopheD. Using setGeometry is bad. It's like designing a webpage with fixed pixel geometry and then wondering why it looks bad on another device.
Qt has a lot of wonderful layout code. Let it do it's job.
Qt by default will paint a widget according to instructions contained in the QStyle. You can test how badly you break your layout in different styles easily enough... run your program with different style options. Like so:
program.py -style motif
Also try -style platinum or -style windows. Even different versions of Windows will probably break your layout.
If you really want to see how bad pixel-based layouts are, try running your program with the -reverse parameter... that's how your program will look to someone running it who speaks a Right-To-Left language, like Hebrew or Farsi.
The problem that you have with widgets not drawing where you want them to can be solved by creating custom painting code for your widget. See the PyQt QPainter docs or better yet, the original Qt QPainter docs..
While I hope my answer is useful, it probably means your program needs to be partially rewritten. In the long term, however, it means that you'll have code that is portable between styles and operating systems, and will even work translated (assuming you care about that).

Resources