3 from PyQt4
import QtCore
4 from PyQt4
.QtGui
import QDialog
5 from PyQt4
.QtGui
import QMainWindow
6 from PyQt4
.QtGui
import QCheckBox
7 from PyQt4
.QtGui
import QSplitter
8 from maingui
import Ui_maingui
9 from outputgui
import Ui_outputgui
10 from optionsgui
import Ui_optionsgui
11 from branchgui
import Ui_branchgui
12 from commitgui
import Ui_commitgui
13 from createbranchgui
import Ui_createbranchgui
14 from pushgui
import Ui_pushgui
15 from syntax
import DiffSyntaxHighlighter
16 from syntax
import LogSyntaxHighlighter
19 class View(Ui_maingui
, QMainWindow
):
20 '''The main ugit interface.'''
21 def __init__(self
, parent
=None):
22 QMainWindow
.__init
__(self
, parent
)
23 Ui_maingui
.__init
__(self
)
25 self
.staged
.setAlternatingRowColors(True)
26 self
.unstaged
.setAlternatingRowColors(True)
27 self
.set_display
= self
.display_text
.setText
28 self
.set_info
= self
.displayLabel
.setText
29 self
.action_undo
= self
.commitmsg
.undo
30 self
.action_redo
= self
.commitmsg
.redo
31 self
.action_paste
= self
.commitmsg
.paste
32 self
.action_select_all
= self
.commitmsg
.selectAll
34 # Handle automatically setting the horizontal/vertical orientation
35 self
.splitter
.resizeEvent
= self
.splitter_resize_event
37 # Qt does not support noun/verbs
38 self
.commit_button
.setText(qtutils
.tr('Commit@@verb'))
39 self
.commit_menu
.setTitle(qtutils
.tr('Commit@@verb'))
40 # Default to creating a new commit(i.e. not an amend commit)
41 self
.new_commit_radio
.setChecked(True)
42 self
.toolbar_show_log
= self
.toolbar
.addAction(
43 qtutils
.get_qicon('git.png'),
44 'Show/Hide Log Window')
45 self
.toolbar_show_log
.setEnabled(True)
47 # Setup the default dock layout
48 self
.tabifyDockWidget(self
.diff_dock
, self
.editor_dock
)
50 dock_area
= QtCore
.Qt
.TopDockWidgetArea
51 self
.addDockWidget(dock_area
, self
.status_dock
)
53 toolbar_area
= QtCore
.Qt
.BottomToolBarArea
54 self
.addToolBar(toolbar_area
, self
.toolbar
)
56 # Diff/patch syntax highlighter
57 DiffSyntaxHighlighter(self
.display_text
.document())
59 def splitter_resize_event(self
, event
):
60 width
= self
.splitter
.width()
61 height
= self
.splitter
.height()
63 self
.splitter
.setOrientation(QtCore
.Qt
.Horizontal
)
65 self
.splitter
.setOrientation(QtCore
.Qt
.Vertical
)
66 QSplitter
.resizeEvent(self
.splitter
, event
)
71 def action_copy(self
):
72 cursor
= self
.commitmsg
.textCursor()
73 selection
= cursor
.selection().toPlainText()
74 qtutils
.set_clipboard(selection
)
75 def action_delete(self
):
76 self
.commitmsg
.textCursor().removeSelectedText()
77 def reset_display(self
):
80 def copy_display(self
):
81 cursor
= self
.display_text
.textCursor()
82 selection
= cursor
.selection().toPlainText()
83 qtutils
.set_clipboard(selection
)
84 def diff_selection(self
):
85 cursor
= self
.display_text
.textCursor()
86 offset
= cursor
.position()
87 selection
= cursor
.selection().toPlainText()
88 num_selected_lines
= selection
.count('\n')
89 return offset
, selection
91 class OutputGUI(Ui_outputgui
, QDialog
):
92 '''A simple dialog to display command output.'''
93 def __init__(self
, parent
=None, output
=None):
94 QDialog
.__init
__(self
, parent
)
95 Ui_outputgui
.__init
__(self
)
97 self
.setWindowTitle(self
.tr('Git Command Output'))
98 # Syntax highlight the log window
99 LogSyntaxHighlighter(self
.output_text
.document())
100 if output
: self
.set_output(output
)
102 self
.output_text
.clear()
103 def set_output(self
, output
):
104 self
.output_text
.setText(output
)
105 def log(self
, output
):
106 if not output
: return
107 cursor
= self
.output_text
.textCursor()
108 cursor
.movePosition(cursor
.End
)
109 text
= self
.output_text
110 cursor
.insertText(time
.asctime() + '\n')
111 for line
in unicode(output
).splitlines():
112 cursor
.insertText(line
+ '\n')
113 cursor
.insertText('\n')
114 cursor
.movePosition(cursor
.End
)
115 text
.setTextCursor(cursor
)
117 class BranchGUI(Ui_branchgui
, QDialog
):
118 '''A dialog for choosing branches.'''
119 def __init__(self
, parent
=None, branches
=None):
120 QDialog
.__init
__(self
, parent
)
121 Ui_branchgui
.__init
__(self
)
124 if branches
: self
.add(branches
)
127 self
.branch_combo
.clear()
128 def add(self
, branches
):
129 for branch
in branches
:
130 self
.branches
.append(branch
)
131 self
.branch_combo
.addItem(branch
)
132 def get_selected(self
):
134 if self
.exec_() == QDialog
.Accepted
:
135 return self
.branches
[self
.branch_combo
.currentIndex()]
139 class CommitGUI(Ui_commitgui
, QDialog
):
140 def __init__(self
, parent
=None, title
=None):
141 QDialog
.__init
__(self
, parent
)
142 Ui_commitgui
.__init
__(self
)
144 if title
: self
.setWindowTitle(title
)
145 # Make the list widget slighty larger
146 self
.splitter
.setSizes([ 50, 200 ])
147 DiffSyntaxHighlighter(self
.commit_text
.document(),
150 class CreateBranchGUI(Ui_createbranchgui
, QDialog
):
151 def __init__(self
, parent
=None):
152 QDialog
.__init
__(self
, parent
)
153 Ui_createbranchgui
.__init
__(self
)
156 class PushGUI(Ui_pushgui
, QDialog
):
157 def __init__(self
, parent
=None):
158 QDialog
.__init
__(self
, parent
)
159 Ui_pushgui
.__init
__(self
)
162 class OptionsGUI(Ui_optionsgui
, QDialog
):
163 def __init__(self
, parent
=None):
164 QDialog
.__init
__(self
, parent
)
165 Ui_optionsgui
.__init
__(self
)