Re: [Tutor] Changing the interpreter prompt symbol from ">>>" to ???

2016-03-12 Thread eryk sun
On Sat, Mar 12, 2016 at 12:46 AM, boB Stepp  wrote:
> I did with the non-printing control character, but not with '\u25ba' !
>  So I had to go through some contortions after some research to get my
> Win7 cmd.exe and PowerShell to display the desired prompt using

The console is hosted by another process named conhost.exe. When
Python is running in the foreground, the cmd shell is just waiting in
the background until Python exits.

> '\u25ba' as the character with utf-8 encoding.  My new
> pythonstartup.py file (Which PYTHONSTARTUP now points to) follows:
>
> #!/usr/bin/env python3
>
> import os
> import sys
>
> os.system('chcp 65001')# cmd.exe and PowerShell require the code
> page to be changed.
> sys.ps1 = '\u25ba '  # I remembered to add the additional space.

chcp.com calls SetConsoleCP (to change the input codepage) and
SetConsoleOutputCP. You can call these functions via ctypes if you
need to separately modify the input or output codepages. For example:

>>> kernel32 = ctypes.WinDLL('kernel32', use_last_error=True)
>>> sys.ps1 = '\u25ba '
Γû║ kernel32.SetConsoleOutputCP(65001)
1
►

UTF-8 in the console is generally buggy, but this example works since
the sys.ps1 prompt is written without buffering (discussed below).
However, Python still thinks the console is using the initial
codepage. To print non-ASCII characters, you'll either have to change
the codepage before starting Python or rebind sys.stdout and
sys.stderr.

► print(''.join(chr(x) for x in range(240, 256)))


Let's try to fix this:

► fd = os.dup(1)
► sys.stdout = open(fd, 'w', encoding='utf-8')
► print(''.join(chr(x) for x in range(240, 256)))
ðñòóôõö÷øùúûüýþÿ
ùúûüýþÿ
�þÿ

►

The above buggy output is in Windows 7. Codepage 65001 was only ever
meant for encoding text to and from files and sockets, via WinAPI
WideCharToMultiByte and MultiByteToWideChar. Using it in the console
is buggy because the console's ANSI API hard codes a lot of
assumptions that fall apart with UTF-8.

For example, if you try to paste non-ASCII characters into the console
using 65001 as the input codepage, Python will quit as if you had
entered Ctrl+Z. Also, in Windows 7 when you print non-ASCII characters
you'll get a trail of garbage written to the end of the print in
proportion to the number of non-ASCII characters, especially with
character codes that take more than 2 UTF-8 bytes. Also, with Python
2, the CRT's FILE buffering can split a UTF-8 sequence across two
writes. The split UTF-8 sequence gets printed as 2 to 4 replacement
characters. I've discussed these problems in more detail in the
following issue:

http://bugs.python.org/issue26345

Windows 10 fixes the problem with printing extra characters, but it
still has the problem with reading non-ASCII input as UTF-8 and still
can't handle a buffered writer that splits a UTF-8 sequence across two
writes. Maybe Windows 20 will finally get this right.

For the time being, programs that use Unicode in the console should
use the wide-character (UTF-16) API. Python doesn't support this out
of the box, since it's not designed to handle UTF-16 in the raw I/O
layer. The win-unicode-console package add this support.

https://pypi.python.org/pypi/win_unicode_console
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: (Continuous) integration testing: Can a solo developer with very limited resources truly do this?

2016-03-12 Thread wolfrage8...@gmail.com
>> 
>>> Does one need to already have installation media for each OS to be
>>> used, or are they pre-loaded?  If the first, for Windows that could
>>> potentially be a chunk of money!
>>
>> See Here Free Virtual Machines for Windows:
>> https://dev.windows.com/en-us/microsoft-edge/tools/vms/windows/
>
> I saw these but my superficial impression was that these were for
> Explorer and Edge browser testing.  Are they in fact usable for any OS
> functions I might have my programs using?

Yes at least the last time I downloaded one from the site it was a
full up and functional version of Windows only stipulation is the
trial period but using Virtual Box Snapshot functionality I am always
able to easily revert the VM back to day 0 of the trial period.
>
> If yes, perhaps we should post to the entire Tutor list, too?

Sorry I mean to post to the entire tutor list; thanks for pointing that out.
>
> --
> boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pmw/Tkinter question

2016-03-12 Thread boB Stepp
On Sat, Mar 12, 2016 at 2:17 AM, Albert-Jan Roskam
 wrote:
