scru 909

Hey I did what you said and I learnt how to use the resources. I like how my images are now globally available, and don't have to use filenames which can lead to problems.

Thanks...and I'm beginning to really like this language after all...

scru 909

Thanks guys. Do you think buying one of those books would be a good investment? (seeing I'm not a working man, I'm still in college)

Apparently the one by Jeffery Suddeth is the only one available to me (from Amazon, those on Microsoft Press aren't being sold anymore O.o).

One more thing, Jerry...as you said you have a huge library, do you have Microsoft Visual C# Programming for the absolute Beginner"? The reason I ask is because I own the coresponding one for python (just replace the MSVC#) and it didnt teach me everything I know, but it taught me enough to feel comfortable with the language...also the approach was kinda fun.

So do you know if MSVC# is anything like that?

Anyway thanks all you guys for helping this guy figure out how to go about learning a spanking new language.

P.S. That intellisense thing is pretty awesome huh???;)

scru 909

quick question. Can I use Tkinter and wxpython in the same app? (See i built this splash screen class in Tkinter --doesn't use buttons, but does a lot of work (loading images/files/wat not)).

If not, is there a way to remove the title bar and border in wxpython like [code=python]root.overideredirect(1)[/code]does in Tkinter?

scru 909

nevermind...i was using overridedirect instead of overideredirect....silly me... (thats why im a big fan of underscores...heh heh)

scru 909

This does not work for me, I get:
AttributeError: overridedirect

scru 909 Posting Virtuoso

sigh...

I need a way to make an image as a background for a window, and still be able to put buttons and other controls on top of it. I even tried using wxPython's wxPanel, but it proved a real pain because I found the documentation very sparce...:sad: (google didn't even help).

Is there anyway I can do this? I've heard about the canvas but I have no idea how to use this...

Thanks.

scru 909 Posting Virtuoso

I might as well back up and start from the very top.

Does anybody know the best way for me to learn this language (from python), because I none of the tutorials I have tried work for me (I feel like I'm moving backwards here, and that's unnerving).

So...

any suggestions on how I should learn this?

..I'm going back to python for now.

scru 909

yes write and read

scru 909 Posting Virtuoso

So here's the deal. I learned to program with python, and C# is my second step up the ladder. I'm currently learning the language by making a Sudoku game (just porting over the code from python..nothing fancy).

So I ran into a dead end just now...I know how to manipulate data files {*.dat) in python, to store objects/arrays/ etc. How is this done in C#? I need a quick way to open a file, and put/get two objects in/from it.

P.S. is shelving available in C# as well, because something like that is what I'm talking about. (It says somewhere in the python docs or something that shelving[what I'm used to using] is domething from C, or C++[memory is foggy])

scru 909

Well im using VS IDE, but i want to the image to change back and forth when the mouse enters and leaves the button's space.

I have not learned how to use resource files. Is there a tutorial for this?

Anyway, i've gotten it to work using the full path as you said, and those other problems seem to be disappearing one by one (i've learned to configure my splash properly and how to show/hide my forms properly...well i think).

One more question though, i'm using vcsharp express 2005. Now that I've gotten it working using full-paths, does the compiler have an option or something to put all my external stuff into a resource file (or something similar) upon compiling? (make it easier for me without having to bother my head about how to use resource files...)

Thanks though...it's actually going smoother now...

scru 909

Oh ok. But I was just thinking, if I were to give the program to a couple friends it might not work since they might store the program seperately....

Thank you, I'll get to it right away

scru 909 Posting Virtuoso

I was just wondering....

There is a python projects for the beginner in the Python section of the site...maybe you guys can do one here too?

Any readers are welcome to second this request..;)

scru 909

Am I authorised to post here?

This one should be nice-ish.

