GUI:-please answer want to learn GUI programming in python , howshould i proceed.

C

Chris Angelico

Let the flame war begin!

I'll try to avoid flamage :)
First off, gitk is a huge unstructured mess. You are not obliged to write
programs like this in Tcl, at least not today. All these global statements
give already a hint, that this is a procedural thing. Think of Python, where
classes are stripped. Tcl has object oriented frameworks for years. If you
use Snit, e.g., all those globals are not needed because they are really
instance variables.

Ah, okay. Don't take gitk as representative. Got it. Unfortunately
there are quite a few languages that I've experienced from, really,
only one program that I've tried to modify (Scheme almost falls in
that category too - all I've ever used it for is LilyPond scripting,
and not much of that), and I'm aware that's not really a fair look at
the language.
This is just syntax and purely a matter of taste.

Yeah. Like I said,

.. But my rule of thumb with bash scripts is: If it exceeds a page or
two in length, it's probably time it got rewritten in an application
language. When a program is the size of gitk (>10KLOC), the benefits
relating to interactive use (as you mention below) become less
significant, and benefits relating to discoverability of the more
obscure features become more significant.
It does command substitution (indeed the brackets [] do) and is one of the
key concepts of Tcl. mc is probably the command from msgcat which translates
i18n strings. Complaining about these basic things is like complaining about
indentation in Python.

Okay. Now, how am I to figure out where this command comes from? It's
not a host command (typing "mc" at the bash prompt comes up failure),
and it's not defined in the script itself (at least, I can't find
"proc mc" anywhere); is it a Tcl built-in? Where do I start looking?

(Yes, I'm aware this is a problem in any language. I'm not now raising
a point in the Python vs Tcl debate, I'm just asking out of
curiosity.)
Tcl also has some strengths.

First off, the syntax is quite flexible, and so things like list
comprehensions[1] or classes[2] can be implemented in Tcl itself. Second,
it's great at interactive use because at a command prompt, you don't want to
type all those () call operators, "quotes" and obey indentation just to get
a simple loop running. Third, its implementation features a few unique
things:

Yeah, that's nice for the interactive interpreter... but I already
have bash for that, and Python's not far off. I've used interactive
Pike and REXX interpreters, which are both more demanding than Python
(in terms of syntax requirements and such), so I'm perfectly happy
with Python; but if you're used to something even lighter, then sure,
use something that lets you type almost nothing. No problem. I just
think that - as mentioned above - a ten thousand line program should
be aiming more at maintainability than ease of manual typing.
* Safe interpreters. Sometimes requested here for Python, you can create a
slave interpreter in Tcl that is restricted and cannot do disk I/O, has
limited execution time etc. You can precisely control which commands are
passed on to the slave.

Cool. Not enough for me to choose the language unless I really REALLY
needed that feature, but there was one time in my programming career
when that was true, so we'll count that a win.
* Interpreters in threads. There is no GIL, Tcl interpreters are thread safe
and more than one can coexist in a process and run concurrently. This is
accessible from script level through the Threads package.

Nice, though Python's threading and/or multiprocessing can do 90% of
what people want. Side point: What about Tk? Can you (a) run separate
GUI threads for separate windows? (b) manipulate widgets created by
another thread?
* Very easy deployment: Starkits/Tclkits bundle an interpreter within a
single executable. Similar to what pyinstaller does. But in my experience,
it's much easier to pack all dependencies into a starkit than it is with
pyinstaller. You can get a rather full-fledged interpreter with GUI support
into a few megabytes, and I've never seen it fail.

Never really needed this, but for the people who do, I'm sure that's a
fairly big deal.

So there definitely are some advantages that Tcl has over Python. Put
against them is a superior object model, a large corpus of first-class
object types (dict, set, list, etc[1]), and a syntax that more clearly
differentiates names and strings without making variable references
look like a lot more than they are.

Huge room in the world for both languages to exist and thrive.

ChrisA

[1] What is an etc() in Python?
 
T

Terry Reedy

Nice, though Python's threading and/or multiprocessing can do 90% of
what people want. Side point: What about Tk? Can you (a) run separate
GUI threads for separate windows? (b) manipulate widgets created by
another thread?

When running tk via tkinter, limiting tkinter/tk calls to the main
thread is the safest thing to do. I do not know whether the problems
people have had doing otherwise are due to Python or inherent in tk itself.
 
G

Grant Edwards

Well... sort of. They can only hold strings, not other arrays.
They're not first-class entities: you can't pass them around
or keep them in local variables; they're always global. (And
there are no modules, so global is *truly* global.)

