[Tutor] Read dictionary data in a specific order...

2007-08-24 Thread Trey Keown
Hello.
I would like to know, how can I read (or sort) a dictionary in a certain
order?
say this is my dictionary-
attrs={u'title': u'example window title', u'name': u'SELF', u'icon':
u'e.ico'}
how could I get the data so that u'name' is read first, u'title' second,
and u'icon' third?
thanks so much for any help-
Trey

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Read dictionary data in a specific order...

2007-08-24 Thread Trey Keown
> "Trey Keown" <[EMAIL PROTECTED]> wrote
>
>> I would like to know, how can I read (or sort) a dictionary in a
>> certain
>> order?
>
> Dictionaries are by design unsorted and indeed may even change
> their order during their lifetime.
>
>> attrs={u'title': u'example window title', u'name': u'SELF', u'icon':
>> u'e.ico'}
>> how could I get the data so that u'name' is read first, u'title'
>> second,
>> and u'icon' third?
>
> Normally you would sort the keys of the dictionary but since
> your order is not a natural sort order then the easiest way is
> probably to create a list of the keys you want in the order you
> want them. Thus:
>
> keys = ['name','title','icon']
> for key in keys: print attrs[key]
>
--
Okay, the reason I need to know this is that expat, my xml parsing module,
returns the attributes of an xml element as a dictionary. Now that i've
done what you recommended above, my xml parsing program returns the
dictionary's value as the value and the tag.
here's my code-
"""""""""""""""""""""""""""""""""""""
...
global window_attrs_key_order
window_attrs_key_order = ["name", "title", "icon"]
def start_element(name, attrs):
global window_attrs_key_order
if name in acceptedelements:
..
if name == "window":
print attrs.iteritems()
for (tag,val) in attrs.iteritems():
if tag in window_attrs_key_order:
for tag in window_attrs_key_order:
if tag == u"name":
print "%s%s = Tk()" 
%(whitespace, val)
print "***^^^%s^^^***" 
%val
whatwindow = val
if tag == u"title":
print 
"%s%s.title(\"%s\")" % (whitespace, whatwindow, val)
if tag == u"icon":
if val == "NONE":
print "#>NO 
ICON"
else:
print 
"%s%s.iconbitmap(\"%s\")" %(whitespace, whatwindow, val)
else:
print "#-Error, unrecognized 
attribute in window element...-"
..
"""""""""""""""""""""""""""""""""""""

here's a likely example of what expat would spit out the attributes as-

"""""""""""""""""""""""""""""""""""""
attrs={u'title': u'example window title', u'name': u'SELF', u'icon':
u'e.ico'}
"""""""""""""""""""""""""""""""""""""

and the program output is this-

"""""""""""""""""""""""""""""""""""""
..

Example Window Title = Tk()
***^^^Example Window Title^^^***
Example Window Title.title("Example Window Title")
Example Window Title.iconbitmap("Example Window Title")
SELF = Tk()
***^^^SELF^^^***
SELF.title("SELF")
SELF.iconbitmap("SELF")
e.ico = Tk()
***^^^e.ico^^^***
e.ico.title("e.ico")
e.ico.iconbitmap("e.ico")
"""""""""""""""""""""""""""""""""""""

why would you think that the program would do this?
Trey



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] A replacement for a "for" loop

2007-08-28 Thread Trey Keown
Hello everybody.
I'm using a couple of "for" loops to help me in xml parsing using expat.
Unfortunately, though, I've found that using more than one of these in a
row, at least in my case, causes a redundancy error.
a snippet of my code (note that this is not the way I set the dictionaries)-

attrs={u'title': u'example window title', u'name': u'SELF', u'icon':
u'e.ico'}
keys = ['name','title','icon']
for (tag, val) in attrs.iteritems():
for key in keys:
print val

the first "for" tag causes the dictionary (attrs) to have its keys called
"tag" and its value called "val". The second "for" loop causes the
dictionary keys to be read in a certain order. How could I take away the
first "for" loop and replace it with something else to do the same general
function?
thanks for any help.
Trey

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] replacement for .mainloop() in Tk

2007-09-02 Thread Trey Keown
Okay, I'm making a program that turns xml code into python code. Here's
the an example of input-










And here would be the corresponding output (well, what I've got so far...)


from Tkinter import *
import tkFileDialog
##
self = Tk()
self.title("Example Window Title")
self.iconbitmap("e.ico")
##
##
##
##


Now, as you probably see, there isn't a "self.mainloop()" function in the
output. My question is-
*Is there any other thing I could use instead of ".mainloop()" to make a
window come up? Because I noticed that only one window can be up at a time
that has a ".mainloop()" attribute.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Need some help with wxPython...

2007-09-03 Thread Trey Keown
Hey all,
I'm starting to drift away from Tkinter and enter the realm of wxPython.
I've recently written a simple text editor in Tkinter, and I would like to
know if anyone knows of a good example of a simple wxPython text editor
(with the lines properly indented!!!), because all the examples I can find
are improperly indented, or just don't work. Or perhaps a tutorial that
covers all I need to know for making a text editor would work.
Thanks for any help,
Trey K. aka thetechgeek

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Problems with wx in Vista...

2007-09-04 Thread Trey Keown
Although I should have expected at least a few problems, I have a question
about a glitch in vista using a wx-implemented script.
Here's the example script-
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#!/usr/bin/python

# togglebuttons.py

import wx

class ToggleButtons(wx.Dialog):
def __init__(self, parent, id, title):
wx.Dialog.__init__(self, parent, id, title, size=(300, 200))

self.colour = wx.Colour(0, 0, 0)

wx.ToggleButton(self, 1, 'red', (20, 25))
wx.ToggleButton(self, 2, 'green', (20, 60))
wx.ToggleButton(self, 3, 'blue', (20, 100))

self.panel  = wx.Panel(self, -1, (150, 20), (110, 110),
style=wx.SUNKEN_BORDER)
self.panel.SetBackgroundColour(self.colour)

self.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleRed, id=1)
self.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleGreen, id=2)
self.Bind(wx.EVT_TOGGLEBUTTON, self.ToggleBlue, id=3)