I'm sure you've heard of Sudoku? Well write a computer program that creates a sudoku game for the user. Try to be innovative in the program rules (tweak the sudoku game rules a little so that the program is fun to play, or maybe more challenging...nothing dratsic though that doesn't make it "sudoku" anymore).

I already started a very limited working console version that tries to generate a solved puzzle, and then plays the game by comparing the solved puzzle to a new grid created to store the user's input.
Scroll down to get the code...

Your objectives are simple(ah...not so much), and ranked by ease(the latter ones may really try you if you are a beginner):

  1. Currently, the program generates a very limited set of very easily solved puzzles(there is an obvious pattern that each and every puzzle follows). You are required to change the program so that it can read a puzzle from a data file.

  2. Create a Gui front end for this program and get rid of this ugly, tedious console prompt...after which, allow the user to input false/temporary entries in the available squares that they can erase at any time they choose. When you've done with that, to really polish your UI, allow the user the ability to undo a max of 10 moves by order in which they made them (this should be separate from the ability to delete temporary squares), HINT: ...

scru 909

ok, i just realised that error description i posted isnt helpful at all...it told me that I can't call a destroyed object? something like that...

scru 909 Posting Virtuoso

Is there anything wrong with this code?
[code=C#]
namespace RotnetSudoku
{
public partial class splash : Form
{
public splash()
{
InitializeComponent();
fclsStartScreen frmStartscreen = new fclsStartScreen();
frmStartscreen.Show();
this.Visible = false;
}
}
}
[/code]
Apart from the indentation?

When i run it ithe splash form doesn't close...Also, if i change [code=c#]this.Visible= false;[/code] to [code=c#]this.close();[/code], i get this error:

System.ObjectDisposedException was unhandled
Message="Cannot access a disposed object.\r\nObject name: 'splash'."
Source="System.Windows.Forms"
ObjectName="splash"
StackTrace:
at System.Windows.Forms.Control.CreateHandle()
at System.Windows.Forms.Form.CreateHandle()
at System.Windows.Forms.Control.get_Handle()
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at RotnetSudoku.Program.Main() in D:\Documents and Settings\T\My Documents\Visual Studio 2005\Projects\RotnetSudoku\RotnetSudoku\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
:!: :sad: :mad:

scru 909 Posting Virtuoso

Apparently the ewase of programming has disappeared when I stopped using python.
[code="C#"]
btnPlay.BackgroundImage = Image.FromFile("\Images\playbtn_down.jpg");
[/code]
Now I have the image in a Images folder...and I don't see why this doesn't work (from build [F5])....
this is making me very bitter......It's one of the many problems I've encountered since I started using this language (all unsolved). BTW...I'm using MS Visual C# 2005 Express for what its worth....guh

scru 909

Is there any reason why your array is so complex? You have a list containing a tuple containing a list containing several tuples containing lists.....

Anyway, try this (no guarantees, don't have an intepreter atm...you may also need to fix the indents):

[code="python"]
def countchar(array, char="a", total=0):
for element in array: #indent-1
array
=False #indent-2. different from "array" above.
try:#indent-2
temp=element[0]#indent-3
array=True#indent-3
if array
:#indent-2
for element_ in element:#indent-3
return total+countchars(element, char=char, total=total)#indent-4
else:#indent-2
for element in array:#indent-3
if element==char:#indent-4
total+=1#indent-5
return total#indent-3
[/code]

You need to realise that i don't have access to an IDLE now to test this, so you're going to have to figure out the indentation on your own (use your discretion). Another thing, if the code crashes or something like that, you should use your discretion fix it if its a minor bug.

NOTES:
Logically, all it does is check if the array conatins another array. If it does, it checks if that array contains another array...and s on. Finally, when it reaches the last array, it checks if each element in that array is an "a", or whichever other character you may want to search for. This uses recursion...it may be frowned upon if you hand it in for homework, or use it to check large arrays.

Happy coding...

scru 909

Sorry I took so long to respond

Here is my code:

[code= python]
import socket, cPickle, select, sys, threading, time
from ftplib import FTP
THREADS=[]

class Server(object):
def init(self):
self.host=''
self.backlog=5
self.port = 30000
self.size = 1048576
self.server=None
self.threads = []
def set_socket(self):
try:
self.server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.server.bind((self.host, self.port))
self.server.listen(5)
except:
self.port+=1
self.set_socket()
def run(self):
self.set_socket()
alert=[self.server]
running=1
while running:
print "running server on "+get_ip()+" at port "+str(self.port)
inputready, outputready, exceptready = select.select(alert, [], [])
print "check 1"
for soc in inputready:
print "check 2"
if soc==self.server:
print "check 3"
cli = Client(self.server.accept())
cli.start()
self.threads.append(cli)

    self.server.close()
    print "ggk"
    for cli in self.threads:
        cli.join()

class Client(threading.Thread):
def init(self, (client, address)):
threading.Thread.init(self)
self.client=client
self.address=address
self.size=1048576
def run(self):
running = 1
while running:
data = self.client.recv(self.size)
if data:
self.client.send(["confirm", 0])
else:
self.client.close()
running=0

def get_ip():
ftp=FTP("garbo.uwasa.fi")
[URL="ftp://ftp.login"]ftp.login[/URL]()
speech=ftp.getwelcome()
[URL="ftp://ftp.quit"]ftp.quit[/URL]()
ip=""
speech=speech[482:]
while speech[0] != "\n":
ip+=speech[0]
speech=speech[1:]
return ip

def send_list(clients):
client_file=file("clients.dat", "w")
cPickle.dump(clients, client_file)
client_file.close()
client_file=file("clients.dat", "rb")
ftp=FTP("rotnet.awardspace.com", "rotnet_client", "rottwylaz")
<A href="ftp://ftp.storbinary("STOR">ftp.storbinary("STOR clients.dat", client_file)
[URL="ftp://ftp.quit"]ftp.quit[/URL]()

def get_list():
ftp=FTP("rotnet.awardspace.com", "rotnet_client", "rottwylaz")
<A href="ftp://ftp.retrbinary("RETR">ftp.retrbinary("RETR clients.dat", file("clients.dat", "wb").write)
[URL="ftp://ftp.quit"]ftp.quit[/URL]()
data_file=file("clients.dat", "r")
clients=cPickle.load(data_file)
data_file.close()
return clients

def print_list():
clients=get_list()
for client in clients:
print "User at "+client[0]+" is connected at port", client[1]
class Printer(threading.Thread):
def init(self):
threading.Thread.init(self)
def run(self):
print_list()
server=Server()
server.run()

[/code]

scru 909 Posting Virtuoso

I know I've been told before to use C++ sockets...and I will if this doesn't work out, but that was before I even knew python had sockets.

Now. The problem here if that my socket enabled program seems to work perfectly well on a LAN, but not over the internet (connection seems impossible). I suspect it may be the DSL modem setting its own local IPs (10.0.0.3 etc).

I tried binding the server to the public ip of the modem(after parsing it from an FTP server's welcome message), but it refuses to do so and scolds me with a few lines of red.

The other thing I tried was to set up port forwarding on the router (not sure if I did it right though), but that didn't work.

So is there some way I can structure the code so that the connecting client can bypass the modem and get to my server? Or (and I know this may not be your expertise) is there someway I can force to modem to assign the public IP to my comp?...however dangerous that may be?

scru 909

Hey, that link that Jeff gave me, has information that works! My friends and I have been able to send messages and even files over the school LAN using python socket module. Now we're going to try it over the internet (I feel it should work, because it uses IP addresses)

So thanks Jeff. We are going to try it in python first (because its unbelievably easy), and then try C++ if that doesn't work out.

Thanks again for awesome help...i tell you this site is just great.

scru 909 Posting Virtuoso

Hi. SInce you guys were so helpful the last time around, I decided to ask a less pressing, but more casual questions.

My friends and I want to build a private p2p client (connects to our computers through this client to share files and do messaging), just for the heck of it...you know, to see if we can.

So I'm thinking, can it be done easily/efficiently in python? Or what language might be best for this? Also, any good resources available as to where to start reading up on how to implement this (yes, I said reading up)?

Here's what we're looking for:

Possibly make it a bit private, or at least, make it only compatible with the client we build.

Remote access. It would be cool if it won't be bound to just the computers we own, but any computer we put the client on (we'd have authorisation of course)

We don't want to have to use an internet server, but have it decentralized over our computers. They just connect and talk.

Send files, and chat messages in real time

Maybe even be able to broadcast and receive multimedia to and from each other. (not a vital, but that would be really good)

I know this is sort of just re-inventing the wheel, but as I said it's really just to see if we can do it.

Also, you should know that we are willing so to learn anything we have to and will have a lot of patience ...

scru 909

Well in a couple weeks (after I finish my database project), Me and my friends are going to commence coding (or feeble attempts at) a private server and a client to go with it.

So...who wants to help? :P

and also, is python the best language for this? I am also open to learning other languages, but python and VB happen to be my languages of preference.

scru 909

WOOHOO! THanks you guys. I now have a working timer. The problem was that I mis-interpreted mawe's post and wrote my own self.update()....that didn't work. But it was from the last post that I got egged on that Tk objects have update methods, and I used it after [code=python]self.hourlbl["text"]=self.hh

etc....[/code] and it works just fine now.

Thanks!

scru 909

Well that doesn't work either. The same thing happens: all i see is the console window.

scru 909

Hey mawe. I take it I need to just write an update method with all the stuff that was there in it?

And yeah Jeff, it was that book. It's the one we use in school....well it's the one the school told us to take and go learn python on our own. It's sitting open on my printer to the livewires reference page right now, incidentally.

Well thanks guys for all your help. I'll try it when I get to work, cause I'm late for school right now. Let you know how it goes.

scru 909

humblest apologies.

Livewires based timer:
[code=python]

Te-je Rodgers
Counter module

from livewires import games, color

class Counter(games.Sprite):
"""My counter is a sprite."""
def init(self, screen, x, y,image, passer):
self.screen = screen
self.init_sprite(screen = screen, x = x, y = y, image=image)
self.name=passer[0]
timer=passer[1]
self.hh=timer[0]
self.mm=timer[1]
self.ss=timer[2]
self.count=0
self.col=color.blue
games.Text(screen=screen, x=200, y=20, text=self.name, color = color.white, size=50)
games.Text(screen=screen, x=200, y=180, text="Press ENTER or F1 to stop",
color=color.white, size=20)

self.display_message()

def close_timer(self):

    if self.hh<0:
        import last
    else:
        self.screen.quit()

def good(self):
    x=0
def display_message(self):
    games.Message(screen = self.screen, x=200, y=100,
                  text=str(self.hh)+" : "+str(self.mm)+" : "+str(self.ss), size=100, after_death=self.good(),
                  color=self.col, lifetime=75)

def decrease_seconds(self):
    self.ss-=1
    if self.hh>=0:
        if self.ss<0:
            self.ss=59
            self.mm-=1
            if self.mm<0:
                self.mm=59
                self.hh-=1
                if self.hh<0:
                    self.close_timer()
                else:
                    self.display_message()
            else:
                self.display_message()
        else:
            self.display_message()
def moved(self):
    self.count+=1
    if self.screen.is_pressed(games.K_RETURN) or self.screen.is_pressed(games.K_F1) or self.screen.is_pressed(games.K_KP_ENTER):
        self.close_timer()
    if self.hh==0 and self.mm==0 and self.ss==6:
        self.col=color.red
    if self.count==75:
        self.decrease_seconds()
        self.count=0

def start(passer):
root32=games.Screen(400, 200)
sprite_image=games.load_image("img.bmp")
back=games.load_image("box2.jpg")
root32.set_background(back)
x=Counter(root32, 296, 139, sprite_image, passer)
root32.mainloop(50)
[/code]

Tkinter timer(not working at all):
[code=python]

Gamal Crichton
Teje's Counter
04/02/07

from Tkinter import *
import time
class Application(Frame):
def init(self,master,actname,time):
Frame.init(self,master)
self.hh=time[0]
self.mm=time
[1]
self.ss=time_[2]
self.name=actname
self.grid()
print time

self.disp_widgets()
self.aggregate()

def disp_widgets(self):
    #Uses labels to diaply time.
    Label(self,
          text=self.name, font=("Arial, 32")
          ).grid(row=0,column=0,columnspan=3,sticky=W)

    self.hourlbl=Label(self,
          text=self.hh, font=("Arial, 40")
          )
    self.hourlbl.grid(row=1,column=0,columnspan=1,sticky=W)
    self.minutelbl=Label(self,
          text=self.mm, font=("Arial, 40")
          )
    self.minutelbl.grid(row=1,column=1,columnspan=1,sticky=W)

    self.secondlbl=Label(self,
          text=self.ss, font=("Arial, 40")
          )
    self.secondlbl.grid(row=1,column=2,columnspan=1,sticky=W)

    Button (self,
            text="Stop",
            command=self.show,
            ).grid(row=2,column=0,sticky=E, columnspan=3)

def show(self):
        print "Booooooooo!"
def aggregate(self): #This function is supposed to decrement the time
    for hours in range(self.hh, -1, -1):
        for minutes in range(self.mm, -1, -1):
            for seconds in range(self.ss, -1, ...

scru 909 Posting Virtuoso

Hi. I've just registered, but I'm not exactly new to here (i've been lurking as a guest). I'm trying to make a countdown timer based on a class that I created, which accepts hours, minutes, and seconds as parameters and counts them down to zero, will displaying them in a Tkinter window.

Now, I did start on it using Tkinter, but the Tkinter window just never appears (for some reason, I suspect this has something to do with the time.sleep() i use in my aggregate function, because everything else seems fine and when I the aggregate() function call, the window runs normally.

I managed to create a temporary fix using livewires, that instead of using time.sleep(), uses the mainloop() cycles to decide when to decrement a second (mainloop in livewires do a certain amount of cycles per second). The problem with this is that it isn't always accurate. That is, sometimes it goes too fast, and sometimes it goes too slow with the exact same FPS settings (I suspect this has to do with my CPU load or something...i'm not very skilled and I don't know a lot about these things).
Another problem with the livewires method is that while in Tkinter, I could just destroy() the timer window when the timer is through and call back the main window(I want the timer to quit, and open back the start screen when it is through), with this livewires version it just locks up when i tell it screen.quit() (The destroy() ...