It's worse that I remembered -- I must have repressed most of
my Tcl memories.
 
R

Rick Johnson

Well, when you take my comments out of their context, that
does seem to be a totally stupid thing to say. But in
context, it's only *mostly* stupid, and mostly stupid
means a little bit sensible *wink* The context was a
complaint, or at least expression of surprise, that Python
use Tcl for a GUI, this being contrasted with
(paraphrasing the legions of people who have expressed
surprise about this in the past) "some hypothetical GUI
written in Python". But in practice, it won't be written
in Python, it will be likely written in C or some other
low-level language with some interface to Python. The main
difference between this hypothetical "Python GUI" and Tcl
is that Tcl is a Turing-complete interpreter which lives
in it's own process.

And how many times would you take advantage of that "turning
complete" functionality in reality? My answer... ZERO! How
many Tcl calls have you, or anybody, made that did have
direct business with creating or managing a TK gui? HOW
MANY???

We don't need that functionality, we ALREADY have a
language... it's called Python and the syntax is MUCH
better. All we want is a damn GUI.

And trying to justify TCL as legit because "Tcl just calls C
routines" is ludicrous. If the intention is to extend C
routines, then by gawd EXTEND them. Don't go writing a whole
new turning complete monstrosity and forcing all calls to
travel through it's front door, sit in waiting room until
it's eyes bleed, before finally exiting out the back door on
it's way to "Cees-ville".

Why should i give a damn about Tcl? All it does is get in my
way. OTOH, if Tcl where more like a Vegas Casino for high
rollers, i might be inclined to overlook the "superfluous
pit-stop". A free luxury room , free all you can eat buffet,
free call girls, etc... but it has no endearing qualities.
 
C

Chris Angelico

We don't need that functionality, we ALREADY have a
language... it's called Python and the syntax is MUCH
better. All we want is a damn GUI.

And trying to justify TCL as legit because "Tcl just calls C
routines" is ludicrous.

Python already ships with another language interpreter - actually,
several wrapped up into one. It's called the pickle module. There's
nothing fundamentally wrong with calling on another language; I was
just curious about it, is all.

ChrisA
 
M

Mark Lawrence

We don't need that functionality, we ALREADY have a
language... it's called Python and the syntax is MUCH
better. All we want is a damn GUI.

Then write it, dear Rick, dear Rick, dear Rick, then write it, dear
Rick, dear Rick, write it.
 
W

wxjmfauth

From all the toolkits, wxPython is probably the most
interesting. I used all versions from 2.0 (?) up to 2.8. Then
it has been decided to go unicode.

Let see in the wx interactive intepreter, it is only
the top of the iceberg. (Py27, wxPy294)
5

---

It has alos been decided to rework wxPython and create
wxPhoenix, unicode of course.

Impossible to put a Python string correctly in a widget
supposed to handle text. The design mistake is more
deeper than in wx29 (unicode).

I do not know the present status, but as the mistake
is a consequence of a unicode non understanding (plus
a little bit Python, plus a little bit wxWidgets), I doubt
that some improvement happened.

I attempted to explain unicode...

jmf
 
M

Mark Lawrence

From all the toolkits, wxPython is probably the most
interesting. I used all versions from 2.0 (?) up to 2.8. Then
it has been decided to go unicode.

Let see in the wx interactive intepreter, it is only
the top of the iceberg. (Py27, wxPy294)

5

---

It has alos been decided to rework wxPython and create
wxPhoenix, unicode of course.

Impossible to put a Python string correctly in a widget
supposed to handle text. The design mistake is more
deeper than in wx29 (unicode).

I do not know the present status, but as the mistake
is a consequence of a unicode non understanding (plus
a little bit Python, plus a little bit wxWidgets), I doubt
that some improvement happened.

I attempted to explain unicode...

jmf

wxPython 3 (Phoenix) will be the first version that supports Python 3.
This will obviously mean that for the first time, wxPython will be able
to take full advantage of the superb PEP393 Flexible String
Representation (FSR) which is available in Python 3.3+.
 
W

wxjmfauth

Le mardi 17 décembre 2013 09:33:24 UTC+1, Mark Lawrence a écrit :
wxPython 3 (Phoenix) will be the first version that supports Python 3.

This will obviously mean that for the first time, wxPython will be able

to take full advantage of the superb PEP393 Flexible String

Representation (FSR) which is available in Python 3.3+.



--

