shadwickman 159 Posting Pro in Training

I'd go with using floats because I'm sure you want to allow for using decimal numbers in your program. And as I said before, math in Python = math in wxPython. All that wxPython is, is a wrapper for the wxWidgets GUI toolkit. It doesn't change Python's language engineering or anything...

So you can make something a float the same way you would in Python: float(variable) . So if you had a string like "11.45" and you called float() on it, you'd get back 11.45 as a number (float), rather than the string. Now you can do calculations with it. You'll want error-catching in your code though so that something like "asd2-)_d2" will get rejected by your program and it will ask for input again until it gets a valid number (I mentioned the str classes' isdigit() function).

shadwickman 159 Posting Pro in Training

All I could for SVG support for wxPython is wxpsvg. They don't have any built downloads so you'd need to grab the source from the trunk and build it yourself. Here's where you can browse the source:
http://wxpsvg.googlecode.com/svn/trunk/

Hope it helps!

EDIT:
The source in the svg folder looks incomplete, so scratch that. I couldn't find much else about wxPython's support for SVG images.

shadwickman 159 Posting Pro in Training

And as a note, you can get rid of all the extra event.type == pygame.KEYDOWN by using that as one conditional and sticking everything else under it; something like this:

if event.type == pygame.KEYDOWN:
    if event.key == pygame.ESCAPE:
        os._exit(1)
    if event.key == pygame.K_LEFT:
        slide -= 1
    # ETC
shadwickman 159 Posting Pro in Training

First, you should change the line where you bind the button to: button.Bind(wx.EVT_BUTTON, self.onClick) or else give the button an id (it's the arg passed second in the button's constructor) and then you can use self.Bind(wx.EVT_BUTTON, self.onClick, id=BTN_ID) . The way you're currently doing it, any button's press will call the onClick function, not just a press on your specific button.

Math is the same in wxPython as Python. The one difference is that you'll be getting input via widgets (not raw_input) and you'll be showing the answer differently (through a widget instead of print).

That being said, when you use GetValue() on a wx.TextCtrl, it returns a string (same deal as raw_input). So you'll need to convert it to an int or float first before you can do calculations. I'd also suggest adding error checking in this part so that it re-asks for a number if bad input was given (i.e. letters, punctuation, etc). The str class in Python has a very handy function "isdigit()" that you may try to use for this.

Once you've converted this to an int or float, then you just need to perform the simple PI * radius^2 calculation. The math module contains a PI constant you can use: from math import pi .

As for output, you have tons of options. Here I'll just show a wx.MessageDialog way of alerting the user to the answer:

# parent, message, title, style (Ok btn and 'information' icon)
dlg = wx.MessageDialog(self, …
shadwickman 159 Posting Pro in Training

A 2D graphical program is not a "basic program". In any case, if you want to use the Python language (simple syntax, easy to learn), you can use the pygame module which is a wrapper for the SDL graphics library. However, if you want to stick with C++, then you can use OpenGL or DirectX (a bit harder) for your 2D interface.

Here's the NeHe OpenGL tutorial page, which seems to be exceedingly well-known. This can get you started into basic 3D (or 2D) stuff with OpenGL.

shadwickman 159 Posting Pro in Training

A note about your programming on a Mac:
As far as I know, the DirectX SDK is Windows only.

shadwickman 159 Posting Pro in Training

ive looked around for some tutorials and cant find a lot, really all i need is a 2d environment, laid out kind of like a computer desktop, different functionality in different areas of the screen, maybe some layers for different things

Sorry, what exactly do you mean by this segment? This is the sort of thing you're looking to program for the game?..

shadwickman 159 Posting Pro in Training

If C++ is working for you, then that's great. It's really popular because it stems from C, which has been around a long time. Python is relatively new in that regard, but is becoming popular and widespread too.

That being said, I would not try developing games (any visual stuff) with C++ yet if I were you. I've been programming heavily in Python for over two years now, and I've just started to get into 2D visual stuff. You'll want a very, very good understanding of the language before you do game stuff, and if you're going to do 3D stuff especially, you'll need a strong understanding of mathematics; matrices, vectors, 3D geometry, etc. And knowledge of a whole lot of other things...

shadwickman 159 Posting Pro in Training

Python is my favourite programming language that I've learned by far. They all have pros and cons of course, which means some are better suited to projects than others. Python has a simple syntax and is easy to get into, but slower to execute as it's highly interpreted. Whereas C or C++ is more difficult I find, and the syntax is less inviting, but you get much faster speeds (which is why it's used for games, especially 3D).

Here's a good free Python book, Dive Into Python. It's fully available for free online :)
http://diveintopython.org/

shadwickman 159 Posting Pro in Training

I'm not sure if this is the best place to post this, but I've noticed a large request for pyHook for Python 2.6. I had a solution to this in a recent thread here, but people are most likely going to miss that.

I built pyHook's source for use with Python 2.6, but keep in mind that this is sort of hacked together. Please take care when using it, because as far as I know it works fine, but there may be deeper-down issues that I hadn't spotted.

I've attached the compiled source that you need to manually install into your Python 2.6's site-packages folder. Navigate to it (C:\Python26\Lib\site-packages) and copy the pyHook folder into it. Then create a file in the site-packages folder named "pyHook.pth" and in it, type "pyHook". That's all. Now you should be able to pop-up IDLE and type "import pyHook" without any errors.

Also, you'll need the win32 extensions by Mark Hammond for this to work, which you can download from SourceForge here.

Please tell me if you encounter any issues with this pyHook build!
Enjoy :)

pyHook is licensed under the MIT License.

shadwickman 159 Posting Pro in Training

Glad I could help :)
And welcome to DaniWeb haha.

