Percect! Thank you so much Gribouillis! The decorator worked perfectly - apparently it was a problem with thread safety.
Thanks again!
Percect! Thank you so much Gribouillis! The decorator worked perfectly - apparently it was a problem with thread safety.
Thanks again!
Hi all, I'm working on a (Python) program which, in short, is a threaded TCP socket server which creates a new "tab" in a wx.Notebook widget for every incoming connection it sees. I've run into a strange problem where when I call notebook.AddPage(...), one of three things happens:
Since it would be inconsiderate to post all of my code here, I wrote a little script (based on something I found online) which also exhibits this behavior (although it works correctly most of the time).
import wx
from wx.lib.pubsub import Publisher
import thread
import time
# Some classes to use for the notebook pages. Obviously you would
# want to use something more meaningful for your application, these
# are just for illustration.
class PageOne(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
t = wx.StaticText(self, -1, "This is a PageOne object", (20,20))
class PageTwo(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
t = wx.StaticText(self, -1, "This is a PageTwo object", (40,40))
class PageThree(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
t = wx.StaticText(self, -1, "This is a PageThree object", (60,60))
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Simple Notebook Example", size=(600, 500))
Publisher.subscribe(self.NewPage, "add.page")
# Here we create a panel and a …
I thought I would post a follow-up to this question, to hopefully provide useful information for future Android developers.
After I marked this thread as solved, I chose to use a sqlite database to store the information for each of the levels in my game. This was very easy to save/load in Python, and I expect the same is true for normal Java, but Android is a different story.
From the Android API, it is impossible to simply place any database in your "assets" folder and load it from your app. Instead, you have to add a special table for Android meta information and add a specially named "_id" column. After this, you have to copy your existing database byte-by-byte to the system database path, and then finally you can work with it.
I personally thought this was way too much work for just loading an external database, so I now somewhat regret using databases. I think I will end up writing my own minimalist text parsing system that is centered around what I truly need.
Hope this proves to be useful to somebody.
I have to say, I loved that article you linked me to. The reason I'm writing this level editor in Python is just because I much prefer it to Java. The only reason I'm writing my game in Java is because its for the Android platform.
Anyways, that article inspired me to not use xml, so I'll either check out configparser or just use a database.
Question answered. Thanks.
Thanks for the relies. I have actually tried the dive into python tutorial, and that's when I got all of those None return types.
Tonyjv, what would you recommend using instead of xml? The hierarchy is very important, but if you have a suggestion that would work, please do tell.
By the way, I'm going to have to generate the "code" just in python, but I will have to parse the information in both python and java.
Thanks again.
I should begin by stating that XML and I don't seem to get along very well. I've just about finished the interface on the level editor for a game I've made, and the next step is generating a XML file so that it can be read into the game dynamically.
The problem is, well, the XML. I've been fighting it for the past hour or two, and still can't achieve what I would like.
This may not be valid XML, but it is a good idea of what I would like to achieve:
<root>
<containers>
<container>
<name>Unsorted Objects</name>
<children>
<object>
<name>Img1 - container 1</name>
<x>420</x>
</object>
<object>
<name>Img2 - container 1</name>
<x>902</x>
</object>
</children>
</container>
<container>
<name>Special Objects</name>
<children>
<object>
<name>Spcl1 - container 2</name>
<x>420</x>
</object>
<object>
<name>Spcl2 - container 2</name>
<x>902</x>
</object>
</children>
</container>
</containers>
</root>
Anyways, what libraries would you all suggest to write XML like this and then, later, parse it? I've tried ElementTree, and I seem to like it, but I just can't do what I want to. Sure, those examples with two objects each with two properties are nice and pretty, but none had the same level of depth as my XML shown above, leaving me confused. When I try to extend them, I keep getting None as the return value for my calls.
If somebody could just give me a little code sample explaining on how to parse/write XML at this level of depth, I would really appreciate it.
…
Hi, I'm in the process of writing an Android game, and I need just a little bit of help with some physics. I do not wish to implement an entire physics engine, as, 1) I have already tried the Java port of Box2D on an Android device, and there is a huge garbage collection problem, and 2) I don't think my problem is complex enough to need a physics engine.
Anyways, let me describe what I want to do with a picture:
http://i189.photobucket.com/albums/z266/Capn_Soul/BasicPhysics.png
Basically, I have some boxes fall from the top of the screen that, when they collide with an object, they stop falling and stack up (as shown in the picture). But rather than the boxes just sitting there and doing nothing, I want boxes to abide by the rules of basic physics. For example, I would like the light blue box on the top of the stack to tilt and fall off to the right. How would I accomplish this?
If anybody could point me to a place where I could learn the physics necessary to do this, I would really appreciate it. I have found a few tutorials about 2D physics, but they all seem to use spheres in their explanations and examples.
Thanks so much in advance.
You could use a separate thread to function as a sort of timer and simply call the .Destroy() function (correct me if I am wrong, can't remember the function name) after a given amount of time.
If you need help with threads or anything feel free to post back.
I have another post entitled 'understanding wxPython' in which my code runs but fails to build the scroll bars as shown by my python programming book. Note that the code in the book is running on Windows and mine is running on Ubuntu.
I tested this myself, and I can see what you are saying. When running it under Vista, you can see the little grayed-out scrollbars, but you cannot use them.
However, on Ubuntu, there are no scrollbars at all.
I am guessing this is simply due to the OS, not your code. I think your window manager is configured so that scrollbars are not shown unless they are needed, like in your case. Since there is not a long selection of text to display, there is no use in having scrollbars.
If you add text to this widget, I'm thinking it will do the right thing and add scrollbars.
Let me know if this is in fact true. Good luck.
Could you be more descriptive than "I can't use this"? Do you get an error? Does it just not do anything in general?
As you probably know, you need elevated privileges to run a command with "sudo," so my guess is that you need to run your script with "sudo": sudo python MyScript.py
Another problem; SoulMazer's code doesn't work. Yes, it gives you a time, but it doesn't end the action. Sorry if I'm taking up time, but I'm desperate to finish this game of mine. :(
What do you mean? The code prompts you for a string, and if you do not enter one within X seconds, it prints some messages. Yes, I do have to admit that it does not cancel the original raw_input call, so the user can still input text, but that's why I originally said it was not truly possible.
If you look back to the links I provided in my first post, it provides alternatives to raw_input for both Windows in Linux without a GUI.
If you want more specific help, please be more specific with your problem, as woooee stated.
Well the problem is that Python and all other CGI scripting languages are server-side scripting languages, which means they are only called when the page is requested for the first time.
From what you say, you will need some sort of client-side scripting language for the web interface. You mentioned Javascript in your post, and that would be a great place to start. You could also use Flash or Java.
I wrote a program a little while ago while was meant to be a desktop application, but I created a web interface to it using some smart CSS/Javascript. The Python does all the processing and the Javascript allows for interaction with the information presented.
Those are my ideas, and if you have any questions feel free to post back.
EDIT: As woooee posted, Tkinter's after function would probably be optimal if you plan on creating a GUI for your script. If not, then the following is probably what you are looking for:
Well apparently I was slightly wrong in my last post. Although raw_input() does block, it is indeed possible to get around with threads. In the piece of code I created myself, (similar to diwakar's) I tested it within an IDE and it did not work. However, when I ran it under normal conditions, it did.
Here's the code if you would like:
#!/usr/bin/python
import threading
from time import sleep
got_input = False
def printStuff():
print
print "Sorry, you didn't enter anything."
print "Have a nice day."
class TimeThread(threading.Thread):
def __init__(self, max_):
threading.Thread.__init__(self)
self.max_ = max_
def run(self):
sleep(self.max_)
if (got_input == False): # the time is up: if the user didn't enter anything, print stuff.
printStuff()
time_thread = TimeThread(3)
time_thread.start()
print "Enter your name: "
name = raw_input("> ")
got_input = True # if this code is executed, it means the user did input something
print "Welcome,", name
Sadly, an easy alternative to raw_input that does not block (that is portable) is not too easy to find.
I tried to create a version myself, but apparently raw_input even blocks other threads in the program from printing to the console. It's pretty strange.
However, if this is just for yourself or only for one platform, take a look at these postings I found around the web:
Good luck.
Thanks again for the information guys. I'm definitely going to try out some tutorials for each of them this weekend.
I'm glad some people were able to come up with alternatives to Flash/Java! Problem solved.
Thanks for both of your replies. I will definitely have to look into both of them. Unity seems like a pretty good choice except does it remove you from all the programming? It seems like it turns you from a programmer more into a designer?
As for JQuery, it looks neat but I can't find any examples that are beyond the very basics. Does that imply that it's not good for a big game project or what?
Thanks again.
Hi, I made a post about a similar subject quite a while ago, but I'm a little more serious about it now. I've created two games in C++ and one in Python, but I'd like to start making games for the web to let them be more visible and more easily accessible.
I know I could use Java or Flash, but I wanted to know what all of you thought. I'm not too keen on using Flash, so are there any good 2D Java game engines that will work in applets? Are there any alternatives to Java or Flash for web games? I mean, you could do Javascript/HTML5 (canvas), but that would be a little strange to program a full game in Javascript.
What are your suggestions?
Thanks in advance.
Gotcha. Okay, thanks. That definitely solves my problem.
Thanks again.
Wow, thanks for the quick reply. And thanks, that got rid of my errors.
However, is it okay to declare a global list like that if many other files are going to be #include'ing Node.h? Wouldn't that reset its value? That's the reason I was originally trying to do a static list.
Hi, I'm new to C++ and I'm having trouble with this dang linker error. The full error is as follows:
Error 4 error LNK2001: unresolved external symbol "public: static class std::list<class Node,class std::allocator<class Node> > NodeManager::node_list" (?node_list@NodeManager@@2V?$list@VNode@@V?$allocator@VNode@@@std@@@std@@A) Nodes.obj
Error 5 fatal error LNK1120: 1 unresolved externals
From this error, I have deduced that the problem is with NodeManager::node_list. After doing a little researching, I have found that LNK2001 refers to an undefined object, right? I do define node_list as a static member of NodeManager, so I'm not quite sure what's wrong.
Here's some code (I cut it short for brevity's sake):
Node.h
#ifndef NODES_H
#define NODES_H
#include <vector>
#include <list>
class Node {
public:
std::vector<int> children;
Node(int num, float x, float y, float z) {
num_ = num;
x_ = x;
y_ = y;
z_ = z;
}
private:
int num_;
float x_;
float y_;
float z_;
};
class NodeManager {
public:
static std::list<Node> node_list;
};
void generateNodes();
#endif
Node.cpp
#include "Nodes.h"
#include <list>
void generateNodes() {
Node n1(1, 346.0, 26.5, -470.0);
n1.children.push_back(2);
n1.children.push_back(4);
n1.children.push_back(5);
NodeManager::node_list.push_back(n1);
// defining more nodes
}
The only reason I created a NodeManager class is because I need a list to keep track of my node list, and I was told that you cannot create, for example, a list of Node's within the Node definition. Is this correct?
Any ideas? Also, feel free to provide constructive criticism.
Thanks in advance.
Okay, I'll look into making a timer for moving units within the game loop. Would it also work to change the max FPS of the game? Or should I not do that, and just stick with the timer?
Thanks.
Hi, I'm in the process of writing my own FPS in C++ and I had a general question about game programming. Up until this week, I was developing the game on a computer with a low-end graphics card and everything was working just fine.
This week, I've changed my development to a newer computer with a brand new graphics card. When I ran my game, everything was moving WAY too fast. I think I know what caused this. Since my current computer is so much faster, the game loop runs more quickly which in turn causes the units to move more often (faster).
What can I do to prevent this? How do I make a game run at the same speed on a low-end computer as a high-end computer?
Thanks in advance.
Thank you everybody for all your help. All of your explanations really helped me; I understand it pretty well. And thanks for the suggestion firstPerson, I might use that in the future, but currently that is above my level and I don't like to use others' code especially when I have no idea how it works.
Thanks again everybody.
Problem solved.
EDIT: Perfect! It works! Thank you so much! So I can hopefully avoid this in the future, could you explain to me what the difference between "++iter" and "iter++" is? They seem to be performing different functions and I would love to know how you came up with this brilliant piece of code. I can see how you are incrementing iter
when the bullet is alive, but why do you pass iter++
to bullet_list.erase
? Why doesn't it erase the next bullet in the list instead of the current one?
Thanks everybody for all your help.
Well, good news and bad news! As for the good news, the code that you provided gets rid of compiler errors! However, for the bad news, I'm still getting a bad error in-game.
Since the error is related to this code, I'll just keep it going in this thread. So, let me give you some background information about my game. It is a FPS-type game, so in the simplest manner, you have a gun and you shoot at enemies by clicking the mouse. During the game loop, I run the above function to check whether or not each bullet is still in play. If they are, each bullet is moved forward by a certain velocity; if not, they are removed from the game.
My problem, as Visual C++ 2008 puts it, is this:
Unhandled exception at 0x0012276a in (Game Name).exe: 0xC0000005: Access violation writing location 0x63207465.
I posted about this on Dark GDK's (game library I use) forum, and they said it was unrelated to the library and that it was just a C++ error. So, that brings me here! Why am I getting the error? I'm almost positive it has to do with the manipulation of my bullet_list, as if I don't remove anything from the list, I don't get the error. I think that sometimes when I shoot new bullets, the program is not quite done deleting the old bullets from the list, so it ends up writing over the old list, causing it to write …
Wow, when I use that code you gave me, I get a whopping 104 errors! New record, baby. Well I guess I should post my real code, since I do quite a bit while iterating.
Code:
struct bullet {
float x, y, z;
float dx, dy, dz;
int id;
float traveledX, traveledY, traveledZ;
bool alive;
bullet(int bulletID) {
id = bulletID;
traveledX = 0.0;
traveledY = 0.0;
traveledZ = 0.0;
alive = true;
}
void create() {
// game code to create object
}
bool move() {
// code
return alive;
}
bool checkCollision(float oldX, float oldY, float oldZ) {
// game code to check collision
return collides;
}
};
list<bullet> bullet_list;
list<bullet>::iterator iter;
bool alive = false;
for (iter = 0; iter < bullet_list.end; ++iter) {
bool isalive = iter->alive;
if (isalive == true) {
alive = iter->move(); // move is a function inside the struct "bullet"
}
if (alive == false) {
int bulletID = iter->id;
bullet_list.erase(bullet_list.begin()+iter);
dbDeleteObject(bulletID); // deletes object from game
}
}
As for the errors....I'll just put in a few. It looks like some of the errors are duplicates:
Error 1 error C2679: binary '=' : no operator found which takes a right-hand operand of type 'int' (or there is no acceptable conversion)
Error 2 error C2784: 'bool std::operator <(const std::list<_Ty,_Ax> &,const std::list<_Ty,_Ax> &)' : could not deduce template argument for 'const std::list<_Ty,_Ax> &' from 'std::list<_Ty>::_Iterator<_Secure_validation>'
Error 8 error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template …
Hi, I'm a beginner to C++ and am having some trouble with my list. I first define a struct named "bullet' like so:
struct bullet {
bool alive;
bullet()
alive = true;
};
Then, I create a list of objects of type "bullet": list<bullet> bullet_list;
In my program, I frequently add new bullets to the list and delete them. At first, I was using a vector, but then I read that using a list was better for my uses because of how often I create/delete bullets from various positions in the list (I actually did this so frequently that I would get buffer overrun errors, which is why I'm now trying lists).
Anyways, when I was using a vector, I could use the following code to check if the bullet was still "alive":
for (int i=0; i < bullet_list.size(); i++) {
bool isalive = bullet_list[i].alive;
// do stuff
But now that I am using a list, I cannot. I get the following error: Error 1 error C2676: binary '[' : 'std::list<_Ty>' does not define this operator or a conversion to a type acceptable to the predefined operator
What do I have to change in order to make this work?
Thanks in advance.
Hi, I've just finished writing a Pong game with Python and pygame and thought it would be cool to make it multiplayer over the net with a friend. So, I changed my old asynchat-based instant messaging server into a server for this multiplayer Pong game.
The only bad thing about this is the fact that there is a noticeable network delay between the two machines (the movement of the opponent paddle lags). Is there any way to get past this? Currently, each machine does all of the processing and simply sends the Y-coordinate of the user's paddle to the server, which forwards it to the other user. Is this a very inefficient setup or will it work?
So, is it possible to reduce the delay of the game? How do the big online games work?
Thanks in advance.
Perfect. Thanks Gribouillis. Problem solved.
That was a great presentation. It took me a second to figure out I had to click to advance the slides.
Okay, then just one last question. Can I write to a database (via sqlite3) in Unicode? Or what should I do?
Thanks.
Sorry, I know this code is for Python 2.x, but hopefully it can point you in the right direction. There is a piece of code that I did NOT write myself but I implemented it in one of my programs. It basically creates a few text widgets in a loop and puts them in a list, also binding the scroll bar to a custom "scrolling" function. I don't think it would be too difficult to adapt this code and rather than binding the scroll bar itself, just bind arrow keys or buttons to the custom "scrolling" function. Good luck. I've pasted the code below; an example of how to implement it is given at the bottom.
from Tkinter import *
class CustomListbox(Frame):
def __init__(self, master, lists):
Frame.__init__(self, master)
self.lists = []
for l,w in lists:
frame = Frame(self); frame.pack(side=LEFT, expand=YES, fill=BOTH)
Button(frame, text=l, bg="#000000", fg="green", activeforeground="#999999", activebackground="#000000", relief=FLAT, highlightthickness=1, highlightbackground="#414141", highlightcolor="#414141", font=("Calibri", 9)).pack(fill=X)
lb = Listbox(frame, bg="#000000", fg="green", highlightthickness=1, width=w, borderwidth=0, selectborderwidth=0,
relief=FLAT, exportselection=FALSE)
lb.pack(expand=YES, fill=BOTH)
self.lists.append(lb)
lb.bind('<B1-Motion>', lambda e, s=self: s._select(e.y))
lb.bind('<Button-1>', lambda e, s=self: s._select(e.y))
lb.bind('<Leave>', lambda e: 'break')
lb.bind('<B2-Motion>', lambda e, s=self: s._b2motion(e.x, e.y))
lb.bind('<Button-2>', lambda e, s=self: s._button2(e.x, e.y))
frame = Frame(self); frame.pack(side=LEFT, fill=Y)
Label(frame, borderwidth=1, relief=RAISED).pack(fill=X)
sb = Scrollbar(frame, orient=VERTICAL, command=self._scroll, bg="black", activebackground="#313131")
sb.pack(expand=YES, fill=Y)
self.lists[0]['yscrollcommand']=sb.set
def _select(self, y):
row = self.lists[0].nearest(y)
self.selection_clear(0, END)
self.selection_set(row)
return 'break'
def _button2(self, x, y):
for l in self.lists: l.scan_mark(x, y)
return 'break'
def _b2motion(self, x, y):
for l in self.lists: l.scan_dragto(x, y)
return 'break'
def _scroll(self, *args): …
Can Any one tell me how to use phython with .net
There's a nice library out there conveniently called "Python for .NET" (link).
and wat is the main use of phython
Come on, at least spell Python correctly! Python, as defined by About.com, is:
Python is a general purpose programming language that is able to be used on any modern computer operating system. It may easily be used for processing text, numbers, images, scientific data, or anything else which one might save on a computer. It is used daily in the operations of the Google search engine, the video sharing web site YouTube, NASA , and the New York Stock Exchange. These are but a few of the places where Python plays important roles in the success of business, government, and non-profit organisations; there are many others.
Python is also an interpreted language. This means that it is not converted to computer-readable code before the program is run but at runtime. In days gone by, this type of language was called a scripting language, intimating its use for trivial or banal tasks. However, programming languages such as Python have forced a change in that nomenclature. Increasingly, large applications are written almost exclusively in Python. As mentioned above, in addition to being used by Google and NASA to complement other languages, Python is used almost exclusively for such applications as YouTube and the web-based transaction system of the New York Stock Exchance (NYSE).
Are you looking for something along the lines of tkSnack? I cannot help you with integrating it into your C program, but from experience it is a highly dependable library that is quite easy to use; it is also cross-platform (at least for Windows & Linux). Its one downside is that it requires Tkinter in order to function.
EDIT: Are you looking for a library or a pre-written music player?
Hi, I'm writing a program that goes through all of the music in a user-specified directory and I am having some trouble with Unicode characters. More specifically, 'ascii' codec can't encode character u'\\xe7'
. The song names need to both be printed to a HTML page as well as be passed to other HTML/CGI pages via the GET method.
What can I do to be more aware of these evil Unicode characters? I tried to simply convert to Unicode where I could in my program but then there comes the trouble of keeping this consistent among the databases and song names/albums/artists they are tied to. Also, I seemed to have trouble looking up things in a dictionary when they had inconsistent encoding.
What do all you intelligent people of the Python forum recommend?
EDIT: Sorry, I did not read the "Active Directory" specification in your post. Well, a Google search turned up an active_directory module which appears to be cross-platform. It can be found here: http://tgolden.sc.sabren.com/python/ad_cookbook.html.
Well, it doesn't even look like deepak's code is Python. I'm not quite sure what is going on with that.
Anyways, I do not see any immediate problems why your code should not work except for the constant calling of the function "create_top." You call it eight times? That would mean you create eight canvases with eight background images? Am I missing something or is that your most apparent problem?
EDIT: If this is actually tyonyjv's code, I will definitely not try to question its methods; his GUI algorithms are above my skill level. He will unquestionably know more about it than I do, so try to ask him politely. Good luck.
Why do they have to make everything so difficult.....
Well, I have some marginally good news. Some users with the same problem as you created a library to hopefully make the connection process easy. Pyfacebook's home: link. This is the current home: do not use the Google code page, as it is supposedly outdated. You can find examples in the "examples" directory on github (link) or from the facebook developer's area (link).
Hopefully that will make things easier.
It's probably not working because you are not supplying all the required arguments. Sadly, it looks like Facebook wants quite a few arguments to log in such as authentication token and api key, but the Facebook devs have provided some information on all of it: http://wiki.developers.facebook.com/index.php/Authorization_and_Authentication_for_Desktop_Applications.
Good luck.
The error is being raised because it is trying to find the integer value of the character '[', which is apparently part of your list. You could either put in a try/except statement to 'pass' when you run into those, or print out the contents of the list and manually remove bogus entries.
Just post back if you need help with any of that.
Ugh, this is quite frustrating. I am writing a series of CGI scripts with Python that all work perfectly until I add in a stylesheet reference. Interestingly, if I put the styling rules inside the CGI script, it runs perfectly; it only throws an error when it is in an external stylesheet. I'm not sure if my "Exec format error: Premature end of script headers" error has to do with Python, so I apologize if this is not in the right forum. Sadly there is no HTML/CSS forum here, so I thought the Python forum would be sufficient.
Anyways, here is some of my Python code:
import cgi
print "Content-Type: text/html\n\n"
print "<html>"
print "<head>"
print "<link href='MyStylesheet.css' rel='stylesheet' type='text/css'>"
print "</head>"
print "<body>"
# Cut out
print "</body>"
print "</html>"
MyStylesheet.css:
body {
background-color: #000000;
}
a:link {
text-decoration: none;
line-height: 2.0;
color: #F1F1F1;
}
a:visited {
text-decoration: none;
line-height: 2.0;
color: #F1F1F1;
}
#colored {
background: #1B1B1B;
}
What's my problem here? Apache's error log says its my stylesheet, but I cannot see any problems with it. Maybe I just need some fresh eyes to look at it?
Thanks in advance everybody.
EDIT: Well, I guess I solved my own problem. Apparently Apache does not like having CSS files anywhere inside the cgi-bin directory. Moving the stylesheet to a different directory and calling it by its full path did the trick.
Hi, I recently found a pair of wireless outdoor speakers (link) that work flawlessly except they lack the central unit (your iPod connects to it and broadcasts music to the speakers). I would like to take advantage of the nice speakers by streaming to them via my computer. Is this possible? If so, what extra hardware would I need and how would I do it? I program in Python and would be able to find a library to do the streaming if I knew how to broadcast to the speakers.
I would really like to do this project, so please respond if you have any ideas at all of how I can do this. Thanks in advance.
Yeah, sure. I think domain name masking would be the solution you're looking for.
http://kb.siteground.com/article/Simple_domain_name_masking.html
Brilliant! I didn't think of just creating a hidden input tag. That will work perfectly. Problem solved.
Thank you.
Hi, I have a very simple problem yet I can't find out how to do it for the life of me. I am creating a simple CGI script with Python and part of it needs a HTML form. This is what I have so far (excludes imports, etc):
font_size = 9
print "<form name='input' action='Player.py' method='get'>"
print "Set Volume: <input type='text' name='volume' />"
print "<input type='submit' value='Submit' />"
print "</form>"
I would like to pass my 'font_size' variable along with the form submission so that my next script knows what font size to use.
How can I do this?
Thanks in advance.
I found a solution! I am still using Tkinter's after method to run asyncore's loop function, but instead of using asyncore.loop(), I use asyncore.poll(0). If I call that function every 100ms or so, it no longer has an effect on Tkinter's main loop.
Victory.
Only a few questions more actually. In the part of:
cursor.execute("SELECT * FROM mytable") # Select everyone in the table results = cursor.fetchall() for entry in results: print entry
1. What is what I call (a string line, array, etc)??
2. And how do I call an specific data??
1. What do you mean? Are you asking what type of objects the results are? The actual variable 'results' is an array which contains an array for each entry. All of the data in these arrays is strings.
2. You mean how can you only select certain results from the table? Let's say you need to look up John Doe's zip code - just change line 22 from my last post into this: cursor.execute("SELECT * FROM mytable where name = 'John Doe'")
Okay, I've done a little more work and hopefully somebody will be able to help me from here. I have found a way to run asyncore's loop after Tkinter's main loop (the after method), but when asyncore does its loop, Tkinter stops doing its main loop, mucking everything up. Is there a way I can run asyncore's loop to change this?
Thanks again.
Hi, so I'm having quite the difficulty here. Let me start by explaining the architecture of my scripts. My "Listener.py" is a script that uses asyncore in order to listen for connections and receive commands from them. If it receives the text "play" from a connection, it calls another script, "MusicPlayer.py," that uses the tkSnack library to play a sound file (which requires root.mainloop() to be called). So, I have that working well. Listener.py receives a connection, receives the text "play," and calls "MusicPlayer.py" to play a sound file.
Now, here is where the trouble begins. What good is playing music if you can't pause/stop/restart/etc. it? If I don't change anything about my scripts, the mainloop of Tkinter prevents Listener.py from receiving any more connections/data.
Immediately, I thought to myself, "Oh, no problem! I can just give MusicPlayer.py it's own thread and then I can continue receiving connections/data!" Sadly, this didn't work. It gives me the following error from Tkinter: RuntimeError: main thread is not in main loop
. I guess Tkinter doesn't want its main loop inside a separate thread.
So...what can I do about this? If I were to put Listener.py into another thread, I would have the same problem...asyncore requires that you call its mainloop method, and I would be willing to bet it would give me the same error as Tkinter did.
Thanks so, so much in advance.
It's really useful, I appreciate but I have some questions.
1. After creating a db, how do I call their objects?
2. The db must still running while my application works or only when I need to insert or call something in the db?
3. Can I create more then one db for my applicate? In the case of yes, how do I work with all of them (switch between db).
3. And if you can explain me more of how do I get something from the db.PD: excuse me if I don't catch something quickly, thats because I'm new at python
1. I'm not sure if I understand what you're asking. Are you asking how to manipulate a database after it has been created? I think you might be mixing up "table" and "database." The database is the entire thing, and it contains tables. A database can be created with this library by simply putting in any file name to a line of code like my line 17 (NOTE: When I refer to line numbers, I am referring to my last post). It doesn't matter if it already exists or not: if it does, the program simply accesses it; if it doesn't, the program creates a new database. Once you have this database, you can create "tables" inside of it. These tables are what actually contain your data...I am manipulating them in lines 27-41 of my code.
2. You can close the handle …
I'm on windows, so I don't think thats the problem.
Hah, I think that might be your exact problem, especially if you're on Vista. Try a good old 'Run as Administrator.' And maybe implement something like so:
import os
if os.geteuid() != 0:
print "You must be root to run this script."