My fellow Pythonistas, ask not what our language can do for you, ask

what you can do for our language.

I'm very happy for you.
You should at least serialized the tasks.

- wxPhoenix (wrapper of wxWidgets) is one thing
- wxPhoenix for Python3 / Python2 is something else
- Ditto for the FSR
- Ditto for "unicode"

For your information, that's at those times I decided
to have a look at the Qt derivatives, it was a very,
very good idea.

jmf
 
S

Steven D'Aprano

From all the toolkits, wxPython is probably the most interesting. I used
all versions from 2.0 (?) up to 2.8. Then it has been decided to go
unicode.

Let see in the wx interactive intepreter, it is only the top of the
iceberg. (Py27, wxPy294)

5


What does that have to do with wxPython? It looks like you're just mis-
using Python 2.7.

In Python 2.7, 'ሴЃ' is not a Unicode string, it is a byte string. The
exact bytes you get are not well-defined but on many systems you may get
a UTF-8 encoded byte string:


py> sys.version
'2.7.4 (default, Apr 18 2013, 17:48:59) \n[GCC 4.4.5]'
py> for b in 'ሴЃ':
.... print hex(ord(b)), b
....
0xe1
0x88 �
0xb4 �
0xd0
0x83 �


If you use a Unicode string instead:

py> for c in u'ሴЃ':
.... print hex(ord(c)), c
....
0x1234 ሴ
0x403 Ѓ

py> for b in u'ሴЃ'.encode('utf-8'):
.... print hex(ord(b)), b
....
0xe1
0x88 �
0xb4 �
0xd0
0x83 �



Even if it is true that wxPython cannot handle Unicode text, you haven't
shown it here.
 
M

Mark Lawrence

Even if it is true that wxPython cannot handle Unicode text, you haven't
shown it here.

Personally I am convinced that wxPython can't handle unicode for the
simple reason that it doesn't yet support Python 3 and we all know that
Python 2 and unicode don't mix.
 
M

Mark Lawrence

Le mardi 17 décembre 2013 09:33:24 UTC+1, Mark Lawrence a écrit :

I'm very happy for you.
You should at least serialized the tasks.

- wxPhoenix (wrapper of wxWidgets) is one thing
- wxPhoenix for Python3 / Python2 is something else
- Ditto for the FSR
- Ditto for "unicode"

For your information, that's at those times I decided
to have a look at the Qt derivatives, it was a very,
very good idea.

jmf

I haven't the faintest idea what your words above are meant to mean.
Your communication skills are clearly lacking, as you also still insist
on sending us double spaced google crap. Do you not understand the
instructions here https://wiki.python.org/moin/GoogleGroupsPython ?
 
S

Steven D'Aprano

Personally I am convinced that wxPython can't handle unicode for the
simple reason that it doesn't yet support Python 3 and we all know that
Python 2 and unicode don't mix.

I don't think this is right. The Unicode support in Python 2 isn't as
good as in Python 3, but it is still pretty good. You just have to
remember to use the u prefix on your strings.

If it is true that wxPython cannot handle Unicode -- and I see no
evidence that this is correct -- then it is due to the underlying wx*
library, not Python 2.
 
W

wxjmfauth

Le mardi 17 décembre 2013 10:29:28 UTC+1, Steven D'Aprano a écrit :
From all the toolkits, wxPython is probably the most interesting. I used
all versions from 2.0 (?) up to 2.8. Then it has been decided to go


Let see in the wx interactive intepreter, it is only the top of the
iceberg. (Py27, wxPy294)

5





What does that have to do with wxPython? It looks like you're just mis-

using Python 2.7.



In Python 2.7, 'ሴЃ' is not a Unicode string, it is a byte string. The

exact bytes you get are not well-defined but on many systems you may get

a UTF-8 encoded byte string:





py> sys.version

'2.7.4 (default, Apr 18 2013, 17:48:59) \n[GCC 4.4.5]'

py> for b in 'ሴЃ':

... print hex(ord(b)), b

...

0xe1

0x88 �

0xb4 �

0xd0

0x83 �





If you use a Unicode string instead:



py> for c in u'ሴЃ':

... print hex(ord(c)), c

...

0x1234 ሴ

0x403 Ѓ



py> for b in u'ሴЃ'.encode('utf-8'):

... print hex(ord(b)), b

...

0xe1

0x88 �

0xb4 �

0xd0

0x83 �







Even if it is true that wxPython cannot handle Unicode text, you haven't

shown it here.
Quich answer.

