Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #46183 > unrolled thread

Problems with python and pyQT

Started bysilusilusilu@gmail.com
First post2013-05-27 02:26 -0700
Last post2013-05-28 06:59 -0400
Articles 4 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Problems with python and pyQT silusilusilu@gmail.com - 2013-05-27 02:26 -0700
    Re: Problems with python and pyQT Chris “Kwpolska” Warrick <kwpolska@gmail.com> - 2013-05-27 15:10 +0200
      Re: Problems with python and pyQT silusilusilu@gmail.com - 2013-05-28 02:41 -0700
        Re: Problems with python and pyQT Dave Angel <davea@davea.name> - 2013-05-28 06:59 -0400

#46183 — Problems with python and pyQT

Fromsilusilusilu@gmail.com
Date2013-05-27 02:26 -0700
SubjectProblems with python and pyQT
Message-ID<8d8fd7fc-2509-457e-a4c9-0a1ac1f65c02@googlegroups.com>
Hi, 
i'm new with python: so excuse me for my questions....
i have this code:

    def updateLog(self, text):
        self.ui.logTextEdit.moveCursor(QTextCursor.End)
        self.ui.logTextEdit.insertHtml("<font color=\"Black\">"+text)
        self.ui.logTextEdit.moveCursor(QTextCursor.End)

logTextEdit is a QTextEdit object.With this code,i can display only ascii characters: how can i diplay text as hex and binary values?
Thanks

[toc] | [next] | [standalone]


#46196

FromChris “Kwpolska” Warrick <kwpolska@gmail.com>
Date2013-05-27 15:10 +0200
Message-ID<mailman.2249.1369660253.3114.python-list@python.org>
In reply to#46183
On Mon, May 27, 2013 at 11:26 AM,  <silusilusilu@gmail.com> wrote:
> Hi,
> i'm new with python: so excuse me for my questions....
> i have this code:
>
>     def updateLog(self, text):
>         self.ui.logTextEdit.moveCursor(QTextCursor.End)
>         self.ui.logTextEdit.insertHtml("<font color=\"Black\">"+text)
>         self.ui.logTextEdit.moveCursor(QTextCursor.End)
>
> logTextEdit is a QTextEdit object.With this code,i can display only ascii characters: how can i diplay text as hex and binary values?
> Thanks
> --
> http://mail.python.org/mailman/listinfo/python-list

You would need to convert them to strings first.  You may want bin()
and hex() for that.  And if you want to convert 'q' to 0x71,
hex(ord("q")).  And if you want to turn 'hello' into 0x68656c6c6f, you
would need to iterate over 'hello' and run the above function over
every letter.

Also, you are able to display Unicode characters, too.

--
Kwpolska <http://kwpolska.tk> | GPG KEY: 5EAAEA16
stop html mail                | always bottom-post
http://asciiribbon.org        | http://caliburn.nl/topposting.html

[toc] | [prev] | [next] | [standalone]


#46271

Fromsilusilusilu@gmail.com
Date2013-05-28 02:41 -0700
Message-ID<646e6bae-b0fc-46fe-bf60-23ec9b4958a3@googlegroups.com>
In reply to#46196
Thanks for your reply: very useful!!
I have another question: with hex command i display (for example)

0x1

is it possible to display 0x01?
Thanks

Il giorno lunedì 27 maggio 2013 15:10:24 UTC+2, Chris “Kwpolska” Warrick ha scritto:
> On Mon, May 27, 2013 at 11:26 AM,  <silusilusilu@gmail.com> wrote:
> 
> > Hi,
> 
> > i'm new with python: so excuse me for my questions....
> 
> > i have this code:
> 
> >
> 
> >     def updateLog(self, text):
> 
> >         self.ui.logTextEdit.moveCursor(QTextCursor.End)
> 
> >         self.ui.logTextEdit.insertHtml("<font color=\"Black\">"+text)
> 
> >         self.ui.logTextEdit.moveCursor(QTextCursor.End)
> 
> >
> 
> > logTextEdit is a QTextEdit object.With this code,i can display only ascii characters: how can i diplay text as hex and binary values?
> 
> > Thanks
> 
> > --
> 
> > http://mail.python.org/mailman/listinfo/python-list
> 
> 
> 
> You would need to convert them to strings first.  You may want bin()
> 
> and hex() for that.  And if you want to convert 'q' to 0x71,
> 
> hex(ord("q")).  And if you want to turn 'hello' into 0x68656c6c6f, you
> 
> would need to iterate over 'hello' and run the above function over
> 
> every letter.
> 
> 
> 
> Also, you are able to display Unicode characters, too.

[toc] | [prev] | [next] | [standalone]


#46273

FromDave Angel <davea@davea.name>
Date2013-05-28 06:59 -0400
Message-ID<mailman.2291.1369738782.3114.python-list@python.org>
In reply to#46271
On 05/28/2013 05:41 AM, silusilusilu@gmail.com wrote:
> Thanks for your reply: very useful!!
> I have another question: with hex command i display (for example)
>
> 0x1
>
> is it possible to display 0x01?

hex() is a function, not a command.  And it only takes the one 
parameter, the int to be converted.

For more generality, try the str.format() method.  The x type converts 
to hex without any prefix, and then you can add the width and fill field.

http://docs.python.org/2/library/stdtypes.html#str.format
http://docs.python.org/2/library/string.html#formatstrings
http://docs.python.org/2/library/string.html#format-specification-mini-language

For starters, try:

print "0x{0:0>2x}".format(12)
or
print "0x{0:0>2X}".format(12)
     if you like uppercase hex characters

-- 
DaveA

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web