PYTHON
Updating the LXF GIT monitoring tool
John Schwartzman adds new features to an existing PyQt5 program that finds all of your git repositories and displays their status.
OUR EXPERT
John Schwartzman has enjoyed an active career as an engineer, college professor, and consultant to business and government. He can be reached at john@forte system.com.
Qt5 Designer shows the edit tab order screen. All of the widgets have been added to the project.
T he program that’s the subject of this tutorial first appeared in LFX260. It found and displayed your git repositories with a colour scheme indicating their status, but we wanted it to be a one-stop shop for monitoring git repositories, viewing or editing files and using git to modify repositories. We achieved this by adding two context-sensitive menus. If you rightclick a selection in the file widget (the right pane), an editor will appear that enables you to view or change a component file of a repository. Select which editor you want to use in the configuration file, gitStatus.ini.
If you right-click a selection in the repository widget (the left pane), a terminal will be opened in the repository directory and you can use git to add, remove or commit files. When you exit the terminal, the gitStatus tool will display any changes you may have made. The gitStatus program is shown in the screenshot (below).
The colour (priority) that’s assigned to each file and to each repository is arbitrary. We decided that a checked-in file should be green, a modified file that hasn’t been checked-in should be red, and that any other variety, for example, added, removed, renamed or untracked files, should be orange. The colour of a repository entry is the colour the colour of worst-case file in the repository. If you want a different colour (priority) scheme, modify quickCheckPriority(repoPath) and repoSelectionChanged() . Each element of a listWidget contains colour data.
The gitStatus tool has found the git repositories. A repository has been selected in the left pane. The right pane shows the status of the files.
We’ll create gitStatus.pyusing Qt 5 Designer. This enables you to create your tool’s main dialog visually. Qt 5 Designer saves your work in an XML file. It gives your file a .ui extension. We’ll use the Qt 5 utility program, pyuic5, to convert the XML file into a python file.
Start Qt 5 Designer from the system menu or by typing designer-qt5 from the command line. Select ‘Dialog without Buttons’ from the File>New menu. (Qt 5 Designer should automatically open the New Form Dialog when you start the program without a file name.)