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.importosimportatexitimportshutilimporttempfilefrom PyQt4.QtCore import *
from PyQt4.QtGui import *
-from PyQt4 import Qsci+from PyQt4.Qsci import *from mercurial import extensions, util
from tortoisehg.util import hglib, paths
from tortoisehg.hgqt.i18n import _
from hgext.color import _styles
-qsci = Qsci.QsciScintilla-tmproot = None
def gettempdir():
global tmproot
defcleanup():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; }'"""app-global stylesheet"""appstylesheet='''/* expander-like check box: checkbox.setProperty('expander', True) */QCheckBox[expander="true"]::indicator:unchecked { image: url(:/icons/plus.png); }QCheckBox[expander="true"]::indicator:checked { image: url(:/icons/minus.png); }'''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])elifeinQColor.colorNames():# Accept any valid QColoreffects.append('color: '+e)elife.endswith('_background'):e=e[:-11]ifeinQColor.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=Qt.escape(msg)msg=msg.replace('\n','<br />')return'<span style="%s">%s</span>'%(style,msg)_iconcache={}defgeticon(name):""" Return a QIcon for the specified name. (the given 'name' parameter must *not* provide the extension). This searches for the icon from Qt resource or icons directory, named as 'name.(svg|png|ico)'. """# TODO: icons should be placed at single location before releasedeffindicon(name):forpfxin(':/icons',paths.get_icon_path()):forextin('svg','png','ico'):path='%s/%s.%s'%(pfx,name,ext)ifQFile.exists(path):returnQIcon(path)returnQIcon(':/icons/fallback.svg')try:return_iconcache[name]exceptKeyError:_iconcache[name]=findicon(name)return_iconcache[name]_pixmapcache={}defgetpixmap(name,width=16,height=16):key='%s_%sx%s'%(name,width,height)try:return_pixmapcache[key]exceptKeyError:pixmap=geticon(name).pixmap(width,height)_pixmapcache[key]=pixmapreturnpixmapdefCommonMsgBox(icon,title,main,text='',buttons=QMessageBox.Close,labels=[],parent=None):msg=QMessageBox(parent)msg.setIcon(icon)msg.setWindowTitle(title)msg.setStandardButtons(buttons)forbutton_id,labelinlabels:msg.setButtonText(button_id,label)msg.setText('<b>%s</b>'%main)info=''forlineintext.split('\n'):info+='<nobr>%s</nobr><br />'%linemsg.setInformativeText(info)returnmsg.exec_()defInfoMsgBox(*args,**kargs):returnCommonMsgBox(QMessageBox.Information,*args,**kargs)defWarningMsgBox(*args,**kargs):returnCommonMsgBox(QMessageBox.Warning,*args,**kargs)defErrorMsgBox(*args,**kargs):returnCommonMsgBox(QMessageBox.Critical,*args,**kargs)defQuestionMsgBox(*args,**kargs):btn=QMessageBox.Yes|QMessageBox.Nores=CommonMsgBox(QMessageBox.Question,buttons=btn,*args,**kargs)returnres==QMessageBox.YesclassCustomPrompt(QMessageBox):def__init__(self,title,message,parent,choices,default=None,esc=None,files=None):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,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(SIGNAL('clicked()'))super(CustomPrompt,self).keyPressEvent(event)defsetup_font_substitutions():QFont.insertSubstitutions('monospace',['monaco','courier new'])classPMButton(QPushButton):"""Toggle button with plus/minus icon images"""def__init__(self,expanded=True,parent=None):QPushButton.__init__(self,parent)size=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(QLabel):clicked=pyqtSignal()def__init__(self,label,parent=None):QLabel.__init__(self,parent)self.setText(label)defmouseReleaseEvent(self,event):self.clicked.emit()classExpanderLabel(QWidget):expanded=pyqtSignal(bool)def__init__(self,label,expanded=True,stretch=True,parent=None):QWidget.__init__(self,parent)box=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())classStatusLabel(QWidget):def__init__(self,parent=None):QWidget.__init__(self,parent)box=QHBoxLayout()box.setContentsMargins(*(0,)*4)self.status_icon=QLabel()self.status_icon.setMaximumSize(16,16)self.status_icon.setAlignment(Qt.AlignCenter)box.addWidget(self.status_icon)self.status_text=QLabel()self.status_text.setAlignment(Qt.AlignVCenter|Qt.AlignLeft)box.addWidget(self.status_text)box.addStretch(0)self.setLayout(box)defset_status(self,text,icon=None):self.set_text(text)self.set_icon(icon)defclear_status(self):self.clear_text()self.clear_icon()defset_text(self,text=''):iftextisNone:text=''self.status_text.setText(text)defclear_text(self):self.set_text()defset_icon(self,icon=None):ificonisNone:self.clear_icon()else:ifisinstance(icon,bool):pixmap=iconandgetpixmap('success')orgetpixmap('error')elifisinstance(icon,basestring):pixmap=getpixmap(icon)elifisinstance(icon,QIcon):pixmap=icon.pixmap(16,16)elifisinstance(icon,QPixmap):pixmap=iconelse:raiseTypeError,'%s: bool, str, QIcon or QPixmap'%type(icon)self.status_icon.setShown(True)self.status_icon.setPixmap(pixmap)defclear_icon(self):self.status_icon.setHidden(True)classLabeledSeparator(QWidget):def__init__(self,label=None,parent=None):QWidget.__init__(self,parent)box=QHBoxLayout()box.setContentsMargins(*(0,)*4)iflabel:label=QLabel(label)box.addWidget(label)sep=QFrame()sep.setFrameShadow(QFrame.Sunken)sep.setFrameShape(QFrame.HLine)box.addWidget(sep,1,Qt.AlignVCenter)self.setLayout(box)classWidgetGroups(object):""" Support for bulk-updating properties of Qt widgets """def__init__(self):object.__init__(self)self.clear(all=True)### Public Methods ###defadd(self,widget,group='default'):ifgroupnotinself.groups:self.groups[group]=[]widgets=self.groups[group]ifwidgetnotinwidgets:widgets.append(widget)defremove(self,widget,group='default'):ifgroupnotinself.groups:returnwidgets=self.groups[group]ifwidgetinwidgets:widgets.remove(widget)defclear(self,group='default',all=True):ifall:self.groups={}else:delself.groups[group]defset_prop(self,prop,value,group='default',cond=None):ifgroupnotinself.groups:returnwidgets=self.groups[group]ifcallable(cond):widgets=[wforwinwidgetsifcond(w)]forwidgetinwidgets:getattr(widget,prop)(value)defset_visible(self,*args,**kargs):self.set_prop('setVisible',*args,**kargs)defset_enable(self,*args,**kargs):self.set_prop('setEnabled',*args,**kargs)deffileEditor(filename):'Open a simple modal file editing dialog'dialog=QDialog() dialog.setWindowFlags(dialog.windowFlags() & ~Qt.WindowContextHelpButtonHint)
vbox = QVBoxLayout()
dialog.setLayout(vbox)
- editor = qsci()
- editor.setBraceMatching(qsci.SloppyBraceMatch)
+ editor = QsciScintilla()
+ editor.setBraceMatching(QsciScintilla.SloppyBraceMatch)
vbox.addWidget(editor)
BB = QDialogButtonBox
bb = QDialogButtonBox(BB.Save|BB.Cancel)
dialog.connect(bb,SIGNAL('accepted()'),dialog,SLOT('accept()')) dialog.connect(bb, SIGNAL('rejected()'),
dialog, SLOT('reject()'))
vbox.addWidget(bb)
- lexer = Qsci.QsciLexerProperties()
+ lexer = QsciLexerProperties()
editor.setLexer(lexer)
s = QSettings()
ret = QDialog.Rejected
try:contents=open(filename,'rb').read()dialog.setWindowTitle(filename)geomname='editor-geom'editor.setText(contents)editor.setUtf8(True)editor.setModified(False)dialog.restoreGeometry(s.value(geomname).toByteArray())ret=dialog.exec_()ifret==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.