Python Gtk Glade app structure. What are the best practises? - python

Since I discovered Python, I've created four little applications with Glade + Python + Gtk. For each of them, the structure is a folder, with the name of the app, containing :
an "images" folder
a main .py file which contains all classes that handle all project windows
a .glade file which contains all windows (main app window, about dialog, config dialog, etc.)
a style.css file
(other files as sqlite file and/or json file if neccessary)
Now I'm wondering if this organization is a good practise. Because I've seen a video tutorial in which each window has its own ".ui" file and .py file. Also, other apps seem to be organized like this too and Anjuta projects seem to follow this rule too.
Furthermore, the tutorials that show how to create a Python-Gtk-Glade app are almost all one-window projects...
So my question is : how do you organize your Python-Gtk-Glade projects or what is the best way to do it?
Thanks in advance.

The way you set up your apps will be dictated by your preferences (coding style), the size of the app, and the purpose of the app. However, here are a couple considerations:
Will total lines of Python code be greater than 1000 lines? A file with over a 1000 lines will be unwieldy to navigate. I know code folding, snippets, and etc help but still.
If you have more than one GtkWindow, put each window's .ui and .py separately. This helps when tracking down bugs or adding features. You mentioned sqlite, and sql queries within a file are easier to master 5 years down the road if the files are somewhat purpose specific. If you put dialogs in the same ui file as the parent window, it makes it easier to use set_transient_for and similar programming. Having more than one GtkWindow in a .ui file will make drag and drop widget reordering a pain.
Are parts of the app code reusable? If you find that you are duplicating features in several different files that have different purposes, make a class or function to simplify that one feature (only applicable to multi-file setup).
And finally, when your folder with .ui and .py files starts becoming large (? 25 - 50 files ?) you might want a subfolder that has a group of files with similar functionality. This is not written in stone. Nemo doesn't use this a lot, others do.
I actively develop my own business management software using Python + Gtk found here. I found the principles described above to work well for me.
I think the reason the documentation for Gtk typically shows single file setups is because they are merely proof of concept and not best app management tutorials. App management (for me, anyway) was trial and error, and from studying other open source apps out there.
Disclaimer: These suggestions are my opinion only. They are not endorsed by Python, Gtk, or Glade. You will need to evaluate these suggestions based on your use case.

Related

How can I create a .exe-File of a python programm consisting out of several classes located in different files?

after several hours of reasearing I havent found a helpful answer to this question on the Internet. I have just seen several solutions about how to convert a single python-file into a .exe-file using pyinstaller.
About my programm: Its i a window application in python, therefore i have used the tkinter-library. The whole program is about restoring and documenting my income an spendings over a year, so that I have an overview over my finances. For that I have separated the program in two big folders[enter image description here][1]. One is called data for handeling all the numbers and other significant information and one is called gui for storing the files about the window and its different frames. In data i have different classes, e.g. a class that represents a year, one that represents a month, etc. As already mentiond, in gui you can find the main window and the different frames where the data is shown and can be manipulated. On top of that i have placed the file where i am storing the data in gui. The whole program is started from the main.py which is in none of the named folders.
I have already tried just converting the main.py which failed instantly. Next I tried the option in auto-py-to-exe where you can add additional files. There i have added the gui and the data folders but it wasnt successful either.
On top information: I have programed in PyCharm, so thats why there are extra folders like .idea etc.
I hope I have explained my problem good enough and out there is somebody that can help me.If you still have question feel free to ask.
Thanks in advance
wotex
ok, i have found a solution by myself. First you have to add the folders gui and data in the auto py to exe program, then you have to add all the different files that are in these folders(e.g. all the files with the classes or the text file).
But take care to import all libraries you use in your program in in main.py(the file you want to convert). Otherwise auto-py-to-exe wont convert these libraries and the program doesnt work. Maybe there is also another solution, but this is the only one that works with me.
Greetings
wotex

Trying to automate the fpga build process in Xilinx using python scripts

