Repository navigation
Example Git
examples/git/git_desk.py puts TurboFrame's Git windows on a repository: Changes (stage, unstage, discard, commit), History, Branches and stashes, Blame, a file's diff and history, pull, push and fetch. The explorer marks what git sees changed, and the editors mark their changed lines in the gutter. It needs the git program on the PATH, and no extra.
python examples/git/git_desk.py --demo # a small repository made for the example, in a temporary folder
python examples/git/git_desk.py path/to/repo # or one of yours
| Key | Does |
|---|---|
| Alt+G | Changes: the files git sees changed, and the diff of the one under the bar |
| Alt+H | History: each commit, with what it changed |
| Alt+F10 in a Git window | its local menu (stage, unstage, discard, open the file, copy...) |
| F10, then Git | every Git command offered |
| Alt+X | exit |
class GitDesk(GitMixin, EditorMixin, ExplorerMixin, DesktopApp):
TITLE = "Git"
GIT_FEATURES = FEATURES # everything: blame, branches, discard, amend, stash, merge, remotes, new branchGitMixin brings the Git menu, its windows, the explorer's marks and the editors' gutter marks. GIT_FEATURES says what is offered: frozenset() keeps a reading Git menu (Changes, History, Branches, Commit, Pull, Push, Fetch, a file's diff and history), and any subset of turboframe.ui.git.FEATURES adds those features. The menu, its keys and the windows' local menus all follow it.
The menu bar takes the Git menu from the mixin, so it lists only what is offered:
def init_menu_bar(self) -> Menu:
return Menu([
SubMenu("~F~ile", MenuItem("~S~ave", Command.SAVE, "F2"), MenuItem("~C~lose", Command.CLOSE, "Alt+F3"),
Separator(), MenuItem("E~x~it", Command.QUIT, "Alt+X")),
SubMenu("~G~it", *self.git_menu_items()), # only what GIT_FEATURES offers
])Once the folder is open, start_git_watch() looks at the repository every GIT_REFRESH seconds. The commands go to git_command, from a worker. It returns True when the command was Git's, so it chains with the editor's dispatcher:
def start(self) -> None:
explorer = self.show_explorer(focus=True)
...
self.start_git_watch() # the explorer's marks and border, the editors' gutters, every GIT_REFRESH seconds
@work(group="command")
async def run_command(self, command: int, info: object = None) -> None:
if command == Command.QUIT:
if await self.close_all():
self.exit()
elif not await self.git_command(command): # True: the command was Git's
await self.editor_command(command, info)The hooks it overrides place the Git windows beside the explorer and show the branch in the status line:
def place_git_window(self, window) -> None:
"""GitMixin: Changes, History, Branches, a diff and Blame take the desktop beside the explorer."""
super().place_git_window(window)
self.beside_explorer(window)
def show_git_status(self, state) -> None:
"""GitMixin: the repository's state changed; the status line says the branch."""
super().show_git_status(state)
if state is not None:
self.hint(f"On {state.branch or 'a detached HEAD'}: {len(state.changes)} changed")![]() |
![]() |
| Changes | History |
![]() |
![]() |
| Branches | Blame |
The git service on its own (status, log, diffs, branches, remotes, stashes, without windows), the diff viewer, every hook of GitMixin and the features: Git and Diffs.
TurboFrame · part of Divengine · GPL-3.0-or-later · report an issue
Tutorial
Examples
The desktop
- The Desktop
- Application Mixins
- Windows and Lists
- Dialogs
- Histories
- Progress
- Themes and Colors
- Glyphs
- Settings and Recent Files
- Command Palette
Editing
Tasks
Languages
Running
Reference
Links



