3 from PyQt4
.QtCore
import Qt
4 from PyQt4
.QtGui
import QDialog
5 from PyQt4
.QtGui
import QMainWindow
6 from maingui
import Ui_maingui
7 from outputgui
import Ui_outputgui
8 from optionsgui
import Ui_optionsgui
9 from branchgui
import Ui_branchgui
10 from commitgui
import Ui_commitgui
11 from createbranchgui
import Ui_createbranchgui
12 from pushgui
import Ui_pushgui
13 from syntax
import DiffSyntaxHighlighter
14 from syntax
import LogSyntaxHighlighter
17 class View(Ui_maingui
, QMainWindow
):
18 '''The main ugit interface.'''
19 def __init__(self
, parent
=None):
20 QMainWindow
.__init
__(self
, parent
)
21 Ui_maingui
.__init
__(self
)
23 self
.set_display
= self
.display_text
.setText
24 self
.set_info
= self
.displayLabel
.setText
25 self
.action_undo
= self
.commit_text
.undo
26 self
.action_redo
= self
.commit_text
.redo
27 self
.action_paste
= self
.commit_text
.paste
28 self
.action_select_all
= self
.commit_text
.selectAll
29 # Qt does not support noun/verbs
30 self
.commit_button
.setText(qtutils
.tr('Commit@@verb'))
31 self
.commit_menu
.setTitle(qtutils
.tr('Commit@@verb'))
32 # Default to creating a new commit(i.e. not an amend commit)
33 self
.new_commit_radio
.setChecked(True)
34 self
.toolbar_show_log
= self
.toolbar
.addAction(
35 qtutils
.get_qicon('git.png'),
36 'Show/Hide Log Window')
37 self
.toolbar_show_log
.setEnabled(True)
38 self
.addToolBar(Qt
.BottomToolBarArea
, self
.toolbar
)
39 # Diff/patch syntax highlighter
40 DiffSyntaxHighlighter(self
.display_text
.document())
45 def action_copy(self
):
46 cursor
= self
.commit_text
.textCursor()
47 selection
= cursor
.selection().toPlainText()
48 qtutils
.set_clipboard(selection
)
49 def action_delete(self
):
50 self
.commit_text
.textCursor().removeSelectedText()
51 def reset_display(self
):
54 def copy_display(self
):
55 cursor
= self
.display_text
.textCursor()
56 selection
= cursor
.selection().toPlainText()
57 qtutils
.set_clipboard(selection
)
58 def diff_selection(self
):
59 cursor
= self
.display_text
.textCursor()
60 offset
= cursor
.position()
61 selection
= cursor
.selection().toPlainText()
62 num_selected_lines
= selection
.count(os
.linesep
)
63 return offset
, selection
65 class OutputGUI(Ui_outputgui
, QDialog
):
66 '''A simple dialog to display command output.'''
67 def __init__(self
, parent
=None, output
=None):
68 QDialog
.__init
__(self
, parent
)
69 Ui_outputgui
.__init
__(self
)
71 self
.setWindowTitle(self
.tr('Git Command Output'))
72 # Syntax highlight the log window
73 LogSyntaxHighlighter(self
.output_text
.document())
74 if output
: self
.set_output(output
)
76 self
.output_text
.clear()
77 def set_output(self
, output
):
78 self
.output_text
.setText(output
)
79 def log(self
, output
):
81 cursor
= self
.output_text
.textCursor()
82 cursor
.movePosition(cursor
.End
)
83 text
= self
.output_text
84 cursor
.insertText(time
.asctime())
85 cursor
.insertText(os
.linesep
)
86 for line
in unicode(output
).splitlines():
87 cursor
.insertText(line
)
88 cursor
.insertText(os
.linesep
)
89 cursor
.insertText(os
.linesep
)
90 cursor
.movePosition(cursor
.End
)
91 text
.setTextCursor(cursor
)
93 class BranchGUI(Ui_branchgui
, QDialog
):
94 '''A dialog for choosing branches.'''
95 def __init__(self
, parent
=None, branches
=None):
96 QDialog
.__init
__(self
, parent
)
97 Ui_branchgui
.__init
__(self
)
100 if branches
: self
.add(branches
)
103 self
.branch_combo
.clear()
104 def add(self
, branches
):
105 for branch
in branches
:
106 self
.branches
.append(branch
)
107 self
.branch_combo
.addItem(branch
)
108 def get_selected(self
):
110 if self
.exec_() == QDialog
.Accepted
:
111 return self
.branches
[self
.branch_combo
.currentIndex()]
115 class CommitGUI(Ui_commitgui
, QDialog
):
116 def __init__(self
, parent
=None, title
=None):
117 QDialog
.__init
__(self
, parent
)
118 Ui_commitgui
.__init
__(self
)
120 if title
: self
.setWindowTitle(title
)
121 # Make the list widget slighty larger
122 self
.splitter
.setSizes([ 50, 200 ])
123 DiffSyntaxHighlighter(self
.commit_text
.document(),
126 class CreateBranchGUI(Ui_createbranchgui
, QDialog
):
127 def __init__(self
, parent
=None):
128 QDialog
.__init
__(self
, parent
)
129 Ui_createbranchgui
.__init
__(self
)
132 class PushGUI(Ui_pushgui
, QDialog
):
133 def __init__(self
, parent
=None):
134 QDialog
.__init
__(self
, parent
)
135 Ui_pushgui
.__init
__(self
)
138 class OptionsGUI(Ui_optionsgui
, QDialog
):
139 def __init__(self
, parent
=None):
140 QDialog
.__init
__(self
, parent
)
141 Ui_optionsgui
.__init
__(self
)