Using TK and the canvas.

2009-02-10 Thread Kalibr
Hi all. I'm experimenting with making a UI for a little (well, not
quite) script that basically draws up a tech tree to some skills from
my favorite game. What I'm aiming for looks a little like this site
here:(apologies if I'm not supposed to direct link)
http://www.anderkoo.com/uploads/271/605/NewTechTree.jpg.

Anyway, I made a script which reads data from several files and saves
the data into an array of skill objects, here's what it looks like:

#define the class
class skill:
def __init__(self, name, description, a1, a2, rank, prereq):
self.name = name #string (example is "Anchoring")
self.desc = description #string (example is "blah blah blah")
self.a1 = a1   #string with attributes affecting the skill
(Example is "Int")
self.a2 = a2   #string
self.rank = rank   #how hard it is to train (example is "5")
(too lazy to convert to int
self.prereq = prereq  #any prerequsites (an array of ["skill",
"levelrequired"])

#the trained level already
self.skillowned = "0" #we change this later on when we access
another file :)

Finally, I set up a class which accepts a parent (normally root), and
the skill in question.
here it is:

class SkillInfo:
def __init__(self, parent, skill):
container = Frame(parent)
container.pack()

#we make this the top frame for some reason
labelcontainer = Frame(container, height=50, width=50)
labelcontainer.pack(side=LEFT, fill=BOTH, expand=YES)

desccont = Frame(container, height=50, width=50) #the
description content
desccont.pack(side=LEFT, fill=BOTH, expand=YES)

#make a name label
Label(labelcontainer, text=skill.name, wraplength=100).pack
(side=TOP, anchor=W)

#print the level buttons
for i in range(1, 6):
button = Button(labelcontainer)
button["text"] = "Level", i
if int(skill.skillowned) >= i:
button["background"] = "green"
button["width"] = 10
else:
button["background"] = "red"
button["width"] = 10
button.pack(anchor=W)

Label(desccont, text=("\n"+skill.desc), wraplength=100).pack()

Now I know all I have to do is set the SkillInfos parent to a canvas,
but how would I arrange and draw the lines? Thanks all :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Using TK and the canvas.

2009-02-10 Thread Kalibr
On Feb 11, 5:51 am, r  wrote:
> On Feb 10, 1:27 pm, Kalibr  wrote:
> [snip]
>
> You should really check out wxPython, there is support for just this
> type of thing. of course you could do this with Tkinter, but just
> thinking about it makes my head hurt :).

Alright, I shall investigate. Thank you.
--
http://mail.python.org/mailman/listinfo/python-list


Finding file details...

2008-05-29 Thread Kalibr
I've been trying to figure out how to find the details of files
(specifically music for now) for a little sorting script I'm making,
My aim is to get details on the artist, album, and genre for mp3 and
wma files (possibly more in the future). My closest match was when I
stumbled accross PyMedia, but it only supports up to 2.4 (I have 2.5).
Now I see a bit mentioned on GetFileVersionInfo, but that doesn't seem
to help (and most of it went over my head). Is there any module I can
use to find this sort of data? I'm trying to not make it specialised
in music, because I may want to extend this to picture, movie, text
etc. files in the future. Any ideas how I could go about this?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Compare 2 files and discard common lines

2008-05-29 Thread Kalibr
On May 29, 6:36 pm, loial <[EMAIL PROTECTED]> wrote:
> I have a requirement to compare 2 text files and write to a 3rd file
> only those lines that appear in the 2nd file but not in the 1st file.
>
> Rather than re-invent the wheel I am wondering if anyone has written
> anything already?

You can use the cmp(x, y) function to tell if a string is similar to
another.

going cmp('spam', 'eggs') will return 1 (spam is greater than eggs)
(have no idea why)
swapping the two give -1
and having 'eggs' and 'eggs' gives 0.

is that what you were looking for?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding file details...