shadwickman 159 Posting Pro in Training

Hooray! I got pyHook working with Python 2.6 for Windows. I just downloaded the source and edited a few things, hacked it together and built. As far as I know, it all works with 2.6 :D
You'd just need to manually install it to your Python's site-packages directory if you want it to be available like any other module.

You can do this on your own, or you can grab the zipped build that I have uploaded here (a much easier method :P).

If you want to install it into your site-packages folder, navigate to it (C:\Python26\Lib\site-packages) and copy the pyHook folder into it. Then create a file in the site-packages folder named "pyHook.pth" and in it, type "pyHook". That's all. Now you should be able to pop-up IDLE and type "import pyHook" without any errors. Good luck!

EDIT:
This is tested and worked without error for me :)
And note, you'll need the win32 modules for Python 2.6 by Mark Hammond (here).

shadwickman 159 Posting Pro in Training

Use this thread class instead of the standard one. It's a killable thread by Connelly Barnes. This one you can cancel without an issue.

http://mail.python.org/pipermail/python-list/2004-May/260937.html

shadwickman 159 Posting Pro in Training

I'd put the window updating segment in a function and call that via a thread as well. Try how that works out.

P.S. As long as your style works for you. I personally can't stand it as whitespace is good, but too much is difficult. It just makes it hard to see some of the OOP-based concepts with the periods being so spaced out.

shadwickman 159 Posting Pro in Training

You'll need to use threading to handle this. One thread calls the function which does the subprocess, and the other calls a function which updates the GUI. Something along the lines of:

# untested!
import thread
from time import sleep

def myFunc():
    while True:
        print 'Hello world!'
        sleep(1)
def func2():
    while True:
       print '#2!'
       sleep(0.5)

thread.start_new_thread(myFunc, ())
thread.start_new_thread(func2, ())

It's started running the myFunc function's endless loop and func2's stuff while it can continue on with other things in the script. Check this for more info:

http://docs.python.org/library/thread.html

Also, please don't use such bad writing style in your code. Only put spaces between non-unary operators. Or, at least don't put spaces between the periods denoting namespaces (like "time . sleep(0.25)") and the colons in your conditional statements. You can check here for a style guide for Python.

shadwickman 159 Posting Pro in Training

Quite. This is where I'll step in and suggest that you try an excellent, open-source, free GNU/Linux distro.

shadwickman 159 Posting Pro in Training

