lllllIllIlllI 178 Veteran Poster

Just remember to find a lot of solution to questions just google it.
I know it is not always the best way but if you put 'playing sound in python' into google the first 3 results would fit your question quite well.
But anyhow no worries for the help. :)

lllllIllIlllI 178 Veteran Poster

have you had a look at Threading?

lllllIllIlllI 178 Veteran Poster

Hi
I have made a program with wxPython and i have this bit of code:

def getpic(self,event,urlp='http://mirror.bom.gov.au/radar/IDR043.gif?20080427173538'):
        fc = url.urlretrieve(urlp,filename='Weather.jpg')
        image_file = 'Weather.jpg'
        self.bmp = wx.Bitmap(image_file)
        self.img = wx.StaticBitmap(self.background, wx.ID_ANY, self.bmp, pos = (20, 60))
        self.background.SetInitialSize()

This is a bit of my code, not the full thing but this is the bit that gets an image from the web and plasters it to self.background. My problem is that i want the picture to change so when i give it a url that is different it cleares the current picture from the screen and adds the new image.

Any help would be greatly appreciated. :)

lllllIllIlllI 178 Veteran Poster

If you were just playing sound the module 'winsound' would do the trick if you were on a windows machine.

lllllIllIlllI 178 Veteran Poster

Government is a great, great thing. As much as it it annoying i think without it helping and 'being the centre of out existance' we all would be in a much worse place today. Governments are sort of like a buisness that has a monopoly on a whole place and can do with it whatever it pleases.
But even though they have a monopoly they dont do all bad. I think one thing that does happen is the news highlights the bad rather then focusing on what Good has happend so in some cases people will think what the media want them to think. The government being the center of out existance it important because even though we sometimes hate it to bits what would we do without it? Who would fix the roads? Who would keep public transport running? What about all the schools. I think that we Need a center of our existance to do those jobs so we dont have to. Sorry if you dont agree thats just my personal opinion

lllllIllIlllI 178 Veteran Poster

_________________________
|Its not how much it costs- |
|Its what you do with it! |
_________________________

lllllIllIlllI 178 Veteran Poster

clap

lllllIllIlllI 178 Veteran Poster

i live in australia and i never hear ANY of the other names for it.

lllllIllIlllI 178 Veteran Poster

Um just a quick note:
Im under the impression you do have parentheses after a class definition becuase this can be used to set class parents and attibutes as well as making it a new-style class.

# a few examples
import wx

class MainFrame(wx.Frame):
    pass
    #this means this class has all the attributes of wx.Frame
class Parent(object):
    #new style class
class Child(Parent):
    #child has all attributes of Parent
lllllIllIlllI 178 Veteran Poster

yeah thats perfect. Thanks everyone!

lllllIllIlllI 178 Veteran Poster

thats a comment, anything after a hash is a comment in python

lllllIllIlllI 178 Veteran Poster

is there any way using the os or sys modules that you can find the resolution of the screen and then maybe apply it to

frame.SetSize((x,y))

so that way it could run on machines that had different resolutions without looking weird

lllllIllIlllI 178 Veteran Poster

oh yeah i forgot all about list comprehensions!:$

lllllIllIlllI 178 Veteran Poster

no worries. :)

lllllIllIlllI 178 Veteran Poster

you could use a set. That would split the word into a set with all individual letters in it or you could go

strings = 'airplane'
letters = []
for letter in strings:
    letters.append(letter)
print letters #['a','i','r','p','l','a','n','e']

There might be a better way to do it but thats what i could come up with. :)

lllllIllIlllI 178 Veteran Poster

166 = 10100110

lllllIllIlllI 178 Veteran Poster

Hi
i have been fiddling around with the wxPython GUI toolkit for a bit and i wanted one of my programs to start with the window expanded. I googled it but couldn't find an answer there so any help here would be greatly appreciated.

lllllIllIlllI 178 Veteran Poster

