2012/05/28

Pesky Etching

While working with Qt buttons I've came across a very nasty behaviour - when you disable a button, it's label receives a pretty ugly shadow that makes the font rather unreadable. This effect is called 'etching'. There is a reminant of a CSS property that controls that behaviour called etch-disabled-text, but it's undocumented and actually doesn't work at all.

There is NO documented way of removing that shadow. Pretty crappy, especially for a very configurable toolkit like Qt.

Anyways, here's a workaround. It'll set the proper global palette rules that will apply this fix to all the buttons.
The first line sets the color of the disabled text, the second - removes the etching.


QPalette pal = QApplication::palette();
pal.setColor(QPalette::Disabled, QPalette::Text, QColor(80, 80, 80));
pal.setColor(QPalette::Disabled, QPalette::Light, QColor(0, 0, 0, 0));
QApplication::setPalette(pal);
view raw etching.cpp hosted with ❤ by GitHub

2012/01/22

OATMEAL2PDF

As a continuation to my wildly popular XKCD2PDF post, here's a script I whipped out to get me some sweet PDFs of a great comic called The Oatmeal.


import re, urllib2,sys
k = 0
for i in range(7,0,-1):
page_url = "http://theoatmeal.com/comics_pg/page:%d"%i
out = open("oatmeal\\out%d.html"%i,"w")
out.write("<html><body>\n")
print "getting " + page_url
f = urllib2.urlopen(page_url)
a = f.read()
results = []
for params in re.findall("""<a href="/comics/(.*?)"><img src="(.*?)" alt="(.*?)" class="border0" /></a>""",a):
title = params[2]
sub_url = "http://theoatmeal.com/comics/" + params[0]
print "getting " + sub_url
try:
sf = urllib2.urlopen(sub_url)
except:
print "Unexpected error:", sys.exc_info()[0]
continue
sa = sf.read()
r1 = re.findall('"(http://s3.amazonaws.com/theoatmeal-img/comics/.*?)"',sa,re.S)
result = {
'title' : title,
'sub_images' : r1
}
if len(result['sub_images'])==0:
print "crap"
else:
results += [ result ]
print result
results.reverse()
for result in results:
out.write("<hr/>\n")
out.write(result['title'] + "<br/>\n")
for si in result['sub_images']:
print "getting " + si
try:
u = urllib2.urlopen(si)
except:
print "Unexpected error:", sys.exc_info()[0]
continue
fn = 'oatmeal\\%d.%s'%(k,si[-3:])
k += 1
localFile = open(fn, 'wb')
localFile.write(u.read())
localFile.close()
out.write("<img src=\"%s\"/> <br/>\n"%fn)
out.flush()
out.write("</body></html>\n");
out.close()
view raw oatmeal.py hosted with ❤ by GitHub

2012/01/03

SCons and Qt Resource files

Today I've stumbled upon a bug/problem with SCons' support for Qt resource files (the ones with QRC extension).
Usually, to add a QRC to your project you add a line like this:
qrcobj = programEnv.Qrc("SomeFile.qrc", QT4_QRCFLAGS="-name SomeFile")
and all is well.
But - probably due to a bug somewhere in qt4.py module, the files that are referenced from inside the QRC (the actual images and stylesheets) are not added as a dependency to the build process, so when you change a CSS file, the QRC will not be rebuilt.
The snippet below parses the QRC manually, fetches the list of files inside and adds the to deps list; Python rocks.


#adding qrc resources compilation
import xml.dom.minidom
qtResourceFile = []
for q in ("GUI.qrc", "UI/UI.qrc",):
baseq = os.path.basename(q)[:-4]
qrcdeps = []
qrc = programEnv['ENV']['PWD'] + "/GUI/" + q
dir = os.path.dirname(qrc)
x = xml.dom.minidom.parse(open(qrc))
for filenode in x.getElementsByTagName("file"):
qrcdeps += [ dir + "/" + filenode.childNodes[0].data ]
qrcobj = programEnv.Qrc(q, QT4_QRCFLAGS="-name "+baseq)
programEnv.Depends(qrcobj, qrcdeps)
qtResourceFile += [ qrcobj ]