Re: [Tutor] Calling variable from two different classes

2009-02-13 Thread Hi
I want to be able to call a variable from one of my classes to my main class
(interface layout) and have it update every minute. I am using Python and
wxPython. Is it better to be in the main class and read the variable or
should I have the class the variable resides in to send the variable along
to the main class?  In my interface class I have it as:

display = wx.StaticText(self, -1, '', (50, 50))

while the class where the variable is in:

data_rate = 5000

and I want to be able to put the value stored in data_rate into display so
that I can show it on my interface. And regarding the update per some time,
I am looking into the poll command. Is that the direction where I should be
heading? (I know updating data_rate won't do anything right now since it's a
constant, but it will vary later on... just one step at a time here).
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Auto Refresh

2009-02-27 Thread Hi
I am trying to read a value in a variable from a different class every time
I click on a refresh button for my GUI program. The problem is I am using
statictext so when I refresh, it displays the new value on top of the old
one.

In my main GUI:

def refresh(self, event):
x = refresh_var()
value = wx.StaticText(self, -1, str(x.var_rate))


In my refresh class:

class refresh_var():

 def var_rate(self):
 random_var = random.randint(5, 100)
 return random_var

So each time I click on the button, which runs refresh, the new value
generated by random.randint will be on top of the old number. Is there any
commands I can use to remove the old value that is on the GUI window before
I put the new one on there? Or is there a better command/syntax that does
the same job? I am ultimately trying to make it so the GUI program refreshes
and rereads random_var on a set interval. Can anyone offer any advice on how
to do it or any commands I can read up on the Internet?
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Auto Refresh

2009-02-28 Thread Hi
Thank you for the reply, SetLabel is exactly what I am looking for. And yes,
you were correct, I just typoed the var_rate() when I was composing the
email. So what I did is in my main GUI class:

wx.StaticText(self, -1, sampling rate':', (107, 150))
self.rate_status = wx.StaticText(self, -1, '', (190, 150))#just to
initialize rate_status to some location

def refresh(self, event):
x = rate()
rate_text = self.rate_status.SetLabel(str(x.rate_var()))


and in my class that contains the variable (which will change every so often
at the end, so right now I'm modeling this with a random generator):

class rate():

def rate_var(self):
samp_rate = random.randint(44100, 48000)
return samp_rate

I want to make it so once def refresh ran, it will continuously update and
display the new value in samp_rate in my main GUI at some time interval, say
every 10 seconds. I have looked up Timer, but I have not been able to make
it work. I looked up the documentation in Python's website to no avail. Can
anyone suggeste anything to help me?


On Fri, Feb 27, 2009 at 5:05 PM,  wrote:

>
> Message: 7
> Date: Sat, 28 Feb 2009 01:00:21 -
> From: "Alan Gauld" 
> Subject: Re: [Tutor] Auto Refresh
> To: tutor@python.org
> Message-ID: 
> Content-Type: text/plain; format=flowed; charset="iso-8859-1";
>reply-type=original
>
>
> "Hi"  wrote
>
>
> > In my main GUI:
> >
> > def refresh(self, event):
> > x = refresh_var()
> > value = wx.StaticText(self, -1, str(x.var_rate))
>
> Its not clear how you are positioning Static Text, I suspect you
> need it as a opart of your main GUI and then reference it in
> here and use the SetLabel() method to update its contents.
>
> But I also not that you are not calling the var_rate method of x.
> Or does your code really look like
>
> value = wx.StaticText(self, -1, str(x.var_rate()))
>
> Notice the extra parens...
>
> > So each time I click on the button, which runs refresh, the new
> > value
> > generated by random.randint will be on top of the old number. Is
> > there any
> > commands I can use to remove the old value that is on the GUI window
> > before
> > I put the new one on there?
>
> I think you can just update the content of the original Text widget
> using SetLabel()
>
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
>
> End of Tutor Digest, Vol 60, Issue 143
> **
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Docking Windows using Python

2009-05-29 Thread Hi
My program will have two windows. I want to be able to dock the two so they
are side by side. I am wondering if this is doable in Python. If so, could
someone lead me to the right direction on where to look? Thank you very
much.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Question on how to open other programs and files

2009-02-07 Thread Hi
I have a question regarding how to open other programs and files in Python
code. I am creating a simple interface and I want it to be able to open
other files, such as a text file or a pdf file. However, those files are
usually associated with other programs - for instance, gedit for text and
document viewer for pdf (I am using Ubuntu 8.10). What syntax or commands do
I need in order to do so. I've used os.popen in Windows XP and it works
fine, but the same code does not work in Ubuntu. This is the part of my code
that deals with opening files/programs:

def openfile(self, event):
 result =  os.popen("home/user/textfile.txt")

In the terminal it simply says, sh: home/user/textfile.txt: not found. And I
have already set permissions via chmod +x on the files of my choosing. Any
help would be greatly appreciated.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] UPDATED: Question on how to open other programs and files

2009-02-08 Thread Hi
Re: Question on how to open other programs and files (Alan Gauld)

Sorry for being confusing on my last e-mail. I will try to clarify my
intents a bit further. In short, I want to be able to read the data in the
file as well as launch document viewer in Python. For one of the files I
want to read the data from a Python script that's in the same folder as the
GUI Python script. For the pdf file I simply want to be able to launch
document viewer from Python. I know it is probably a lengthy and demanding
request, but I just want to be able to do both eventually in my GUI program.
I am still very new at Python, and so any help would be very useful for me.
I have tried to look up different tutorials online, but I have not found one
that addresses my issues.

On Sun, Feb 8, 2009 at 1:10 AM,  wrote:

> Send Tutor mailing list submissions to
>tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>tutor-requ...@python.org
>
> You can reach the person managing the list at
>tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>   1. Completed project. Is this correct? Can I simplify my
>  formulas? (cclpia...@comcast.net)
>   2. Oops! I just corrected my file:RE Completed project is this
>      correct? (cclpia...@comcast.net)
>   3. Question on how to open other programs and files (Hi)
>   4. Re: Exec(uting) Code in a Dictionary? (spir)
>   5. Re: Question on how to open other programs and files (Alan Gauld)
>   6. Re: WINSOCK stdin question (Alan Gauld)
>
>
> --
>
> Message: 1
> Date: Sat, 7 Feb 2009 20:45:25 -0700
> From: cclpia...@comcast.net
> Subject: [Tutor] Completed project. Is this correct? Can I simplify my
>formulas?
> To: tutor@python.org
> Message-ID: <4070a0f9-63dc-4bbf-80fa-6d369b656...@comcast.net>
> Content-Type: text/plain; charset="us-ascii"; Format="flowed";
>DelSp="yes"
>
> Hello, I've enclosed a completed project (my first!) and would like
> to know of it's accuracy. Also, what I could do to simplify the
> language.
>
> Thanks,
>
> Pat
>
> -- next part --
> A non-text attachment was scrubbed...
> Name: Grant.py
> Type: text/x-python-script
> Size: 2935 bytes
> Desc: not available
> URL: <
> http://mail.python.org/pipermail/tutor/attachments/20090207/940c1e50/attachment-0001.bin
> >
>
> --
>
> Message: 2
> Date: Sat, 7 Feb 2009 21:02:21 -0700
> From: cclpia...@comcast.net
> Subject: [Tutor] Oops! I just corrected my file:RE Completed project
>is this correct?
> To: tutor@python.org
> Message-ID: <47b95607-d82c-4c70-b16b-d4be610bf...@comcast.net>
> Content-Type: text/plain; charset="us-ascii"; Format="flowed"
>
> Forget the first, this is the corrected version.
>
> Thanks,
>
> Pat
> -- next part --
> A non-text attachment was scrubbed...
> Name: Grant.py
> Type: text/x-python-script
> Size: 2901 bytes
> Desc: not available
> URL: <
> http://mail.python.org/pipermail/tutor/attachments/20090207/afc8b9e6/attachment-0001.bin
> >
>
> --
>
> Message: 3
> Date: Sat, 7 Feb 2009 22:09:04 -0800
> From: Hi 
> Subject: [Tutor] Question on how to open other programs and files
> To: tutor@python.org
> Message-ID:
>
> Content-Type: text/plain; charset="iso-8859-1"
>
> I have a question regarding how to open other programs and files in Python
> code. I am creating a simple interface and I want it to be able to open
> other files, such as a text file or a pdf file. However, those files are
> usually associated with other programs - for instance, gedit for text and
> document viewer for pdf (I am using Ubuntu 8.10). What syntax or commands
> do
> I need in order to do so. I've used os.popen in Windows XP and it works
> fine, but the same code does not work in Ubuntu. This is the part of my
> code
> that deals with opening files/programs:
>
> def openfile(self, event):
> result =  os.popen("home/user/textfile.txt")
>
> In the terminal it simply says, sh: home/user/textfile.txt: not found. And
> I
> have already set permissions via chmod +x on the files of my choosing. Any
> help would be greatly appreciated.
> -- next part --
> An HTML attac