Ohh ok. I just thought syntactically that it was incorrect because I just hadn't ever seen int main(void) before. So then why are there compilers in C++ that accept this, even if it conflicts with C++'s overloading abilities? Why would they have designed these compilers (even back in the day) to do this if it is wrong? Perhaps overloading was included in C++ in the future after these crappy old compilers were written? Is that the case?

shadwickman 159 Posting Pro in Training

MinGW is what I use so that I can use GCC's G++ on Windows.

shadwickman 159 Posting Pro in Training

Why does your main function accept the keyword void as an argument?

EDIT:
Wow I'm retarded. Please excuse this.

shadwickman 159 Posting Pro in Training

Well, that's a nice statement in your post. I see no question in there whatsoever! So obviously you don't have a problem.

It was awful nice of you to tell us what you need, although I don't think anyone here has any interest in pumping out code for you or your project when you're not showing any effort on your part. I'll be glad to help you with problems in the code as you write it, or help you think some things out, but not to do it all for you. It irritates me when people have the notion that DaniWeb is some sort of magical no-effort, code-generating machine.

shadwickman 159 Posting Pro in Training
shadwickman 159 Posting Pro in Training

In the code block where the movement of the player gets updated and applied, just run a simple check through it for something like this:

Get the position that the player would be at based on the movement they just pressed a key for, and then, if it's allowable, move the player's character, otherwise, don't.

If the player's character is a pygame.surface object, then you can use the get_pos() function to get their coordinates. Then figure out what the new coordinates would be with the movement they're wanting to do. Check to see if these new coords are allowed or not, and if they are, move the character surface to them and re-blit, etc. You'll most likely need to be taking the character's surface's dimensions into account here too.

And if it helps explain the above, here's some pseudo-code:

# within the segment controlling the player's movement:
# delta_x  and  delta_y  are the proposed changes in x and y (respectively)

cur_x, cur_y = player_surface.get_pos()

new_x = cur_x + delta_x
new_y = cur_y + delta_y

# for my example, I won't allow the player to be within
# 12 - 20 for the x, and 45 for the y
if new_x not in range(12, 21):
    if new_y not in range(45, 46):
        # allow player movement here
# otherwise, nothing will happen, i.e. they won't move.

That's sort of a skeleton anyways...

Hope that helped!

shadwickman 159 Posting Pro in Training

Try looking into MS Windows' services. You could set your program as a service and then have it run automatically on start-up. You may need to look into running Python scripts as services; here's an example.

shadwickman 159 Posting Pro in Training

Maybe I ought to wait till the Google Chrome OS comes out a year later. That one is supposed to be safe from virus attack.

Ah, but I don't trust Google with my whole OS :P They already know enough about me... (my paranoia is kicking in) And it'll just be one more Linux distro out there, only with a big name plastered onto it.

As for Windows 2k, the lack of updates will be a bit of an issue, but to be honest, I'd say keep what you're comfortable with. If your computer is customized for you and everything's golden, then there's not a huge issue with using an outdated version.

I love XP (Vista was awful), and I've tried Windows 7 (rc1?), but to be honest, 7 seems to be able to do all I need out of XP, but with more eye-candy and bugginess (at least until it's fully stable). I still run XP on my home computer and will be happy to stick with it into the future.

P.S. to jephthah, nice idea about sticking with XP indefinitely :P

shadwickman 159 Posting Pro in Training

You can't just swap them - strip() is for strings and after you've called split(), you have a list. If you swap them in order you'll get an error. Hence splitting, then cycling the indices to strip() each one in that list comprehension. As shown:

>>> a = "hello world!"
>>> a.split(" ").strip()

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    a.split(" ").strip()
AttributeError: 'list' object has no attribute 'strip'
shadwickman 159 Posting Pro in Training

Baki is right. Iterate the lines and split them at the equals sign (but strip it properly!), then take the latter index (the right side of the sign). Strip off the leading and trailing whitespace (of each index), and voila. Here's if you wanted to make sure that the left-side was "number":

for line in open('myfile.txt','r').readlines():
    # split at = and then strip whitespace from both sides
    data = [x.strip() for x in line.split('=')]
    if data[0] == 'number':
        number = data[1]