yeah i replaced all the -1's in the program with wx.ID_ANY and thanks for the help with the ampersand sign

lllllIllIlllI 178 Veteran Poster

have you added the path in which Class1 is situated to sys.path?

Try this:

import sys
sys.path.append(place where myclass1 is located)
import MyClass1

class MyClass2():
    anobject = MyClass1()

Make sure the file in which MyClass1 is located is called MyClass1.py or pyw or something like that

lllllIllIlllI 178 Veteran Poster

I have one last question about menus in the above program.

self.save = self.menufile.Append(-1,'&Save')

what is the -1 there for and also why is there a & sign?

lllllIllIlllI 178 Veteran Poster

Yeah i just found that right click stuff then too.
The event.Skip() thing worked flawlessly thanks for pointing that out.
Just wondering also where you find the documentation for wxPython because i have nothing of the sort installed on my computer when i installed all of the wxPython modules

lllllIllIlllI 178 Veteran Poster

Hi
Using a template from the tutorial Fuse offered i made this program:

import wx
import os

WINDOW_WIDTH = 700
WINDOW_HEIGHT = 600

class MainFrame(wx.Frame,object):
    
    def __init__(self):
        
        wx.Frame.__init__(self,None,
                          title = "Paul's Text Editor",
                          pos = (200,75),
                          size = (WINDOW_WIDTH,WINDOW_HEIGHT))

        self.menubar = wx.MenuBar()
        self.menufile = wx.Menu()
        self.menuinfo = wx.Menu()
        self.SetMenuBar(self.menubar)

        self.menubar.Append(self.menufile,'&File')

        self.loadItem = self.menufile.Append(-1,'&Load')

        self.Bind(wx.EVT_MENU,self.loadEvent,self.loadItem)

        self.save = self.menufile.Append(-1,'&Save')
        self.Bind(wx.EVT_MENU,self.saveevent,self.save)

        self.exititem = self.menufile.Append(-1,'E&xit')
        self.Bind(wx.EVT_MENU,self.exitevent,self.exititem)

        self.menubar.Append(self.menuinfo,'&Info')

        self.aboutitem = self.menuinfo.Append(-1,'&About')
        self.Bind(wx.EVT_MENU,self.aboutevent,self.aboutitem)

        self.helpitem = self.menuinfo.Append(-1,'&Help')
        self.Bind(wx.EVT_MENU,self.helpevent,self.helpitem)
        
        


        
        self.background = wx.Panel(self)
        

        
        self.tbut = wx.Button(self.background,label = 'transfer')
        self.tbut.Bind(wx.EVT_BUTTON,self.transferEvent)
        self.first = 1
        self.inarea = wx.TextCtrl(self.background,style=wx.PROCESS_ENTER)
        self.inarea.Bind(wx.EVT_TEXT_ENTER,self.transferEvent)
        self.inarea.SetValue("Enter Data Line by Line")
        self.inarea.Bind(wx.EVT_LEFT_UP,self.clearin)
        self.transarea = wx.TextCtrl(self.background,
                                     style =  wx.TE_MULTILINE)

        self.transarea.SetValue("Or go for it in here!")
        self.transarea.Bind(wx.EVT_LEFT_UP,self.cleartransarea)
        self.horbox = wx.BoxSizer()
        self.horbox.Add(self.inarea,proportion = 1,border=0)
        self.horbox.Add(self.tbut,proportion=0,border = 0)


        self.vbox = wx.BoxSizer(wx.VERTICAL)
        self.vbox.Add(self.horbox,proportion=0,flag=wx.EXPAND,
                      border=0)
        self.vbox.Add(self.transarea,proportion=1,flag=wx.EXPAND,
                      border=0)

        
        self.background.SetSizer(self.vbox)
        self.Show()
        self.loaded=0
        self.Bind(wx.EVT_CLOSE,self.OnExit)
    def cleartransarea(self,event):
        self.transarea.SetValue('')
    def clearin(self,event):
        print event
        self.inarea.SetValue('')


        
    def loadEvent(self,event):
        
        loadbox = wx.FileDialog(self,message='open',
                                defaultDir=os.getcwd(),
                                defaultFile='',
                                style = wx.OPEN)
        if loadbox.ShowModal() == wx.ID_OK:
            self.filename=loadbox.GetPath()
            target = open(self.filename,'rb')
            self.transarea.SetValue(target.read())
            target.close
            self.loaded = 1
        loadbox.Destroy()

        
    def OnExit(self,event):
        self.exitevent(wx.EVT_CLOSE)
        self.Destroy()

        
    def exitevent(self,event):
        if self.loaded:
            checksave = wx.MessageDialog(self,message = 'do you want to save?',
                                         style = wx.YES_NO)
            if checksave.ShowModal() == wx.ID_YES:
                f = open(self.filename,'w')
                f.write(self.transarea.GetValue())
                f.close()
        else:
            if len(self.transarea.GetValue()) >0:
                checksave = wx.MessageDialog(self,message = 'do you want to save?',
                                             style = wx.YES_NO)
                if checksave.ShowModal() == wx.ID_YES:

                    self.saveevent(None)
                
        self.Destroy()
    
    def saveevent(self,event):
        if self.loaded:
            overwrite = wx.MessageDialog(self,message="Would you like to overwrite the file?"
                                         ,style = wx.YES_NO)
            if overwrite.ShowModal()==wx.ID_YES:
                g = wx.MessageDialog(self,message='Saved!',style=wx.OK)
                g.ShowModal()
                f = open(self.filename,'w')
                f.write(self.transarea.GetValue())
                f.close()
        else:
            savebox = wx.FileDialog(self,message = 'Where will you save the file?',
                                    defaultDir="C:\\", …
lllllIllIlllI 178 Veteran Poster

Hi
I am making a program that collects data and then saves it to a text file.
Then i want it to print the text file on a Network Printer and i was wondering how i would go about doing that?

lllllIllIlllI 178 Veteran Poster

yeahs its all really good and great to learn with. Well done and thanks. :)

lllllIllIlllI 178 Veteran Poster

have you tried making the stuff you get from the file an integer
That way it compares two integers not a string and an integer.

lllllIllIlllI 178 Veteran Poster

yeah. Wx certainly looks good. I take it it is a lot more powerful than Tkinter in the end too. I was looking for some tutorials on it but i cannot find any that go slowly from the start. I just want a tutorial that doesn't rush through the start.

lllllIllIlllI 178 Veteran Poster

You could always do something like this:

m= int(start[1])*60+int(start[4])
n= int(finish[1])*60+int(finish[4])

That will make M and N integers so you do not need to convert them at all but i did my own program to do the same thing to see if i could change anything and this is what i got:

def length(): #using a function
    print 'Please enter the start of the show in the format 03,16'
    start = raw_input(">")
    print "Please enter the end of the show in the format 03,16"
    end = raw_input(">")
    m = int(start[:2]) *60+int(start[3:])
    n = int(end[:2]) *60+int(end[3:])
    length = n-m
    print "the show lasted for %i minutes" %length


while True: 
    length()
    print "Press enter to restart and x to exit"
    f = raw_input()
    if f.lower() == 'x':
        break
    else:
        pass
lllllIllIlllI 178 Veteran Poster

Hi
I have been doing text programming for a while now and i was going to start doing some graphical interfaces for my programs but i was wondering which one is the best for beginners and also what and ther advantages/disadvantages of each of them.
Thanks

lllllIllIlllI 178 Veteran Poster

yeah that [0] was only there becuase there was a tuple in the previous versions of code

lllllIllIlllI 178 Veteran Poster

ah heres a quick idea.

f = file(filename+".txt",'w')
in = raw_input(">")
f.write(in+"\n")
f.close()

This will open a file with the extention of .txt and then it will get a raw_input and write it to a text file and then add a new line and then close the file.
If what you are trying to write an integer to a text file make sure to do this:

f.write(str(integer here))
f.close()

yeah this might not be the fastest way but its the best i can do.

lllllIllIlllI 178 Veteran Poster

you can do a

While True:
    ##insert program
    print "press enter to restart"
    raw_input()

OR

exec file(filename here)
lllllIllIlllI 178 Veteran Poster

alright how about this:

import time
day = time.localtime()[2]
month = time.localtime()[1]
year = time.localtime()[0]
print day,'/',month,'/',year

This does not show the name of the day but the date in the same format as dd/mm/yy

lllllIllIlllI 178 Veteran Poster

Hi
I was wondering if there was any way i could use a module or some code to enable and disable my wireless network becuase i often have the problem that it wont connect and enabling and disabling it a number of times nearly always fixes it and i was wondering if i could use a python script that would do that for me. I have looked around at a few modules like socket but im really not sure about anything when it comes to network programming so any help would be really appreciated.

lllllIllIlllI 178 Veteran Poster

no worries

lllllIllIlllI 178 Veteran Poster

you could do it by making it into the amount of minutes. This way you can make sure it stays base 60
TO get the difference in minutes:

g = time.localtime()[3:5]
f = time.localtime()[3:5]
m = g[0]*60+g[1]
n = f[0]*60+f[1]
print n-m

to make it back into hours and minutes:

g = time.localtime()[3:5]
f = time.localtime()[3:5]
m = g[0]*60+g[1]
n = f[0]*60+f[1]
g=n-m
hours = g/60
g=g-hours*60
mn = g
print hours,":",mn

I think that works

lllllIllIlllI 178 Veteran Poster

you can use the following code:

time.localtime()[3:5]

that just gives the hour and the minutes

lllllIllIlllI 178 Veteran Poster

You should try using the time module

import time
print time.localtime()
lllllIllIlllI 178 Veteran Poster

Yeah it all depends on what you want. I used IDLE for a long time too but i found PyScripter really, really good becuase you could debug it really well and that worked for me.
So yeah it really depends on what you are looking for.

lllllIllIlllI 178 Veteran Poster

Yeah i gave up.. If only they had an all in one installer. Oh well i have been trying Pyscripter and it is working really well.

lllllIllIlllI 178 Veteran Poster

Try this: write a program that tests someones reaction times and records them in a text file and then makes comparisons to see the level of improvment or the lack of.

sneekula commented: nice idea +4
lllllIllIlllI 178 Veteran Poster

OH thanks that really did the trick!

lllllIllIlllI 178 Veteran Poster

Hi
I have been working on a blackjack program and i have hit a brick wall as one of my Global assignments isn't working for some reason

import random
class Cards(object):
    def __init__(self):
        global cards
        global player  
        global comp
        global comp_tot
        global playert
        cards = {2:4,3:4,4:4,5:4,6:4,7:4,8:4,9:4,10:16,'ace':4}
        player = []
        playert = 0
        comp_tot=0
        comp = []
        print playert,'hi'
        print "The Game is Blackjack"
    def draw(self):
        f = cards.keys()
        a = random.choice(cards.keys())
        cards[a]-=1
        if cards[a] == 0:
            del cards[a]
            if len(cards)==0:
                print "out of cards"
                return False
        return a
    def First_turn(self):
        print comp_tot
        print cards
        print player
        print playert
        card1=self.draw()
        card2=self.draw()
        card2='ace'
        if card1 is not 'ace' and card2 is not 'ace':
            player.append(card1)
            player.append(card2)
            value=card1+card2
            print "your cards are:",card1,"and",card2
            print value
            playert+=value
        else:
            player.append(card1)
            player.append(card2)
            count =0
            if card1 =='ace':
                count = 'c1'
                if playert+11>21:
                    val = 1
                else:
                    val=11
            elif card2 == 'ace':
                count ='c2'
                if playert + 11 >21:
                    val = 1
                else:
                    val = 11
            
                

c = Cards()
c.First_turn()

every other global variable works exept playert. Any help on how to fix this would be appreciated. Oh also the error i am getting goes like this

Traceback (most recent call last):
  File "C:/Documents and Settings/Paul/My Documents/Python/projects/Blackjack/jack1.0.py", line 61, in <module>
    c.First_turn()
  File "C:/Documents and Settings/Paul/My Documents/Python/projects/Blackjack/jack1.0.py", line 30, in First_turn
    print playert
UnboundLocalError: local variable 'playert' referenced before assignment

oh and also sorry for all the added prints, they were for debugging purposes

lllllIllIlllI 178 Veteran Poster

I thought got told by some people at school to try it out

lllllIllIlllI 178 Veteran Poster

Hi
I was wondering if there was any way in which using Python i would be able to move the mouse pointer and make it click at certain x and y values. This would be used in a Macro type machine for the mouse. I have looked around for modules that can be used with the mouse but i can't find any at all.
Any help would be greatly appreciated.

lllllIllIlllI 178 Veteran Poster

I have made some progress and now i get this error message

Compiling debugger files.
Listing eric ...

Installing eric4 ...
An internal error occured.  Please report all the output of the program,
including the following traceback, to eric4-bugs@die-offenbachs.de.

Traceback (most recent call last):
  File "C:\Python25\install.py", line 658, in <module>
    main(sys.argv)
  File "C:\Python25\install.py", line 633, in main
    installEric()
  File "C:\Python25\install.py", line 355, in installEric
    shutil.copy(wname, cfg['bindir'])
  File "C:\Python25\lib\shutil.py", line 80, in copy
    copyfile(src, dst)
  File "C:\Python25\lib\shutil.py", line 41, in copyfile
    raise Error, "`%s` and `%s` are the same file" % (src, dst)
Error: `eric4-api.bat` and `C:\Python25\eric4-api.bat` are the same file

No idea what to do

lllllIllIlllI 178 Veteran Poster

yeah i have that installed but for some reason the message still comes up

lllllIllIlllI 178 Veteran Poster

Hi
I have been trying to install the ERIC python IDE
http://www.die-offenbachs.de/eric/eric-links.html
for a while now to no sucess. I could not i kept getting errors when installing the QT module

Determining the layout of your Qt installation...
Error: Make sure you have a working Qt v4 qmake on your PATH.

i have no idea what i am doing wrong becuase i cant find any good installation tutorials
To run ERIC needs these certain modules but i can't seem to get them working at all
Any help would be appreciated.

lllllIllIlllI 178 Veteran Poster

You could do it like this.

how_many_fibs = 100
x,y=0,1
while how_many_fibs:
    x,y=y,y+x
    print y
    how_many_fibs-=1

This will make 100 fibonacci numbers
how this helps
;)

lllllIllIlllI 178 Veteran Poster

sorry for double posting but i have finished my code and i have taken all the stuff inside the brackets out with the following code:

count = data.count('<')

while count:
    start = data.find('<')
    end = data.find('>')
    rem = data[start:end+1]
    data = data.replace(rem,'',1)
    count-=1

the other code i tried didn't work because of the bit where i said:

data[start:end] = ''

that got me some error relating to how strings are immutable and stuff like that. But anyhow i have used this to make a script that finds and returns my local weather forecast for the next few days.
Thanks for all the help!

lllllIllIlllI 178 Veteran Poster

Okay.
The tags are just bits in the source like <b> and </b> to make the text inbetween bold.
I had an idea of how to do it though. Hows this?

code = "source of webpage goes here"
count = code.count('>')
while count:
    start = code.rfind("<")
    end = code.rfind(">")
    code[start:end] = ''
    count-=1

i think that ought to do it!