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

Chris Angelico rosuav at gmail.com
Mon Dec 16 11:10:51 EST 2013


On Tue, Dec 17, 2013 at 2:32 AM, Kevin Walzer <kw at codebykevin.com> wrote:
> On 12/16/13, 10:20 AM, Chris Angelico wrote:
>>
>> Having made a tweak to gitk at one point, I have to say Tcl is
>> definitely inferior to Python.
>
>
> Without starting a flame war, can you elaborate? I'm curious about your
> perspective.
>
> (I studied PSL--Python as a Second Language--so develop in it with a slight
> accent. I'm a native Tcl developer, for better or worse.)

Here's the Tcl procedure that I tweaked. This is from gitk; I find the
word diff not all that useful, but a character diff at times is very
useful. I haven't found a way to configure the word diff regex through
gitk's options, so I tweaked it in the source code.

proc getblobdiffs {ids} {
    global blobdifffd diffids env
    global diffinhdr treediffs
    global diffcontext
    global ignorespace
    global worddiff
    global limitdiffs vfilelimit curview
    global diffencoding targetline diffnparents
    global git_version currdiffsubmod

    set textconv {}
    if {[package vcompare $git_version "1.6.1"] >= 0} {
        set textconv "--textconv"
    }
    set submodule {}
    if {[package vcompare $git_version "1.6.6"] >= 0} {
        set submodule "--submodule"
    }
    set cmd [diffcmd $ids "-p $textconv $submodule  -C --cc
--no-commit-id -U$diffcontext"]
    if {$ignorespace} {
        append cmd " -w"
    }
    if {$worddiff ne [mc "Line diff"]} {
        append cmd " --word-diff=porcelain --word-diff-regex=."
    }
    if {$limitdiffs && $vfilelimit($curview) ne {}} {
        set cmd [concat $cmd -- $vfilelimit($curview)]
    }
    if {[catch {set bdf [open $cmd r]} err]} {
        error_popup [mc "Error getting diffs: %s" $err]
        return
    }
    set targetline {}
    set diffnparents 0
    set diffinhdr 0
    set diffencoding [get_path_encoding {}]
    fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
    set blobdifffd($ids) $bdf
    set currdiffsubmod ""
    filerun $bdf [list getblobdiffline $bdf $diffids]
}

First off, everything's done with commands, rather than assignment
("set diffinhdr 0"), which is very shell-style and not very
programming-style. Can live with that, though even shells can use
equals signs for simplicity. Similarly, the shell style of adorning
variable usage feels messy. There are string literals, some of which
contain interpolated variables; there are dollar-sign adorned
variables; and then there are other words. What are the other words?
Are they implicit strings (as they would be in, say, bash)? I've never
really liked that style. Anyway. Can get past that.

Secondly, what does this do?
    if {$worddiff ne [mc "Line diff"]}

I *think* it means 'if $worddiff is not equal to "Line diff" (this
code is executed for the options "Markup words" and "Color words", but
what's the mc do? How am I supposed to figure out what it does? Where
do I begin to look?

This is where, IMO, Python tends to be a lot clearer. It's easy to see
what's an object and what's a method on it, and every bare word is
either a local name or a standard built-in name. I'm sure Tcl's a
great language, but I'd rather not have to drop out of Python into it
if I can help it. :)

ChrisA



More information about the Python-list mailing list