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.QtCoreimportQt,QObject,pyqtSignalfromPyQt4.QtGuiimportQDialog,QDialogButtonBox,QLabel,QProgressBarfromPyQt4.QtGuiimportQTextBrowser,QHBoxLayout,QGridLayout,QMessageBoxfromPyQt4.QtGuiimportQWidget,QVBoxLayoutfromtortoisehg.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=None### Public Methods ###defrun(self,cmdline):'''Execute Mercurial command'''self.thread=thread.CmdThread(cmdline)self.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)ifhasattr(self,'pmon'):self.thread.progressReceived.connect(self.progress_received)self.thread.start()defcancel(self):'''Cancel running Mercurial command'''self.thread.abort()self.commandCanceling.emit()defset_pmon(self,pmon): self.pmon = pmon
def is_running(self):
- return self.thread.isRunning()
+ return self.thread and self.thread.isRunning()
### Private Method ###
defappend_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)### Signal Handlers ###defcommand_started(self):ifhasattr(self,'pmon'):self.pmon.set_text(_('Running...'))self.pmon.unknown_progress()self.commandStarted.emit()defcommand_finished(self,wrapper):ifhasattr(self,'pmon'):ret=wrapper.dataifretisNone: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)self.commandFinished.emit(wrapper)defcommand_canceling(self):ifhasattr(self,'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):self.core.run(cmdline)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):super(Dialog,self).__init__(parent)self.setWindowFlags(self.windowFlags()&~Qt.WindowContextHelpButtonHint)self.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()defcommand_canceling(self):self.cancel_btn.setDisabled(True)
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.