1 """This module creates simple wrapper classes around the auto-generated
9 from PyQt4
import QtCore
10 from PyQt4
import QtGui
11 from PyQt4
.QtGui
import QDialog
12 from PyQt4
.QtGui
import QListWidget
13 from PyQt4
.QtGui
import qApp
14 from PyQt4
.QtCore
import SIGNAL
17 from cola
.views
.standard
import create_standard_view
18 from cola
.views
.bookmark
import BookmarkView
19 from cola
.views
.option
import OptionsView
20 from cola
.views
.syntax
import DiffSyntaxHighlighter
23 from cola
.gui
.combo
import Ui_combo
24 from cola
.gui
.compare
import Ui_compare
25 from cola
.gui
.createbranch
import Ui_createbranch
26 from cola
.gui
.items
import Ui_items
27 from cola
.gui
.remote
import Ui_remote
28 from cola
.gui
.stash
import Ui_stash
30 sys
.stderr
.write('\nThe cola gui modules have not been built.\n'
31 'Try running "make" in the cola source tree.\n')
35 from cola
.views
.compare
import BranchCompareView
36 CreateBranchView
= create_standard_view(Ui_createbranch
, QDialog
)
37 StashView
= create_standard_view(Ui_stash
, QDialog
)
38 CompareView
= create_standard_view(Ui_compare
, QDialog
)
40 class ItemView(object):
41 def __init__(self
, parent
, title
="", items
=[], dblclick
=None):
42 self
.setWindowTitle(title
)
43 self
.items_widget
.addItems(items
)
44 if dblclick
and type(self
.items_widget
) is QListWidget
:
45 self
.connect(self
.items_widget
,
46 SIGNAL('itemDoubleClicked(QListWidgetItem*)'),
51 geom
= qApp
.desktop().screenGeometry()
53 height
= geom
.height()
55 x
= self
.parent().x() + self
.parent().width()/2 - self
.width()/2
56 y
= self
.parent().y() + self
.parent().height()/3 - self
.height()/2
59 if self
.exec_() == QDialog
.Accepted
:
64 ComboViewBase
= create_standard_view(Ui_combo
, QDialog
, ItemView
)
65 class ComboView(ComboViewBase
, ItemView
):
66 """A dialog for choosing branches."""
68 return self
.items_widget
.currentIndex()
70 return str(self
.items_widget
.currentText())
72 ListViewBase
= create_standard_view(Ui_items
, QDialog
, ItemView
)
73 class ListView(ListViewBase
, ItemView
):
74 """A dialog for an item from a list."""
76 return self
.items_widget
.currentRow()
78 item
= self
.items_widget
.currentItem()
81 return str(item
.text())
84 RemoteViewBase
= create_standard_view(Ui_remote
, QDialog
)
85 class RemoteView(RemoteViewBase
):
86 """Dialog used by Fetch, Push and Pull"""
88 def __init__(self
, parent
, action
):
89 """Customizes the dialog based on the remote action
91 RemoteViewBase
.__init
__(self
, parent
)
93 self
.action_button
.setText(action
.title())
94 self
.setWindowTitle(action
.title())
96 self
.tags_checkbox
.hide()
97 self
.ffwd_only_checkbox
.hide()
98 self
.local_label
.hide()
99 self
.local_branch
.hide()
100 self
.local_branches
.hide()
102 self
.rebase_checkbox
.hide()
104 def select_first_remote(self
):
105 """Selects the first remote in the list view"""
106 return self
.select_remote(0)
108 def select_remote(self
, idx
):
109 """Selects a remote by index"""
110 item
= self
.remotes
.item(idx
)
112 self
.remotes
.setItemSelected(item
, True)
113 self
.remotes
.setCurrentItem(item
)
114 self
.remotename
.setText(item
.text())
119 def select_local_branch(self
, idx
):
120 """Selects a local branch by index in the list view"""
121 item
= self
.local_branches
.item(idx
)
124 self
.local_branches
.setItemSelected(item
, True)
125 self
.local_branches
.setCurrentItem(item
)
126 self
.local_branch
.setText(item
.text())