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.
# qtlib.py - Qt utility code## Copyright 2010 Steve Borho <steve@borho.org>## This software may be used and distributed according to the terms of the# GNU General Public License version 2 or any later version.importosimportatexitimportshutilimporttempfilefromPyQt4importQtCore,QtGuifromPyQt4importQscifrommercurialimportextensions,utilfromtortoisehg.utilimporthglibfromtortoisehg.hgqt.i18nimport_fromhgext.colorimport_stylesqsci=Qsci.QsciScintillatmproot=Nonedefgettempdir():globaltmprootdefcleanup():try:shutil.rmtree(tmproot)except:passifnottmproot:tmproot=tempfile.mkdtemp(prefix='thg.')atexit.register(cleanup)returntmproot# _styles maps from ui labels to effects# _effects maps an effect to font style properties. We define a limited# set of _effects, since we convert color effect names to font style# effect programatically._effects={'bold':'font-weight: bold','italic':'font-style: italic','underline':'text-decoration: underline',}thgstylesheet='* { white-space: pre; font-family: monospace; font-size: 9pt; }'defconfigstyles(ui):# extensions may provide more labels and default effectsforname,extinextensions.extensions():_styles.update(getattr(ext,'colortable',{}))# tortoisehg defines a few labels and default effects_styles.update({'ui.error':'red bold','control':'black bold'})# allow the user to overrideforstatus,cfgeffectsinui.configitems('color'):if'.'notinstatus:continuecfgeffects=ui.configlist('color',status)_styles[status]=' '.join(cfgeffects)forstatus,cfgeffectsinui.configitems('thg-color'):if'.'notinstatus:continuecfgeffects=ui.configlist('thg-color',status)_styles[status]=' '.join(cfgeffects)# See http://doc.trolltech.com/4.2/richtext-html-subset.html# and http://www.w3.org/TR/SVG/types.html#ColorKeywordsdefgeteffect(labels):'map labels like "log.date" to Qt font styles'effects=[]# Multiple labels may be requestedforlinlabels.split():ifnotl:continue# Each label may request multiple effectses=_styles.get(l,'')foreines.split():ifein_effects:effects.append(_effects[e])elifeinQtGui.QColor.colorNames():# Accept any valid QColoreffects.append('color: '+e)elife.endswith('_background'):e=e[:-11]ifeinQtGui.QColor.colorNames():effects.append('bgcolor: '+e)return';'.join(effects)# Copy of patch.difflabel from Mercurial, hacked to always return# a label for unmatched text, so it gets escaped by our htmluidefdifflabel(func,*args,**kw):'''yields 2-tuples of (output, label) based on the output of func()'''prefixes=[('diff','diff.diffline'),('copy','diff.extended'),('rename','diff.extended'),('old','diff.extended'),('new','diff.extended'),('deleted','diff.extended'),('---','diff.file_a'),('+++','diff.file_b'),('@@','diff.hunk'),('-','diff.deleted'),('+','diff.inserted')]forchunkinfunc(*args,**kw):lines=chunk.split('\n')fori,lineinenumerate(lines):ifi!=0:yield('\n','')stripline=lineiflineandline[0]in'+-':# highlight trailing whitespace, but only in changed linesstripline=line.rstrip()forprefix,labelinprefixes:ifstripline.startswith(prefix):yield(stripline,label)breakelse:yield(line,'ui.status')ifline!=stripline:yield(line[len(stripline):],'diff.trailingwhitespace')NAME_MAP={'fg':'color','bg':'background-color','family':'font-family','size':'font-size','weight':'font-weight','space':'white-space','style':'font-style','decoration':'text-decoration',}defmarkup(msg,**styles):style={'white-space':'pre'}forname,valueinstyles.items():ifnotvalue:continueifNAME_MAP.has_key(name):name=NAME_MAP[name]style[name]=valuestyle=';'.join(['%s: %s'%tfortinstyle.items()])msg=hglib.tounicode(msg)msg=QtCore.Qt.escape(msg)msg=msg.replace('\n','<br />')return'<span style="%s">%s</span>'%(style,msg)_iconcache={}defgeticon(name):""" Return a QIcon for the resource named 'name.(svg|png)' (the given 'name' parameter must *not* provide the extension). """try:return_iconcache[name]exceptKeyError:forextin('svg','png','ico'):path=':/icons/%s.%s'%(name,ext)ifQtCore.QFile.exists(path):icon=QtGui.QIcon(path)breakelse:icon=QtGui.QIcon(':/icons/fallback.svg')_iconcache[name]=iconreturnicondefCommonMsgBox(icon,title,main,text='',buttons=QtGui.QMessageBox.Close,parent=None):msg=QtGui.QMessageBox(parent)msg.setIcon(icon)msg.setWindowTitle(title)msg.setStandardButtons(buttons)msg.setText('<b>%s</b>'%main)info=''forlineintext.split('\n'):info+='<nobr>%s</nobr><br />'%linemsg.setInformativeText(info)returnmsg.exec_()defInfoMsgBox(*args,**kargs):returnCommonMsgBox(QtGui.QMessageBox.Information,*args,**kargs)defWarningMsgBox(*args,**kargs):returnCommonMsgBox(QtGui.QMessageBox.Warning,*args,**kargs)defErrorMsgBox(*args,**kargs):returnCommonMsgBox(QtGui.QMessageBox.Critical,*args,**kargs)defQuestionMsgBox(*args,**kargs):returnCommonMsgBox(QtGui.QMessageBox.Question,*args,**kargs)classCustomPrompt(QtGui.QMessageBox):def__init__(self,title,message,parent,choices,default=None,esc=None,files=None):QtGui.QMessageBox.__init__(self,parent)self.setWindowTitle(hglib.toutf(title))self.setText(hglib.toutf(message))iffiles:msg=''fori,fileinenumerate(files):msg+=' %s\n'%fileifi==9:msg+=' ...\n'breakself.setDetailedText(hglib.toutf(msg))self.hotkeys={}fori,sinenumerate(choices):btn=self.addButton(s,QtGui.QMessageBox.AcceptRole)try:char=s[s.index('&')+1].lower()self.hotkeys[char]=btnifdefault==i:self.setDefaultButton(btn)ifesc==i:self.setEscapeButton(btn)exceptValueError:passdefrun(self):returnself.exec_()defkeyPressEvent(self,event):fork,btninself.hotkeys.iteritems():ifevent.text()==k:btn.emit(QtCore.SIGNAL('clicked()'))super(CustomPrompt,self).keyPressEvent(event)defsetup_font_substitutions():QtGui.QFont.insertSubstitutions('monospace',['monaco','courier new'])classPMButton(QtGui.QPushButton):"""Toggle button with plus/minus icon images"""def__init__(self,expanded=True,parent=None):QtGui.QPushButton.__init__(self,parent)size=QtCore.QSize(11,11) self.setIconSize(size)
self.setMaximumSize(size)
self.setFlat(True)
+ self.setAutoDefault(False) self.plus = geticon('plus')
self.minus = geticon('minus')
icon=expandedandself.minusorself.plusself.setIcon(icon)defclicked():icon=self.is_expanded()andself.plusorself.minusself.setIcon(icon)self.clicked.connect(clicked)defset_expanded(self,state=True):icon=stateandself.minusorself.plusself.setIcon(icon)defset_collapsed(self,state=True):icon=stateandself.plusorself.minusself.setIcon(icon)defis_expanded(self):returnself.icon().serialNumber()==self.minus.serialNumber()defis_collapsed(self):returnnotself.is_expanded()classClickableLabel(QtGui.QLabel):clicked=QtCore.pyqtSignal()def__init__(self,label,parent=None):QtGui.QLabel.__init__(self,parent)self.setText(label)defmouseReleaseEvent(self,event):self.clicked.emit()classExpanderLabel(QtGui.QWidget):expanded=QtCore.pyqtSignal(bool)def__init__(self,label,expanded=True,stretch=True,parent=None):QtGui.QWidget.__init__(self,parent)box=QtGui.QHBoxLayout()box.setSpacing(4)box.setContentsMargins(*(0,)*4)self.button=PMButton(expanded,self)self.button.clicked.connect(self.pm_clicked)box.addWidget(self.button)self.label=ClickableLabel(label,self)self.label.clicked.connect(lambda:self.button.click())box.addWidget(self.label)ifnotstretch:box.addStretch(0)self.setLayout(box)defpm_clicked(self):self.expanded.emit(self.button.is_expanded())deffileEditor(filename):'Open a simple modal file editing dialog'dialog=QtGui.QDialog()dialog.setWindowFlags(dialog.windowFlags()&~QtCore.Qt.WindowContextHelpButtonHint)vbox=QtGui.QVBoxLayout()dialog.setLayout(vbox)editor=qsci()editor.setBraceMatching(qsci.SloppyBraceMatch)vbox.addWidget(editor)BB=QtGui.QDialogButtonBoxbb=QtGui.QDialogButtonBox(BB.Save|BB.Cancel)dialog.connect(bb,QtCore.SIGNAL('accepted()'),dialog,QtCore.SLOT('accept()'))dialog.connect(bb,QtCore.SIGNAL('rejected()'),dialog,QtCore.SLOT('reject()'))vbox.addWidget(bb)lexer=Qsci.QsciLexerProperties()editor.setLexer(lexer)s=QtCore.QSettings()ret=QtGui.QDialog.Rejectedtry:contents=open(filename,'rb').read()dialog.setWindowTitle(filename)geomname='editor-geom'editor.setText(contents)editor.setModified(False)dialog.restoreGeometry(s.value(geomname).toByteArray())ret=dialog.exec_()ifret==QtGui.QDialog.Accepted:f=util.atomictempfile(filename,'wb',createmode=None)f.write(hglib.fromunicode(editor.text()))f.rename()s.setValue(geomname,dialog.saveGeometry())exceptEnvironmentError,e:qtlib.WarningMsgBox(_('Unable to read/write config file'),hglib.tounicode(e),parent=dialog)returnret
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.