> Hello,
>
> Below is a slightly modified example about Pmw/Tkinter from 
> http://pmw.sourceforge.net/doc/howtouse.html.
> I changed the geometry manager from 'pack' to 'grid', because I use that in 
> all other parts of my program.
> The problem is, 'broccoli' won't display nicely under vege_menu. I want it to 
> left-align, not center (I don't case that it's truncated)...

Not having run your code (I did not have Pmw installed.), I think I
misunderstood your question(s).  I went ahead and installed Pmw and
ran your code.  I don't have Py 2 installed, so I had to do the usual
conversions to make it Py 3 compatible.  Once I did that I got all of
your labels showing up on the right side of the menu buttons.  I
presume you want them on the left side of each button?  To do that you
with the grid manager, you do not want the buttons to attach to the
left side of the overall megawidget.  Instead, allow the menu buttons
to center in each row by omitting the sticky option from grid() and
then your labels have room to attach on the left side.  Assuming that
I am now trying to solve the correct problem, my Py *3* code is:

# -*- coding: utf-8 -*-

import tkinter
import Pmw

class Demo:
def __init__(self, parent):
# Create and pack the OptionMenu megawidgets.
# The first one has a textvariable.
self.var = tkinter.StringVar()
self.var.set('steamed')
self.method_menu = Pmw.OptionMenu(parent,
labelpos = 'w',
label_text = 'Choose method:',
menubutton_textvariable = self.var,
items = ['baked', 'steamed', 'stir fried', 'boiled', 'raw'],
menubutton_width = 10,
)
self.method_menu.grid(row=0, column=0, padx = 10, pady = 10)

self.vege_menu = Pmw.OptionMenu (parent,
labelpos = 'w',
label_text = 'Choose vegetable:',
items = ('broccoli', 'peas','carrots', 'pumpkin'),
menubutton_width = 10,
command = self._printOrder,
)
self.vege_menu.grid(row=1, column=0, padx = 10, pady = 10)

self.direction_menu = Pmw.OptionMenu (parent,
labelpos = 'w',
label_text = 'Menu direction:',
items = ('flush', 'above', 'below', 'left', 'right'),
menubutton_width = 10,
command = self._changeDirection,
)
self.direction_menu.grid(row=2, column=0, padx = 10, pady = 10)

menus = (self.method_menu, self.vege_menu, self.direction_menu)
Pmw.alignlabels(menus)

def _printOrder(self, vege):
# Can use 'self.var.get()' instead of 'getcurselection()'.
print('You have chosen %s %s.' % \
(self.method_menu.getcurselection(), vege))

def _changeDirection(self, direction):
for menu in (self.method_menu, self.vege_menu, self.direction_menu):
menu.configure(menubutton_direction = direction)

if __name__ == "__main__" :
root = Pmw.initialise()
root.title("Demo")
widget = Demo(root)
root.mainloop()

I omitted the extra "broccoli" words, to clarify the alignment issues.
I hope I am going in the direction you wanted!  Nonetheless, having
never used the Python megawidgets before, I found this educational.
In passing, I was surprised that it does not matter about the case of
the sticky positions.  I know I have gotten errors at work by not
having the proper case for these, but then, I wasn't doing classes.

boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pmw/Tkinter question

2016-03-12 Thread boB Stepp
On Sat, Mar 12, 2016 at 2:17 AM, Albert-Jan Roskam
 wrote:

> Below is a slightly modified example about Pmw/Tkinter from 
> http://pmw.sourceforge.net/doc/howtouse.html.
> I changed the geometry manager from 'pack' to 'grid', because I use that in 
> all other parts of my program.
> The problem is, 'broccoli' won't display nicely under vege_menu. I want it to 
> left-align, not center...

I cracked my copy of Grayson and went to his example for OptionMenu
widget.  His example from page 64-65 is:

var = StringVar()
var.set('Quantity Surveyor')
opt_menu = Pmw.OptionMenu(root, labelpos=W,
   label_text='Choose profession:', menubutton_textvariable=var,
   items=('Stockbroker', 'Quantity Surveyor', 'Church Warden', 'BRM'),
   menubutton_width=16)
opt_menu.pack(anchor=W, padx=20, pady=30)

In your case you use a lowercase 'w', where Grayson uses uppercase for
labelpos.  I have not tried this out, but is it possible correct case
matters here?  On page 584 for the labelpos option he gives:


Option: labelpos; Units: anchor; Default: None

Specifies where to place the label component.  If not None, it should
be a concatenation of one or two of the letters N, S, E and W.  The
first letter specifies on which side of the megawidget to place the
label.  If a second letter is specified, it indicates where on that
side to place the label.  For example, if labelpos is W, the label is
placed in the center of the left-hand side; if it is WN, the label is
placed at the top of the left-hand side; if it is WS, the label is
placed at the bottom of the left-hand side.


