Mercurial and Git clients can push and pull from this alias URL to interact with this repository. You can change to which repository an alias points by going to the Aliases link on the project page.
# cmdui.py - A widget to execute Mercurial command for TortoiseHg## Copyright 2010 Yuki KODAMA <endflow.net@gmail.com>## This software may be used and distributed according to the terms of the# GNU General Public License version 2, incorporated herein by reference.fromPyQt4.QtCoreimport*fromPyQt4.QtGuiimport*fromtortoisehg.utilimporthglibfromtortoisehg.hgqt.i18nimport_,localgettextfromtortoisehg.hgqtimportqtlib,threadlocal=localgettext()classProgressMonitor(QWidget):def__init__(self):super(ProgressMonitor,self).__init__()# main layout boxvbox=QVBoxLayout()vbox.setContentsMargins(*(0,)*4)self.setLayout(vbox)## status layout boxhbox=QHBoxLayout()hbox.setContentsMargins(*(0,)*4)vbox.addLayout(hbox)self.status_label=QLabel()hbox.addWidget(self.status_label,1)self.prog_label=QLabel()hbox.addWidget(self.prog_label,0,Qt.AlignRight)## progressbarself.pbar=QProgressBar()self.pbar.setTextVisible(False)self.pbar.setMinimum(0)vbox.addWidget(self.pbar)# prepare to showself.clear_progress()### Public Methods ###defclear_progress(self):self.pbar.setMaximum(100)self.pbar.reset()self.status_label.setText('')self.prog_label.setText('')self.inprogress=Falsedeffillup_progress(self):"""stick progress to full"""self.clear_progress()self.pbar.setValue(self.pbar.maximum())defunknown_progress(self):self.pbar.setMinimum(0)self.pbar.setMaximum(0)defset_text(self,text):self.status_label.setText(text)classCore(QObject):"""Core functionality for running Mercurial command. Do not attempt to instantiate and use this directly. """commandStarted=pyqtSignal()commandFinished=pyqtSignal(thread.DataWrapper)commandCanceling=pyqtSignal()def__init__(self):super(Core,self).__init__()self.thread=Noneself.output_text=QTextBrowser()self.output_text.document().setDefaultStyleSheet(qtlib.thgstylesheet)self.pmon=Noneself.queue=[]### Public Methods ###defrun(self,cmdline,*cmdlines):'''Execute or queue Mercurial command'''self.queue.append(cmdline)iflen(cmdlines):self.queue.extend(cmdlines)ifnotself.is_running():self.run_next()defcancel(self):'''Cancel running Mercurial command'''ifself.is_running():self.thread.abort()self.commandCanceling.emit()defset_pmon(self,pmon):self.pmon=pmondefis_running(self):returnbool(self.threadandself.thread.isRunning())### Private Method ###defrun_next(self):try:cmdline=self.queue.pop(0)self.thread=thread.CmdThread(cmdline)exceptIndexError:returnFalseself.thread.started.connect(self.command_started)self.thread.commandFinished.connect(self.command_finished)self.thread.outputReceived.connect(self.output_received)self.thread.errorReceived.connect(self.error_received)ifself.pmon:self.thread.progressReceived.connect(self.progress_received)self.thread.start()returnTruedefappend_output(self,msg,style=''):msg=msg.replace('\n','<br />')self.output_text.insertHtml('<font style="%s">%s</font>'%(style,msg))max=self.output_text.verticalScrollBar().maximum()self.output_text.verticalScrollBar().setSliderPosition(max)defclear_output(self):self.output_text.clear()### Signal Handlers ###defcommand_started(self):ifself.pmon:self.pmon.set_text(_('Running...'))self.pmon.unknown_progress()self.commandStarted.emit()defcommand_finished(self,wrapper):ret=wrapper.dataifself.pmon:ifretisNone:self.pmon.clear_progress()ifself.pmon.pbar.maximum()==0:# busy indicatorifret==0:# finished successfullyself.pmon.fillup_progress()else:self.pmon.clear_progress()ifretisNone:ifself.thread.abortbyuser:status=_('Terminated by user')else:status=_('Terminated')else:status=_('Finished')self.pmon.set_text(status)ifret==0andself.run_next():return# run next commandself.commandFinished.emit(wrapper)defcommand_canceling(self):ifself.pmon:self.pmon.set_text(_('Canceling...'))self.pmon.unknown_progress()self.commandCanceling.emit()defoutput_received(self,wrapper):msg,label=wrapper.datamsg=hglib.tounicode(msg)msg=Qt.escape(msg)style=qtlib.geteffect(label)self.append_output(msg,style)deferror_received(self,wrapper):msg,label=wrapper.datamsg=hglib.tounicode(msg)msg=Qt.escape(msg)style=qtlib.geteffect(label)self.append_output(msg,style)defprogress_received(self,wrapper):ifself.thread.isFinished():self.pmon.clear_progress()returncounting=Falsetopic,item,pos,total,unit=wrapper.dataifposisNone:self.pmon.clear_progress()returniftotalisNone:count='%d'%poscounting=Trueelse:self.pmon.pbar.setMaximum(total)self.pmon.pbar.setValue(pos)count='%d / %d'%(pos,total)ifunit:count+=' '+unitself.pmon.prog_label.setText(hglib.tounicode(count))ifitem:status='%s: %s'%(topic,item)else:status=local._('Status: %s')%topicself.pmon.status_label.setText(hglib.tounicode(status))self.pmon.inprogress=Trueifnotself.pmon.inprogressorcounting:# use indeterminate modeself.pmon.pbar.setMinimum(0)classWidget(QWidget):"""An embeddable widget for running Mercurial command"""commandStarted=pyqtSignal()commandFinished=pyqtSignal(thread.DataWrapper)commandCanceling=pyqtSignal()def__init__(self):super(Widget,self).__init__()self.core=Core()self.core.commandStarted.connect(lambda:self.commandStarted.emit())self.core.commandFinished.connect(lambdaw:self.commandFinished.emit(w))self.core.commandCanceling.connect(lambda:self.commandCanceling.emit())# main layout gridgrid=QGridLayout()grid.setSpacing(4)grid.setContentsMargins(*(1,)*4)## status and progress labelsself.pmon=ProgressMonitor()self.core.set_pmon(self.pmon)grid.addWidget(self.pmon,0,0)# command output areagrid.addWidget(self.core.output_text,1,0,5,0)grid.setRowStretch(1,1)# widget settingself.setLayout(grid)# prepare to showself.core.output_text.setHidden(True)### Public Methods ###defrun(self,cmdline,*args):self.core.run(cmdline,*args)defcancel(self):self.core.cancel()defshow_output(self,visible):self.core.output_text.setShown(visible)defis_show_output(self):returnself.core.output_text.isVisible()classDialog(QDialog):"""A dialog for running random Mercurial command"""commandStarted=pyqtSignal()commandFinished=pyqtSignal(thread.DataWrapper)commandCanceling=pyqtSignal()def__init__(self,cmdline,parent=None,finishfunc=None):super(Dialog,self).__init__(parent)self.setWindowFlags(self.windowFlags()&~Qt.WindowContextHelpButtonHint)self.finishfunc=finishfuncself.core=Core()self.core.commandFinished.connect(self.command_finished)self.core.commandCanceling.connect(lambda:self.commandCanceling.emit())# main layout gridgrid=QGridLayout()grid.setSpacing(6)grid.setContentsMargins(*(7,)*4)## status and progress labelsself.pmon=ProgressMonitor()self.core.set_pmon(self.pmon)grid.addWidget(self.pmon,0,0)# command output areagrid.addWidget(self.core.output_text,1,0,5,0)grid.setRowStretch(1,1)# bottom buttonsbuttons=QDialogButtonBox()self.cancel_btn=buttons.addButton(QDialogButtonBox.Cancel)self.cancel_btn.clicked.connect(self.cancel_clicked)self.close_btn=buttons.addButton(QDialogButtonBox.Close)self.close_btn.clicked.connect(self.reject)self.detail_btn=buttons.addButton(_('Detail'),QDialogButtonBox.ResetRole)self.detail_btn.setAutoDefault(False)self.detail_btn.setCheckable(True)self.detail_btn.setChecked(True)self.detail_btn.toggled.connect(self.show_output)grid.addWidget(buttons,7,0)self.setLayout(grid)self.setWindowTitle(_('TortoiseHg Command Dialog'))self.resize(540,420)# prepare to showself.close_btn.setHidden(True)# start commandself.core.run(cmdline)defshow_output(self,visible):"""show/hide command output"""self.core.output_text.setVisible(visible)self.detail_btn.setChecked(visible)# workaround to adjust only window heightself.setMinimumWidth(self.width())self.adjustSize()self.setMinimumWidth(0)### Private Method ###defreject(self):ifself.core.is_running():ret=QMessageBox.question(self,_('Confirm Exit'),_('Mercurial'' command is still running.\nAre you sure you want'' to terminate?'),QMessageBox.Yes|QMessageBox.No,QMessageBox.No)ifret==QMessageBox.Yes:self.cancel_clicked()# don't close dialogreturn# close dialogifself.core.thread.ret==0:self.accept()# means command successfully finishedelse:super(Dialog,self).reject()### Signal Handlers ###defcancel_clicked(self):self.core.cancel()defcommand_finished(self,wrapper):self.cancel_btn.setHidden(True)self.close_btn.setShown(True)self.close_btn.setFocus()ifself.finishfunc:self.finishfunc() def command_canceling(self):
self.cancel_btn.setDisabled(True)
++class Runner(QObject):+ """A component for running Mercurial command without UI++ This command runner doesn't show any UI element unless it gets a warning+ or an error while the command is running. Once an error or a warning is+ received, it pops-up a small dialog which contains the command log.+ """++ commandStarted = pyqtSignal()+ commandFinished = pyqtSignal(thread.DataWrapper)+ commandCanceling = pyqtSignal()++ def __init__(self, title=_('TortoiseHg'), parent=None):+ super(Runner, self).__init__()++ self.title = title+ self.parent = parent++ self.core = Core()+ self.core.commandStarted.connect(lambda: self.commandStarted.emit())+ self.core.commandFinished.connect(self.command_finished)+ self.core.commandCanceling.connect(lambda: self.commandCanceling.emit())++ self.core.output_text.setMinimumSize(460, 320)++ ### Public Methods ###++ def run(self, cmdline, *args):+ self.core.run(cmdline, *args)++ def cancel(self):+ self.core.cancel()++ def show_output(self, visible=True):+ if not hasattr(self, 'dlg'):+ self.dlg = QDialog(self.parent)+ self.dlg.setWindowTitle(self.title)+ flags = self.dlg.windowFlags() & ~Qt.WindowContextHelpButtonHint+ self.dlg.setWindowFlags(flags)+ box = QVBoxLayout()+ box.setContentsMargins(*(0,)*4)+ box.addWidget(self.core.output_text)+ self.dlg.setLayout(box)+ self.dlg.setVisible(visible)++ ### Signal Handler ###++ def command_finished(self, wrapper):+ if wrapper.data != 0:+ self.show_output()+ self.commandFinished.emit(wrapper)
Attach a Trello Card
Add a tag
Your session has expired
You are no longer logged in. Please log in and try your request again.
Filter RSS Feed
This RSS feed URL allows you to see the contents of your current filter using any feed reader.
This link includes a special authentication token. If you share the URL with anyone else, they can see this RSS feed's activity. You can disable these tokens when needed.
Your current filter is unsaved; changing it won't affect this RSS feed.