Re: [FAQ] "Best" GUI toolkit for python

2016-10-18 Thread pozz

Il 18/10/2016 02:57, Wildman ha scritto:

On Tue, 18 Oct 2016 00:58:42 +0200, pozz wrote:


I'm sorry, I know it is a FAQ..., but I couldn't find a good answer.

I'm learning python and I'd like to start creating GUI applications,
mainly for Windows OS. In the past, I wrote many applications in Visual
Basic 4: it was very fast and you could create simple but effective GUIs
in Windows in some minutes.


I am also learning Python so my experience is limited.  I have
tried pyGTK and Tkinter.  GTK's concept of the hbox and vbox
gave me of difficulty.  I couldn't get the GUI to look the way
I wanted.


Yes, it's exactly my situation.  I understand boxes give a lot of 
flexibility, but for simple GUI they are very complex.

Did you try Glade GUI builder applcation?



OTOH, Tkinter offers a way to place widgets on a
window/frame in a precise way:  self.widget.place(x=#, y=#)
That is similar to VB's move statement.  GTK may have such a
feature but I was not able to find it.


Yes, it seems GTK has a similar feature.  It is the container GtkFixed 
(https://developer.gnome.org/gtk3/stable/GtkFixed.html).


  The GtkFixed widget is a container which can place child
  widgets at fixed positions and with fixed sizes, given in
  pixels. GtkFixed performs no automatic layout management.

At the moment, I didn't tested GtkFixed yet, but it seems very simple to 
use. I hope Glade gives a good support for it.




Anyway, my choice based
on my limited experience is Tkinter.  Here is a good place to
start...

http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/index.html

This will give you several places to look for additional info...

https://duckduckgo.com/?q=tkinter+tutorials&t=h_&ia=web



Ok, thank you.
--
https://mail.python.org/mailman/listinfo/python-list


function call questions

2016-10-18 Thread chenyong20000
Hi,
I got a function call as this:

>>>def add_to_tree(root,value_string):
...print "root is %s, value_string is %s" % (root, value_string)
...for ch in value_string:
...  print "ch is %s" % ch
...  root = root.setdefault(ch,{})
...  print "root is", root
...  print "tree is", tree
...
>>> tree={}
>>> txt='abc'
>>> add_to_tree(tree,txt)
root is {}, value_string is abc
ch is a
root is {}
tree is {'a': {}}
ch is b
root is {}
tree is {'a': {'b': {}}}
ch is c
root is {}
tree is {'a': {'b': {'c': {

My question is:
(1) why root is always {}?
(2) why tree is {'a': {'b': {'c': {?
(3) why root isn't the same as tree? shouldn't they be the same because tree is 
argument passed as root?


regards
skyworld
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [FAQ] "Best" GUI toolkit for python

2016-10-18 Thread Mark Summerfield
PySide/PyQt

On Windows I use Python 3.4 + PySide 1.2.4 (Qt 4.8). I have found this
very reliable and use it for both my personal projects and for my
commercial products. I don't use a GUI design tool but you could use Qt
Designer to visually draw your GUI since PySide can read the .ui files it
outputs.

Eventually PySide 2 will be available, and that will support Qt 5 (for what 
that's worth) and presumably Python 3.5+ (which I look forward to).

Gtk/PyGObject/PyGI

Windows is in no way a first class platform for this, so I wouldn't use
it. (I wouldn't use it on any other platform either: I think the introspection 
idea is excellent and wish Qt had done it; but I personally really dislike the 
direction Gtk has gone in recent years.)

Tkinter

This is okay for many simple use cases. However, creating custom widgets in
Tkinter is non-trivial to say the least (especially compared with say, PySide 
or wxPython), and there is no support for _editable_ styled text. (If someone 
can prove me wrong I'd be glad to know how to edit text in Tkinter and toggle 
bold, italic, underline, super- and sub-script, font family, font size, and 
color. I can do most of these - but not all, and haven't seen any other code 
that can do them all either. Note that I'm not talking here about syntax 
highlighting but rather word-processor-style styling.)

wxPython

I've heard some people say they use Python 3 + Phoenix successfully.
On the plus side it uses the native widgets so has a native look and feel.
But what I find frustrating is that there are many widgets with
overlapping functionality so it isn't clear which one is the best to use.

For Windows specifically, you could use https://pythonnet.github.io/
This gives you access to the CLR so you should be able to use a lot of
stuff you're familiar with from VB; some of which might even work on Linux
with the Mono runtime.

A completely different cross-platform approach is to use a web browser as
the GUI toolkit. For example:
https://github.com/r0x0r/pywebview + https://github.com/dddomodossola/remi
or https://flexx.readthedocs.io/en/stable/

There are other toolkits too, e.g.,
http://pybee.org/project/projects/libraries/toga/
(but this has very little documentation)

Or

https://kivy.org/#home

And there are more (e.g., libui, IUP, SDL2).

Good luck!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [FAQ] "Best" GUI toolkit for python

2016-10-18 Thread pozz

Il 18/10/2016 03:25, Paul Rubin ha scritto:

If you're just getting started and you're not trying to make something
super slick, I'd suggest Tkinter.  It's easy to learn and use, you can
bang stuff together with it pretty fast, it's included with various
Python distributions so you avoid download/installation hassles, and
it's pretty portable across various desktop OS's (not mobile for some
reason).


Is there a visual GUI builder for Tkinter?  What I like about gtk/glade 
is a good separation between the code of graphical elements and the code 
of funcionality/behaviour (somewhat similar to CSS).  The widgets are 
designed and customized with Glade application that generates a xml 
(.glade) file that can be supplied directly to the python script.

In theory, it is very clean and simple.

So I'd like to have a visual GUI builder.  I have many problems to 
imagine the GUI in my mind when writing code.




The downside is that you get industrial-looking UI's that
implement typical GUI functionality but don't have ultra precise control
or carefully crafted widgets like some of the other toolkits do.


Could you explain better what do you mean with "industrial-looking UI"? 
What can I do and what *can't* I do with Tkinter?




Kivy (kivy.org) also seems worth looking at if you're trying to be
cross-platform.  It runs on both desktop and mobile.


It seems nice.  Does it use the native look&feel on Windows?





Although, one of
my mobile-using buddies tells me that mobile apps are now passé and
these days people just write web apps for mobile.


I'm not sure this sentence is correct.  *Big* services (mainly social, 
facebook, linkedin, ...) have a custom mobile app for Android and iOS. 
They also have a website (I can check my Facebook profile through a 
simple web browser or through the related app), but they insist to 
install an app.




--
https://mail.python.org/mailman/listinfo/python-list


Re: [FAQ] "Best" GUI toolkit for python

2016-10-18 Thread pozz

Il 18/10/2016 09:42, Mark Summerfield ha scritto:

PySide/PyQt

On Windows I use Python 3.4 + PySide 1.2.4 (Qt 4.8). I have found this
very reliable and use it for both my personal projects and for my
commercial products. I don't use a GUI design tool but you could use Qt
Designer to visually draw your GUI since PySide can read the .ui files it
outputs.

Eventually PySide 2 will be available, and that will support Qt 5
(for what that's worth) and presumably Python 3.5+ (which I look
forward to).


Why don't you use a GUI design tool?  Better... how can you design a GUI 
without seeing it?  For me it's very difficult to "code the GUI".




Gtk/PyGObject/PyGI

Windows is in no way a first class platform for this, so I wouldn't
use it. (I wouldn't use it on any other platform either: I think the
introspection idea is excellent and wish Qt had done it; but I
personally really dislike the direction Gtk has gone in recent
years.)


Could you explain those... "directions" that you don't like?



Tkinter

This is okay for many simple use cases. However, creating custom
widgets in  Tkinter is non-trivial to say the least (especially compared with
say,PySide or wxPython), and there is no support for _editable_ styled text.
(If someone can prove me wrong I'd be glad to know how to edit text in
Tkinter and toggle bold, italic, underline, super- and sub-script, font
family, font size, and color. I can do most of these - but not all, and
haven't seen any other code that can do them all either. Note that I'm
not talking here about syntax highlighting but rather
word-processor-style styling.)

wxPython

I've heard some people say they use Python 3 + Phoenix successfully.
On the plus side it uses the native widgets so has a native look and feel.
But what I find frustrating is that there are many widgets with
overlapping functionality so it isn't clear which one is the best to use.

For Windows specifically, you could use https://pythonnet.github.io/
This gives you access to the CLR so you should be able to use a lot of
stuff you're familiar with from VB; some of which might even work on Linux
with the Mono runtime.

A completely different cross-platform approach is to use a web browser as
the GUI toolkit. For example:
https://github.com/r0x0r/pywebview + https://github.com/dddomodossola/remi
or https://flexx.readthedocs.io/en/stable/

There are other toolkits too, e.g.,
http://pybee.org/project/projects/libraries/toga/
(but this has very little documentation)

Or

https://kivy.org/#home

And there are more (e.g., libui, IUP, SDL2).

Good luck!



--
https://mail.python.org/mailman/listinfo/python-list


testfixtures 4.12.0 Released!

2016-10-18 Thread Chris Withers

Hi All,

I'm pleased to announce the release of testfixtures 4.12.0 featuring the 
following:


- Add support for specifying a callable to extract rows from log records
  when using LogCapture().

- Add support for recursive comparison of log messages with
  LogCapture().

The package is on PyPI and a full list of all the links to docs, issue 
trackers and the like can be found here:


https://github.com/Simplistix/testfixtures

Any questions, please do ask on the Testing in Python list or on the 
Simplistix open source mailing list...


cheers,

Chris
--
https://mail.python.org/mailman/listinfo/python-list


Re: function call questions

2016-10-18 Thread Peter Otten
[email protected] wrote:

> Hi,
> I got a function call as this:
> 
def add_to_tree(root,value_string):
> ...print "root is %s, value_string is %s" % (root, value_string)
> ...for ch in value_string:
> ...  print "ch is %s" % ch
> ...  root = root.setdefault(ch,{})
> ...  print "root is", root
> ...  print "tree is", tree
> ...
 tree={}
 txt='abc'
 add_to_tree(tree,txt)
> root is {}, value_string is abc
> ch is a
> root is {}
> tree is {'a': {}}
> ch is b
> root is {}
> tree is {'a': {'b': {}}}
> ch is c
> root is {}
> tree is {'a': {'b': {'c': {
> 
> My question is:
> (1) why root is always {}?

Because that's what you bind it to in the line

> ...  root = root.setdefault(ch,{})

See 
for a description of the the setdefault() method.

> (2) why tree is {'a': {'b': {'c': {?

Basically the same answer -- you bind root to the innermost dict and that's 
where you insert the ch key on the next iteration of the for loop
.
> (3) why root isn't the same as tree? shouldn't they be the same because
> tree is argument passed as root?

You should know the answer by now ;)

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [FAQ] "Best" GUI toolkit for python

2016-10-18 Thread Mark Summerfield
On Tuesday, October 18, 2016 at 9:04:48 AM UTC+1, pozz wrote:
> Il 18/10/2016 09:42, Mark Summerfield ha scritto:
[snip]
> Why don't you use a GUI design tool?  Better... how can you design a GUI 
> without seeing it?  For me it's very difficult to "code the GUI".

When I started out I used Qt Designer to produce .ui files (XML) and then used 
the Qt uic tool to convert this to C++ (although you can convert to Python 
using pyuic). I then studied the code and learnt from that. And it turns out 
that it isn't very hard. There is QVBoxLayout - widgets one above the other; 
QHBoxLayout; widgets side by side; QGridLayout - widgets in a grid. The only 
complication is when you nest these, say a QVBoxLayout inside a QHBoxLayout 
inside a QGridLayout; but in practice, once you've done it a few times it isn't 
hard to picture. However, I know highly skilled people who prefer to use Qt 
Designer, so it is no big deal either way.

> > Gtk/PyGObject/PyGI
> >
> > Windows is in no way a first class platform for this, so I wouldn't
> > use it. (I wouldn't use it on any other platform either: I think the
> > introspection idea is excellent and wish Qt had done it; but I
> > personally really dislike the direction Gtk has gone in recent
> > years.)
> 
> Could you explain those... "directions" that you don't like?

I'll give you two examples.

Gtk introduced a really useful feature: scrollbar warp. This meant that if you 
clicked the scrollbar you would be taken to that position proportionally in the 
list. This is brilliant for very long lists (e.g., in a huge email folder). 
However, I had to switch the feature off (and that wasn't easy). Why get rid of 
something so useful? Because they put scrollbar warp on the left click. But I 
use applications that are built with Gtk 2, Gtk 3, Qt, Motif, etc., and all 
except for Gtk 3 use left click to scroll down one 'page'. So, depending on the 
underlying toolkit a left click would do different things and this 
inconsistency was too annoying to live with. The solution would have been to 
put scrollbar warp on the right click and left the left click to work like 
every other scrollbar.

If you use many modern Gtk applications they no longer have a menu bar but 
instead a menu button. This is due to the influence of mobile. But for desktop 
users with big screens it now means that to say, open a file, instead of 
clicking File, then Open, you now have to click Menu button, then File, then 
Open. So you need an extra click for *everything* you want to do. Thankfully, 
Firefox allows you to get the menu bar back; but I can't get Evince to do that 
so I had to switch to Okular (these are PDF viewers). I have no problem with 
making things nice for mobile users, but at least either detect a big screen 
and act accordingly, or give the user the choice (as Firefox does although the 
default of no scrollbar on the desktop version still seems wrong to me).

[snip]

Incidentally, I'm not "picking on Gtk"; I could give lots of criticisms of Qt 
and other GUI toolkits too.

I really wish there was a "native" pure Python cross-platform toolkit - and 
people have tried, e.g., 
http://www.cosc.canterbury.ac.nz/greg.ewing/python_gui/ but sadly, none has 
reached the point of being able to replace Tkinter.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: function call questions

2016-10-18 Thread Anssi Saari
[email protected] writes:

> My question is:
> (1) why root is always {}?

Because that's what you wrote. root.setdefault(ch, {}) returns {} and
you assign that to root. You probably want to do just
root.setdefault(ch, {}) instead of root = root.setdefault(ch, {}).

> (2) why tree is {'a': {'b': {'c': {?

That I don't know. Seems odd to me. From some debugging it seems that
after root = root.setdefault(ch,{}) tree['a'] and root are the same
object. So on the second round your code calls
tree['a'].setdefault('b',{}) and on the third round
tree['a'].setdefault('c',{}) which results in {'a': {'b': {'c': { as
the value of tree.

> (3) why root isn't the same as tree? shouldn't they be the same because tree 
> is argument passed as root?

They are the same until you bind root to a new object with root =
root.setdefault(ch,{}).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python-based monads essay part 2

2016-10-18 Thread Chris Angelico
On Fri, Oct 14, 2016 at 9:52 AM, Gregory Ewing
 wrote:
> A bit more on SMFs, and then some I/O.
>
> http://www.cosc.canterbury.ac.nz/greg.ewing/essays/monads/DemystifyingMonads2.html

Finally finished reading this - it's been up in a tab in Chrome for
the past few days.

So here's how I summarize your explanation of monads:

1) Functional programming can describe states and transitions.
2) We can cheat with those by hiding the states and implementing
things imperatively.
3) Once we're already implementing things imperatively, we can do I/O.

If you want to prove to me that monads are still functional, *REVERSE*
your transformation in the original article. You can take your
original set-builder monad and turn it into genuinely functional code;
show me that you can do the same with I/O. Otherwise, what you're
really saying is "we can cheat until we can do I/O", not "we can do
I/O in a functional way".

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: function call questions

2016-10-18 Thread chenyong20000
> > My question is:
> > (1) why root is always {}?
> 
> Because that's what you bind it to in the line
> 
> > ...  root = root.setdefault(ch,{})
> 
> See 
> for a description of the the setdefault() method.

I'm still confused here. root.setdefault(ch,{}) should return {'a':{}}, right? 
then this dictionary is referenced by root by "root = root.setdefault(ch,{})". 
why root is an empty dictionary now?


> 
> > (2) why tree is {'a': {'b': {'c': {?
> 
> Basically the same answer -- you bind root to the innermost dict and that's 
> where you insert the ch key on the next iteration of the for loop
> .
> > (3) why root isn't the same as tree? shouldn't they be the same because
> > tree is argument passed as root?
> 
> You should know the answer by now ;)

In fact i'm still confused by these answers. Could you please described more? 
thanks

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: function call questions

2016-10-18 Thread Peter Otten
[email protected] wrote:

>> > My question is:
>> > (1) why root is always {}?
>> 
>> Because that's what you bind it to in the line
>> 
>> > ...  root = root.setdefault(ch,{})
>> 
>> See 
>> for a description of the the setdefault() method.
> 
> I'm still confused here. root.setdefault(ch,{}) should return {'a':{}},
> right? 

No. Try with something you can recognize (all empty dicts look the same; you 
have to use id() to tell them apart):

>>> d = {1.0: "one"}
>>> d.setdefault(1, "ONE")
'one'
>>> d
{1.0: 'one'}
>>> d.setdefault(2, "TWO")
'TWO'
>>> d
{1.0: 'one', 2: 'TWO'}

setdefault() always returns the value, not the whole dict; if the first 
argument doesn't already exist as a key in the dict the second argument 
becomes the value of the new entry. 

> then this dictionary is referenced by root by "root =
> root.setdefault(ch,{})". why root is an empty dictionary now?
> 
> 
>> 
>> > (2) why tree is {'a': {'b': {'c': {?
>> 
>> Basically the same answer -- you bind root to the innermost dict and
>> that's where you insert the ch key on the next iteration of the for loop
>> .
>> > (3) why root isn't the same as tree? shouldn't they be the same because
>> > tree is argument passed as root?
>> 
>> You should know the answer by now ;)
> 
> In fact i'm still confused by these answers. Could you please described
> more? thanks


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python-based monads essay part 2

2016-10-18 Thread Rustom Mody
On Tuesday, October 18, 2016 at 2:55:07 PM UTC+5:30, Chris Angelico wrote:
> On Fri, Oct 14, 2016 at 9:52 AM, Gregory Ewing wrote:
> > A bit more on SMFs, and then some I/O.
> >
> > http://www.cosc.canterbury.ac.nz/greg.ewing/essays/monads/DemystifyingMonads2.html
> 
> Finally finished reading this - it's been up in a tab in Chrome for
> the past few days.
> 
> So here's how I summarize your explanation of monads:
> 
> 1) Functional programming can describe states and transitions.
> 2) We can cheat with those by hiding the states and implementing
> things imperatively.
> 3) Once we're already implementing things imperatively, we can do I/O.

Seems like a reasonable summary (to me; would like to hear Greg tho')

> 
> If you want to prove to me that monads are still functional, *REVERSE*
> your transformation in the original article. You can take your
> original set-builder monad and turn it into genuinely functional code;
> show me that you can do the same with I/O. Otherwise, what you're
> really saying is "we can cheat until we can do I/O",

Dont understand the 'until'

> not "we can do I/O in a functional way".

Not sure what you mean by 'cheat' and 'functional'
I have a feeling you are assuming a definition of 'functional that is
unusable in practice such as "programming without any effects"

People who actually use FP to do serious work probably need to use a more
nuanced definition such as
- being very explicit about effects (disallowing side-effects is quite 
different from disallowing all effects)
- making sure the effects are well documented
  'Documented' could be quite different: eg in scheme its an informal naming
   convention — names containing a '!' and pronouned SHRIEK are non-functional
   In haskell its more formal: effectful things must have monadic types

One thing probably is correct in what you are saying (if you are saying!):
The IO monad cannot be programmed at the vanilla user/programmer level but must 
be hardwired into the system (for an FPL of course; for python its all demo 
anyway)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python-based monads essay part 2

2016-10-18 Thread Chris Angelico
On Tue, Oct 18, 2016 at 8:56 PM, Rustom Mody  wrote:
> One thing probably is correct in what you are saying (if you are saying!):
> The IO monad cannot be programmed at the vanilla user/programmer level but 
> must
> be hardwired into the system (for an FPL of course; for python its all demo 
> anyway)

That's about right. (And yeah, I'm fine with the Python demos being a
bit forced - it's a lot easier than all of us trying to learn Haskell
syntax. Though I do appreciate the examples of the Haskell
equivalents, where we get to see how clean it looks in actual usage.)

So what that really means is:

1) In actual Haskell code (as opposed to standard library code), there
are certain restrictions, including that your functions must be pure.
2) Standard library code is allowed to play fast and loose with the rules.
3) This makes Haskell actually useful, instead of being an interesting
research project.

For comparison, Python has similar rules:

1) In actual Python code, there are certain restrictions, including
that your object references must be perfectly maintained.
2) Standard library code is allowed to play fast and loose (eg making
weakrefs that don't count as actual references, or releasing the GIL
while doing heavy computation, etc).
3) This makes Python actually perform fast, instead of being a pure
and naive byte-code interpreter.

In each case, I absolutely agree with the third point. There is
nothing wrong with sacrificing a bit of purity in order to gain a ton
of practicality, especially if you can bury the sacrifice away in some
deep corner of the language. However, it is patently false to claim
that all of CPython could be implemented using equivalent Python code;
for instance, you would have no way of ever creating the top-of-tree
loop wherein 'object' is an instance of 'type', and 'type' is a
subclass of 'object'. In the same way, I think, it is patently false
to claim that Haskell is purely functional - but the I/O monads are a
crucial feature in making the language useful.

Just please, stop trying to claim that it's purely functional. It
isn't. It's imperative with functional paint.

(Unless I'm flat wrong in my analysis, of course, in which case I'm
happy to be corrected in my understanding.)

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


How to overlay data points on a static google image?

2016-10-18 Thread Madhavan Bomidi
Hello everyone,

I have been using IDL for making plots until recently and currently 
transitioning to Python programming. I have a task to obtain a static google 
image for my region of interest and then overlay the variable frequency counts 
at different lat-long coordinates. While I have succeeded in plotting the 
frequency counts with lat-lon coordinates without the google static image as 
background. I really don't know how to obtain the google static image for a 
region of interest = (10.0 - 50.0 N, 50.0 - 100.0 E) in Python? How can I 
overlay the data points onto the same?

For an example, I am actually looking for something as shown in the following 
link (for IDL): http://www.idlcoyote.com/ng_tips/mapnogrid.php

Look forward to your help,
With best regards,
Madhavan

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python-based monads essay part 2

2016-10-18 Thread Marko Rauhamaa
Chris Angelico :
> If you want to prove to me that monads are still functional,

Ultimately, monads are simply the pipelining pattern. It is used
extensively in Unix shells. (I don't know Microsoft's PowerShell, but it
used to be called "Monad".)

> Otherwise, what you're really saying is "we can cheat until we can do
> I/O", not "we can do I/O in a functional way".

I guess it's justified as follows: in functional programming, your
program is a function that produces an output out of its input. IOW:

program(input)
=> output

Because of lazy evaluation, the program can start before the input is
prepared and output can be returned gradually before the program
finishes. This principle is analogous to Python's generators:

   def program(input):
   for data in input:
   whenever output is produced:
   yield output

Similarly, a Haskell program can take in lines, keypresses, mouse clicks
etc through its input stream and consume the stream gradually, and
generate lines, sounds, animation etc to its output stream gradually.

That gradual inputting and outputting can be carried out purely
functionally. Consider, for example, the task of finding a zero in an
infinite stream of numbers in Python:

def skip_over_zero(stream, cont):
if stream.head() == 0:
return cont(stream)
return skip_over_zero(stream.tail(), cont)


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python-based monads essay part 2

2016-10-18 Thread Marko Rauhamaa
Chris Angelico :
> I think, it is patently false to claim that Haskell is purely
> functional - but the I/O monads are a crucial feature in making the
> language useful.

As soon as you accept that values can exist in "a superposition," that
is, in a not-yet-fully-materialized form, you can see that functionality
is not broken.

Similarly you can imagine a function that returns the exact decimal
representation of π; the function returns its value, which is printed on
your screen by the REPL. Digits start whizzing by well before the
function has completed its computation.

No side effects needed, but digit ordering is, of course, crucial.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python-based monads essay part 2

2016-10-18 Thread Rustom Mody
On Tuesday, October 18, 2016 at 4:07:53 PM UTC+5:30, Marko Rauhamaa wrote:
> Chris Angelico wrote:
> > If you want to prove to me that monads are still functional,
> 
> Ultimately, monads are simply the pipelining pattern. It is used
> extensively in Unix shells. (I don't know Microsoft's PowerShell, but it
> used to be called "Monad".)
> 
> > Otherwise, what you're really saying is "we can cheat until we can do
> > I/O", not "we can do I/O in a functional way".
> 
> I guess it's justified as follows: in functional programming, your
> program is a function that produces an output out of its input. IOW:
> 
> program(input)
> => output
> 
> Because of lazy evaluation, the program can start before the input is
> prepared and output can be returned gradually before the program
> finishes.

This would be an ok view if 'world' consisted of only stdin/stdout
As it happens it consists of files, filesystems, NICs talking to... uh a
more real and somewhat bigger world

Now we can functionalize all this by making 'the world' as a parameter to our 
functions.
Greg talks of this as do other writings on functional IO
I personally find talking of 'world' as though its an object in my little
world to be a sleight of hand.

OTOH I dont know any better...
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python-based monads essay part 2

2016-10-18 Thread Chris Angelico
On Tue, Oct 18, 2016 at 9:50 PM, Rustom Mody  wrote:
> Now we can functionalize all this by making 'the world' as a parameter to our 
> functions.
> Greg talks of this as do other writings on functional IO
> I personally find talking of 'world' as though its an object in my little
> world to be a sleight of hand.

There is some value in this concept. If you're trying to unit-test
something, you need to be able to pin down all the inputs and outputs
of a piece of code. Thus, when you document that code, you need to
acknowledge that "the world" is one of its inputs - and that unit
testing it requires either access to said world, or a mocked version
of the significant parts of it.

Doesn't magically make the function pure, except in the trivial and
useless sense that mutable globals just count as inputs and outputs,
and thus all functions are pure.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Generator comprehension - list None

2016-10-18 Thread Sayth Renshaw
I was solving a problem to create a generator comprehension with 'Got ' and a 
number for each in range 10.

This I did however I also get a list of None. I don't understand where none 
comes from. Can you please clarify?

a = (print("Got {0}".format(num[0])) for num in enumerate(range(10)))

# for item in a:
#   print(item)

b = list(a)
print(b)

Output
Got 0
Got 1
Got 2
Got 3
Got 4
Got 5
Got 6
Got 7
Got 8
Got 9
[None, None, None, None, None, None, None, None, None, None]
=> None

Thanks

Sayth

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generator comprehension - list None

2016-10-18 Thread Chris Angelico
On Tue, Oct 18, 2016 at 10:43 PM, Sayth Renshaw  wrote:
> I was solving a problem to create a generator comprehension with 'Got ' and a 
> number for each in range 10.
>
> This I did however I also get a list of None. I don't understand where none 
> comes from. Can you please clarify?
>
> a = (print("Got {0}".format(num[0])) for num in enumerate(range(10)))
>

The print function returns None. When you create a comprehension or
generator expression, you're collecting up the values of the
expressions - in this case, the return values from the print calls -
as the end result. If you don't want that, use a regular 'for' loop.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generator comprehension - list None

2016-10-18 Thread Bob Gailer
On Oct 18, 2016 7:45 AM, "Sayth Renshaw"  wrote:
>
> I was solving a problem to create a generator comprehension with 'Got '
and a number for each in range 10.
>
> This I did however I also get a list of None. I don't understand where
none comes from. Can you please clarify?
>
> a = (print("Got {0}".format(num[0])) for num in enumerate(range(10)))
>
The comprehension collects the values of the 10 calls to print(). print()
always returns None.

> # for item in a:
> #   print(item)
>
> b = list(a)
> print(b)
>
> Output
> Got 0
> Got 1
> Got 2
> Got 3
> Got 4
> Got 5
> Got 6
> Got 7
> Got 8
> Got 9
> [None, None, None, None, None, None, None, None, None, None]
> => None
>
> Thanks
>
> Sayth
>
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generator comprehension - list None

2016-10-18 Thread Ben Finney
Sayth Renshaw  writes:

> This I did however I also get a list of None. I don't understand where
> none comes from. Can you please clarify?

Every function in Python, if it returns, returns a value.

In an expression that consists of only a function call, the expression
resolves to the return value from calling that function.

The ‘print’ function's return value is always None.

> a = (print("Got {0}".format(num[0])) for num in enumerate(range(10)))
> b = list(a)
> print(b)

Try this:

a = (None for num in enumerate(range(10)))
b = list(a)
print(b)
print(repr(b))

Now try this:

def always_return_none(dummy):
return None

a = (always_return_none("Got {0}".format(num[0])) for num in 
enumerate(range(10)))
b = list(a)
print(b)
print(repr(b))

Now try this:

c = print("Foo")
print(c)
print(repr(c))

Does that help?

-- 
 \“I knew it was a shocking thing to say, but … no-one has the |
  `\right to spend their life without being offended.” —Philip |
_o__)  Pullman, 2010-03-28 |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generator comprehension - list None

2016-10-18 Thread Steve D'Aprano
On Tue, 18 Oct 2016 10:43 pm, Sayth Renshaw wrote:

> I was solving a problem to create a generator comprehension with 'Got '
> and a number for each in range 10.
> 
> This I did however I also get a list of None. I don't understand where
> none comes from. Can you please clarify?

You get None because print() returns None.

Try this:

result = print("Hello")
result is None


Every time you call print(), it returns None. Normally that just gets thrown
away, and no harm is done, but when you do it in a generator expression,
the None values are collected and returned.

Your code:

a = (print("Got {0}".format(num[0])) for num in enumerate(range(10)))
b = list(a)
print(b)


is equivalent to this:

b = []
for two_numbers in enumerate(range(10)):
num = two_numbers[0]  # pick the first number
message = "Got {0}".format(num)
result = print(message)
b.append(result)

print(b)









-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need help for an assignment plz noob here

2016-10-18 Thread Kaur Männamaa
How exactly did you get the final product if you don't know how to get 
there? I'm sorry but what you are trying to do does not seem fair:)

One hint: for loops

PS generators are actually specific functions in Python: 
http://stackoverflow.com/questions/1756096/understanding-generators-in-python#1756156

However, considering your goal (just one call), you don't need one.

Kaur

18.10.2016 00:44 [email protected] kirjutas:
> Hello guys. so my assignment consists in creating a key generator so i can 
> use it in later steps of my work. In my first step i have to write a function 
> called key_generator that receives an argument, letters, that consists in a 
> tuple of 25 caracters. The function returns a tuple of 5 tuples of caracters, 
> each tuple with 5 elements.
>  Sounds confusing right? well I have the final product but i dont know how to 
> get there. I was told by my professor that I dont really have to use any 
> complicated knowledge of python so I have to keep it simple. Can u help me 
> plz? just give me a hint how to do it and i'll do everything plz.
>
> example:
> Python Shell
>
 letters = (‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’, \
> ... ‘H’, ‘I’, ‘J’, ‘ ’, ‘L’, ‘M’, ‘N’, \
> ... ‘O’, ‘P’, ‘Q’, ‘R’, ‘S’, ‘T’, ‘U’, \
> ... ‘V’, ‘X’, ‘Z’, ‘.’)
 key_generator(letters)
> ... ((‘A’, ‘B’, ‘C’, ‘D’, ‘E’),
> ... (‘F’, ‘G’, ‘H’, ‘I’, ‘J’),
> ... (‘ ’, ‘L’, ‘M’, ‘N’, ‘O’),
> ... (‘P’, ‘Q’, ‘R’, ‘S’, ‘T’),
> ... (‘U’, ‘V’, ‘X’, ‘Z’, ‘.’))
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generator comprehension - list None

2016-10-18 Thread Jon Ribbens
On 2016-10-18, Steve D'Aprano  wrote:
> On Tue, 18 Oct 2016 10:43 pm, Sayth Renshaw wrote:
>> I was solving a problem to create a generator comprehension with 'Got '
>> and a number for each in range 10.
>> 
>> This I did however I also get a list of None. I don't understand where
>> none comes from. Can you please clarify?
>
> You get None because print() returns None.
>
> Try this:
>
> result = print("Hello")
> result is None
>
>
> Every time you call print(), it returns None. Normally that just gets thrown
> away, and no harm is done, but when you do it in a generator expression,
> the None values are collected and returned.
>
> Your code:
>
> a = (print("Got {0}".format(num[0])) for num in enumerate(range(10)))
> b = list(a)
> print(b)
>
>
> is equivalent to this:
>
> b = []
> for two_numbers in enumerate(range(10)):
> num = two_numbers[0]  # pick the first number
> message = "Got {0}".format(num)
> result = print(message)
> b.append(result)
>
> print(b)

I must admit I find the idea of enumerate(range(n)) quite pleasing.
gotta keep track of which numbers those numbers are!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generator comprehension - list None

2016-10-18 Thread Chris Angelico
On Tue, Oct 18, 2016 at 11:57 PM, Jon Ribbens  wrote:
> I must admit I find the idea of enumerate(range(n)) quite pleasing.
> gotta keep track of which numbers those numbers are!

Heh! I'm assuming that's a placeholder for
enumerate(some_other_iterable), where the actual iterable in question
isn't particularly interesting to the question. But it is funny.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Generator comprehension - list None

2016-10-18 Thread Sayth Renshaw

Thank you quite easy, was trying to work around it in the generator, the print 
needs to be outside the generator to avoid the collection of "None".

Wasn't really liking comprehensions though python 3 dict comprehensions are a 
really nice utility.

Sayth
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: need help for an assignment plz noob here

2016-10-18 Thread Sayth Renshaw

> 
> > Hello guys. so my assignment consists in creating a key generator so i can 
> > use it in later steps of my work. In my first step i have to write a 
> > function called key_generator that receives an argument, letters, that 
> > consists in a tuple of 25 caracters. The function returns a tuple of 5 
> > tuples of caracters, each tuple with 5 elements.
> >  Sounds confusing right? well I have the final product but i dont know how 
> > to get there. I was told by my professor that I dont really have to use any 
> > complicated knowledge of python so I have to keep it simple. Can u help me 
> > plz? just give me a hint how to do it and i'll do everything plz.
> >
> > example:
> > Python Shell
> >
>  letters = (‘A’, ‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’, \
> > ... ‘H’, ‘I’, ‘J’, ‘ ’, ‘L’, ‘M’, ‘N’, \
> > ... ‘O’, ‘P’, ‘Q’, ‘R’, ‘S’, ‘T’, ‘U’, \
> > ... ‘V’, ‘X’, ‘Z’, ‘.’)
>  key_generator(letters)
> > ... ((‘A’, ‘B’, ‘C’, ‘D’, ‘E’),
> > ... (‘F’, ‘G’, ‘H’, ‘I’, ‘J’),
> > ... (‘ ’, ‘L’, ‘M’, ‘N’, ‘O’),
> > ... (‘P’, ‘Q’, ‘R’, ‘S’, ‘T’),
> > ... (‘U’, ‘V’, ‘X’, ‘Z’, ‘.’))
> 
> Start by playing with letters in the shell and seeing what you can do
> with it.  The word you're looking for is 'slices'.  Figure out
> interactively what you need to do, then write it up.

I would a assume a key generator to be random so this may help.
http://stackoverflow.com/a/306417

Also about tuples
http://openbookproject.net/thinkcs/python/english3e/tuples.html

* from the link
Of course, even if we can’t modify the elements of a tuple, we can always make 
the julia variable reference a new tuple holding different information. To 
construct the new tuple, it is convenient that we can slice parts of the old 
tuple and join up the bits to make the new tuple. So if julia has a new recent 
film, we could change her variable to reference a new tuple that used some 
information from the old one:

>>> julia = julia[:3] + ("Eat Pray Love", 2010) + julia[5:]
>>> julia
("Julia", "Roberts", 1967, "Eat Pray Love", 2010, "Actress", "Atlanta, Georgia")

Sayth
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Meta classes - real example

2016-10-18 Thread Ethan Furman

On 10/17/2016 11:44 PM, Mr. Wrobel wrote:


Ok,so in general, we could say that using Metclasses is ok for manipulating 
__new__ but not that what is setting by __init__. Am I right?


No and yes.

In this code (python 2 syntax):

#untested
class Wonderful(object):

__metaclass__ = SomeMetaClass

diamond = Sparkly(7)

club = 9

def display(self):
print "I'm an instance!"

The metaclass controls what happens when Wonderful is created:

- it can add the name 'diamond' to the Sparkly descriptor;
-  it can change/remove/add other attributes such as club, spade, or whatever;
- it can wrap methods such as display to pre- or post-process calls to it
- etc.

Once the class (Wonderful, in this example) has been created:

- x = Wonderful()  # metaclass not called
- x.display()  # metaclass not called
- x.diamond# metaclass not called

- list(Wonderful)  # metaclass called (e.g. SomeMetaClass.__iter__(cls) )
   # where cls = Wonderful


Check out http://stackoverflow.com/a/35730545/208880 for a simple demonstration 
of a metaclass.

--
~Ethan~
--
https://mail.python.org/mailman/listinfo/python-list


Re: New to python

2016-10-18 Thread Chris Warrick
On 17 October 2016 at 21:51, Bill Cunningham  wrote:
> I just installed python I might start with 3. But there is version 2 out
> too. So far I can '3+4' and get the answer. Nice. I typed the linux man page
> and got a little info. So to learn this language is there an online
> tutorial? I am interested in the scripting too.
>
> Bill

Learn Python 3. Good resources (that I can actually vouch for being
good…) include:

https://docs.python.org/3/tutorial/index.html (if you can already program)
http://greenteapress.com/wp/think-python/
https://automatetheboringstuff.com/

-- 
Chris Warrick 
PGP: 5EAAEA16
-- 
https://mail.python.org/mailman/listinfo/python-list


Inplace shuffle function returns none

2016-10-18 Thread Sayth Renshaw
If shuffle is an "in place" function and returns none how do i obtain the 
values from it.

from random import shuffle

a = [1,2,3,4,5]
b = shuffle(a)
print(b[:3])

For example here i just want to slice the first 3 numbers which should be 
shuffled. However you can't slice a noneType object that b becomes.

So how do i get shuffle to give me my numbers?

Cheers

Sayth 


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Inplace shuffle function returns none

2016-10-18 Thread Chris Angelico
On Wed, Oct 19, 2016 at 1:48 AM, Sayth Renshaw  wrote:
> If shuffle is an "in place" function and returns none how do i obtain the 
> values from it.
>
> from random import shuffle
>
> a = [1,2,3,4,5]
> b = shuffle(a)
> print(b[:3])
>
> For example here i just want to slice the first 3 numbers which should be 
> shuffled. However you can't slice a noneType object that b becomes.
>
> So how do i get shuffle to give me my numbers?
>

In place means that it changes the list. Try print(a) after the shuffle.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Inplace shuffle function returns none

2016-10-18 Thread John Gordon
In  Sayth Renshaw 
 writes:

> If shuffle is an "in place" function and returns none how do i obtain
> the values from it.

The values are still in the original object -- variable "a" in your example.

> from random import shuffle

> a = [1,2,3,4,5]
> b = shuffle(a)
> print(b[:3])

> For example here i just want to slice the first 3 numbers which should
> be shuffled. However you can't slice a noneType object that b becomes.

> So how do i get shuffle to give me my numbers?

a = [1,2,3,4,5]
shuffle(a)
print(a[:3])

-- 
John Gordon   A is for Amy, who fell down the stairs
[email protected]  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [FAQ] "Best" GUI toolkit for python

2016-10-18 Thread Michael Torrie
On 10/18/2016 02:33 AM, Mark Summerfield wrote:
> When I started out I used Qt Designer to produce .ui files (XML) and
> then used the Qt uic tool to convert this to C++ (although you can
> convert to Python using pyuic). I then studied the code and learnt
> from that. And it turns out that it isn't very hard. There is
> QVBoxLayout - widgets one above the other; QHBoxLayout; widgets side
> by side; QGridLayout - widgets in a grid. The only complication is
> when you nest these, say a QVBoxLayout inside a QHBoxLayout inside a
> QGridLayout; but in practice, once you've done it a few times it
> isn't hard to picture. However, I know highly skilled people who
> prefer to use Qt Designer, so it is no big deal either way.

I am certainly not highly skilled. But I definitely do use the Designer
for everything related to the GUI.  I don't, however, use uic or pyuic.
What I recommend these days is to use the xml .ui file directly in your
program to create the objects for you.  In C++ with an EXE, you can
incorporate the .ui file into the executable as a resource.  In Python,
I would just bundle it with all the other resources I might be using.
For custom widgets I either build a simple plugin for Designer that lets
me use the widgets as any other in the visual layout.  Alternatively,
I'll just change the class type in properties.

The way you use the .ui file loader is to create a class in Python,
usually for each window or dialog, and subclass it from the appropriate
Qt type such as QDialog.  Then in the __init__() method, you call
PyQt.uic.loadUi and it brings all the widgets in and initializes them
and adds them to the QDialog you are defining. And if you follow the
naming scheme for your callbacks of on_widgetname_signalName(), it will
auto connect them. For example, if my button was called "myButton", I
could name a slot to be on_myButton_clicked() and it would connect
automatically.  PySides allows something similar with QUiLoader. I use a
wrapper class that Sebastion Wiesner wrote to make it closer to a
one-liner wrapper function like PyQt offers.

I agree with you about making GUIs programmatically being not hard,
especially when one is learning.  When I first started using Qt, coming
from GTK, I had to get used to a similar but different boxing model.  In
GTK, when packing widgets you specify both the expansion and spacing
while packing.  In Qt, you have explicit spacers to insert into the
boxes.  I'm not sure which method is better.

> If you use many modern Gtk applications they no longer have a menu
> bar but instead a menu button. This is due to the influence of
> mobile. But for desktop users with big screens it now means that to
> say, open a file, instead of clicking File, then Open, you now have
> to click Menu button, then File, then Open. So you need an extra
> click for *everything* you want to do. Thankfully, Firefox allows you
> to get the menu bar back; but I can't get Evince to do that so I had
> to switch to Okular (these are PDF viewers). I have no problem with
> making things nice for mobile users, but at least either detect a big
> screen and act accordingly, or give the user the choice (as Firefox
> does although the default of no scrollbar on the desktop version
> still seems wrong to me).

Correction. You are talking about Gnome applications that follow the
Gnome UI guidelines, not necessarily GTK applications.  And you as a
programmer are not forced to use the HeaderBar and make your application
look like a Gnome application.  And don't confuse Firefox's
Chromification with anything that has to do with GTK.  GTK is used very
little in Firefox; Firefox does its own widgets, event-handling, etc.

GTK still very much offers the foundation for traditional applications,
thank goodness.  The Mate Desktop is porting many of the traditional
Gnome 2 apps to GTK 3 and the look and feel about the same as they
always have.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [FAQ] "Best" GUI toolkit for python

2016-10-18 Thread Michael Torrie
On 10/18/2016 01:16 AM, pozz wrote:
>> I am also learning Python so my experience is limited.  I have
>> tried pyGTK and Tkinter.  GTK's concept of the hbox and vbox
>> gave me of difficulty.  I couldn't get the GUI to look the way
>> I wanted.
> 
> Yes, it's exactly my situation.  I understand boxes give a lot of 
> flexibility, but for simple GUI they are very complex.
> Did you try Glade GUI builder applcation?

Using hbox, vbox, and tables within Glade should give you a good idea
how they work and how to use them I think. They are not complex, even
for simple GUIs.  Get familiar with how the various packing flags work
(expand, fill, pack type).  And you feel free to use several kinds of
nested packing managers. It's not uncommon to have an hbox inside of a
vbox inside of an hbox, for example.

>> OTOH, Tkinter offers a way to place widgets on a
>> window/frame in a precise way:  self.widget.place(x=#, y=#)
>> That is similar to VB's move statement.  GTK may have such a
>> feature but I was not able to find it.
> 
> Yes, it seems GTK has a similar feature.  It is the container GtkFixed 
> (https://developer.gnome.org/gtk3/stable/GtkFixed.html).
> 
>The GtkFixed widget is a container which can place child
>widgets at fixed positions and with fixed sizes, given in
>pixels. GtkFixed performs no automatic layout management.
> 
> At the moment, I didn't tested GtkFixed yet, but it seems very simple to 
> use. I hope Glade gives a good support for it.

Glade does support the use of GtkFixed, but I highly recommend avoiding
the temptation to use it. It's there because there are the occasional
cases where you need pixel-perfect placing, but you should never use it
for general GUI use.  Why would you want your GUI to not be able to
resize or adapt to HiDPI screens?  I think Visual Studio and Windows did
us all a huge disfavor promoting fixed layouts.  There's simply no need
for them.  I've yet to see a layout that didn't work with a combination
of vboxes, hboxes, and table layouts. If you posted a fixed layout, I
would be willing to show you how to do it with a dynamic layout.

-- 
https://mail.python.org/mailman/listinfo/python-list


QPython ?

2016-10-18 Thread Askfor
What is te status of QPython on Android. I managed to run some scripts 
directly on the phone. Found some examples in Ferrill Paul's book which 
is about SL4A. They worked after some editing and looking into very few 
examples which came with installation. I even manage to develop some 
scripts of my own.


Does QPthon depend on SL4A ? Because SL4A seems to be dead. There seem 
to be no serious manual or documentation available.


I know about Kivy and got it installed. Just wondering about QPython.
--
https://mail.python.org/mailman/listinfo/python-list


Re: [FAQ] "Best" GUI toolkit for python

2016-10-18 Thread pozz

Il 18/10/2016 16:56, Michael Torrie ha scritto:

On 10/18/2016 02:33 AM, Mark Summerfield wrote:

When I started out I used Qt Designer to produce .ui files (XML) and
then used the Qt uic tool to convert this to C++ (although you can
convert to Python using pyuic). I then studied the code and learnt
from that. And it turns out that it isn't very hard. There is
QVBoxLayout - widgets one above the other; QHBoxLayout; widgets side
by side; QGridLayout - widgets in a grid. The only complication is
when you nest these, say a QVBoxLayout inside a QHBoxLayout inside a
QGridLayout; but in practice, once you've done it a few times it
isn't hard to picture. However, I know highly skilled people who
prefer to use Qt Designer, so it is no big deal either way.


I am certainly not highly skilled. But I definitely do use the Designer
for everything related to the GUI.  I don't, however, use uic or pyuic.
What I recommend these days is to use the xml .ui file directly in your
program to create the objects for you.  In C++ with an EXE, you can
incorporate the .ui file into the executable as a resource.  In Python,
I would just bundle it with all the other resources I might be using.
For custom widgets I either build a simple plugin for Designer that lets
me use the widgets as any other in the visual layout.  Alternatively,
I'll just change the class type in properties.

The way you use the .ui file loader is to create a class in Python,
usually for each window or dialog, and subclass it from the appropriate
Qt type such as QDialog.  Then in the __init__() method, you call
PyQt.uic.loadUi and it brings all the widgets in and initializes them
and adds them to the QDialog you are defining. And if you follow the
naming scheme for your callbacks of on_widgetname_signalName(), it will
auto connect them. For example, if my button was called "myButton", I
could name a slot to be on_myButton_clicked() and it would connect
automatically.  PySides allows something similar with QUiLoader. I use a
wrapper class that Sebastion Wiesner wrote to make it closer to a
one-liner wrapper function like PyQt offers.


What are the differences between PySides and PyQt... apart the licence?
Is PySides usable as PyQt?



I agree with you about making GUIs programmatically being not hard,
especially when one is learning.  When I first started using Qt, coming
from GTK, I had to get used to a similar but different boxing model.  In
GTK, when packing widgets you specify both the expansion and spacing
while packing.  In Qt, you have explicit spacers to insert into the
boxes.  I'm not sure which method is better.


So you have some experience on GTK and QT.  Could you spend some time to 
describe a few differences? What do you like with Gtk and what you 
don't? And for Qt?


When you worked with Gtk, have you used Glade as GUI Builder? Could you 
compare Glade and QT Designer?


--
https://mail.python.org/mailman/listinfo/python-list


Re: cannot import name pyhop

2016-10-18 Thread Gipper
On Friday, October 14, 2016 at 1:05:03 PM UTC-5, Irmen de Jong wrote:
> On 14-10-2016 7:31, Gipper wrote:
> > I'm trying to run a script that calls pyhop (from pyhop import pyhop).  
> > Details here > https://docs.extrahop.com/5.0/extrahop-python-api/#metrics
> > 
> > I've followed the directions to install and import pyhop, but no matter 
> > what I do, I always get the following error when running a script that 
> > calls pyhop >
> > 
> > Traceback (most recent call last):
> >   File "Migration.py", line 1, in 
> > from pyhop import pyhop
> > ImportError: cannot import name pyhop
> > 
> > Any ideas where I'm going wrong?  
> > 
> 
> What does:
> 
> import pyhop
> print(pyhop.__file__)
> 
> tell you?
> 
> -Irmen


C:\Python27\Lib\site-packages\pyhop\__init__.pyc
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [FAQ] "Best" GUI toolkit for python

2016-10-18 Thread Michael Torrie
On 10/18/2016 10:01 AM, pozz wrote:
> What are the differences between PySides and PyQt... apart the licence?
> Is PySides usable as PyQt?

PySide aims to be pretty close to PyQt. Both of them wrap the C++ api,
so class names and method calls should be identical.  There are some
differences though. PyQt provides a number of python wrappers around
some functionality, (prefixed with pyqt such as pyqtSignal, pyqtSlot,
etc), whereas in PySide would call them just Signal or Slot.  And due to
how PySide generates the bindings, there are occasional bugs that aren't
present in PyQt but can be worked around.  For example,
https://bugreports.qt.io/browse/PYSIDE-79.

PyQt is more mature than PySide, and already supports Qt5, whereas
PySide's support for Qt5 is still in beta as far as I know.  For my
purposes, PySide is as usable as PyQt.  In my latest project I've tried
to keep my code compatible with both PyQt4 and PySide (mainly a matter
of changing some imports).  That said, there's little reason to use
PySide over PyQt if the license for PyQt meets your needs.

> So you have some experience on GTK and QT.  Could you spend some time to 
> describe a few differences? What do you like with Gtk and what you 
> don't? And for Qt?

I do have some experience in both, and in Python.  Lately I've been
using Qt (PySide) since I need to have my project work on Windows and
maybe Mac.  GTK's support for both of those platforms is not so great in
my opinion.

As for differences, well I find that the Python wrappers around Qt are
quite thin and a lot of C++-ims leak up into your Python code. For
example, there are various structures used to wrap up values for passing
things around including QVariant, QPoint, QRect, etc.  In Python there's
less of a need for such wrappers but you have to use them in Qt.  In
some cases the wrapper will convert to a standard Python type like a
list or python string.  But in general you'll find PyQt code feels and
looks a lot like C++ code but in Python, except that MOC stuff is
replaced with decorators (yay!).  I also really find PySide and PyQt's
use of camelCase to be rather ugly (but that's the way Qt is).

Even now I kind of like GTK better than Qt. Not totally sure why. Just
feels a bit better to me.  And the Python bindings for it seem more
pythonic. And it helps that GTK natively uses PEP8-style names for
methods, so the wrappers look more pythonic to me.  As mentioned, GTK
support for Windows and Mac lags behind Linux/X11 or Linux/Wayland and
GTK apps don't feel quite as native there as Qt apps do.  That said, on
Linux I always prefer the look of Gtk apps to Qt apps.

> When you worked with Gtk, have you used Glade as GUI Builder? Could you 
> compare Glade and QT Designer?

Glade is very similar to Qt Designer.  They both do the job and do it in
similar ways.  Designer is probably more polished and mature.  the
"glade-3" command invokes glade for GTK 2.x, and just "glade" invokes
glade for GTK 3. They are separate programs and packages and that can be
very confusing especially when glade-3 is something like version 3.8 and
glade is something like 3.20 (tracks GTK3's version).

And I recommend using the GtkBuilder class to load the Glade xml files
into your app rather than use a code generator.

Your best bet is to create a simple dialog box in both toolkits, set up
signals and slots, and see which one you like best.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [FAQ] "Best" GUI toolkit for python

2016-10-18 Thread Demosthenes Koptsis

My favorite GUIs are PyQt and wxPython.

I prefer PyQt than PySide because PySide seem to me like an abandoned 
project.


Also i prefer PyQt than wxPython because i can design the forms in 
QtDesigner easily.


wxPython and wxWidgets do not have a GUI designer competitor to QtDesigner.

So, my choice is PyQt !


On 10/18/2016 07:01 PM, pozz wrote:

Il 18/10/2016 16:56, Michael Torrie ha scritto:

On 10/18/2016 02:33 AM, Mark Summerfield wrote:

When I started out I used Qt Designer to produce .ui files (XML) and
then used the Qt uic tool to convert this to C++ (although you can
convert to Python using pyuic). I then studied the code and learnt
from that. And it turns out that it isn't very hard. There is
QVBoxLayout - widgets one above the other; QHBoxLayout; widgets side
by side; QGridLayout - widgets in a grid. The only complication is
when you nest these, say a QVBoxLayout inside a QHBoxLayout inside a
QGridLayout; but in practice, once you've done it a few times it
isn't hard to picture. However, I know highly skilled people who
prefer to use Qt Designer, so it is no big deal either way.


I am certainly not highly skilled. But I definitely do use the Designer
for everything related to the GUI.  I don't, however, use uic or pyuic.
What I recommend these days is to use the xml .ui file directly in your
program to create the objects for you.  In C++ with an EXE, you can
incorporate the .ui file into the executable as a resource.  In Python,
I would just bundle it with all the other resources I might be using.
For custom widgets I either build a simple plugin for Designer that lets
me use the widgets as any other in the visual layout. Alternatively,
I'll just change the class type in properties.

The way you use the .ui file loader is to create a class in Python,
usually for each window or dialog, and subclass it from the appropriate
Qt type such as QDialog.  Then in the __init__() method, you call
PyQt.uic.loadUi and it brings all the widgets in and initializes them
and adds them to the QDialog you are defining. And if you follow the
naming scheme for your callbacks of on_widgetname_signalName(), it will
auto connect them. For example, if my button was called "myButton", I
could name a slot to be on_myButton_clicked() and it would connect
automatically.  PySides allows something similar with QUiLoader. I use a
wrapper class that Sebastion Wiesner wrote to make it closer to a
one-liner wrapper function like PyQt offers.


What are the differences between PySides and PyQt... apart the licence?
Is PySides usable as PyQt?



I agree with you about making GUIs programmatically being not hard,
especially when one is learning.  When I first started using Qt, coming
from GTK, I had to get used to a similar but different boxing model.  In
GTK, when packing widgets you specify both the expansion and spacing
while packing.  In Qt, you have explicit spacers to insert into the
boxes.  I'm not sure which method is better.


So you have some experience on GTK and QT.  Could you spend some time 
to describe a few differences? What do you like with Gtk and what you 
don't? And for Qt?


When you worked with Gtk, have you used Glade as GUI Builder? Could 
you compare Glade and QT Designer?




--
https://mail.python.org/mailman/listinfo/python-list


Re: Inplace shuffle function returns none

2016-10-18 Thread Sayth Renshaw
So why can't i assign the result slice to a variable b?

It just keeps getting none. 

Sayth
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [FAQ] "Best" GUI toolkit for python

2016-10-18 Thread Adam M
If my dusty memory is not wrong they were two projects aiming for GUI designer 
for wx: wxGlade (with option to generate code for Python) and Boa Contructor. I 
have no idea however if they are still available or working with newer wx.

I prefer for simple stuff Tk for something more sophisticated Qt (PySide or 
PyQt)

On Tuesday, October 18, 2016 at 4:09:46 PM UTC-4, Demosthenes Koptsis wrote:
> My favorite GUIs are PyQt and wxPython.
> 
> I prefer PyQt than PySide because PySide seem to me like an abandoned 
> project.
> 
> Also i prefer PyQt than wxPython because i can design the forms in 
> QtDesigner easily.
> 
> wxPython and wxWidgets do not have a GUI designer competitor to QtDesigner.
> 
> So, my choice is PyQt !
> 
> 
> On 10/18/2016 07:01 PM, pozz wrote:
> > Il 18/10/2016 16:56, Michael Torrie ha scritto:
> >> On 10/18/2016 02:33 AM, Mark Summerfield wrote:
> >>> When I started out I used Qt Designer to produce .ui files (XML) and
> >>> then used the Qt uic tool to convert this to C++ (although you can
> >>> convert to Python using pyuic). I then studied the code and learnt
> >>> from that. And it turns out that it isn't very hard. There is
> >>> QVBoxLayout - widgets one above the other; QHBoxLayout; widgets side
> >>> by side; QGridLayout - widgets in a grid. The only complication is
> >>> when you nest these, say a QVBoxLayout inside a QHBoxLayout inside a
> >>> QGridLayout; but in practice, once you've done it a few times it
> >>> isn't hard to picture. However, I know highly skilled people who
> >>> prefer to use Qt Designer, so it is no big deal either way.
> >>
> >> I am certainly not highly skilled. But I definitely do use the Designer
> >> for everything related to the GUI.  I don't, however, use uic or pyuic.
> >> What I recommend these days is to use the xml .ui file directly in your
> >> program to create the objects for you.  In C++ with an EXE, you can
> >> incorporate the .ui file into the executable as a resource.  In Python,
> >> I would just bundle it with all the other resources I might be using.
> >> For custom widgets I either build a simple plugin for Designer that lets
> >> me use the widgets as any other in the visual layout. Alternatively,
> >> I'll just change the class type in properties.
> >>
> >> The way you use the .ui file loader is to create a class in Python,
> >> usually for each window or dialog, and subclass it from the appropriate
> >> Qt type such as QDialog.  Then in the __init__() method, you call
> >> PyQt.uic.loadUi and it brings all the widgets in and initializes them
> >> and adds them to the QDialog you are defining. And if you follow the
> >> naming scheme for your callbacks of on_widgetname_signalName(), it will
> >> auto connect them. For example, if my button was called "myButton", I
> >> could name a slot to be on_myButton_clicked() and it would connect
> >> automatically.  PySides allows something similar with QUiLoader. I use a
> >> wrapper class that Sebastion Wiesner wrote to make it closer to a
> >> one-liner wrapper function like PyQt offers.
> >
> > What are the differences between PySides and PyQt... apart the licence?
> > Is PySides usable as PyQt?
> >
> >
> >> I agree with you about making GUIs programmatically being not hard,
> >> especially when one is learning.  When I first started using Qt, coming
> >> from GTK, I had to get used to a similar but different boxing model.  In
> >> GTK, when packing widgets you specify both the expansion and spacing
> >> while packing.  In Qt, you have explicit spacers to insert into the
> >> boxes.  I'm not sure which method is better.
> >
> > So you have some experience on GTK and QT.  Could you spend some time 
> > to describe a few differences? What do you like with Gtk and what you 
> > don't? And for Qt?
> >
> > When you worked with Gtk, have you used Glade as GUI Builder? Could 
> > you compare Glade and QT Designer?
> >

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Inplace shuffle function returns none

2016-10-18 Thread Ian Kelly
On Tue, Oct 18, 2016 at 2:25 PM, Sayth Renshaw  wrote:
> So why can't i assign the result slice to a variable b?
>
> It just keeps getting none.

Because shuffle returns none. If you want to keep both the original
list and the shuffled list, then do something like:

b = a[:]
shuffle(b)
print(a)
print(b)

Copy it first, then shuffle it.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [FAQ] "Best" GUI toolkit for python

2016-10-18 Thread Dietmar Schwertberger

On 18.10.2016 00:58, pozz wrote:
So I'm thinking to evaluate other solutions. wxWidgets is attractive 
for it's native look&feel, but python implementation Phoenix for 
Python3 is in alpha stage. Moreover wxGlade (the GUI builder 
application) needs Python2, but I couldn't understand if the generated 
code is compatible with wxPython/Phoenix.

I can recommend wx.
I have been using wxPython for more than 15 years and Phoenix for about 
one year now.
Phoenix has been working quite stable for me. It's not released yet 
finally, but there's much work going on to make a release happen.


For learning:
 - get the book "wxPython in Action"
 - download the snapshot, including the html documentation and source 
archive from https://wxpython.org/Phoenix/snapshot-builds/
 - bookmark the comparison at 
https://wxpython.org/Phoenix/docs/html/classic_vs_phoenix.html
 - unpack the demo directory from the source archive and run demo.py; 
maybe also have a look at the samples directory
 - also download the chm file from 
https://github.com/wxWidgets/wxWidgets/releases/download/v3.0.2/wxWidgets-3.0.2-docs-chm.zip
   (you may prefer the single file chm documentation, even though it's 
for C++; for a start look at Categories -> Class List by Category -> 
Controls / Window Layout / Events / Managed Windows / Miscellaneous 
Windows / Common Dialogs)


The demo is the most important resource for learning!


In the last months I spent a lot of time to make wxGlade more usable and 
maintainable.
It runs already under Phoenix. Just use the DEV_DS_2016 branch from the 
repository (it can be downloaded as zip from 
https://bitbucket.org/wxglade/wxglade/downloads?tab=branches )
When wxGlade runs under Phoenix, the generated code should be Phoenix 
compatible.
This version is not yet released and also the Phoenix support is not yet 
official. It should fit your purpose, though and it's probably the 
easiest option to get started with a Python GUI. Please provide bug 
reports and also general feedback about potential improvements.
For 100% Phoenix support I need to modify a lot under the hood, but I 
hope to have it done not too late after a wxPython Phoenix release.
A better menu editor, better integration with custom code and a new 
tutorial are on the todo list. Contributions are welcome. Just as you 
seem to do, I also see the old Visual BASIC versions as reference when 
it comes to creating a GUI without much learning and effort.
The current wxGlade tutorial does not yet reflect the fact that you can 
now edit the structure directly in the tree view.



Regards,

Dietmar

--
https://mail.python.org/mailman/listinfo/python-list


Re: Inplace shuffle function returns none

2016-10-18 Thread breamoreboy
On Tuesday, October 18, 2016 at 9:25:19 PM UTC+1, Sayth Renshaw wrote:
> So why can't i assign the result slice to a variable b?
> 
> It just keeps getting none. 
> 
> Sayth

You are misunderstanding something that is fundamental in Python, namely that 
anything that is done inplace *ALWAYS* returns None as a warning that the 
operation has been done inplace, so you're never going to get anything back.  
All you need do is change your original code as follows:-

from random import shuffle

a = [1,2,3,4,5]
shuffle(a)
b = a[:3]
print(b)

Kindest regards.

Mark Lawrence.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [FAQ] "Best" GUI toolkit for python

2016-10-18 Thread pozz

Il 18/10/2016 18:41, Demosthenes Koptsis ha scritto:
> My favorite GUIs are PyQt and wxPython.
>
> I prefer PyQt than PySide because PySide seem to me like an abandoned
> project.
>
> Also i prefer PyQt than wxPython because i can design the forms in
> QtDesigner easily.
>
> wxPython and wxWidgets do not have a GUI designer competitor to 
QtDesigner.

>
> So, my choice is PyQt !

Have you compared pyQt with pyGObject (GTK)?

--
https://mail.python.org/mailman/listinfo/python-list


Re: Inplace shuffle function returns none

2016-10-18 Thread John Gordon
In <[email protected]> Sayth Renshaw 
 writes:

> So why can't i assign the result slice to a variable b?

Because shuffle() modifies the list directly, and returns None.
It does NOT return the shuffled list.

-- 
John Gordon   A is for Amy, who fell down the stairs
[email protected]  B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python-based monads essay part 2

2016-10-18 Thread Gregory Ewing

Chris Angelico wrote:

You can take your
original set-builder monad and turn it into genuinely functional code;
show me that you can do the same with I/O. Otherwise, what you're
really saying is "we can cheat until we can do I/O", not "we can do
I/O in a functional way".


I don't think I'm saying either of those things.

What I'm saying is, monads provide a way of reasoning
algebraically about sequential programs.

The things being reasoned about -- the actions -- are
not themselves functions, but that doesn't mean there's
any cheating going on. Would you say it was cheating
to perform algebraic manipulations on an expression
involving numbers or strings? Why should it be any
different when the things being manipulated represent
actions that affect the world?

I may not have brought this point out as clearly as
I could have in the essay. Looking back, I can see
that the phrase "perform I/O in a functional way" is
open to misinterpretation. I didn't mean to say that
we can write a function (in the mathematical sense)
that performs I/O, only that we can apply functional
techniques if we represent I/O in a particular way.

If you still want to call that "cheating" I can't
stop you, but I think you're directing your scorn at
an imagined claim that functional programmers are not
actually making. In so doing you risk missing potential
benefits of what they actually are claiming.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: cannot import name pyhop

2016-10-18 Thread Irmen de Jong
On 18-10-2016 19:14, Gipper wrote:
> On Friday, October 14, 2016 at 1:05:03 PM UTC-5, Irmen de Jong wrote:
>> On 14-10-2016 7:31, Gipper wrote:
>>> I'm trying to run a script that calls pyhop (from pyhop import pyhop).  
>>> Details here > https://docs.extrahop.com/5.0/extrahop-python-api/#metrics
>>>
>>> I've followed the directions to install and import pyhop, but no matter 
>>> what I do, I always get the following error when running a script that 
>>> calls pyhop >
>>>
>>> Traceback (most recent call last):
>>>   File "Migration.py", line 1, in 
>>> from pyhop import pyhop
>>> ImportError: cannot import name pyhop
>>>
>>> Any ideas where I'm going wrong?  
>>>
>>
>> What does:
>>
>> import pyhop
>> print(pyhop.__file__)
>>
>> tell you?
>>
>> -Irmen
> 
> 
> C:\Python27\Lib\site-packages\pyhop\__init__.pyc

   ^^^
Are you sure it says .pyc? That looks weird to me, usually you get a .py file 
here.
It seems the installation of the module didn't go as it should have.
Have a look in your C:\Python27\Lib\site-packages\pyhop\ directory to get a 
clue why
there's no 'pyhop' symbol made available.  Is there a pyhop.py[c] there? Is 
there even a
readable __init__.py in there that you can study to see why there's no 'pyhop' 
symbol in
there?


Irmen

-- 
https://mail.python.org/mailman/listinfo/python-list


Python | Data Science : Become a Data Scientist with Huge Employment Opportunities

2016-10-18 Thread Jayanth Nair
This course will help you to expertise the usage of Python in Data Science 
world.


Why should you take this Training Course?

Data Science skills are in huge demand with enterprises ready to pay big 
salaries to the right candidates with in-depth expertise. Python is a 
general-purpose programming language that can be used extensively in the Big 
Data domain. This Combo Course will help you understand the versatility of 
Python and provide extensive learning in the Python Libraries and tools to work 
in Big Data analytics. Getting your dream job in the Data Science domain is 
easier with this Training Course.

What you will learn in this Training Course?

Learn the concepts of Python and Data Science
Understand data discovery using Python
Analytical and Statistical methods to work with data
OOP concepts, looping functions, and Regular Expressions
Python for creating data models and business algorithms
Extensive use of Python libraries for data analysis
Perform web scraping using Python
Integrate Python with Spark and MapReduce
Work on real-time projects to gain extensive experience.

Try and Apply Here...
https://goo.gl/gFks30
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: [FAQ] "Best" GUI toolkit for python

2016-10-18 Thread Demosthenes Koptsis

I have no experience of GTK


On 10/19/2016 12:23 AM, pozz wrote:

Il 18/10/2016 18:41, Demosthenes Koptsis ha scritto:
> My favorite GUIs are PyQt and wxPython.
>
> I prefer PyQt than PySide because PySide seem to me like an abandoned
> project.
>
> Also i prefer PyQt than wxPython because i can design the forms in
> QtDesigner easily.
>
> wxPython and wxWidgets do not have a GUI designer competitor to 
QtDesigner.

>
> So, my choice is PyQt !

Have you compared pyQt with pyGObject (GTK)?



--
https://mail.python.org/mailman/listinfo/python-list


Re: [FAQ] "Best" GUI toolkit for python

2016-10-18 Thread Michael Torrie
On 10/18/2016 03:23 PM, pozz wrote:
> Il 18/10/2016 18:41, Demosthenes Koptsis ha scritto:
>  > My favorite GUIs are PyQt and wxPython.
>  >
>  > I prefer PyQt than PySide because PySide seem to me like an abandoned
>  > project.
>  >
>  > Also i prefer PyQt than wxPython because i can design the forms in
>  > QtDesigner easily.
>  >
>  > wxPython and wxWidgets do not have a GUI designer competitor to 
> QtDesigner.
>  >
>  > So, my choice is PyQt !
> 
> Have you compared pyQt with pyGObject (GTK)?

I have and pyGOjbect and GTK work pretty well. In many respects they are
nearly equivalent of PyQt.  pyGObject leaks a few implementation details
into Python (more than PyGTK did), but it works well enough and the neat
thing about it is that you can get bindings for any gobject-based
library through it fairly easily, even one you might write yourself
(custom widgets for example).  I've not looked into it much but this
fact might make Vala and Python go well together.

You can ask opinions for a long time. But really it comes down to what
platforms you want to run on (PyQt5 can port to Android, for example),
what license you like, and your own personal preferences.

I've heard it said that a good programmer should pick up a new language
every year and do something in it, just for fun. Maybe the same should
be said of GUI toolkits!

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Inplace shuffle function returns none

2016-10-18 Thread Steve D'Aprano
On Wed, 19 Oct 2016 07:25 am, Sayth Renshaw wrote:

> So why can't i assign the result slice to a variable b?
> 
> It just keeps getting none.

Of course you can assign the result slice to b. You just have to do it the
right way. 

You keep getting None because you do it the wrong way. Unfortunately you
aren't showing us your code, so we have no idea what you are doing wrong.
My guess is that you are doing something like this:


a = [1, 2, 3, 4, 5, 6, 7, 8]
b = random.shuffle(a)[0:3]

That's wrong -- shuffle() modifies the list you pass, and returns None. You
cannot take a slice of None. Try this:

a = [1, 2, 3, 4, 5, 6, 7, 8]
random.shuffle(a)
b = a[0:3]
print(b)




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

-- 
https://mail.python.org/mailman/listinfo/python-list


Survey About Package Requirements Management

2016-10-18 Thread Robert Roskam
Hey all,

To clarify my title quickly, this survey is not about replacing pip, as yarn 
(https://github.com/yarnpkg/yarn) did recently with npm. This is about helping 
you throughout the lifespan of projects you maintain keep a handle on the 
dependencies it has.

Where I work, we've already made something internally, and we're trying to 
figure out how useful this is to other people.

So if you could fill out this survey 
(https://docs.google.com/forms/d/e/1FAIpQLSfuXl-UCIJ4PEyQCAWLBB1zPG3Ay86lOxBblV5YJCiFVldFGg/viewform?c=0&w=1),
 it would help us gauge interest.

Thanks all!
-- 
https://mail.python.org/mailman/listinfo/python-list


Button Widget and Key Binding Problem

2016-10-18 Thread Wildman via Python-list
I am working on a program with a GUI created with Tkinter.  I
want to enable key bindings for the button widgets.  Below is
some of the code to show how the window and button widget was
created.  The button calls a routine that will load an image.


class Window(tk.Frame):

def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.master = master
root.bind("", self.load_image)
root.bind("", self.load_image)
self.init_window()

def init_window(self):
self.loadButton = tk.Button(self,
text="Load Image",
underline=0,
width=10,
command=self.load_image)

def load_image(self):
# code to load an image


When I click the load button everything works as expected.
But if I hit the hot key I get this error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1535, in __call__
return self.func(*args)
TypeError: load_image() takes exactly 1 argument (2 given)

The key binding is making the call with an extra argument.
If I change the definition for the load_image routine for
an additional argument, the key binding works but the button
click produces this error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1535, in __call__
return self.func(*args)
TypeError: load_image() takes exactly 2 arguments (1 given)

As a workaround I changed the binding code to call a different
routine named launch_load_image and that routine calls load_image:

def launch_load_image(self, _):
self.load_image()

Both the key bindings and the button click work.  My question
is whether my workaround is the correct way?  Could my key
binding code be wrong in some way?  An insight appreciated.

-- 
 GNU/Linux user #557453
May the source be with you.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: function call questions

2016-10-18 Thread chenyong20000
Thanks Peter and Anssi for your kind help. Now I'm ok with the first question. 
But the second question still confused me. Why "it seems that 
after root = root.setdefault(ch,{}) tree['a'] and root are the same 
object" and follows tree['a']['b']? Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Button Widget and Key Binding Problem

2016-10-18 Thread MRAB

On 2016-10-19 03:13, Wildman via Python-list wrote:

I am working on a program with a GUI created with Tkinter.  I
want to enable key bindings for the button widgets.  Below is
some of the code to show how the window and button widget was
created.  The button calls a routine that will load an image.


class Window(tk.Frame):

def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.master = master
root.bind("", self.load_image)
root.bind("", self.load_image)
self.init_window()

def init_window(self):
self.loadButton = tk.Button(self,
text="Load Image",
underline=0,
width=10,
command=self.load_image)

def load_image(self):
# code to load an image


When I click the load button everything works as expected.
But if I hit the hot key I get this error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1535, in __call__
return self.func(*args)
TypeError: load_image() takes exactly 1 argument (2 given)

The key binding is making the call with an extra argument.
If I change the definition for the load_image routine for
an additional argument, the key binding works but the button
click produces this error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1535, in __call__
return self.func(*args)
TypeError: load_image() takes exactly 2 arguments (1 given)

As a workaround I changed the binding code to call a different
routine named launch_load_image and that routine calls load_image:

def launch_load_image(self, _):
self.load_image()

Both the key bindings and the button click work.  My question
is whether my workaround is the correct way?  Could my key
binding code be wrong in some way?  An insight appreciated.

The 'bind' method passes an 'event' object when it calls; the 'command' 
callback doesn't.


You don't care about the 'event' object anyway, so you can just define a 
single method with a default argument that you ignore:


def load_image(self, event=None):
# code to load an image

--
https://mail.python.org/mailman/listinfo/python-list


Re: function call questions

2016-10-18 Thread MRAB

On 2016-10-19 03:15, [email protected] wrote:

Thanks Peter and Anssi for your kind help. Now I'm ok with the first question. But 
the second question still confused me. Why "it seems that
after root = root.setdefault(ch,{}) tree['a'] and root are the same
object" and follows tree['a']['b']? Thanks.


You call the .setdefault method with a key and a default value.

The .setdefault method does this: if the key is in the dict, it returns 
the associated value, else it puts the key and the default into the dict 
and then returns the default.


--
https://mail.python.org/mailman/listinfo/python-list


Re: function call questions

2016-10-18 Thread chenyong20000
在 2016年10月19日星期三 UTC+8上午11:46:28,MRAB写道:
> On 2016-10-19 03:15, [email protected] wrote:
> > Thanks Peter and Anssi for your kind help. Now I'm ok with the first 
> > question. But the second question still confused me. Why "it seems that
> > after root = root.setdefault(ch,{}) tree['a'] and root are the same
> > object" and follows tree['a']['b']? Thanks.
> >
> You call the .setdefault method with a key and a default value.
> 
> The .setdefault method does this: if the key is in the dict, it returns 
> the associated value, else it puts the key and the default into the dict 
> and then returns the default.

thanks for the reply. I understand this. I'm now confused on why tree got its 
magic result.
-- 
https://mail.python.org/mailman/listinfo/python-list