I presume the second letter possibilities are referring to vertical spacing.

Hope this helps!

boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: (Continuous) integration testing: Can a solo developer with very limited resources truly do this?

2016-03-12 Thread Danny Yoo
On Sat, Mar 12, 2016 at 10:10 AM, boB Stepp  wrote:
> From "Practices of an Agile Developer" by Venkat Subramaniam and Andy
> Hunt, c. 2006, page 90:
>
> 
> You're already writing unit tests to exercise your code.  Whenever you
> modify or refactor your code, you exercise your test cases before you
> check in the code.  All you have to do now is exercise your test cases
> on each supported platform or environment.


Hi Bob,


There are some common infrastructure that folks can use.  For example,
Travis CL is one such continuous integration system that's getting
traction:

 https://travis-ci.org/

I think there's another CI system called Jenkins CI that's also used
quite a bit.


Hope this helps!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: (Continuous) integration testing: Can a solo developer with very limited resources truly do this?

2016-03-12 Thread boB Stepp
On Sat, Mar 12, 2016 at 2:02 PM, Alan Gauld  wrote:
> On 12/03/16 18:10, boB Stepp wrote:


> Virtual machines, eg VirtualBox.
> You can install all of the required OS on a single physical machine
> (assuming the same hardware of course). For example, on my
> Linux Mint box I have 2 versions of Windows(XP and Win 8.1)
> plus Ubuntu and Mandriva Linux virtual machines ready to run.
> It only takes a few seconds to start/stop each one.
>
> It might be possible to run an intel based MacOS in a virtual
> machine too but I've not tried that and limit my Apple testing
> to my ancient G3 based iBook...

Does one need to already have installation media for each OS to be
used, or are they pre-loaded?  If the first, for Windows that could
potentially be a chunk of money!

boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: (Continuous) integration testing: Can a solo developer with very limited resources truly do this?

2016-03-12 Thread wolfrage8...@gmail.com
> You're already writing unit tests to exercise your code.  Whenever you
> modify or refactor your code, you exercise your test cases before you
> check in the code.  All you have to do now is exercise your test cases
> on each supported platform or environment.
>
> If your application is expected to run on different operating systems
> (MacOS, Linux, Windows, etc.), *** you need to test on all of them ***
> [My emphasis.].  If you expect your application to work on different
> versions of the Java Virtual Machine (VM) or .NET common language
> runtime (CLR), *** you need to test that as well *** [My emphasis.].
> 
>
> I firmly agree that this -- in principle -- must be done.  But how on
> earth can a solo developer, perhaps hoping to make a buck or two, with

I as a solo developer have been unable to achieve this task too; but
once my software is closer to complete that is when I look to do
integration testing.

> very limited resources, accomplish manual (much less continuous,
> automated) integration testing on all reasonable environment
> possibilities?  Just the possibilities for Windows with their
> constant, unending (albeit, necessary) string of security updates
> boggles my imagination!

You can always download the free test versions of windows; that is
what I do and then I throw them on a virtual machine so as to not have
to suck up that cost. But dealing with what security updates break is
a different story all together.

>
> One of the many beauties of Python is its portability across many
> platforms, but it is not perfect.  And surprises can occur, even if it
> is not Python's fault.  I *thought* I was finally finished with
> supporting Python 2.4 at work, and could start using features
> available in Python 2.6.  While testing some new code where I had
> starting using "with ..." to take care of closing files, I started
> receiving erratic crashes.  Sure enough the traceback pointed to the
> sections of code using the "with ..." blocks.  Huh?!?  After
> investigation, I found that when my IS and commercial vendor friends
> installed the second computational server for the planning software we
> use, they did *not* install the *exact* same environment.  The OS
> version was the same, but not all of the other ancillary software was
> the same.  In this instance, they went backwards with Python and
> installed Python 2.4 on the new server.  Since which server gets used
> is out of the user's control, sometimes my tests ran on one server,
> sometimes on the other.  And since I am stuck doing manual testing,
> these kinds of things are especially hard to catch!  The only way I
> will ever be able to automate testing at work will be to write my own
> custom testing framework that can bridge the "automation gap" between
> the software we use with its proprietary scripting language which does
> not support automated testing of any sort and the Python that I find
> myself using more and more, where I have the potential to automate.
> But the bottom line is -- at work -- the core data I need is in the
> proprietary environment and after the needed processing with Python it
> has to be translated back into the proprietary environment's scripting
> language and run there.