That's PyShell, the wxPy interpreter.

You are right in pointing all this missmatch: byte string,
unicode, utf-8, mixing a "unicode" tool kit wiht a non
unicode native engine, plus plenty of related things, ...

You may be not aware. I contributed to wxPython from
practically 2.0, 2.1. 2.2 during 6, 7, 8 yeaurs, testing,
reporting about/with all versions, then I gave up.

---

Yout quote.
"Even if it is true that wxPython cannot handle Unicode text..."

It's a confusing vision and that's not correct. It's a little bit
more complicate than this.

jmf
 
R

Robert Kern

I don't think this is right. The Unicode support in Python 2 isn't as
good as in Python 3, but it is still pretty good. You just have to
remember to use the u prefix on your strings.

If it is true that wxPython cannot handle Unicode -- and I see no
evidence that this is correct --

It most certainly is not. wxPython has handled Unicode (via `unicode` strings)
for many, many years now.

--
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
that is made terrible by our own mad attempt to interpret it as though it had
an underlying truth."
-- Umberto Eco
 
C

Chris Angelico

Am 16.12.13 23:40, schrieb Chris Angelico:

I do not know, whether bash has means to structure large programs, I suppose
not. Tcl has (see below), and concerning discoverability, see also below.

You can create functions, which then effectively become new commands.
You can source (the . command) another file, which mostly is a
#include style of thing. But mainly, a bash script is doing exactly
what would happen at the interactive shell (modulo environment
differences - your interactive shell might well have a different $PATH
or something, but command execution still follows the same rules). If
I look at a bash script and see it execute "bc", I can type "man bc"
and have a reasonable chance of it being the same thing.
In the gitk case, mc comes from these lines:

package require msgcat
namespace import ::msgcat::mc

Now, be prepared: These lines do almost the same as

import msgcat
from msgcat import mc

would do in Python.

Okay. Now that you've told me that, I can find those lines... down the
very bottom of the script. The first thing I did when trying to figure
this out was to go to the top of the file and search for "mc", and I
didn't find a definition.

