Re: [Tutor] GUI

2015-02-02 Thread Alan Gauld

On 02/02/15 20:59, Marc Tompkins wrote:


I suspect the standard GUI framework Tkinter is not going to be your best
bet. You might find that PyQt or PyGTK will offer better multi lingual
support  (although thats just a guess on my part!).


Might I also suggest wxPython?  I tried Tk and Qt early on, but found that
wx fit my needs much better (and I like the looks of the result better too.)


I, too, like wxPython, but I don't recall it having any explicit support 
for multi-lingual display whereas I think I've seen references to Qt and 
GTk supporting it via native widgets. That's why I left it out this time.



--
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] GUI

2015-02-02 Thread Mark Lawrence

On 02/02/2015 21:48, Marc Tompkins wrote:

On Mon, Feb 2, 2015 at 1:18 PM, Mark Lawrence 
wrote:


On 02/02/2015 20:59, Marc Tompkins wrote:


On Mon, Feb 2, 2015 at 9:13 AM, Alan Gauld 
wrote:

  Don't expect a whole heap of support from the GUIs. A lot of the work

will
have to come from you.
I suspect the standard GUI framework Tkinter is not going to be your best
bet. You might find that PyQt or PyGTK will offer better multi lingual
support  (although thats just a guess on my part!).



Might I also suggest wxPython?  I tried Tk and Qt early on, but found that
wx fit my needs much better (and I like the looks of the result better
too.)
I have little to no experience with LTR handling myself, but there's a
very
good, active support list for wxPython and I suspect that someone on that
list may have insights that can help...
wxpython-us...@googlegroups.com



For the type of work the OP has previously described I doubt that wxPython
fits the bill as the Python 3 version called Phoenix is still in
development.  More here http://wiki.wxpython.org/ProjectPhoenix



Still under development, true - but all but a few of the controls are up
and running, and a lot of the people on the list are using Phoenix now.
(Not I - I'm still using 2.7 - but I've been following developments with
interest.)



So wxPython Phoenix 1.0 doesn't get released until all controls are up 
and running, which might be tomorrow, might be this time next year.  I 
therefore could not recommend using it to someone who's trying to put a 
Hebrew Dictionary database together.  Much better IMHO to use something 
that's already proven in the field.


--
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] GUI

2015-02-02 Thread Marc Tompkins
On Mon, Feb 2, 2015 at 1:18 PM, Mark Lawrence 
wrote:

> On 02/02/2015 20:59, Marc Tompkins wrote:
>
>> On Mon, Feb 2, 2015 at 9:13 AM, Alan Gauld 
>> wrote:
>>
>>  Don't expect a whole heap of support from the GUIs. A lot of the work
>>> will
>>> have to come from you.
>>> I suspect the standard GUI framework Tkinter is not going to be your best
>>> bet. You might find that PyQt or PyGTK will offer better multi lingual
>>> support  (although thats just a guess on my part!).
>>>
>>>
>> Might I also suggest wxPython?  I tried Tk and Qt early on, but found that
>> wx fit my needs much better (and I like the looks of the result better
>> too.)
>> I have little to no experience with LTR handling myself, but there's a
>> very
>> good, active support list for wxPython and I suspect that someone on that
>> list may have insights that can help...
>> wxpython-us...@googlegroups.com
>>
>
> For the type of work the OP has previously described I doubt that wxPython
> fits the bill as the Python 3 version called Phoenix is still in
> development.  More here http://wiki.wxpython.org/ProjectPhoenix
>

Still under development, true - but all but a few of the controls are up
and running, and a lot of the people on the list are using Phoenix now.
(Not I - I'm still using 2.7 - but I've been following developments with
interest.)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] os module question

2015-02-02 Thread Cameron Simpson

On 02Feb2015 17:01, alan.ga...@btinternet.com  wrote:

On 02/02/15 13:46, maurice.ho...@thomsonreuters.com wrote:

Basically I have trouble with two things:
1)  Get the server to take the hostname and use it to run a command against 
it


os.uname() will return a tuple.
The second item is the hostname


That gets this machine's hostname. The OP wants to use an arbitrary machine's 
hostname, since he's looking up an asset db. He needs to use the sys.argv 
array. (We he's doing as it turns out, so not to worry.)


Cheers,
Cameron Simpson 

I must really get a thinner pencil. I can't manage this one a bit. It writes
all manner of things I don't intend.
   - rhe...@csugrad.cs.vt.edu (Bolo Mk XXXIX)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] GUI

