1 """This module creates simple wrapper classes around the auto-generated
9 from PyQt4
.QtGui
import QDialog
10 from PyQt4
.QtGui
import QListWidget
11 from PyQt4
.QtGui
import qApp
12 from PyQt4
.QtCore
import SIGNAL
14 from cola
.syntax
import DiffSyntaxHighlighter
15 from cola
.syntax
import LogSyntaxHighlighter
16 from cola
.core
import decode
20 from main
import CreateStandardView
21 from cola
.gui
.bookmark
import Ui_bookmark
22 from cola
.gui
.branchview
import Ui_branchview
23 from cola
.gui
.combo
import Ui_combo
24 from cola
.gui
.commit
import Ui_commit
25 from cola
.gui
.compare
import Ui_compare
26 from cola
.gui
.createbranch
import Ui_createbranch
27 from cola
.gui
.items
import Ui_items
28 from cola
.gui
.logger
import Ui_logger
29 from cola
.gui
.merge
import Ui_merge
30 from cola
.gui
.options
import Ui_options
31 from cola
.gui
.remote
import Ui_remote
32 from cola
.gui
.search
import Ui_search
33 from cola
.gui
.stash
import Ui_stash
35 sys
.stderr
.write('\nThe cola gui modules have not been built.\n'
36 'Try running "make" in the cola source tree.\n')
39 # These are views that do not contain any custom methods
40 OptionsView
= CreateStandardView(Ui_options
, QDialog
)
41 BranchCompareView
= CreateStandardView(Ui_branchview
, QDialog
)
42 CreateBranchView
= CreateStandardView(Ui_createbranch
, QDialog
)
43 BookmarkView
= CreateStandardView(Ui_bookmark
, QDialog
)
44 StashView
= CreateStandardView(Ui_stash
, QDialog
)
45 CompareView
= CreateStandardView(Ui_compare
, QDialog
)
47 class LogView(CreateStandardView(Ui_logger
, QDialog
)):
48 """A simple dialog to display command logs."""
49 def init(self
, parent
=None, output
=None):
50 self
.setWindowTitle(self
.tr('Git Command Log'))
51 self
.syntax
= LogSyntaxHighlighter(self
.output_text
.document())
53 self
.set_output(output
)
55 self
.output_text
.clear()
56 def set_output(self
, output
):
57 self
.output_text
.setText(output
)
58 def log(self
, output
):
61 cursor
= self
.output_text
.textCursor()
62 cursor
.movePosition(cursor
.End
)
63 text
= self
.output_text
64 cursor
.insertText(time
.asctime() + '\n')
65 for line
in unicode(decode(output
)).splitlines():
66 cursor
.insertText(line
+ '\n')
67 cursor
.insertText('\n')
68 cursor
.movePosition(cursor
.End
)
69 text
.setTextCursor(cursor
)
71 class ItemView(object):
72 def init(self
, parent
, title
="", items
=[], dblclick
=None):
73 self
.setWindowTitle(title
)
74 self
.items_widget
.addItems(items
)
75 if dblclick
and type(self
.items_widget
) is QListWidget
:
76 self
.connect(self
.items_widget
,
77 SIGNAL('itemDoubleClicked(QListWidgetItem*)'),
81 def get_selected(self
):
82 geom
= qApp
.desktop().screenGeometry()
84 height
= geom
.height()
85 x
= self
.parent_view
.x() + self
.parent_view
.width()/2 - self
.width()/2
86 y
= self
.parent_view
.y() + self
.parent_view
.height()/3 - self
.height()/2
89 if self
.exec_() == QDialog
.Accepted
:
94 class ComboView(CreateStandardView(Ui_combo
, QDialog
, ItemView
), ItemView
):
95 """A dialog for choosing branches."""
97 return self
.items_widget
.currentIndex()
99 return str(self
.items_widget
.currentText())
101 class ListView(CreateStandardView(Ui_items
, QDialog
, ItemView
), ItemView
):
102 """A dialog for an item from a list."""
104 return self
.items_widget
.currentRow()
106 item
= self
.items_widget
.currentItem()
109 return str(item
.text())
111 class CommitView(CreateStandardView(Ui_commit
, QDialog
)):
112 def init(self
, parent
=None, title
=None):
113 if title
: self
.setWindowTitle(title
)
114 # Make the list widget slighty larger
115 self
.splitter
.setSizes([ 50, 200 ])
116 self
.syntax
= DiffSyntaxHighlighter(self
.commit_text
.document(),
119 class SearchView(CreateStandardView(Ui_search
, QDialog
)):
120 def init(self
, parent
=None):
121 self
.input.setFocus()
122 self
.syntax
= DiffSyntaxHighlighter(self
.commit_text
.document(),
125 class MergeView(CreateStandardView(Ui_merge
, QDialog
)):
126 def init(self
, parent
=None):
127 self
.revision
.setFocus()
129 class RemoteView(CreateStandardView(Ui_remote
, QDialog
)):
130 def init(self
, parent
=None, button_text
=''):
132 self
.action_button
.setText(button_text
)
133 self
.setWindowTitle(button_text
)
134 def select_first_remote(self
):
135 item
= self
.remotes
.item(0)
137 self
.remotes
.setItemSelected(item
, True)
138 self
.remotes
.setCurrentItem(item
)
139 self
.remotename
.setText(item
.text())