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
9 from ugit
import qtutils
10 from ugit
.syntax
import DiffSyntaxHighlighter
11 from ugit
.syntax
import LogSyntaxHighlighter
13 from maingui
import Ui_maingui
14 from outputgui
import Ui_outputgui
15 from optionsgui
import Ui_optionsgui
16 from branchgui
import Ui_branchgui
17 from commitgui
import Ui_commitgui
18 from createbranchgui
import Ui_createbranchgui
19 from pushgui
import Ui_pushgui
21 class View(Ui_maingui
, QMainWindow
):
22 '''The main ugit interface.'''
23 def __init__(self
, parent
=None):
24 QMainWindow
.__init
__(self
, parent
)
25 Ui_maingui
.__init
__(self
)
27 self
.staged
.setAlternatingRowColors(True)
28 self
.unstaged
.setAlternatingRowColors(True)
29 self
.set_display
= self
.display_text
.setText
30 self
.set_info
= self
.displayLabel
.setText
31 self
.action_undo
= self
.commitmsg
.undo
32 self
.action_redo
= self
.commitmsg
.redo
33 self
.action_paste
= self
.commitmsg
.paste
34 self
.action_select_all
= self
.commitmsg
.selectAll
36 # Handle automatically setting the horizontal/vertical orientation
37 self
.splitter
.resizeEvent
= self
.splitter_resize_event
39 # Qt does not support noun/verbs
40 self
.commit_button
.setText(qtutils
.tr('Commit@@verb'))
41 self
.commit_menu
.setTitle(qtutils
.tr('Commit@@verb'))
42 # Default to creating a new commit(i.e. not an amend commit)
43 self
.new_commit_radio
.setChecked(True)
44 self
.toolbar_show_log
= self
.toolbar
.addAction(
45 qtutils
.get_qicon('git.png'),
46 'Show/Hide Log Window')
47 self
.toolbar_show_log
.setEnabled(True)
49 # Setup the default dock layout
50 self
.tabifyDockWidget(self
.diff_dock
, self
.editor_dock
)
52 dock_area
= QtCore
.Qt
.TopDockWidgetArea
53 self
.addDockWidget(dock_area
, self
.status_dock
)
55 toolbar_area
= QtCore
.Qt
.BottomToolBarArea
56 self
.addToolBar(toolbar_area
, self
.toolbar
)
58 # Diff/patch syntax highlighter
59 DiffSyntaxHighlighter(self
.display_text
.document())
61 def splitter_resize_event(self
, event
):
62 width
= self
.splitter
.width()
63 height
= self
.splitter
.height()
65 self
.splitter
.setOrientation(QtCore
.Qt
.Horizontal
)
67 self
.splitter
.setOrientation(QtCore
.Qt
.Vertical
)
68 QSplitter
.resizeEvent(self
.splitter
, event
)
73 def action_copy(self
):
74 cursor
= self
.commitmsg
.textCursor()
75 selection
= cursor
.selection().toPlainText()
76 qtutils
.set_clipboard(selection
)
77 def action_delete(self
):
78 self
.commitmsg
.textCursor().removeSelectedText()
79 def reset_display(self
):
82 def copy_display(self
):
83 cursor
= self
.display_text
.textCursor()
84 selection
= cursor
.selection().toPlainText()
85 qtutils
.set_clipboard(selection
)
86 def diff_selection(self
):
87 cursor
= self
.display_text
.textCursor()
88 offset
= cursor
.position()
89 selection
= cursor
.selection().toPlainText()
90 num_selected_lines
= selection
.count('\n')
91 return offset
, selection
93 class OutputGUI(Ui_outputgui
, QDialog
):
94 '''A simple dialog to display command output.'''
95 def __init__(self
, parent
=None, output
=None):
96 QDialog
.__init
__(self
, parent
)
97 Ui_outputgui
.__init
__(self
)
99 self
.setWindowTitle(self
.tr('Git Command Output'))
100 # Syntax highlight the log window
101 LogSyntaxHighlighter(self
.output_text
.document())
102 if output
: self
.set_output(output
)
104 self
.output_text
.clear()
105 def set_output(self
, output
):
106 self
.output_text
.setText(output
)
107 def log(self
, output
):
108 if not output
: return
109 cursor
= self
.output_text
.textCursor()
110 cursor
.movePosition(cursor
.End
)
111 text
= self
.output_text
112 cursor
.insertText(time
.asctime() + '\n')
113 for line
in unicode(output
).splitlines():
114 cursor
.insertText(line
+ '\n')
115 cursor
.insertText('\n')
116 cursor
.movePosition(cursor
.End
)
117 text
.setTextCursor(cursor
)
119 class BranchGUI(Ui_branchgui
, QDialog
):
120 '''A dialog for choosing branches.'''
121 def __init__(self
, parent
=None, branches
=None):
122 QDialog
.__init
__(self
, parent
)
123 Ui_branchgui
.__init
__(self
)
126 if branches
: self
.add(branches
)
129 self
.branch_combo
.clear()
130 def add(self
, branches
):
131 for branch
in branches
:
132 self
.branches
.append(branch
)
133 self
.branch_combo
.addItem(branch
)
134 def get_selected(self
):
136 if self
.exec_() == QDialog
.Accepted
:
137 return self
.branches
[self
.branch_combo
.currentIndex()]
141 class CommitGUI(Ui_commitgui
, QDialog
):
142 def __init__(self
, parent
=None, title
=None):
143 QDialog
.__init
__(self
, parent
)
144 Ui_commitgui
.__init
__(self
)
146 if title
: self
.setWindowTitle(title
)
147 # Make the list widget slighty larger
148 self
.splitter
.setSizes([ 50, 200 ])
149 DiffSyntaxHighlighter(self
.commit_text
.document(),
152 class CreateBranchGUI(Ui_createbranchgui
, QDialog
):
153 def __init__(self
, parent
=None):
154 QDialog
.__init
__(self
, parent
)
155 Ui_createbranchgui
.__init
__(self
)
158 class PushGUI(Ui_pushgui
, QDialog
):
159 def __init__(self
, parent
=None):
160 QDialog
.__init
__(self
, parent
)
161 Ui_pushgui
.__init
__(self
)
164 class OptionsGUI(Ui_optionsgui
, QDialog
):
165 def __init__(self
, parent
=None):
166 QDialog
.__init
__(self
, parent
)
167 Ui_optionsgui
.__init
__(self
)