Yes in my virtual environments I have over time been diligently
writing a testing automation tool; that starts when the OS boots; then
looks to a specific server for a specific directory to download the
code to be tested. But it is very rough; the key is to start small and
write code that can be re-used. But I am still missing an android and
IOS client so I have to test those manually.

>
> The above was just a single practical example (Rant?  Sorry!).  But
> even for stuff I do at home, even with using some complex combination
> of virtual environments to test all relevant OS's (Assuming I could
> even afford copies WinXP, WinVista, Win7, Win10, etc., with all their
> many permutations.), how can automated, continuous integration testing
> be accomplished *in practice* for the severely resource-constrained
> solo developer?

Good Luck!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] OT: (Continuous) integration testing: Can a solo developer with very limited resources truly do this?

2016-03-12 Thread Alan Gauld
On 12/03/16 18:10, boB Stepp wrote:

> 
> You're already writing unit tests to exercise your code.  Whenever you
> modify or refactor your code, you exercise your test cases before you
> check in the code.  All you have to do now is exercise your test cases
> on each supported platform or environment.

That's not what I'd call integration testing. Integration testing
tests the interfaces between your classes/modules/processes.
And that's a completely different set of tests from your unit
tests.

That nit-pick aside...

> If your application is expected to run on different operating systems
> (MacOS, Linux, Windows, etc.), *** you need to test on all of them ***

> I firmly agree that this -- in principle -- must be done.  But how on
> earth can a solo developer, perhaps hoping to make a buck or two, with
> very limited resources, accomplish manual (much less continuous,
> automated) integration testing on all reasonable environment
> possibilities?  

Virtual machines, eg VirtualBox.
You can install all of the required OS on a single physical machine
(assuming the same hardware of course). For example, on my
Linux Mint box I have 2 versions of Windows(XP and Win 8.1)
plus Ubuntu and Mandriva Linux virtual machines ready to run.
It only takes a few seconds to start/stop each one.

It might be possible to run an intel based MacOS in a virtual
machine too but I've not tried that and limit my Apple testing
to my ancient G3 based iBook...

> the same.  In this instance, they went backwards with Python and
> installed Python 2.4 on the new server.  Since which server gets used
> is out of the user's control, sometimes my tests ran on one server,
> sometimes on the other.  

Eeek, that's bad. Mirrored servers should be mirrors.
Somebody deserves a serious kicking!

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] OT: (Continuous) integration testing: Can a solo developer with very limited resources truly do this?

2016-03-12 Thread boB Stepp
>From "Practices of an Agile Developer" by Venkat Subramaniam and Andy
Hunt, c. 2006, page 90:


You're already writing unit tests to exercise your code.  Whenever you
modify or refactor your code, you exercise your test cases before you
check in the code.  All you have to do now is exercise your test cases
on each supported platform or environment.

If your application is expected to run on different operating systems
(MacOS, Linux, Windows, etc.), *** you need to test on all of them ***
[My emphasis.].  If you expect your application to work on different
versions of the Java Virtual Machine (VM) or .NET common language
runtime (CLR), *** you need to test that as well *** [My emphasis.].


I firmly agree that this -- in principle -- must be done.  But how on
earth can a solo developer, perhaps hoping to make a buck or two, with
very limited resources, accomplish manual (much less continuous,
automated) integration testing on all reasonable environment
possibilities?  Just the possibilities for Windows with their
constant, unending (albeit, necessary) string of security updates
boggles my imagination!

One of the many beauties of Python is its portability across many
platforms, but it is not perfect.  And surprises can occur, even if it
is not Python's fault.  I *thought* I was finally finished with
supporting Python 2.4 at work, and could start using features
available in Python 2.6.  While testing some new code where I had
starting using "with ..." to take care of closing files, I started
receiving erratic crashes.  Sure enough the traceback pointed to the
sections of code using the "with ..." blocks.  Huh?!?  After
investigation, I found that when my IS and commercial vendor friends
installed the second computational server for the planning software we
use, they did *not* install the *exact* same environment.  The OS
version was the same, but not all of the other ancillary software was
the same.  In this instance, they went backwards with Python and
installed Python 2.4 on the new server.  Since which server gets used
is out of the user's control, sometimes my tests ran on one server,
sometimes on the other.  And since I am stuck doing manual testing,
these kinds of things are especially hard to catch!  The only way I
will ever be able to automate testing at work will be to write my own
custom testing framework that can bridge the "automation gap" between
the software we use with its proprietary scripting language which does
not support automated testing of any sort and the Python that I find
myself using more and more, where I have the potential to automate.
But the bottom line is -- at work -- the core data I need is in the
proprietary environment and after the needed processing with Python it
has to be translated back into the proprietary environment's scripting
language and run there.