2015-02-02 Thread Mark Lawrence

On 02/02/2015 20:59, Marc Tompkins wrote:

On Mon, Feb 2, 2015 at 9:13 AM, Alan Gauld 
wrote:


Don't expect a whole heap of support from the GUIs. A lot of the work will
have to come from you.
I suspect the standard GUI framework Tkinter is not going to be your best
bet. You might find that PyQt or PyGTK will offer better multi lingual
support  (although thats just a guess on my part!).



Might I also suggest wxPython?  I tried Tk and Qt early on, but found that
wx fit my needs much better (and I like the looks of the result better too.)
I have little to no experience with LTR handling myself, but there's a very
good, active support list for wxPython and I suspect that someone on that
list may have insights that can help...
wxpython-us...@googlegroups.com


For the type of work the OP has previously described I doubt that 
wxPython fits the bill as the Python 3 version called Phoenix is still 
in development.  More here http://wiki.wxpython.org/ProjectPhoenix


--
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] GUI

2015-02-02 Thread Marc Tompkins
On Mon, Feb 2, 2015 at 9:13 AM, Alan Gauld 
wrote:

> Don't expect a whole heap of support from the GUIs. A lot of the work will
> have to come from you.
> I suspect the standard GUI framework Tkinter is not going to be your best
> bet. You might find that PyQt or PyGTK will offer better multi lingual
> support  (although thats just a guess on my part!).
>

Might I also suggest wxPython?  I tried Tk and Qt early on, but found that
wx fit my needs much better (and I like the looks of the result better too.)
I have little to no experience with LTR handling myself, but there's a very
good, active support list for wxPython and I suspect that someone on that
list may have insights that can help...
wxpython-us...@googlegroups.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] GUI

2015-02-02 Thread Alan Gauld

On 01/02/15 20:16, D.Edmons wrote:


I've compiled both python2 and python3 and am starting to learn them
well enough to do a GUI application that requires UTF-8.


OK, We can help with the basics, thats what this group is for.
Learning Python and its standard library.


Anyway, I suspect that I'll have to use python3 to take advantage of the
UTF-8 (is there a __FUTURE__ option for python2?).


Python2 can work with unicode but its more effort than in Python 3 so I 
suspect you should go straight to Python 3.



minor GUI stuff, but what I need is an application that will do Hebrew
(left <-- right) that actually attempts to "get it right".  Also, I'm
creating a Hebrew Dictionary database and my GUI will have to work with
it (ie. it is the whole purpose of this exercise).


Don't expect a whole heap of support from the GUIs. A lot of the work 
will have to come from you.
I suspect the standard GUI framework Tkinter is not going to be your 
best bet. You might find that PyQt or PyGTK will offer better multi 
lingual support  (although thats just a guess on my part!).



I started out with Perl, but haven't made much progress.  Python kept
coming up in my searches, so I'm attempting to switch over.


Python or Perl do much the same thing. Python is easier to read 
(although being a Python group I'm biased...)



the major features I hope to incorporate into the application:
 ื) Hebrew keyboard application that will easily switch back and
forth between English and Hebrew character sets.  Key assignments will
be user defined or easily reprogrammed so that both standard and custom
configurations can be made: (ie similar to
http://www.lexilogos.com/keyboard/hebrew.htm )


I've no idea how you support that in a GUI. It may well be beyond the 
scope of this list too. I suspect that once you identify your target GUI 
framework that their support forums will be better suited to answer.



 ื‘) Dual screen editor for simplified search and replace (hebrew
with nikkud, with option to ignore the nikkud/vowels to find
shoreshim/roots) feature.  One window will be the compiled dictionary.
The second window will be any Hebrew text (Torah, Siddur, etc...).  The
application will--hopefully--automatically search the "dictionary" based
upon the current cursor and add the English definition of the Hebrew
word with a click or two.  (I'm learning Hebrew, as I go, studying every
week, if not every day.)


This sounds very advanced for a first project (but then, so is a device 
driver!) Certainly probably beyond this lists scope.



 ื’) Obviously, a menu bar with tools and other standard GUI bits and
pieces.


Yep, that kind of stuff we might help with. But again the GUI support 
forum is likely to be better still.



Actual Request:

I'm running an older Debian Linux, that doesn't upgrade very well.  Is
there anybody willing to help me at least get started or point me in the
right direction?


We don't really provide 1-1 mentoring. You ask questions on the list and 
the list members answer. You might be very lucky and find someone who is 
familiar with your problem domain, but its a long shot.



Knowledge of Hebrew would be a *huge* plus, but isn't required in any
...  Thus, leafpad would be a reasonable model for the editor.


Again thats a pretty specialized set of skills on top of Python. You 
might try the main Python mailing list/nesgroup. You have a bigger 
audience there to find someone suitable to help you.


--
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] os module question

2015-02-02 Thread Alan Gauld

On 02/02/15 13:46, maurice.ho...@thomsonreuters.com wrote:

This is my first post. I'm a sysadmin and I'm new enough to python so I'm 
trying to practice.


Welcome to the list.
It looks like you are running a Unix variant but it helps to tell us 
exactly which OS and Python version.



I'm want to run a script that takes a server name from the command line and

> takes that servername which queries an internal asset database.


I thought I could use the os module to take servername and run a

> command against it to query the database and then populate

a variable.


You can, although you will also want the subprocess module to
run the shell commands. Thee are several functions that will execute 
external programs in the os module but they are all deprecated in favour 
of subprocess which is safer and more flexible.



Basically I have trouble with two things:
1)  Get the server to take the hostname and use it to run a command against 
it


os.uname() will return a tuple.
The second item is the hostname


2)  Send a variable (as opposed to a string) to the function to print


myfunc('astring')   # call func with string

myvar = 'astring'   # assign string to a variable
myfunc(myvar)   # call func with variable

notice where the quotes go...and that there are no $ or % signs
needed to indicate variables, as per the shell/perl etc.


#!/usr/bin/env python

import sys
import os

hostname = sys.argv[1]
no_of_args = len(sys.argv)

# Colours for pass and fail
class bcolours:
 PASS = '\033[32m'
 FAIL = '\033[31m'
 ENDC = '\033[0m'

 def disable(self):
 self.PASS = ''
 self.FAIL = ''
 self.ENDC = ''


I'm not sure if you realize what this does? It does not change the 
values defined above. It creates local values in a specific object instance.


I'll assume you know what the colour values are for your
own terminal...



def print_red(string):
 red_string = bcolours.FAIL + string + bcolours.ENDC
 print(red_string)

def print_green(string):
 green_string = bcolours.PASS + string + bcolours.ENDC
 print(green_string)


And I assume you tested these at the >>> prompt.


if no_of_args != 2:
 print_red("Incorrect number of arguments entered")
 sys.exit(1)

#hostname_ppid = os.system('queryhost', '-c patch', hostname)
hostname_ppid1 = "queryhost -c patch 'hostname'"
hostname_ppid = os.system(hostname_ppid1)


This why you need subprocess. os.system only returns the error code,
it will not let you access the command output.

Read the subprocess docs they give many examples to show how
to use it.

I suspect you want something like:

query = subprocess.Popen(['queryhost', '-c patch', hostname],
  stdout=subvprocess.PIPE)
hostname_ppid = query.communicate()[0]

It looks (and is) complicated compared to os.system() but its more 
secure and offers a lot of flexibility. Its well worth the extra pain.


HTH
--
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] Wondering about a project

2015-02-02 Thread Alan Gauld

On 02/02/15 13:45, dw wrote:

Hi Python gang.
In my Ubuntu system, I'm pondering a first GUI Python project:
1) Prompt for a user input string.
 The intended string would be a youtube URL
2) Call youtube-dl to download the file
3) When the file is downloaded, call GnomePlayer or VLC to play the file

I'm new at Python and haven't built a GUI application yet.
I wonder if this project would be over my head?
Perhaps I should attempt to build it in terminal mode first?


Its usually a good idea to build a command line version first
and in this case I'd say essential. The GUI bit is so trivial
compared to the back end section that it should be simple - an
input box and a button or two. Its much easier to build a GUI
on top of something you know works, especially when you are
new to GUIs!

Your biggest choice is which GUI framework to use. Tkinter is the 
standard library option but wxPython, PyGTK and PyQt/pySide are

also popular although third party downloads.

--
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] os module question

2015-02-02 Thread maurice.horan
Hi,

This is my first post. I'm a sysadmin and I'm new enough to python so I'm 
trying to practice.

I'm want to run a script that takes a server name from the command line and 
takes that servername which queries an internal asset database. I thought I 
could use the os module to take servername and run a command against it to 
query the database and then populate a variable. If the variable is equal to 
none it produces an error message in red, if it's successful then it prints it 
in green. I left a comment in for the first.

Basically I have trouble with two things:

1)  Get the server to take the hostname and use it to run a command against 
it

2)  Send a variable (as opposed to a string) to the function to print

Thanks for reading geveryone!
Maurice

#!/usr/bin/env python

import sys
import os

hostname = sys.argv[1]
no_of_args = len(sys.argv)

# Colours for pass and fail
class bcolours:
PASS = '\033[32m'
FAIL = '\033[31m'
ENDC = '\033[0m'

def disable(self):
self.PASS = ''
self.FAIL = ''
self.ENDC = ''

def print_red(string):
red_string = bcolours.FAIL + string + bcolours.ENDC
print(red_string)

def print_green(string):
green_string = bcolours.PASS + string + bcolours.ENDC
print(green_string)

if no_of_args != 2:
print_red("Incorrect number of arguments entered")
sys.exit(1)

#hostname_ppid = os.system('queryhost', '-c patch', hostname)
hostname_ppid1 = "queryhost -c patch 'hostname'"
hostname_ppid = os.system(hostname_ppid1)

if hostname_ppid == "None":
print_red("No PPID")
sys.exit(1)
else:
print_green(hostname_ppid)
sys.exit(1)



This e-mail is for the sole use of the intended recipient and contains 
information that may be privileged and/or confidential. If you are not an 
intended recipient, please notify the sender by return e-mail and delete this 
e-mail and any attachments. Certain required legal entity disclosures can be 
accessed on our website.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


[Tutor] Wondering about a project

2015-02-02 Thread dw
Hi Python gang.
In my Ubuntu system, I'm pondering a first GUI Python project:
1) Prompt for a user input string.
The intended string would be a youtube URL
2) Call youtube-dl to download the file
3) When the file is downloaded, call GnomePlayer or VLC to play the file

I'm new at Python and haven't built a GUI application yet.
I wonder if this project would be over my head?
Perhaps I should attempt to build it in terminal mode first?
-- 
 bw...@fastmail.net

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


Re: [Tutor] Assistance with UnicodeDecodeError

2015-02-02 Thread Dave Angel

On 02/02/2015 02:52 AM, Cristian Di Stefano wrote:

Hi Dave,

you should set the correct encoding (maybe utf-8) in order to handle
data from web. You cannot handle unicode data with simple string, you
should encode to ASCII or manage data with the unicode type

Best
Cristian



Please don't top-post, as it confuses who wrote what part and in what 
sequence.  But I can see you're already confused, as you're addressing 
me when replying to J Mberia.


In any case, one cannot encode to ASCII, so you have to be much more 
explicit in what you're trying to say.  Or just wait till the OP 
clarifies his own code.




Il 31/01/2015 23:44, Dave Angel ha scritto:

On 01/31/2015 08:37 AM, J Mberia wrote:

Hi,








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


Re: [Tutor] Assistance with UnicodeDecodeError

2015-02-02 Thread Cristian Di Stefano

Hi Dave,

you should set the correct encoding (maybe utf-8) in order to handle 
data from web. You cannot handle unicode data with simple string, you 
should encode to ASCII or manage data with the unicode type


Best
Cristian

Il 31/01/2015 23:44, Dave Angel ha scritto:

On 01/31/2015 08:37 AM, J Mberia wrote:

Hi,



Welcome to Python tutor.  Thanks for posting using text email, and for 
specifying both your Python version and Operating system.



I am teaching myself programming in python and assistance with
UnicodeDecodeError

I am trying to scrap text from a website using Python 2.7 in windows 
8 and
i am getting this error *"**UnicodeDecodeError: 'charmap codec can't 
encode

character u'\u2014 in position 11231 character maps to "*

*How do i resolve? Pls assist.*



You can start by posting the whole error message, including the stack 
trace.  Then you probably should include an appropriate segment of 
your code.


The message means that you've got some invalid characters that you're 
trying to convert.  That can either be that the data is invalid, or 
that you're specifying the wrong encoding, directly or implicitly.





---
Questa e-mail รจ stata controllata per individuare virus con Avast antivirus.
http://www.avast.com

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