2008-05-29 Thread Kalibr
On May 29, 7:55 pm, Tim Golden <[EMAIL PROTECTED]> wrote:
>
> You don't say, but I assume you're on Windows since you mention
> GetFileVersionInfo (which doesn't have anything to do with media
> files, by the way) and WMA. There may be packages out there
> to do all this already but if not you'll need to pull in a few disparate
> modules and mix'n'match.
>
> While ID3 readers (which determine the metadata for MP3) are reasonably
> common few of them come ready-compiled for Windows. I've used Ned
> Batchelder's id3reader [1] successfully for simple tasks so you might try
> that. On the WMA side, you can automate Windows Media Player to get
> metadata. (And it might work for .mp3; I've not tried).
>
> 
> import win32com.client
>
> player = win32com.client.gencache.EnsureDispatch ("WMPlayer.OCX")
> wmedia = player.mediaCollection.add (r"c:\temp\bells.mp3")
> try:
>   artist = wmedia.getItemInfo ("Artist")
> finally:
>   player.mediaCollection.remove (wmedia, False)
>
> print "bells.mp3 has artist", artist
>
> 
>
> You're going to have to dig around for docs on this one. And it's not
> pretty. Try starting from:
>
> http://msdn.microsoft.com/en-us/library/bb249009(VS.85).aspx
>
> TJG
>
> [1]http://nedbatchelder.com/code/modules/id3reader.html

Hmm, thanks for the info. Yes, I am using Winders (Vista to be exact)
and I just assumed that there must be a way to programmatically get
the stuff you get from choosing properties in the right click menu.
But I guess there isn't (hard to believe, because I can't see MS hard-
coding each and every file format's metadata into it's OS). I might
have to learn more about the command prompt ( I hear there is a module
for fiddling with it) and work from there.

Cheers for the links though, I will be checking them out :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding file details...

2008-05-29 Thread Kalibr
On May 30, 1:41 am, "Roger Upole" <[EMAIL PROTECTED]> wrote:
>
> You can use the shell COM objects to access media properties
> as shown by Explorer.
>
> import win32com.client
> sh=win32com.client.Dispatch('Shell.Application')
>
> folder= r'M:\Music\Bob Dylan\Highway 61 Revisited'
> ns=sh.NameSpace(folder)
>
> ## the column index for Artist may vary from folder to folder
> for c in range(0,255):
> colname=ns.GetDetailsOf(None, c)
> if colname=='Artists':  ## This shows up as just Artist on XP
> for i in ns.Items():
> artist=ns.GetDetailsOf(i, c)
> if artist:
> print ns.GetDetailsOf(i, 0), artist
> break
>
> Roger