The above was just a single practical example (Rant?  Sorry!).  But
even for stuff I do at home, even with using some complex combination
of virtual environments to test all relevant OS's (Assuming I could
even afford copies WinXP, WinVista, Win7, Win10, etc., with all their
many permutations.), how can automated, continuous integration testing
be accomplished *in practice* for the severely resource-constrained
solo developer?

-- 
boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Changing the interpreter prompt symbol from ">>>" to ???

2016-03-12 Thread boB Stepp
On Sat, Mar 12, 2016 at 2:14 AM, Cameron Simpson  wrote:
> On 12Mar2016 00:46, boB Stepp  wrote:


>> Additionally, one must set the font for cmd.exe and PowerShell to
>> "Lucida Console" or the above will not work.
>
>
> You may find some other fonts also work if you don't like that one.

On my Win7 64-bit OS, the only font options available for both
PowerShell and cmd.exe are 1) Consolas; 2) Lucida Console; and 3)
Raster Fonts.  The online research I did stated that only Lucida
Console would provide full access to all the characters available in
utf-8 with the code page set to 65001.  For my particular choice of a
single character, 1) Consolas will work as well, though it looks
raggedy compared to 2) Lucida Console.  However, usually where there
is a will there is a way, so I would not be surprised if research
would reveal that other workable fonts could be installed in
PowerShell and cmd.exe.  But (For the moment!) I am quite satisfied
with the results of Lucida Console.

boB
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Changing the interpreter prompt symbol from ">>>" to ???

2016-03-12 Thread David Rock
* boB Stepp  [2016-03-12 00:46]:
> 
> So let's see if this copies and pastes into a plain text Gmail and is
> visible to "many environments":
> 
> Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:54:25) [MSC v.1900
> 64 bit (AMD64)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> Active code page: 65001
> ► print("Can everyone read the prompt?")
> Can everyone read the prompt?
> ►
> 
> It looks good to me in Gmail.  Any issues?  Angry users of pure ASCII
> terminals? ~(:>)

I'm using mutt in a screen session on raspbian.  Looks fine to me.
I have put a lot of effort into "properly" displaying "weird" things, though.

-- 
David Rock
da...@graniteweb.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do I access and manipulate files?

2016-03-12 Thread Alan Gauld
On 12/03/16 08:51, Mark Lawrence wrote:
> On 12/03/2016 01:03, Justin Hayes wrote:
> 
> Would you please read this 
> http://www.catb.org/esr/faqs/smart-questions.html and then try again, 

To be fair to Justin his original post did include a paragraph
of text providing some context. But somewhere between the
moderation queue and appearing on the list it got stripped.

I've asked him to repost in plain text.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do I access and manipulate files?

2016-03-12 Thread Mark Lawrence

On 12/03/2016 01:03, Justin Hayes wrote:

Would you please read this 
http://www.catb.org/esr/faqs/smart-questions.html and then try again, 
thanks.


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

Mark Lawrence

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pmw/Tkinter question

2016-03-12 Thread Albert-Jan Roskam
> To: tutor@python.org
> From: __pete...@web.de
> Date: Sat, 12 Mar 2016 10:28:36 +0100
> Subject: Re: [Tutor] Pmw/Tkinter question
> 
> Albert-Jan Roskam wrote:
> 
> > Hello,
> > 
> > Below is a slightly modified example about Pmw/Tkinter from
> > http://pmw.sourceforge.net/doc/howtouse.html. I changed the geometry
> > manager from 'pack' to 'grid', because I use that in all other parts of my
> > program. The problem is, 'broccoli' won't display nicely under vege_menu.
> > I want it to left-align, not center (I don't case that it's truncated). In
> > plain Tkinter I could do "self.vege_menu.configure(anchor=Tkinter.W)" but
> > this raises a KeyError in Pmw.
> 
> I don't see an official way to to change the alignment, but looking into the 
> source there's
> 
> class OptionMenu(Pmw.MegaWidget):
> 
> def __init__(self, parent = None, **kw):
> 
> [...]
>   self._menubutton = self.createcomponent('menubutton',
>   (), None,
>   Tkinter.Menubutton, (interior,),
>   borderwidth = 2,
>   indicatoron = 1,
>   relief = 'raised',
>   anchor = 'c',
>   highlightthickness = 2,
>   direction = 'flush',
> takefocus = 1,
>   )
> 
> so if you don't mind touching _private attributes
> 
> > self.vege_menu = Pmw.OptionMenu (parent,
> > labelpos = 'w',
> > label_text = 'Choose vegetable:',
> > items = ('broccoli-broccoli-broccoli-broccoli', 'peas',
> > 'carrots', 'pumpkin'), menubutton_width = 10,
> > command = self._printOrder,
> > )
>   self.vege_menu._menubutton.config(anchor=Tkinter.W)
> 
> > #self.vege_menu.pack(anchor = 'w', padx = 10, pady = 10)
> > self.vege_menu.grid(row=1, column=0, sticky = 'w', padx = 10, pady
> > = 10)
> 
> should work.

Ahh, yes, that works! Thank you!! I should indeed have looked at the source 
myself.
The Tk website is often informative, but not everything is exposed by 
Tkinter/Pmw.
This is also the first time I tried Pmw. A lot less verbose than Tkinter, but 
it takes some time
to learn the names/meaning of various parameters. They differ from the 
equivalent params in 
Tkinter and are often more descriptive, but pre-existing knowledge of Tkinter 
creates some "noise".

Best wishes,
Albert-Jan


  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pmw/Tkinter question

2016-03-12 Thread Peter Otten
Albert-Jan Roskam wrote:

> Hello,
> 
> Below is a slightly modified example about Pmw/Tkinter from
> http://pmw.sourceforge.net/doc/howtouse.html. I changed the geometry
> manager from 'pack' to 'grid', because I use that in all other parts of my
> program. The problem is, 'broccoli' won't display nicely under vege_menu.
> I want it to left-align, not center (I don't case that it's truncated). In
> plain Tkinter I could do "self.vege_menu.configure(anchor=Tkinter.W)" but
> this raises a KeyError in Pmw.

I don't see an official way to to change the alignment, but looking into the 
source there's

class OptionMenu(Pmw.MegaWidget):

def __init__(self, parent = None, **kw):

[...]
self._menubutton = self.createcomponent('menubutton',
(), None,
Tkinter.Menubutton, (interior,),
borderwidth = 2,
indicatoron = 1,
relief = 'raised',
anchor = 'c',
highlightthickness = 2,
direction = 'flush',
takefocus = 1,
)

so if you don't mind touching _private attributes

> self.vege_menu = Pmw.OptionMenu (parent,
> labelpos = 'w',
> label_text = 'Choose vegetable:',
> items = ('broccoli-broccoli-broccoli-broccoli', 'peas',
> 'carrots', 'pumpkin'), menubutton_width = 10,
> command = self._printOrder,
> )
  self.vege_menu._menubutton.config(anchor=Tkinter.W)

> #self.vege_menu.pack(anchor = 'w', padx = 10, pady = 10)
> self.vege_menu.grid(row=1, column=0, sticky = 'w', padx = 10, pady
> = 10)

should work.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Program Arcade Games Help

2016-03-12 Thread Alan Gauld
On 12/03/16 05:15, DiliupG wrote:
> All the help and guidance you need are in the pages here.
> 
> http://programarcadegames.com/
> 
> if you follow the book slowly from the start you shouldn't have a problem.
> If you do, stackoverflow is a good place to ask.

As is the tutor list of course. :-)


> When ever you ask a question try to give as much details as possible so
> that who ever answers do not have to go searching over the web to figure
> out what you are asking.
> 
> Lab 9 deals with questions on functions. If you are unable to do these it
> most probably means that you have not grasped the concepts of what
> functions are. ...



-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pmw/Tkinter question

2016-03-12 Thread Alan Gauld
On 12/03/16 08:17, Albert-Jan Roskam wrote:
> Hello,
> 
> Below is a slightly modified example about Pmw/Tkinter from 
> http://pmw.sourceforge.net/doc/howtouse.html.
> I changed the geometry manager from 'pack' to 'grid', because I use that in 
> all other parts of my program.
> The problem is, 'broccoli' won't display nicely under vege_menu. I want it to 
> left-align, not center (I don't case that it's truncated). In plain Tkinter I 
> could do "self.vege_menu.configure(anchor=Tkinter.W)" but this raises a 
> KeyError in Pmw.
> 
> The real reason for switching from Tkinter to Pmw is that Pmw is more 
> compact, and it has an 'index' method that I could use to link two 
> optionmenus.
> 
> Any ideas? Hope this is ok to ask as Pmw is a layer on top of Tkinter.

You can always ask :-)
But this is a pretty specific question and I'd expect a better response
from the tkinter mailing list. It is pretty active and very helpful.

The gmane link is

gmane.comp.python.tkinter

on

news://news.gmane.org:119/gmane.comp.python.tkinter