I want to automate the entire process of creating ngs,bit and mcs files in xilinx and have these files be automatically be associated with certain folders in the svn repository. What I need to know is that is there a log file that gets created in the back end of the Xilinx gui which records all the commands I run e.g open project,load file,synthesize etc.
Also the other part that I have not been able to find is a log file that records the entire process of synthesis, map,place and route and generate programming file. Specially record any errors that the tool encountered during these processes.
If any of you can point me to such files if they exist it would be great. I haven't gotten much out of my search but maybe I didn't look enough.
Thanks!
Well, it is definitely a nice project idea but a good amount of work. There's always a reason why an IDE was built – a simple search yields the "Command Line Tools User Guide" for various versions of Xilinx ISE, like for 14.3, 380 pages about
Overview and list of features
Input and output files
Command line syntax and options
Report and message information
ISE is a GUI for various command line executables, most of them are located in the subfolder 14.5/ISE_DS/ISE/bin/lin/ (in this case: Linux executables for version 14.5) of your ISE installation root. You can review your current parameters for each action by right clicking the item in the process tree and selecting "Process properties".
On the Python side, consider using the subprocess module:
The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes.
Is this the entry point you were looking for?
As phineas said, what you are trying to do is quite an undertaking.
I've been there done that, and there are countless challenges along the way. For example, if you want to move generated files to specific folders, how do you classify these files in order to figure out which files are which? I've created a project called X-MimeTypes that attempts to classify the files, but you then need a tool to parse the EDA mime type database and use that to determine which files are which.
However there is hope, so to answer the two main questions you've pointed out:
To be able to automatically move generated files to predetermined paths. From what you are saying it seems like you want to do this to make the versioning process easier? There is already a tool that does this for you based on "design structures" that you create and that can be shared within a team. The tool is called Scineric Workspace so check it out. It also have built in Git and SVN support which ignores things according to the design structure and in most cases it filters all generated things by vendor tools without you having to worry about it.
You are looking for a log file that shows all commands that were run. As phineas said, you can check out the Command Line Tools User guides for ISE, but be aware that the commands to run have changed again in Vivado. The log file of each process also usually states the exact command with its parameters that have been called. This should be close to the top of the report. If you look for one log file that contains everything, that does not exist. Again, Scineric Workspace supports evoking flows from major vendors (ISE, Vivado, Quartus) and it produces one log file for all processes together while still allowing each process to also create its own log file. Errors, warning etc. are also marked properly in this big report. Scineric has a tcl shell mode as well, so your python tool can run it in the background and parse the complete log file it creates.
If you have more questions on the above, I will be happy to help.
Hope this helps,
Jaco

can i use plone workflow to manage autocad related drawings?

How can I use Plone 4.1.4 to manage autocad drawings with different roles like architect, sr.architect, Project Manager, accounts manager(who manages the user accounts). I would first of all like to know whether Plone can be used to crease a workflow for uploaded autocad drawing files or for uploaded files as such? Doubt arises due to certain plone documentation which say that plone By default, content types Image and File have no workflow.
I wish to track the comments and changes made by the different user roles to the drawing files as well provide a lock i.e iterate through the working copy of the drawing files that have been uploaded. Can anyone suggest the best approach to this project using Plone?
You can change the workflow used for File objects, or indeed copy the File type in portal_types to a a new Drawing type and change the workflow for that new type if you want to treat them differently to standard files in your CMS.

web2py PDF - Where do I put this code?

http://code.google.com/p/pyfpdf/wiki/Web2Py#Sample_Table_Listing
This would be my first time using web2py, I'm using it because the example code is exactly what I need for part of a project.
My problem is I have no idea where to put this code. I'm using Google App Engine.
To understand where to put that code, you'll need at least a basic understanding of how web2py applications are structured. I recommend at least looking at the Overview chapter of the book.
The function definitions shown (i.e., report(), listing(), and invoice()) would go in a controller file in your applications's '/controllers' folder (the scaffolding application includes a 'default.py' controller file, though you could rename that or create a new controller file). The calls to db.define_table would typically go in a model file in your application's '/models' folder (the scaffolding application includes a 'db.py' model file, though again, you could rename that or create a new model file).
Note, there was a recent discussion on the mailing list regarding getting pyfpdf to work on GAE.

How to show list of deleted files in windows file system

I am wondering if it is possible to compile a list of deleted files on a windows file system, FAT or NTFS. I do not need to actually recover the files, only have access to their name and any other accessible time (time deleted, created etc).
Even if I can run a cmd line tool to achieve this it would be acceptable.
The application is being developed in Python, however if another language has the capability I could always create a small component implemented in that language.
Thanks.
This is a very complex task. I woudl look at open-source forensic tools.
You also should analyze the recylcing bin ( not completly deleted file )
For FAT you will not be able to get the first character of a deleted file.
For some deleted files the metadata will be gone.
NTFS is much more complex and time consuming due to the more complex nature of this file system.

Categories