The list comprehension I used strips each index that it gets from splitting at the equals sign. Baki's way would strip the beginning and end of whitespace. But when it's split, you'd get a space left before and after the indices, so I stripped that off.

shadwickman 159 Posting Pro in Training

What specifically can you not get to work about them? If you're just confused in general about how they work, try reading up on the documentation and examples through Google. Here's a quick example, and the API documentation.

If this isn't it, can you better specify what your exact problem is? Then I may be able to help better :P

shadwickman 159 Posting Pro in Training

If the variable userinput is waiting for the user to press a key (like Heftiger implied), then you'd need to use threading in order to process waiting for a keystroke and running a continuous loop side-by-side. That being said, yes, you can use conditional testing each time the loop runs, or you can set it to infinite and then break out when your program wants, like so:

while True:  # or while 1:
    read_the_data  # do your thing here
    if end:  # some conditional to end the loop
        break  # will break out of the loop

Just watch out that your break isn't inside any other while or for loops inside the overall while loop, as it breaks out of the deepest-nested loop that it's in.

shadwickman 159 Posting Pro in Training

if my best friends dont get featured i am going to organize them to leave for a better c# forum where their skills are appreciated.

I'm not trying to start slinging shit here, but is this a mutual agreement or are you just putting words into your friends' mouths? Hmm... by the way this isn't a union thing or nothing. Please feel free to leave if you are fed up helping people.

shadwickman 159 Posting Pro in Training

No idea. Jephthah started it haha. Just for random fun...

shadwickman 159 Posting Pro in Training

Just read the file as-is and then write the output with the lines that aren't blank. Here's an example:

# Read lines as a list
fh = open("myfile", "r")
lines = fh.readlines()
fh.close()

# Weed out blank lines with filter
lines = filter(lambda x: not x.isspace(), lines)

# Write
fh = open("output", "w")
fh.write("".join(lines))
# should also work instead of joining the list:
# fh.writelines(lines)
fh.close()

Also, if you don't understand my lambda expression there, here's a longer route instead of using filter :

fh = open("myfile", "r")
lines = fh.readlines()
fh.close()

keep = []
for line in lines:
    if not line.isspace():
        keep.append(line)

fh = open("output", "w")
fh.write("".join(keep))
# should also work instead of joining the list:
# fh.writelines(keep)
fh.close()

All this is untested as I'm at work! But this should give you an idea of how to do it.
Hope that helps!

shadwickman 159 Posting Pro in Training

Give Google control of my desktop? I'm too paranoid for that.

True enough. It's already a little creepy just how much personal information they have about so many individuals...

shadwickman 159 Posting Pro in Training

I'll definitely check it out. Maybe just as a virtual installation with VirtualBox or something, but I'm still curious what it's got to offer.

shadwickman 159 Posting Pro in Training

Hahahah I'll give you a hint. They're from a famous book which was also made into a movie. Hope that narrows it down for ya :P

shadwickman 159 Posting Pro in Training

You need to use the 'self' keyword. So inside the function variable, you'd say self.f = 5 . Then when you call printf, you'd say print(self.f) .

By not making the variable a property of the class by using 'self', you're just making it in the local scope of the function. And, when you call a class' functions from within itself, you also need to attach 'self' in front. Like if within a function on class W, you wanted to make a call to its printf function, you'd use self.printf() .

Here's is the documentation about scopes and name spaces regarding classes in Python:
http://docs.python.org/tutorial/classes.html#python-scopes-and-name-spaces.

Hope that helped!

shadwickman 159 Posting Pro in Training

I'm not.... I'm following the rules for posting questions on this forum. Maybe you should take a look at them.

shadwickman 159 Posting Pro in Training

So... what have you tried so far? You need to show effort as we're not some sort of request forum that just whips up all the code for you. Post what code you have so far, specifics of what you need help with, etc. Then I'll consider helping you.

shadwickman 159 Posting Pro in Training

Sir, why are you running?

Why are you running?

Are you doing this for world peace?

Are you doing this for women's right?

Or for the environment?

Or for animals?

Or for nuclear arms?