Although my Grayson book on Tkinter covers PMW I've never used
it so can't help directly.

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How do I access and manipulate files?

2016-03-12 Thread wolfrage8...@gmail.com
On Fri, Mar 11, 2016 at 8:03 PM, Justin Hayes
 wrote:
>
Access:  https://docs.python.org/2/library/functions.html#open
Basic Manipulation: http://stackoverflow.com/posts/9283052/revisions
Please try some code and ask some more specific questions. The Python
documentation is pretty good and there is a wealth of information
online.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Changing the interpreter prompt symbol from ">>>" to ???

2016-03-12 Thread wolfrage8...@gmail.com
On Sat, Mar 12, 2016 at 1:53 AM, boB Stepp  wrote:

>
> Thanks for the feedback.  I tried out your link, codeanywhere.com .  I
> have to confess my experience was not a good one.  Firstly, the
> environment supplied would not accept my space bar characters!  So I
> could not type any import statements.  However, I did try:

Yes I do not endorse codeanywhere.com; but it is the only editor I
have access to while at work; so as the only it meets my needs barely.

>
> print('\u25ba'), which did not require any spaces and received an
> error stating that it would not accept values greater than hex ff.  So
> it is pretty clear that following Cameron's suggestion is not (At
> least on the surface.) doable in the codeanywhere environment.  Might
> I suggest pythonanywhere?  All of this works fine with utf-8 there.

I used to use Pythonanywhere.com but it is blocked; so it is no longer
an option.

>
> boB
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Changing the interpreter prompt symbol from ">>>" to ???

2016-03-12 Thread Cameron Simpson

On 12Mar2016 00:46, boB Stepp  wrote:

On Fri, Mar 11, 2016 at 11:02 PM, Cameron Simpson  wrote:

 0x25ba BLACK RIGHT-POINTING POINTER

So it seems that your environment has chosen to transcribe your chr(26) and
chr(16) into some glyphs for display, and matched those glyphs with suitable
Unicode codepoints. (Well, "suitable" if you also see a right-arrow and a
right pointing triangle; do you?)


I did with the non-printing control character, but not with '\u25ba' !
So I had to go through some contortions after some research to get my
Win7 cmd.exe and PowerShell to display the desired prompt using
'\u25ba' as the character with utf-8 encoding.  My new
pythonstartup.py file (Which PYTHONSTARTUP now points to) follows:

#!/usr/bin/env python3

import os
import sys

os.system('chcp 65001')# cmd.exe and PowerShell require the code
page to be changed.
sys.ps1 = '\u25ba '  # I remembered to add the additional space.


Looks good to me. (I'm not a Windows person; the _logic_ looks good to me!)


Additionally, one must set the font for cmd.exe and PowerShell to
"Lucida Console" or the above will not work.


You may find some other fonts also work if you don't like that one.


So: I would not rely on your stuff being presented nicely if you use 16 and
26 because they are not printable to start with, and you just got lucky. If,
OTOH, you figure out some nice glyphs and their Unicode points, then many
environments will render them sensibly. Though, of course, not a pure ACII
terminal - those are rare these days though.


So let's see if this copies and pastes into a plain text Gmail and is
visible to "many environments":

Python 3.5.1 (v3.5.1:37a07cee5969, Dec  6 2015, 01:54:25) [MSC v.1900
64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
Active code page: 65001
► print("Can everyone read the prompt?")
Can everyone read the prompt?
►

It looks good to me in Gmail.  Any issues?  Angry users of pure ASCII
terminals? ~(:>)


I see a right pointing triangle. In green:-) But my terminals are 
green-on-black.


Cheers,
Cameron Simpson 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] How do I access and manipulate files?

2016-03-12 Thread Justin Hayes


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Program Arcade Games Help

2016-03-12 Thread DiliupG
All the help and guidance you need are in the pages here.

http://programarcadegames.com/

if you follow the book slowly from the start you shouldn't have a problem.
If you do, stackoverflow is a good place to ask.
When ever you ask a question try to give as much details as possible so
that who ever answers do not have to go searching over the web to figure
out what you are asking.

Lab 9 deals with questions on functions. If you are unable to do these it
most probably means that you have not grasped the concepts of what
functions are. Again stackoverflow and Daniweb are good places of reference
to learn more.


On Fri, Mar 11, 2016 at 8:41 PM, Ethan Batterman 
wrote:

> I am really struggling with Lab 9: Functions pt 3 and 4 of program arcade
> games. Any help or guidance would be greatly appreciated. I am completely
> lost. Thank you in advance!
>
>
> Ethan
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>



-- 
Diliup Gabadamudalige

