PyQT, Sharp Zaurus and color in the QTextBrowser

S

Sybren Stuvel

Hi there!

I'm a beginning Python programmer, and I like it a lot already. Since my
Sharp Zaurus has a fairly complete Python environment including PyQT, I
thought it would be the perfect language for programming some nice
things on my Zaurus. The thing I really missed on the Z was a good
Jabber client. That's why I'm building my own. Things are going good,
and in a few nights I've been able to get a fairly decent though
under-featured client.

There is a small thing annoying me, though I'm trying to show the name
of the person saying something in color: red = someone else, blue = me.
This is an example of the text I'm adding to the QTextBrowser:

<font color='#0000ff'>&lt;me&gt;</font>: hello world

It works like a charm on my PC, but on the Zaurus the text is all black.
Does anyone know how I can fix this?

~~~ brainwave flash ~~~

I just thought of something: what if the Z doesn't allow single quotes
around the "color" attribute? I gave it a try, and replaced the text
with:

<font color="#0000ff">&lt;me&gt;</font>: hello world

And it works!

Anyways, perhaps this will be picked up by others having the same
problem. I'll stick around in this group and try to soak up as many good
knowledge from people as I can ;-)

A bit about myself: I'm a 24 year old, studying Computer Sciences at the
University of Amsterdam, I'm Dutch (like Guido ;-)) and I currently live
in Amsterdam too. I've been a programmer for half my life now :)

Sybren
 
T

Tim Gerla

I just thought of something: what if the Z doesn't allow single quotes
around the "color" attribute? I gave it a try, and replaced the text
with:

<font color="#0000ff">&lt;me&gt;</font>: hello world

And it works!

Very fun stuff. Someday I hope to have a Zaurus or similar device to
toy with. Anyway, to actually be on topic, "proper" HTML (XHTML 1.0,
and maybe HTML 4.0? I don't recall...) requires double-quotes to be
used. Single quotes are illegal. So, the Qt version your Zaurus is
using must be a little more strict.

-Tim
 
F

Fredrik Lundh

P

Peter Hansen

Tim said:
Very fun stuff. Someday I hope to have a Zaurus or similar device to
toy with. Anyway, to actually be on topic, "proper" HTML (XHTML 1.0,
and maybe HTML 4.0? I don't recall...) requires double-quotes to be
used. Single quotes are illegal.

Are you certain about that? It seems very unlikely that it would
outlaw use of single quotes when it is supposed to be XML-compatible,
and XML explicitly allows either single or double quotes around attributes.

I checked a page or two at W3C and couldn't find an obvious way to
prove that you are wrong, but I think the onus is on you to prove
that you are right here.

-Peter
 
S

Sybren Stuvel

Peter Hansen enlightened us with:
Are you certain about that? It seems very unlikely that it would
outlaw use of single quotes when it is supposed to be XML-compatible,
and XML explicitly allows either single or double quotes around
attributes.

I can't find it right now, but I've had the same discussion with a few
collegues of mine, and according to W3C, both single and double quotes
are accepted for both HTML and XML, and thus XHTML too.

Sybren
 
T

Tim Gerla

Are you certain about that? It seems very unlikely that it would
outlaw use of single quotes when it is supposed to be XML-compatible,
and XML explicitly allows either single or double quotes around attributes.

You're right--I was under the wrong impression about single & double quotes.
For some reason I recall reading somewhere (can't trust everything you read online)
that XML only allowed double quotes, and I never bothered to verify it.

Anyway, does that mean that the Qt parser has a bug?

-Tim
 
S

Sybren Stuvel

Tim Gerla enlightened us with:
Anyway, does that mean that the Qt parser has a bug?

If it wants to be HTML-compliant: yes.
If it wants to use HTML-like codes for markup: no

Al least, that's the way I see it. I dont't know Trolltech's
intentions. I'll check out the docs.

Sybren
 
S

Sybren Stuvel

Jeremy Bowers enlightened us with:
The confusion probably stems from the fact that as of the latest XHTML
specification at the time I read it, every single example XHTML
fragment used double quotes. At no point is it ever specified either
way in the XHTML specification, except by reference to the XML
specification.

Got a point there. I use single quotes all the time thouhg, in HTML generated
in PHP:

<?php
echo "<span class='$class'>$msg</span>"
?>

It's a lot better than something I otHften see in other people's code:

echo "<span class=\"$class\">$msg</span>"

Doing it the other way around doesn't work, since PHP doesn't do
variable substitution between single quotes.

Sybren
 
F

Fredrik Lundh

Jeremy said:
At no point is it ever specified either way in the XHTML specification,
except by reference to the XML specification.

which is the whole point, of course.

(we've been through this in the XML-RPC and RSS universes
lately; for some reason, some people have a really hard time
understanding that when you base a format on XML, you get
more than just tags in angle brackets ;-)

</F>
 
S

Sybren Stuvel

Jeremy Bowers enlightened us with:
At no point is it ever specified either way in the XHTML
specification, except by reference to the XML specification.

I'm sorry to tell you, but you're wrong in that. It is clearly stated in
the HTML 4.01 specification at
http://www.w3.org/TR/html401/intro/sgmltut.html#h-3.2.2

I found that by going to the index, looking up the item "attibutes" and
then clicking the link at "quotation marks around value". Not that hard
to find.

The XML specification of attributes can be found at
http://www.w3.org/TR/REC-xml#sec-common-syn and is a little harder to
find, but not impossible.

Since XHTML 1.0 is defined as "A Reformulation of HTML 4 in XML 1.0",
this should be enough to also allow single and double quoted attribute
values in XHTML.

Sybren
 
G

Greg Fortune

Are you intended on releasing the source for this? If so, dump something up
there so we can play ;o)

Greg Fortune
 
S

Sybren Stuvel

Greg Fortune enlightened us with:
Are you intended on releasing the source for this? If so, dump
something up there so we can play ;o)

Yes, I am going to release the source for this ;-) I'll post it on
http://zaurus.thirdtower.com/ when I'm a bit further in the building
process. I'll let the group know when I do that!

Sybren
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top