self.Centre()
self.ShowModal()
self.Destroy()

def ToggleRed(self, event):
green = self.colour.Green()
blue = self.colour.Blue()
if  self.colour.Red():
self.colour.Set(0, green, blue)
else:
self.colour.Set(255, green, blue)
self.panel.SetBackgroundColour(self.colour)

def ToggleGreen(self, event):
red = self.colour.Red()
blue = self.colour.Blue()
if  self.colour.Green():
self.colour.Set(red, 0, blue)
else:
self.colour.Set(red, 255, blue)
self.panel.SetBackgroundColour(self.colour)

def ToggleBlue(self, event):
red = self.colour.Red()
green = self.colour.Green()
if  self.colour.Blue():
self.colour.Set(red, green, 0)
else:
self.colour.Set(red, green, 255)
self.panel.SetBackgroundColour(self.colour)


app = wx.App(0)
ToggleButtons(None, -1, 'togglebuttons.py')
app.MainLoop()
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
This makes a window pop up with 3 buttons that changes the color of a box.
Now, my question is, is this a vista-specific problem, am I just doing
something wrong, or is the example messed up.
Note- the name I saved the program as is testwx.py
Thanks for any help

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] WxPython Splashscreen?

2007-09-07 Thread Trey Keown
Hey all,
Does anyone know how to make a wxPython splashscreen? It would be great if
you could show a (working) example, as I have googled this topic, yet have
not found any working examples.
Thanks.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Undo/Redo in wxpython?

2007-09-07 Thread Trey Keown
What is the proper way to undo/redo changes in a text box? I read
somewhere that the default undo depth is 1. How could I change this to,
say, about 35?
Here's a snippet of my code-


#!/usr/bin/python
import wx
import os
...
...
...
class MainWin(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(850, 450))
...
...
...
#Program body section start
self.code = wx.TextCtrl(self, ID_TEXTBOX, size=(200, 130),
style=wx.TE_MULTILINE)
...
...
...
app = MyApp(redirect=True, filename = "_error.log")
app.MainLoop()



Now, how would it be possible for me to do undo/redo for the "self.code"
TextCtrl widget?

Help is greatly appreciated.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Disable keyboard/mouse input on windows?

2007-09-29 Thread Trey Keown
Hey everybody,
I was wondering, how could I disable all keyboard/mouse input for the
whole windows system while I have a video playing? So the user can't
press, for example, the super key [one with windows logo on it], and have
the windows menu pop up?
Could this be accomplished somehow through system hooks?

Thanks

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Getting single values of a tuple & storing them

2007-10-31 Thread Trey Keown
Hey all,
I was wondering, how could I get each value inside of a tuple, say it's
(2,4) .
The only value I really need is the second one (the tuple will always have
only two values.

Thanks for any help.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Calling a function within a function within a class...

2007-11-09 Thread Trey Keown
Hey all...
I'm creating a module for my program, and I need to call a function.
Here's how it's set up:
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
class DoStuff:
def Thing1(self):
def ThingToCall(self):
print "It worked!"
def Thing2(self):
#Call the function "ThingToCall" here.
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Thanks for any help. I haven't used classes that much before...

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python on T-Mobile Wing???

2007-11-20 Thread Trey Keown
Hey all,
I just got a brand new T-Mobile Wing, and, as you might guess, I want to
install python on it. Well, I tried both the pythonce main build (with the
.exe), and the build for the smartphone (also used .exe), but once I
downloaded them, when I tried to run them, a dialog comes up saying that
this is not a valid pocket pc app. Any ideas?

Note- the wing uses windows mobile 6. The specs can be found at-
http://www.t-mobile.com/shop/phones/Detail.aspx?device=acc8102d-4506-4eaa-bc2f-9c7b8ec1b1e0

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Best way of learning

2007-12-06 Thread Trey Keown
The way I learned python was through this wikibook:
http://en.wikibooks.org/wiki/Python_Programming

I found it very easy to understand and very helpful.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Need help with encoder & decryption keys

2008-02-29 Thread Trey Keown
Hey all,
  Been away for a while. So, I'm in the process of making a program for
encrypting and decrypting strings of text. And I was wondering how it
would be possible to perhaps keep keys in a .pyc file, and keep them
from being isolated, and messages being intercepted. So... is it
possible to decompile things within a .pyc file?
  This isn't for any serius project, just me attempting to make something
to prove that I can do it.

Thanks for any help.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] cross-compile python?

2008-03-23 Thread Trey Keown
Hey all,
  I've started trying to make homebrew programs for my wii the past couple
of days, and have found that programming it in c is quite hard. I was
wondering how I would go about compiling python for something like this.
The wii has a ppc processor, and runs homebrew in the native .elf format.

Thanks

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Python-windows command prompt interaction?

2008-06-10 Thread Trey Keown
Hey all,
  I'm creating a program that will copy a user's internet history from
Internet Explorer, and I'm having a bit of trouble.

I need to get python to either initiate a command via the command prompt,
or open a file with its default program (in this case, a .bat file with
cmd.exe).

I've been googling a bit, but I can't seem to find any answers.

Thanks for any help.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor