Have you tried self.Refresh? I know it dosent do that much but i find it helps in many circumstances.
Have you tried self.Refresh? I know it dosent do that much but i find it helps in many circumstances.
Never mind i have found out the answer to my question. What i wanted to do was change a style of a button/TextCtrl/ListBox/Frame mid way through my program. I found out i can do this with:
#Change a panel for example
self.panel.SetWindowStyleFlag(self.panel.GetWindowStyleFlag()|STYLE TO ADD)
#This will add all the ones already there as well as the other one you add on.
Thanks for trying, i will mark this as solved now.
Remember to mark the post as solved if you have solved your problem! :)
Why are you using a flex Grid Sizer? You could do exactly what you want with just a wx.Sizer.
you can use such flags as
wx.TOP
wx.BOTTOM
wx.LEFT
wx.RIGHT
#Here is an example
self.sizer.Add(self.Tree,proportion=1,flag = wx.TOP|wx.BOTTOM)
#Now that would only expand top and botton
# I cant remember if you need wx.EXPAND in there too....
to tell the sizers which ways it is allowed to expand.
Could we see a sample of code perhaps?
Hi everyone
What i am doing now is creating a program that the user can change the way buttons look half way through. My problem is i couldnt work out how to update the wx.Button's style while the program is running. I was wondering if anyone could help me for this.
Thanks!
Hi
What i am trying to do is make a wx.FileDialog() show Import as the label on the button. I know you can change it to such things as open and save but i cant find a way to let me change it to a label saying import.
Any help would be greatly appreciated. :)
I think you might we able to use sizers to do this. There is a flag you can use when making a sizer called wx.ALIGN_CENTER and this will keep it in the center no matter what.
Hi
Just download the wxPython Docs and Demos and go to the wxWidgets Reference. I think that might help.
It would be cool if you could have a text file full of all of the words so the user could add their own.
Your text file could look like this:
Python:yothnp
spam:apms
This was the user could add their own and you could just import it to a dictionary at the start like:
f = open("Words.txt")
for thing in f.split(":"):
dictionary[thing[0]]=thing[1]
why do they need to be different files, couldn't you just make them definitions in the one file and then just call them when they are needed?
I tried it and liked it. I thought it was nice to just have a web browser that was so simple for once.
As much as it is good i just cant see why google needed to enter the web browser wars!
How about this
Where are the nearest Toilets - Ahi Nai Ta Pai
Oh that is so mean! The poor people. The chimps looked pretty into it though! :)
Py2exe is probably the easiest one to use and there are code snippets helping you to use it as well. Vegaseat did this one -
http://www.daniweb.com/code/snippet499.html
Oh i'm so sorry Ene. The program uses the mouse to draw the picture. I should have said that above. Also it is best to try a small picture otherwise it will take some time to do. The amount of beeps will tell you how many minutes. Anyhow dont worry about it. I think i should do some more coding before i post it again. Thanks for trying though and sorry!
Hey everyone
I am interested in learning Pygame as a GUI that is suited to making games and i was wondering if it was worth it?
My question is, is it good for anything else than games or animations?
Hi guys
Im pretty new to java after programming with python for about a year i thought i'd give it a go. I did have a quick question though.
How would i check for membership in a string.
For example
String str1="Hello world";
String str2 = "world";
Is there any way to check if str2 in str1?
Thanks!
Sorry to double post and all its just i thought it might be useful to people if i posted the links to all of the modules this code needs so they could run it.
Win32 modules - python.net/crew/mhammond/win32/Downloads.html
Sendkeys - http://www.rutherfurd.net/python/sendkeys/
pyHook - http://sourceforge.net/project/showfiles.php?group_id=65529
wxPython - http://www.wxpython.org/download.php
Python Imaging Libary - http://www.pythonware.com/products/pil/
Sorry there is so many modules that people might not have.
Oh i will also attach the .py file this time in case people want to help. It is in the zip file i attach.
I am not trying to do that.
What i want to do is have it so you supply an image in the program and the program then draws it in paint. I really dont want to just shortcut and re-save it.
The point of the program is to see the actual image being drawn in paint. If you want just grab the source code i have attached to the previous post and have a look.
Hi guys
I have been making a program over the last few days that grabs an image and re-paints it in paint in 256 colour. The main thing this program is for is so you can watch it getting painted in paint.
It works perfectly on my computer but i find that as soon as i take it to faster computers the whole thing goes haywire. It just stuffs up the whole image becuase the program seems to just get ahead of itself. I am finding it difficult to debug as i do not have access to a computer that is fast enough to make is stuff up and so i was wondering if anybody out there with a fast computer is willing to lend a hand and help find a way to fix it so nothing goes wrong.
Note that you will need the Win32 extensions to python installed as well as PyHook so the program can exit when you press the Q key (to do this try it while it is changing colour otherswise it sometimes wont work). You will also need Sendkeys.
Any help would be appreciated!
import win32api
import win32con
from ctypes import windll
import time
import os
from SendKeys import SendKeys as s
import Image as i
import winsound
from threading import Thread
import sys
import pyHook as ph
import pythoncom, pyHook
import wx
def m(x,y):
windll.user32.SetCursorPos(x,y)
def l(x="current", y="current",keepdown = 1):
if x == "current" and y == "current":
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, 0, 0)
elif keepdown == 1:
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y)
win32api.mouse_event(win32con.MOUSEEVENTF_LEFTUP, x, y)
def r(x="current", y="current"):
if x == "current" and y == "current":
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, 0, 0)
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, 0, 0)
else:
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTDOWN, x, y)
win32api.mouse_event(win32con.MOUSEEVENTF_RIGHTUP, x, y)
class Get_Pic(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,title = "Choose Picture")
self.panel = wx.Panel(self)
self.vbox = wx.BoxSizer(wx.VERTICAL)
self.text = wx.StaticText(self,label = 'Please Pick a picture')
self.butload = wx.Button(self,-1,label = 'Load Picture')
self.butload.Bind(wx.EVT_LEFT_DOWN,self.get)
self.Bind(wx.EVT_CLOSE,self.exiting)
self.vbox.Add(self.text,proportion=0,border = wx.SUNKEN_BORDER)
self.vbox.Add(self.butload,proportion=1,flag = wx.EXPAND)
self.SetSizer(self.vbox)
self.Show()
def exiting(self,event):
sys.exit()
def get(self,event):
loadbox = wx.FileDialog(self,message='open',
defaultDir=os.getcwd(),
defaultFile='',
wildcard = 'Image Files|*.bmp;*.jpg;*.png',
style = wx.OPEN)
if loadbox.ShowModal() == wx.ID_OK:
self.file = loadbox.GetPath()
global path
path = self.file
global f
f = i.open(self.file)
os.startfile(r'mspaint.exe')
time.sleep(2)
s('%F')
s('O')
s('%N')
fil = self.file
fil = fil.replace(' ','{SPACE}')
s(str(fil))
s('{ENTER}')
s('%F')
s('A')
s('%N')
cur = os.getcwd()
cur = cur.replace(' ','{SPACE}')
t = open('debug.txt','w')
t.write(str(cur))
t.close()
s(str(cur))
s('\\template.bmp')
s('%t')
s('{DOWN}')
s('2')
s('{ENTER}')
s('{ENTER}')
s('Y')
s('Y')
s('%F')
s('a')
s('%t')
s('{DOWN}')
s('{DOWN}')
s('{ENTER}')
s('{ENTER}')
s('Y')
loadbox.Destroy()
self.Destroy()
app = wx.App(False)
g = Get_Pic()
app.MainLoop()
def OnKeyboardEvent(event):
if event.Key == 'Q':
sys.exit()
return True
# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
# wait forever
class Stop(Thread):
def __init__(self):
Thread.__init__(self)
def run(self):
pythoncom.PumpMessages()
s("%{F4}")
os.startfile(r'mspaint.exe')
time.sleep(2)
m(150,150)
st = Stop()
st.start()
m(20,140)
l()
m(61,51)
x = 61
y = 51
oldr = 999
oldg = 999
olrb = 999
f = i.open('template.bmp')
size = f.size
colours = f.getcolors()
s('^e')
s('%p')
s('%w')
send = size[0]
s(str(send))
sennd = str(size[1])
s('%h')
s(sennd)
s('{ENTER}')
imagedata = {}
for col in f.getdata():
if str(col) not in imagedata.keys():
imagedata[str(col)] = [[(x,y)]]
else:
imagedata[str(col)][0]+=[(x,y)]
x+=1
if x==61+size[0]:
y+=1
x=61
print "Time approx:",((size[0]*size[1])*0.003)
for f in range(int(((size[0]*size[1])*0.003)/60)):
winsound.Beep(1000,10)
time.sleep(0.001)
max_one = max([len(imagedata[g][0]) for g in imagedata.keys()])
max_c = 0
for z in imagedata.keys():
if len(imagedata[z][0]) == max_one:
max_c = z
temp2 = max_c.split(',')
temp = []
for x in temp2:
x = x.replace('[','')
x = x.replace(']','')
x= x.replace('(','')
x = x.replace(')','')
temp.append(x)
r = temp[0]
g = temp[1]
b= temp[2]
s('%c')
s('e')
s('%d')
s('%r')
s(str(r))
s('%g')
s(str(g))
s('%u')
s(str(b))
s('{ENTER}')
s('{ENTER}')
l(62,52)
m(35,80)
l()
m(62,52)
l()
m(20,140)
l()
m(61,51)
nono = (str(r),str(g),str(b))
print nono
temp = []
temp2=''
r=0
g=0
b=0
for key in imagedata.keys():
temp2 = key.split(',')
temp = []
for x in temp2:
x = x.replace('[','')
x = x.replace(']','')
x= x.replace('(','')
x = x.replace(')','')
temp.append(x)
temp = tuple(temp)
r = temp[0]
g = temp[1]
b = temp[2]
for pos in list(imagedata[str(key)]):
for e in pos:
if temp != nono:
m(e[0],e[1])
l()
time.sleep(.000001)
if oldr == r and oldg == g and oldb == b:
pass
else:
s("%c")
s("E")
s("%D")
s("%R")
s(r)
s('%G')
s(g)
s('%u')
s(b)
s('{ENTER}')
oldr = r
oldg = g
oldb = b
winsound.PlaySound('Windows XP Print complete.wav',1)
time.sleep(2)
s("%f")
s("A")
s('%n')
if os.path.exists(str(os.getcwd()+r"\Finished Pictures"))==False:
os.system('mkdir "%s"'%(os.getcwd()+r"\Finished Pictures"))
filen = os.getcwd()+r"\Finished Pictures"+'\\'+path.split('\\')[-1]
filen = str(filen)
filen = filen.replace(' ','{SPACE}')
s(str(filen))
s("{ENTER}")
s("y")
sys.exit()
I think this might have a lot to do with the competition being held in Australia for High School Students in python at the moment, it sound suspiciously like a problem that is stumping almost all of the people on the final week.
you counld use string.replace
For example:
words = 'hello i enjoy eating rasberry muffins'
words = words.replace('rasberry muffins','toasted bread')
print words
# this will output 'hello i enjoy eating toasted bread'
Hope this solves your problem. :)
Well it worked fine for wxPython. Though it didnt work when i had it in window mode rather than console mode.
Its not perfect but never the less its still cool.
Everyone loves a game. So why not make a series of Dice games such as Two up and Yahtzee.
For an extra challenge make an AI to play with and also add a GUI!
yeah thanks everyone. They all worked really well.
I especially liked the Gpy2exe. It is really easy to use, it lets you automatically add an icon. So thanks guys for all the help. It is all looking a lot lot better now. :)
Hi
I have made a program that uses a GUI for most of its functions but as soon as i change it to an exe using py2exe all the buttons turn all square and everythin looks like it came from windows 98 rather than XP.
Is there any way to change this so the program keeps its XP styling?
If you want to can use the pyHook module
Download-http://sourceforge.net/project/showfiles.php?group_id=65529
Here is a program that will listen for any keystrokes really easily:
import pythoncom, pyHook
def OnKeyboardEvent(event):
print 'MessageName:',event.MessageName
print 'Message:',event.Message
print 'Time:',event.Time
print 'Window:',event.Window
print 'WindowName:',event.WindowName
print 'Ascii:', event.Ascii, chr(event.Ascii)
print 'Key:', event.Key
print 'KeyID:', event.KeyID
print 'ScanCode:', event.ScanCode
print 'Extended:', event.Extended
print 'Injected:', event.Injected
print 'Alt', event.Alt
print 'Transition', event.Transition
print '---'
# return True to pass the event to other handlers
return True
# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.KeyDown = OnKeyboardEvent
# set the hook
hm.HookKeyboard()
# wait forever
pythoncom.PumpMessages()
Oh you also need pythomcom, i think that is in the win32 package which you can get from here:
python.net/crew/mhammond/win32/Downloads.html
as i said i only think it is in there.
That first module worked a treat! It is also so simple to use, ill show you a quick demo:
from SendKeys import SendKeys
SendKeys('Hello{SPACE}world{ENTER}')
This still needs some special characters to be put in differently but other then that it is really simple to use, great for running macros.
Thanks Grib :)
Hi
What i want to do for this is to have my program run in the background simulate pressing a button such as ENTER every 10 seconds or so. I have trauled the net and found solutions for VB and C++ but none for python.
Is this possible in python and if so how would i do it?
What kind of editing? Do you mean automated resizing or drawing new things onto the picture and then saving it?
wxPython has a lot of cool image/paint tools so you could check that out but in the end it really depends on exactly what kind of editing you want to do.
Hi
I have been trying to do one of the projects in the projects for beginners section that asks you to get your computer to log off after a certain amount of time has passed without any mouse or keyboard movement. I am not yet up to that bit, in fact i can't work out how to log off/shut down. It says to use the os module but i cant find anything that will do the trick.
I was wondering if anybody could point me in the right direction? Thanks in advance :).
just quickly i wanted to remind Darkangel or the NCSS Challenge rules. Rule 3 stated that:
"The solutions you submit must be your own. It is fine to discuss the problems, and to read code in books or on web sites to get ideas, but you must be the author of any code you submit. It is not okay to copy anybody else's code and submit that as if it is your own."
This just means discuss it all you like but you are not allowed to directly use code that other people have made.
People at Daniweb just remember for this comp that people are not meant to do get direct answers.
Vegaseat gives a few options in this post:
http://www.daniweb.com/forums/thread34434.html
They include alternatives to Winsound.
how would i do that?
Hi
I have a weather forecasting program that uses a few threads. These threads stop and start at different times throughout the program so there is no set amount of threads at one time. My problem is when i try and close the main thread the program keeps going because there are still threads alive.
Seeing as the threads which are alive change all the time i was wondering if there was any way to kill all threads.
Any help would be greatly appreciated :)
This is how i do it:
a=b=c=None
Hope that helps! :)
you could change the 'while play' to something else that was an integer that equalled 10 and then every time the person has their turn you subtract one away from it until it is zero and the program ends.
import random
words = ['sprinkles', 'computer', 'mouse', 'shooter', 'edge', 'guard', 'python']
myword = random.choice(words)
guesses = "aeiou"
turns = 10
while turns:
turns-=1
print "Do you want to play a game?"
play = raw_input('Answer (y) yes or (n) no:')
if play == 'y':
print 'Let\'s begin'
print ""
for letter in random.choice(words):
if letter in guesses:
print letter,
else:
print '_',
break
if play == 'n':
print 'Good-Bye.'
break
Oh and also a quick question. Why are you breaking at line 20. Remember a break will end the loop forever so i dont see why you would want it there?
Hi Guys
What i am trying to do here is have a tuple of numbers, lets say X. Then i have a list of a few other tuples. I want the program to find the tuple that is closest in value.
x = (214,521)
lis = [(200,500),(250,550),(300,600)]
I am doing this becuase i want to find where a person clicks on screen and then work out which function to run by finding which one in the list the person clicked closest to. Im having trouble getting started here so any help would be greatly appreciated.
yeah i get this error a lot. What i do to fix it is to go Ctrl+Alt+Del and then go to processes and then stop and python process.
Hope that works! :)
Okay this is my solution
Hope that works
yeah. I really think Bill has been really charitable and well i understand why he would retire. I mean he would be super rich. Its not like he needs to save for his super annuation is it!
Could you hook the modem to the wired router and then run a CAT-5 cable or something to the wireless router?
also This site looks like it has some ideas to.
I dunno but thats what the site says that they are doing at the moment. They got about 13 million downloads and that must have to count for something at least!
that is one of the most Random games i have ever played! I got 70%
Are you running it in something like IDLE because if so getch wont work. Try using the python command window.
yeah i just checked the code in the command window and it works a-okay! :)
For easy 3d design programs you can't go past the free Google Sketchup
I also really like ashampoo CD and DVD burner, there is a free version wich is still quite good.
Sorry for unmarking it as solved but i had one more question.
Is there another way apply a bitmap to a panel without making it static?
Yeah that works without a hitch.
Thanks vega!