Re: [Tkinter-discuss] listdir

2018-02-16 Thread Vasilis Vlachoudis
When I run your program

Download$ python codec.py 
utf-8
Download$ LC_ALL=C python codec.py 
ansi_x3.4-1968
Download$ LC_ALL=en_US.UTF-8 python codec.py 
utf-8

it seems that python properly recognizes the LC_ALL setting

Cheers
Vasilis


From: Michael Lange [klappn...@web.de]
Sent: Friday, February 16, 2018 10:24
To: Vasilis Vlachoudis
Cc: tkinter-discuss@python.org
Subject: Re: [Tkinter-discuss] listdir

Hi,

On Fri, 16 Feb 2018 08:49:01 +
Vasilis Vlachoudis  wrote:

> Thank you Michael,
>
> my locale is UTF-8 when I get the error
>
> $ locale
> LANG=en_US.UTF-8
> LANGUAGE=en_US.UTF-8
> LC_CTYPE="en_US.UTF-8"
> ...
> LC_ALL=en_US.UTF-8

ok. Don't know if it is possible that there is something in the configuration
that stops python from properly detecting the system encoding? Some ten
years ago (while using Python 2.3 :) I wrote myself a function that tries
to detect the system encoding (see below); since it is so old some of the things
that function does may be obsolete now, but I still use it today in
a number of my projects and it still works. If you like you can run this
snippet as a test script and see what it says.
Of course it is also well possible that my guess was wrong and the problem
lies somewhere else.

Best regards

Michael

###
import codecs
import locale

def _find_codec(encoding):
# return True if the requested codec is available, else return False
try:
codecs.lookup(encoding)
return 1
except (TypeError, LookupError):
return 0

def _sysencoding():
# try to guess the system default encoding
# this is mainly stolen from IDLE's IOBinding.py
# thanks for guidance to Martin v. Loewis
locale.setlocale(locale.LC_CTYPE, "")# don't mess the numeric types here, 
we might replace the decimal point with a comma and break Tk!
try:
enc = locale.getpreferredencoding()
if enc and _find_codec(enc):
return enc
except AttributeError:
# our python is too old, try something else
pass
try:
enc = locale.nl_langinfo(locale.CODESET)
if enc and _find_codec(enc):
return enc
except AttributeError:
pass
# the last try
try:
enc = locale.getdefaultlocale()[1]
if enc and _find_codec(enc):
return enc
except ValueError:
pass
# aargh, nothing good found, fall back to ascii and hope for the best
print 'warning: unable to find usable encoding, using ascii.'
return 'ascii'

print(_sysencoding().lower())

###


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Vulcans believe peace should not depend on force.
-- Amanda, "Journey to Babel", stardate 3842.3

___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] multicolumn list/tree with images

2018-02-16 Thread Michael Lange
On Fri, 16 Feb 2018 22:06:58 +0100
 wrote:

> Dear Michael,
> 
> thank you very much for your valuable reply.
> 
> > there does not seem to be a way to
> > make only the "checkbutton" icon sensitive to mouse clicks
> 
> The event object have the exact coordinates of the click position.
> Based on them you can identify the row and column. Quick & Dirty
> example
> 
> def on_click(event):
> iid = event.widget.selection()[0]
> col = event.widget.identify(component='column',
> x=event.x, y=event.y)
> print('iid: {} column: {}'.format(iid, col))
> 

Yes, but that column includes a few pixels of white space on the left of
the checkbox and a few pixels of space (including the space the "active"
rectangle takes) to the checkbox's right. At least I could not find a way
to work around this without having to try something rather fancy with
absolute screen coordinates which I thought would not be worth the effort
and besides bear potential for bugs.

> 
> > There are several third party solutions available, though.
> 
> I know. But I had some problems with their documentation, missing
> support channels, inactive community, unclear project status, ...
> 
> > TkinterTreectrl is a wrapper for the tktreectrl tcl extension
> > ...
> > https://sourceforge.net/projects/tktreectrl/
> > https://sourceforge.net/projects/tkintertreectrl/
> 
> What is the difference compared to tkinter.Treeview?
> What is the difference between your two links? Which one is more active
> and up to date? There is also a fork on GitHub where I opened an Issue
> about project status
> https://github.com/apnadkarni/tktreectrl/issues/1
> No examples no documentation.

To learn about the difference between the ttk.Treeview and the tktreectrl
widget I would like to be able to point you to their web page, but
unfortunately sf still appears to be in service. There is an archived
page available at:
https://web.archive.org/web/20170301130644/http://tktreectrl.sourceforge.net/

Just look at the screenshots and you will get an idea about how much more
capable this widget is than the ttk Treeview.
The difference between the two links is, that *tktreectrl* is the tk
extension library (written in C, windows binaries are available on the sf
download site, linux binaries included in most recent distributions) and
*tkintertreectrl* is a Python wrapper module I wrote for it (both
Python2 and -3). The docs on sf are of course currently down with the rest
of their pages, but are included in the download, plus a few very simple
demos. In case of questions you can always ask me :)

> 
> > able to do this, like tablelist and maybe tktable, you can look at
> > this archived page for more information and download links:
> > 
> > https://web.archive.org/web/20140412080251/http://tkinter.unpythonic.net:80/wiki/Widgets
> 
> Very important link - good to have the archive!
> 
> I checked the links: Some dead, some unclear about project status,
> features, screenshots, docu. I wrote some mails, issues and bug-tickets
> to be clearer in this points.
> 
> "TkTable"
> https://sourceforge.net/p/tktable/bugs/318/

I guess I could answer what you asked there :)
The last release was made in 2008. I bet it still works :)

> 
> Very interesting sounds the "The Multi-Column Listbox and Tree Widget
> Package Tablelist 6.0" where screenshots are available, too.
> 
> But it is pure Tcl code. I don't know how to use that with Python3.
> There is some quick and dirty code around on the web. But no official
> supported or infos about how much it fits to the Tcl code. No
> repository or support channel.

Kevin Walzer's python wrapper for tablelist is available here:
https://web.archive.org/web/20150920011432/http://tkinter.unpythonic.net/wiki/TableListWrapper

Looks like Python2 only, but it shouldn't be a problem to adapt it to
Python3. Personally I never used it, but I have been hearing good things
about it. I think Kevin probably still reads the list, so if you ask
questions about it here there might be a good chance to get help.

> 
> Pmw megawidgets
> 
> Website currently offline. No docu, no examples, no screenshots.

There is actually excellent documentation about Pmw on their page and
will hopefully soon be available again once sf have restored their
content. Probably downloads will still work, and they include the
documentation. However, unless something new showed up recently there is
no multi colomn listbox widget with icon support included.

> 
> > Finally there seems to be a tix.TList widget which might be able to do
> > what you want, though I never used it myself, see
> > https://docs.python.org/3/library/tkinter.tix.html
> The docu is currently offline.

Seems like right now we are learning something about the bad side effects
of monopoly structures... :)

> Don't know how to use or if it fit my
> needs. The little words about tix in the official Python3 docu doesn't
> help. 

Re: [Tkinter-discuss] multicolumn list/tree with images

2018-02-16 Thread c.buhtz
Dear Michael,

thank you very much for your valuable reply.

> there does not seem to be a way to
> make only the "checkbutton" icon sensitive to mouse clicks

The event object have the exact coordinates of the click position.
Based on them you can identify the row and column. Quick & Dirty
example

def on_click(event):
iid = event.widget.selection()[0]
col = event.widget.identify(component='column',
x=event.x, y=event.y)
print('iid: {} column: {}'.format(iid, col))


> There are several third party solutions available, though.

I know. But I had some problems with their documentation, missing
support channels, inactive community, unclear project status, ...

> TkinterTreectrl is a wrapper for the tktreectrl tcl extension
> ...
> https://sourceforge.net/projects/tktreectrl/
> https://sourceforge.net/projects/tkintertreectrl/

What is the difference compared to tkinter.Treeview?
What is the difference between your two links? Which one is more active
and up to date? There is also a fork on GitHub where I opened an Issue
about project status
https://github.com/apnadkarni/tktreectrl/issues/1
No examples no documentation.

> able to do this, like tablelist and maybe tktable, you can look at
> this archived page for more information and download links:
> 
> https://web.archive.org/web/20140412080251/http://tkinter.unpythonic.net:80/wiki/Widgets

Very important link - good to have the archive!

I checked the links: Some dead, some unclear about project status,
features, screenshots, docu. I wrote some mails, issues and bug-tickets
to be clearer in this points.

"TkTable"
https://sourceforge.net/p/tktable/bugs/318/

Very interesting sounds the "The Multi-Column Listbox and Tree Widget
Package Tablelist 6.0" where screenshots are available, too.

But it is pure Tcl code. I don't know how to use that with Python3.
There is some quick and dirty code around on the web. But no official
supported or infos about how much it fits to the Tcl code. No
repository or support channel.

Pmw megawidgets

Website currently offline. No docu, no examples, no screenshots.

> Finally there seems to be a tix.TList widget which might be able to do
> what you want, though I never used it myself, see
> https://docs.python.org/3/library/tkinter.tix.html
The docu is currently offline. Don't know how to use or if it fit my
needs. The little words about tix in the official Python3 docu doesn't
help. No code no examples no features or screenshots.

That is the situation.
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] listdir

2018-02-16 Thread Michael Lange
Hi,

On Fri, 16 Feb 2018 09:51:33 +
Vasilis Vlachoudis  wrote:

> When I run your program
> 
> Download$ python codec.py 
> utf-8
> Download$ LC_ALL=C python codec.py 
> ansi_x3.4-1968
> Download$ LC_ALL=en_US.UTF-8 python codec.py 
> utf-8
> 
> it seems that python properly recognizes the LC_ALL setting

maybe some other environment variable causes confusion, it seems like
LC_CTYPE can cause problems, AFAIR that's why it's overridden in my
function call.
The following issue I found at bugs.python.org talks about this (not the
same as your problem, but somehow similar looking; seems like even a
terminal program can be the culprit :)