I shall give that a go. (is the module you reference this one?
http://python.net/crew/mhammond/win32/Downloads.html )
--
http://mail.python.org/mailman/listinfo/python-list


Re: Finding file details...

2008-05-30 Thread Kalibr
On May 30, 3:03 pm, Kam-Hung Soh <[EMAIL PROTECTED]> wrote:
> Kalibr wrote:
> > On May 30, 1:41 am, "Roger Upole" <[EMAIL PROTECTED]> wrote:
> >> You can use the shell COM objects to access media properties
> >> as shown by Explorer.
>
> >> import win32com.client
> >> sh=win32com.client.Dispatch('Shell.Application')
>
> >> folder= r'M:\Music\Bob Dylan\Highway 61 Revisited'
> >> ns=sh.NameSpace(folder)
>
> >> ## the column index for Artist may vary from folder to folder
> >> for c in range(0,255):
> >> colname=ns.GetDetailsOf(None, c)
> >> if colname=='Artists':  ## This shows up as just Artist on XP
> >> for i in ns.Items():
> >> artist=ns.GetDetailsOf(i, c)
> >> if artist:
> >> print ns.GetDetailsOf(i, 0), artist
> >> break
>
> >> Roger
>
> > I shall give that a go. (is the module you reference this one?
> >http://python.net/crew/mhammond/win32/Downloads.html)
>
> If you installed ActiveState's Python, the win32com module should be
> installed.
>
> --
> Kam-Hung Soh http://kamhungsoh.com/blog";>Software Salariman

I gave your program a go, and it works magnificently.
Now I have to figure out how tro use it on a song by song basis
(I still suck at using classes).
Thanks so much for your help.
--
http://mail.python.org/mailman/listinfo/python-list


Dynamically naming objects.

2008-06-06 Thread Kalibr
I've been developing a small script to fiddle with classes, and came
accross the following problem. Assuming I get some user input asking
for a number, how would I spawn 'n' objects from a class?

i.e. I have a class class 'user' and I don't know how many of them I
want to spawn.

Any ideas?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamically naming objects.

2008-06-06 Thread Kalibr
On Jun 7, 1:20 pm, Hans Nowak <[EMAIL PROTECTED]> wrote:
> Kalibr wrote:
> > I've been developing a small script to fiddle with classes, and came
> > accross the following problem. Assuming I get some user input asking
> > for a number, how would I spawn 'n' objects from a class?
>
> > i.e. I have a class class 'user' and I don't know how many of them I
> > want to spawn.
>
> > Any ideas?
>
> Sure. This will give you a list of n instances of user:
>
>[user() for i in range(n)]
>
> Of course, you could also use a good old for loop:
>
>for i in range(n):
>u = user()
>...do something with u...
>
> Hope this helps!
>
> --
> Hans Nowak (zephyrfalcon at gmail dot com)http://4.flowsnake.org/

whoops, replied to author

What I wanted to ask before was won't 'u' be overwritten with a new
object each time the loop ticks over?

what I want to do is have, say 5 users in a game, so I'd have to spawn
5 objects. I can't do that because I have'nt hardcoded any object
names for them.

or does it somehow work? how would I address them if they all have the
name 'u'?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamically naming objects.

2008-06-07 Thread Kalibr
Thanks for all this info.

I'll try all your scripts out.

from what you guys have said, I did the following:

I set up a 'computer class' (I'lm leaving out the mutators)

class computer:

def __init__(self, IP, owner, ph_connections, connections):

assert isIP(IP) == True
self.IP = IP
self.owner = owner

for i in ph_connections:
assert isIP(i) == True
self.ph_connections = ph_connections

for i in connections:
assert isIP(i) == True
self.connections = connections

isIP(IP) is a function that checks if it looks like an IP based on
some rules.

Anyway

I set up a list of users, each with their computer object named after
them, so:
users = ['Kal', 'Noob', 'Fred']

I ran through them with some code based vaguely on what you guys have
said:

for i in users:
i = computer('', i, [], [])

I set up the ph_connections and connections lists as empty for ease of
use.
Does this code seem right? I can't get it to work.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Dynamically naming objects.

2008-06-07 Thread Kalibr
On Jun 8, 2:58 am, Hans Nowak <[EMAIL PROTECTED]> wrote:
> Kalibr wrote:
> > On Jun 7, 1:20 pm, Hans Nowak <[EMAIL PROTECTED]> wrote:
> >> Kalibr wrote:
> >>> I've been developing a small script to fiddle with classes, and came
> >>> accross the following problem. Assuming I get some user input asking
> >>> for a number, how would I spawn 'n' objects from a class?
> >>> i.e. I have a class class 'user' and I don't know how many of them I
> >>> want to spawn.
> >>> Any ideas?
> >> Sure. This will give you a list of n instances of user:
>
> >>[user() for i in range(n)]
>
> >> Of course, you could also use a good old for loop:
>
> >>for i in range(n):
> >>u = user()
> >>...do something with u...
>
> >> Hope this helps!
>
> >> --
> >> Hans Nowak (zephyrfalcon at gmail dot com)http://4.flowsnake.org/
>
> > whoops, replied to author
>
> > What I wanted to ask before was won't 'u' be overwritten with a new
> > object each time the loop ticks over?
>
> Yes, so you have to store it somewhere, if you want to keep the object around.
> The list comprehension mentioned above stores all the objects in a list, after
> which they can be accessed at will via indexing.
>
> > what I want to do is have, say 5 users in a game, so I'd have to spawn
> > 5 objects. I can't do that because I have'nt hardcoded any object
> > names for them.
>
> > or does it somehow work? how would I address them if they all have the
> > name 'u'?
>
> users = [user() for i in range(n)]
>
> # use: users[0], users[1], etc
>
> --
> Hans Nowak (zephyrfalcon at gmail dot com)http://4.flowsnake.org/

Ok, wait, I see where this is going.
I just did the list comprehension.
I was under some misguided idea that you actually had to have a unique
variable name for all the new objects you spawned. Thanks for all you
help guys!
--
http://mail.python.org/mailman/listinfo/python-list