Finished the option gui
[ugit.git] / ugitlibs / views.py
blob8b5b53c4a8578b4ad863194c7ad231eea63de00d
1 import os
2 from PyQt4.QtGui import QDialog
3 from PyQt4.QtGui import QMainWindow
4 from maingui import Ui_maingui
5 from outputgui import Ui_outputgui
6 from optionsgui import Ui_optionsgui
7 from branchgui import Ui_branchgui
8 from commitgui import Ui_commitgui
9 from createbranchgui import Ui_createbranchgui
10 from pushgui import Ui_pushgui
11 from syntax import DiffSyntaxHighlighter
12 import qtutils
14 class View(Ui_maingui, QMainWindow):
15 '''The main ugit interface.'''
16 def __init__(self, parent=None):
17 QMainWindow.__init__(self, parent)
18 Ui_maingui.__init__(self)
19 self.setupUi(self)
20 DiffSyntaxHighlighter(self.displayText.document())
21 self.set_display = self.displayText.setText
22 self.set_info = self.displayLabel.setText
23 self.action_undo = self.commitText.undo
24 self.action_redo = self.commitText.redo
25 self.action_paste = self.commitText.paste
26 self.action_select_all = self.commitText.selectAll
27 # Qt does not support noun/verbs
28 self.commitButton.setText(qtutils.tr('Commit@@verb'))
29 self.menuCommit.setTitle(qtutils.tr('Commit@@verb'))
30 def action_cut(self):
31 self.action_copy()
32 self.action_delete()
33 def action_copy(self):
34 cursor = self.commitText.textCursor()
35 selection = cursor.selection().toPlainText()
36 qtutils.set_clipboard(selection)
37 def action_delete(self):
38 self.commitText.textCursor().removeSelectedText()
39 def reset_display(self):
40 self.set_display('')
41 self.set_info('')
42 def copy_display(self):
43 cursor = self.displayText.textCursor()
44 selection = cursor.selection().toPlainText()
45 qtutils.set_clipboard(selection)
46 def diff_selection(self):
47 cursor = self.displayText.textCursor()
48 offset = cursor.position()
49 selection = cursor.selection().toPlainText()
50 num_selected_lines = selection.count(os.linesep)
51 return offset, selection
53 class OutputGUI(Ui_outputgui, QDialog):
54 '''A simple dialog to display command output.'''
55 def __init__(self, parent=None, output=None):
56 QDialog.__init__(self, parent)
57 Ui_outputgui.__init__(self)
58 self.setupUi(self)
59 if output: self.set_output(output)
60 def set_output(self, output):
61 self.outputText.setText(output)
63 class BranchGUI(Ui_branchgui, QDialog):
64 '''A dialog for choosing branches.'''
65 def __init__(self, parent=None, branches=None):
66 QDialog.__init__(self, parent)
67 Ui_branchgui.__init__(self)
68 self.setupUi(self)
69 self.reset()
70 if branches: self.add(branches)
71 def reset(self):
72 self.branches = []
73 self.comboBox.clear()
74 def add(self, branches):
75 for branch in branches:
76 self.branches.append(branch)
77 self.comboBox.addItem(branch)
78 def get_selected(self):
79 self.show()
80 if self.exec_() == QDialog.Accepted:
81 return self.branches [ self.comboBox.currentIndex() ]
82 else:
83 return None
85 class CommitGUI(Ui_commitgui, QDialog):
86 def __init__(self, parent=None):
87 QDialog.__init__(self, parent)
88 Ui_commitgui.__init__(self)
89 self.setupUi(self)
90 # Make the list widget slighty larger
91 self.splitter.setSizes([ 50, 200 ])
92 DiffSyntaxHighlighter(self.commitText.document())
94 class CreateBranchGUI(Ui_createbranchgui, QDialog):
95 def __init__(self, parent=None):
96 QDialog.__init__(self, parent)
97 Ui_createbranchgui.__init__(self)
98 self.setupUi(self)
100 class PushGUI(Ui_pushgui, QDialog):
101 def __init__(self, parent=None):
102 QDialog.__init__(self, parent)
103 Ui_pushgui.__init__(self)
104 self.setupUi(self)
106 class OptionsGUI(Ui_optionsgui, QDialog):
107 def __init__(self, parent=None):
108 QDialog.__init__(self, parent)
109 Ui_optionsgui.__init__(self)
110 self.setupUi(self)