Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 2.1, 2.1.1, and 2.1.2

repowidget: show error of sync operation at InfoBar area

It introduces InfoBar area at top of RepoWidget.
InfoBar is only visible when a warning/confirmation is available.

Changeset 105f1d354e0b

Parent 26c8e6c497a0

by Yuya Nishihara

Changes to 2 files · Browse files at 105f1d354e0b Showing diff from parent 26c8e6c497a0 Diff from another changeset...

 
735
736
737
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
738
739
740
 
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
@@ -735,6 +735,69 @@
    self.setLayout(box)   +class InfoBar(QFrame): + """Non-modal confirmation/alert (like web flash or Chrome's InfoBar) + + You shouldn't reuse InfoBar object after close(). It is automatically + deleted. + + Layout:: + + |widgets ... |right widgets ...|x| + """ + linkActivated = pyqtSignal(unicode) + + # type of InfoBar (the number denotes its priority) + INFO = 1 + ERROR = 2 + + infobartype = INFO + + _colormap = { + INFO: '#e7f9e0', + ERROR: '#f9d8d8', + } + + def __init__(self, parent=None): + super(InfoBar, self).__init__(parent, frameShape=QFrame.StyledPanel, + frameShadow=QFrame.Plain) + self.setAttribute(Qt.WA_DeleteOnClose) + + self.setAutoFillBackground(True) + p = self.palette() + p.setColor(QPalette.Window, QColor(self._colormap[self.infobartype])) + self.setPalette(p) + + self.setLayout(QHBoxLayout()) + self.layout().setContentsMargins(2, 2, 2, 2) + + self.layout().addStretch() + self._closebutton = QPushButton(self, flat=True, autoDefault=False, + icon=self.style().standardIcon(QStyle.SP_DockWidgetCloseButton)) + self._closebutton.clicked.connect(self.close) + self.layout().addWidget(self._closebutton) + + def addWidget(self, w): + self.layout().insertWidget(self.layout().count() - 2, w) + + def addRightWidget(self, w): + self.layout().insertWidget(self.layout().count() - 1, w) + +class CommandErrorInfoBar(InfoBar): + """Show command execution failure (with link to open log window)""" + infobartype = InfoBar.ERROR + + def __init__(self, message, parent=None): + super(CommandErrorInfoBar, self).__init__(parent) + + self._msglabel = QLabel(message, self, + textInteractionFlags=Qt.TextSelectableByMouse) + self.addWidget(self._msglabel) + + self._loglabel = QLabel('<a href="log:">%s</a>' % _('Show Log')) + self._loglabel.linkActivated.connect(self.linkActivated) + self.addRightWidget(self._loglabel) +  class WidgetGroups(object):   """ Support for bulk-updating properties of Qt widgets """  
 
102
103
104
 
 
 
105
106
107
 
230
231
232
 
233
234
235
 
240
241
242
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
243
244
245
 
278
279
280
 
281
282
283
 
102
103
104
105
106
107
108
109
110
 
233
234
235
236
237
238
239
 
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
 
301
302
303
304
305
306
307
@@ -102,6 +102,9 @@
  self.layout().setContentsMargins(0, 0, 0, 0)   self.layout().setSpacing(0)   + self._infobarlayout = QVBoxLayout() # placeholder for InfoBar + self.layout().addLayout(self._infobarlayout) +   hbox = QHBoxLayout()   hbox.setContentsMargins(0, 0, 0, 0)   hbox.setSpacing(0) @@ -230,6 +233,7 @@
  def _openLink(self, link):   link = unicode(link)   handlers = {'cset': self.goto, + 'log': lambda a: self.makeLogVisible.emit(True),   'subrepo': self.repoLinkClicked.emit,   'shelve' : self.shelve}   if ':' in link: @@ -240,6 +244,25 @@
    QDesktopServices.openUrl(QUrl(link))   + def setInfoBar(self, cls, *args, **kwargs): + """Show the given infobar at top of RepoWidget""" + self.clearInfoBar() + w = cls(*args, **kwargs) + w.linkActivated.connect(self._openLink) + self._infobarlayout.insertWidget(0, w) + return w + + def clearInfoBar(self): + """Close current infobar if available""" + it = self._infobarlayout.itemAt(0) + if it: + it.widget().close() + + @pyqtSlot(unicode, unicode) + def _showOutputOnInfoBar(self, msg, label): + if label == 'ui.error': + self.setInfoBar(qtlib.CommandErrorInfoBar, unicode(msg).strip()) +   def createCommitWidget(self):   pats, opts = {}, {}   cw = CommitWidget(self.repo, pats, opts, True, self) @@ -278,6 +301,7 @@
  def createSyncWidget(self):   sw = SyncWidget(self.repo, self)   sw.output.connect(self.output) + sw.output.connect(self._showOutputOnInfoBar)   sw.progress.connect(self.progress)   sw.makeLogVisible.connect(self.makeLogVisible)   sw.outgoingNodes.connect(self.setOutgoingNodes)