http://www.diliupg.com
http://soft.diliupg.com/

**
This e-mail is confidential. It may also be legally privileged. If you are
not the intended recipient or have received it in error, please delete it
and all copies from your system and notify the sender immediately by return
e-mail. Any unauthorized reading, reproducing, printing or further
dissemination of this e-mail or its contents is strictly prohibited and may
be unlawful. Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability for any
errors or omissions.
**
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Changing the interpreter prompt symbol from ">>>" to ???

2016-03-12 Thread Cameron Simpson

On 12Mar2016 00:53, boB Stepp  wrote:

On Fri, Mar 11, 2016 at 10:08 PM, wolfrage8...@gmail.com
 wrote:

 On a web based terminal via codeanywhere.com setting sys.ps1 =
chr(16) results in no character being displayed. It is literally just
a new line. So something to think about. I set it back to sys.ps1 =
'>>>'


Thanks for the feedback.  I tried out your link, codeanywhere.com .  I
have to confess my experience was not a good one.  Firstly, the
environment supplied would not accept my space bar characters!  So I
could not type any import statements.  However, I did try:

print('\u25ba'), which did not require any spaces and received an
error stating that it would not accept values greater than hex ff.  So
it is pretty clear that following Cameron's suggestion is not (At
least on the surface.) doable in the codeanywhere environment.  Might
I suggest pythonanywhere?  All of this works fine with utf-8 there.


Sounds like codeanywhere is an 8-bit environment. Maybe ISO8859-1 (untested 
assumption).


Cheers,
Cameron Simpson 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Pmw/Tkinter question

2016-03-12 Thread Albert-Jan Roskam
Hello,

Below is a slightly modified example about Pmw/Tkinter from 
http://pmw.sourceforge.net/doc/howtouse.html.
I changed the geometry manager from 'pack' to 'grid', because I use that in all 
other parts of my program.
The problem is, 'broccoli' won't display nicely under vege_menu. I want it to 
left-align, not center (I don't case that it's truncated). In plain Tkinter I 
could do "self.vege_menu.configure(anchor=Tkinter.W)" but this raises a 
KeyError in Pmw.

The real reason for switching from Tkinter to Pmw is that Pmw is more compact, 
and it has an 'index' method that I could use to link two optionmenus.

Any ideas? Hope this is ok to ask as Pmw is a layer on top of Tkinter.

Thank you!
Albert-Jan


# -*- coding: utf-8 -*-

import Tkinter
import Pmw

class Demo:
def __init__(self, parent):
# Create and pack the OptionMenu megawidgets.
# The first one has a textvariable.
self.var = Tkinter.StringVar()
self.var.set('steamed')
self.method_menu = Pmw.OptionMenu(parent,
labelpos = 'w',
label_text = 'Choose method:',
menubutton_textvariable = self.var,
items = ['baked', 'steamed', 'stir fried', 'boiled', 'raw'],
menubutton_width = 10,
)
#self.method_menu.pack(anchor = 'w', padx = 10, pady = 10)
self.method_menu.grid(row=0, column=0, sticky = 'w', padx = 10, pady = 
10)

self.vege_menu = Pmw.OptionMenu (parent,
labelpos = 'w',
label_text = 'Choose vegetable:',
items = ('broccoli-broccoli-broccoli-broccoli', 'peas', 
'carrots', 'pumpkin'),
menubutton_width = 10,
command = self._printOrder,
)
#self.vege_menu.pack(anchor = 'w', padx = 10, pady = 10)
self.vege_menu.grid(row=1, column=0, sticky = 'w', padx = 10, pady = 10)

self.direction_menu = Pmw.OptionMenu (parent,
labelpos = 'w',
label_text = 'Menu direction:',
items = ('flush', 'above', 'below', 'left', 'right'),
menubutton_width = 10,
command = self._changeDirection,
)
#self.direction_menu.pack(anchor = 'w', padx = 10, pady = 10)
self.direction_menu.grid(row=2, column=0, sticky = 'w', padx = 10, pady 
= 10)

menus = (self.method_menu, self.vege_menu, self.direction_menu)
Pmw.alignlabels(menus)

def _printOrder(self, vege):
# Can use 'self.var.get()' instead of 'getcurselection()'.
print 'You have chosen %s %s.' % \
(self.method_menu.getcurselection(), vege)

def _changeDirection(self, direction):
for menu in (self.method_menu, self.vege_menu, self.direction_menu):
menu.configure(menubutton_direction = direction)

if __name__ == "__main__" :
root = Pmw.initialise()
root.title("Demo")
widget = Demo(root)
root.mainloop()   
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor