
I present to your attention a small excerpt from my course work (more precisely, this is educational practice).
Omitting a lot of theoretical water that is unnecessary on Habré, I will demonstrate on a fairly synthetic example how to transfer a small program from Linux to Windows.
I note that this is not an instruction and does not in any way pretend to it. This is a small overview of the process to show how things are going.Python, Qt and PyQt are in almost any distro, and in which case you can quickly and easily deliver (I don’t know exactly the size of the packages, but subjectively - small).
Our application is a list of named colors and a text field with customizable background and font colors. Its code can be viewed in the links below.
The result is a
col.py file of 6.31 KB in size (6,468 bytes) and a
cui.py interface
file - 6.56 KB (6,724 bytes). The file
col.txt contains a list of colors.
The interface is formed using a visual editor - QtDesigner. The program creates a file with the ui extension, where the interface structure is described in XML format. Then, using the pyuic utility, this class generates a Python language class that connects to the main file with the following code.
I apologize in advance for the crooked interface - as long as there is no possibility to redo it.
Actually, it remains for us to give the file permission to execute and can be run.
The situation is completely different with Windows. To run this file we have to:
• Install
Python interpreter (14 MB)• Install
the Qt library (200-280 mb)• Set
PyQt bindings (17mb)Too much for a 12kb program, given that we will have to independently search for where to download distributions and install them manually. In order not to force the user to download more than three hundred megabytes, we will compile the executable exe-file, which will require only the library files themselves (about 20 MB). Of course, this is also far from ideal, but it clearly demonstrates the state of affairs.
To compile the executable file, in addition to the above, we need the program
py2exe (200kb) . Following the instructions, we create a file setup.py with which we pass the necessary arguments to the utility. By the way, to work with PyQt4, we will have to conjure a little with the compiler files. The compilation process (do not forget about the parameters of the type "--include sip") and at the output we have a folder with an executable file and libraries. The total size of 19 mb. The exe file itself weighs only 20 kb, but it still requires many more files to work.
Now let's talk about how well it works.
For example, take the function of copying color to the clipboard. Pretty soon it turns out that there is no single buffer in Linux, but X server, Qt or Gtk buffers are used. And PyQt for Windows does not support clipboard functions. That is, in order for the function to work as it should, from the very beginning we will have to determine on which platform the program is running and connect the corresponding functions.
Or another example - a menu item that generates a signal to exit the application. I did not manage to find out the reason why the program did not respond to it under Windows.
')
Alas, in order for the program to work perfectly for different operating systems, you will have to either write different versions of the source code, as we have already seen that even the use of cross-platform functions of the interpreted language and the library known for its portability does not allow proper functioning. And in order for the same code to work on different platforms, you will have to significantly complicate the development cycle - correction, testing, porting, testing, compiling, testing.
It should be noted that the executable file compiled by us running on Linux using the Wine program behaved in the same way as in real Windows, except that it refused to display the text. Although all fonts are installed and configured.
PS My first topic is waiting for criticism. I note that this is a work on a topic about which at least 2-2.5 teachers at the department know something, so they’ll have the technical details ... But if you have any comments or suggestions, you are welcome.