Added interactive diff gui
[ugit.git] / py / views.py
blobe8fadf07a7f5b7716e9f84b3f1b92d9b94bedcbe
1 import os
2 from PyQt4 import QtCore, QtGui
3 from PyQt4.QtCore import SIGNAL
4 from PyQt4.QtGui import QDialog
5 from Window import Ui_Window
6 from CommandDialog import Ui_CommandDialog
7 from CommitBrowser import Ui_CommitBrowser
8 from BranchDialog import Ui_BranchDialog
9 from CreateBranchDialog import Ui_CreateBranchDialog
11 from syntax import GitSyntaxHighlighter
13 class GitView (Ui_Window, QtGui.QMainWindow):
14 '''The main ugit interface.'''
15 def __init__ (self, parent=None):
16 QtGui.QMainWindow.__init__ (self, parent)
17 Ui_Window.__init__ (self)
18 self.setupUi (self)
19 self.display_splitter.setSizes ([ 300, 400 ])
20 GitSyntaxHighlighter (self.displayText.document())
22 class GitCommandDialog (Ui_CommandDialog, QtGui.QDialog):
23 '''A simple dialog to display command output.'''
24 def __init__ (self, parent=None, output=None):
25 QtGui.QDialog.__init__ (self, parent)
26 Ui_CommandDialog.__init__ (self)
27 self.setupUi (self)
28 if output: self.set_command (output)
30 def set_command (self, output):
31 self.commandText.setText (output)
33 class GitBranchDialog (Ui_BranchDialog, QtGui.QDialog):
34 '''A dialog to display available branches.'''
35 def __init__ (self, parent=None, branches=None):
36 QtGui.QDialog.__init__ (self, parent)
37 Ui_BranchDialog.__init__ (self)
38 self.setupUi (self)
39 self.reset()
40 if branches: self.addBranches (branches)
42 def reset (self):
43 self.branches = []
44 self.comboBox.clear()
46 def addBranches (self, branches):
47 for branch in branches:
48 self.branches.append (branch)
49 self.comboBox.addItem (branch)
51 def getSelectedBranch (self):
52 self.show()
53 if self.exec_() == QDialog.Accepted:
54 return self.branches [ self.comboBox.currentIndex() ]
55 else:
56 return None
58 class GitCommitBrowser (Ui_CommitBrowser, QtGui.QDialog):
59 '''A dialog to display commits in for selection.'''
60 def __init__ (self, parent=None):
61 QtGui.QDialog.__init__ (self, parent)
62 Ui_CommitBrowser.__init__ (self)
63 self.setupUi (self)
64 # Make the list widget slighty larger
65 self.splitter.setSizes ([ 50, 200 ])
66 GitSyntaxHighlighter (self.commitText.document())
68 class GitCreateBranchDialog (Ui_CreateBranchDialog, QtGui.QDialog):
69 '''A dialog for creating or updating branches.'''
70 def __init__ (self, parent=None):
71 QtGui.QDialog.__init__ (self, parent)
72 Ui_CreateBranchDialog.__init__ (self)
73 self.setupUi (self)