In Python, it's conventional to put imports at the top, so this would
have worked. (Unless there's a "from x import *", but this is
precisely why that's frowned upon.) Is the convention different in
Tcl, or is gitk just laid out unhelpfully?
You can't run Tk more than once, that applies to almost every toolkit I
know. But you can pass a message to the main thread to do it for you. This
is quite easy; it looks like

thread::send -async $main [list doit $somedata]

Everything I ever did on OS/2 allowed GUI operations from multiple
threads. The C APIs, I think, were restricted to manipulating each
widget from the thread that created it (or at least, you could confuse
yourself thoroughly if you didn't; I always just stuck to "this
window, this thread"); VX-REXX allowed any thread to manipulate any
object belonging to that process. If you send a message to a widget,
its thread will handle it (and yours will block until you get a
response - or you can post a message, which doesn't block); this
functions the same whether it's a thread in your process or one in
another process.
You pass an arbitrary Tcl command which executes in the main thread as soon
as it is idle. In fact, because of the embedded event loop in Tcl (not bound
to Tk), you rarely need threads at all. Asynchronous I/O is very easy in Tcl
(fileevent command).

I learned to love async processing a couple of years ago with Pike.
You just return a negative number from main(), which normally has no
meaning, and it goes into a back-end event loop. (And there are other
ways to invoke the back-end.) That can then handle callbacks from
files/sockets, clock-based timeouts ("call this function in X
seconds"), GUI events, pretty much everything (except signals - they
interrupt everything else, as they should). It takes a bit of getting
your head around, if you're used to thread-based programming (as I had
been for a decade or so), but it's so convenient.
So there definitely are some advantages that Tcl has over Python. Put
against them is a superior object model, a large corpus of first-class
object types (dict, set, list, etc[1]), and a syntax that more clearly
differentiates names and strings without making variable references
look like a lot more than they are.
[1] What is an etc() in Python?

Is this a quizzy question? I have no idea.

I mentioned four of Python's fundamental types: the dict, the set, the
list, and the etc. :)
Lists and dicts exist in Tcl as first class objects. You just can't tell
them apart from strings. Sets are in tcllib. Python is more strongly typed
than Tcl in that respect, which can be an advantage. Specifically doing math
is easier in an evaluation based syntax than in a command based syntax, this
sometimes sucks in Tcl.

Having grown up with REXX, I completely understand the concept of
"everything is a string" (though REXX does have compound variables,
which aren't quite lists, aren't quite dicts, and aren't quite sets,
and definitely aren't quite multidimensional anything, but are their
own beast with unique semantics); and having since met Python and Pike
and other such languages, I prefer object semantics. The only
first-class type in REXX is the string; a compound variable is a
different sort of name, not a different sort of value, so you can't
actually pass an array as an argument. What you have to do is pass the
_name_ of the compound variable, so it's a lot fiddlier.
Yes, you name it. I wish people who criticize Tcl would not use their
knowledge from 15 years ago; that beast has evolved. I'm not complaining
about Python 1.0 either. And I wish Tcl would be used more often for
large-scale programs, such that the idioms really develop.

That's true of every language, but sometimes the community adopts
habits based on the early versions and those habits don't change.
Coding styles and best-practices are nearly as much a part of the
language ecosystem as semantics and standard library - a typical Ruby
application has piles and piles and PILES of dependencies (gems),
whereas a typical Python program will need maybe just a couple of
non-standard modules. Is that a fundamental difference between the
languages? Unless the Ruby standard library is positively minimalist,
I don't think it is. It's just the way the community works... which
changes very, very slowly. Maybe in 2015 there'll be a version of Ruby
with a hundred times as much in its stdlib as the current versions
have, but people will still use their favorite gems, because they're
used to them. Python programs will still tend to have shorter chains
of dots in their method calls than Java programs will have, even if
Python were to get compile-time lookups. C programs will still tend to
crash, even if C gets a refcounting garbage collector... hmm, that
one's already happened, and yep, still true. :)

ChrisA
 
I

Igor Korot

Hi, guys,
I think you are doing exactly what Steven D'Aprano said:

Please compare:

"abc" vs 'abc'

from wxPython point of view.
Also remember that wxPython is a wrapper around C++ library where
string are usually
defined with double quotes.

Thank you.
From all the toolkits, wxPython is probably the most interesting. I used
all versions from 2.0 (?) up to 2.8. Then it has been decided to go
unicode.

Let see in the wx interactive intepreter, it is only the top of the
iceberg. (Py27, wxPy294)

len('ሴЃ')
5


What does that have to do with wxPython? It looks like you're just mis-
using Python 2.7.

In Python 2.7, 'ሴЃ' is not a Unicode string, it is a byte string. The
exact bytes you get are not well-defined but on many systems you may get
a UTF-8 encoded byte string:


py> sys.version
'2.7.4 (default, Apr 18 2013, 17:48:59) \n[GCC 4.4.5]'
py> for b in 'ሴЃ':
... print hex(ord(b)), b
...
0xe1
0x88 �
0xb4 �
0xd0
0x83 �


If you use a Unicode string instead:

py> for c in u'ሴЃ':
... print hex(ord(c)), c
...
0x1234 ሴ
0x403 Ѓ

py> for b in u'ሴЃ'.encode('utf-8'):
... print hex(ord(b)), b
...
0xe1
0x88 �
0xb4 �
0xd0
0x83 �



Even if it is true that wxPython cannot handle Unicode text, you haven't
shown it here.
 
M

Mark Lawrence

I don't think this is right. The Unicode support in Python 2 isn't as
good as in Python 3, but it is still pretty good. You just have to
remember to use the u prefix on your strings.

If it is true that wxPython cannot handle Unicode -- and I see no
evidence that this is correct -- then it is due to the underlying wx*
library, not Python 2.

Sorry folks, I'd been up all night and messed that up completely. I
meant to say "Personally I am convinced that *IF* wxPython can't handle
unicode *IT WILL BE* for the simple reason that it doesn't yet support
Python 3 and we all know that Python 2 and unicode don't mix". It would
have been better still if I'd added right at the end "particularly
well", with this being the impression I get from the bug tracker, with
far fewer bugs being raised against Python 3 unicode that I'm aware of
rather than Python 2. I'm now crossing my fingers and legs and hoping
that my impression is correct.
 
W

wxjmfauth

Le mardi 17 décembre 2013 14:03:03 UTC+1, Robert Kern a écrit :
It most certainly is not. wxPython has handled Unicode (via `unicode` strings)

for many, many years now.

---

Correct.

Output of my last interactive interpreter I wrote with
that toolkit.

Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32psi runs psizero.py...
....psizero has been executed
And if I cut/copy/paste something like this:
'ሴ䕧'
into that interpreter, it behaves like this ('??'):


jmf
 

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
474,082
Messages
2,570,588
Members
47,210
Latest member
JuliaMulli

Latest Threads

Top