https://bugs.python.org/issue18378

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Sometimes a feeling is all we humans have to go on.
-- Kirk, "A Taste of Armageddon", stardate 3193.9
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] listdir

2018-02-16 Thread Michael Lange
Hi,

On Fri, 16 Feb 2018 08:49:01 +
Vasilis Vlachoudis  wrote:

> Thank you Michael,
> 
> my locale is UTF-8 when I get the error
> 
> $ locale
> LANG=en_US.UTF-8
> LANGUAGE=en_US.UTF-8
> LC_CTYPE="en_US.UTF-8"
> ...
> LC_ALL=en_US.UTF-8

ok. Don't know if it is possible that there is something in the configuration
that stops python from properly detecting the system encoding? Some ten
years ago (while using Python 2.3 :) I wrote myself a function that tries
to detect the system encoding (see below); since it is so old some of the things
that function does may be obsolete now, but I still use it today in
a number of my projects and it still works. If you like you can run this
snippet as a test script and see what it says.
Of course it is also well possible that my guess was wrong and the problem
lies somewhere else.

Best regards

Michael

###
import codecs
import locale

def _find_codec(encoding):
# return True if the requested codec is available, else return False
try:
codecs.lookup(encoding)
return 1
except (TypeError, LookupError):
return 0

def _sysencoding():
# try to guess the system default encoding
# this is mainly stolen from IDLE's IOBinding.py
# thanks for guidance to Martin v. Loewis
locale.setlocale(locale.LC_CTYPE, "")# don't mess the numeric types here, 
we might replace the decimal point with a comma and break Tk!
try:
enc = locale.getpreferredencoding()
if enc and _find_codec(enc):
return enc
except AttributeError:
# our python is too old, try something else
pass
try:
enc = locale.nl_langinfo(locale.CODESET)
if enc and _find_codec(enc):
return enc
except AttributeError:
pass
# the last try
try:
enc = locale.getdefaultlocale()[1]
if enc and _find_codec(enc):
return enc
except ValueError:
pass
# aargh, nothing good found, fall back to ascii and hope for the best
print 'warning: unable to find usable encoding, using ascii.'
return 'ascii'

print(_sysencoding().lower())

###


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

Vulcans believe peace should not depend on force.
-- Amanda, "Journey to Babel", stardate 3842.3
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss


Re: [Tkinter-discuss] listdir

2018-02-16 Thread Vasilis Vlachoudis
Thank you Michael,

my locale is UTF-8 when I get the error

$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_CTYPE="en_US.UTF-8"
...
LC_ALL=en_US.UTF-8

python v3 works ok though

Vasilis

From: Tkinter-discuss 
[tkinter-discuss-bounces+vasilis.vlachoudis=cern...@python.org] on behalf of 
Michael Lange [klappn...@web.de]
Sent: Thursday, February 15, 2018 20:32
To: tkinter-discuss@python.org
Subject: Re: [Tkinter-discuss] listdir

Hi,

On Thu, 15 Feb 2018 10:24:10 +
Vasilis Vlachoudis  wrote:

> Hi all,
>
> I know that it it is not related to tkinter, but I had troubles in
> submitting in the general python list.
>
> I was trying to make my custom FileDialog to handle unicode filenames
> and I stuck with the following behavior (python v2.7)
>
> #path = "/home/bnv/Download"
> path = u"/home/bnv/Download"
> for fn in os.listdir(path):
> print(fn,type(fn))
> fullpath = os.path.join(path, fn)
>
> If the "path" is defined as unicode I get the following output and error
> (u'foo.py', )
> ('Gewu\xccrzhalter.Part1.nc', )
> Traceback (most recent call last):
>   File "foo.py", line 20, in 
> filename = os.path.join(path, fn)
>   File "/usr/lib/python2.7/posixpath.py", line 73, in join
> path += '/' + b
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xcc in position 5:
> ordinal not in range(128)
>
> While if the "path" is defined as str. I get
> ('foo.py', )
> ('Gewu\xccrzhalter.Part1.nc', )
>
> I don't understand why if the path is unicode the output of listdir is
> unicode the filenames containing only ascii and str for the file with
> the non-ascii character. While if the path is str, all output is in str

I think this is because with "foo.py" no UnicodeError occurs and so the
str->unicode conversion succeeds.

I can only guess why that UnicodeError occurs though, this doesn't happen
here. When I do $ export LANG=C before starting the python interpreter
however I get this same error as you (by default I have UTF-8 here).
So I think maybe your system default encoding is set to something that
does not support the non-ascii character in the filename which causes the
problem. This might also explain why the default tk file dialogs do not
seem to work for you (they work well here with unicode filenames).
Just a guess, of course.

Best regards

Michael


.-.. .. ...- .   .-.. --- -. --.   .- -. -..   .--. .-. --- ... .--. . .-.

If a man had a child who'd gone anti-social, killed perhaps, he'd still
tend to protect that child.
-- McCoy, "The Ultimate Computer", stardate 4731.3
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss
___
Tkinter-discuss mailing list
Tkinter-discuss@python.org
https://mail.python.org/mailman/listinfo/tkinter-discuss