They just couldn't believe that somebody would do all that running for no particular reason.

Why are you doing this?

I just felt like running.

shadwickman 159 Posting Pro in Training

Oh thanks! Now I learned something new too :D

EDIT:

exec code in globals(), locals()
shadwickman 159 Posting Pro in Training

I'm not entirely sure... Just have a look through the Python documentation! :P

shadwickman 159 Posting Pro in Training

Well if you're using Python 2.x there's the exec expression. I don't know if it still exists in Python 3.0, and I wouldn't normally use it, but it's all I can think of in this case. All you have to do is provide a string that's valid Python and it'll get executed. Like this:

code = "print 'Hello World!'"
exec code

You just need to be careful of quotes and properly escaping them inside the string that will be executed.
Hope that helps!

shadwickman 159 Posting Pro in Training

I personally think (as a side note), that he should:

a) Use a relative path so that he can keep the project in one folder and use a hierarchy of folders within that. This allows him to move the project's folder but keep all the paths in the script valid because they're relative.
b) Use single, forward slashes in his path as that's accepted on Windows and Linux. So "C:/python26/stuff/bg.jpg" works even better.

Just my two cents :P

shadwickman 159 Posting Pro in Training

I forgot to mention that in solution #2, you assign temp_list2 to the same address of memory as list2, but then that's undone as you create a new list (and new address in memory for it) consisting of four ones. Therefore, temp_list2 no longer refers to the same data as list2.

If you want to copy the list over without making the new name reference the same data, how about

list1 = ['a', 'b', 'c', 'd']
list2 = [x for x in list1]

That'll copy all the indices of list1 into a new address for list2, and thus, they are independent of each other.

shadwickman 159 Posting Pro in Training

Here's an example of how to get the current date and time (as a string) using the datetime module.

import datetime
timestamp = str(datetime.datetime.now())
"""result ->
'2009-07-08 01:16:25.968000'
"""

Hope that helps!

shadwickman 159 Posting Pro in Training

Because your temporary list is the same thing as your other list. You said temp_list1 = list1 . This means that the value for temp_list1 will be the same address in memory as the value for list1, i.e. they reference the same thing. Modifying one modifies the other because they are just 2 different names for the same data.

shadwickman 159 Posting Pro in Training

There are plenty of things you could have easily found through Google. You're just showing absolutely no effort on your part.

shadwickman 159 Posting Pro in Training

Please take Ancient Dragon's advice. If you don't even know how to compile and run a C++ program, you obviously shouldn't be working on a game. Look up tutorials and books on the language so that you can actually get an understanding of how it all works, then practice. And practice a lot. 3D (or 2D) game programming requires A LOT of knowledge on various topics.

shadwickman 159 Posting Pro in Training

Ah, good point, I hadn't thought of that. This illustrates what woooee means:

>>> a = b = []
>>> a.append('hi')
>>> a.append('world!')
>>> a
['hi', 'world!']
>>> b.remove('hi')
>>> b
['world!']
>>> a
['world!']
>>> id(a) == id(b)  # same address in memory
True

They both refer to the same list because of the way they were declared ( a = b = [] ), so both names are actually for only one list.

shadwickman 159 Posting Pro in Training

Like I showed in my previous post, use a boolean to track it. It's initially False, but when it encounters a line you want to remove, it becomes True. While it's True, it will disregard the lines it encounters until it finds one starting with ">". It will be set to False when it finds that again, but as it continues, any lines that have that "rs" will set it to True again, etc.

It basically starts skipping lines after a line it finds with "rs" until it finds a line starting with ">", and then it check that one to see if it's good. If it is, it stops ignoring lines, but if it's a bad line, it'll keep skipping, etc.

shadwickman 159 Posting Pro in Training

Also, please put your code in [code]

[/code] tags next time so that the indentation is kept, as it's a crucial part of Python.

Other than that, I'm still confused what you are having a problem with. Maybe the removing of the number from the whole square has to do with a different bit of your code - say if you're calling this eliminate function in a loop somewhere else which is causing the error.
Please just try to rephrase your question to be a little bit clearer, thanks.