bumsfeld 413 Nearly a Posting Virtuoso

I am making progress learning Python. and English. I understands tuples, lists and dictionaries, but sets don't make muchly sense. Why use a set? What is a set good for?

bumsfeld 413 Nearly a Posting Virtuoso

Went to the Boo code snipet here on this site. Downloaded BOO from recomended site and a nice editor/IDE called Boodle (hehe). The snipet works well and seems fun.

bumsfeld 413 Nearly a Posting Virtuoso

factorials get BIG really fast and exceed the limits of 32-bit unsigned integer variables by 13!.

If you want to play with them use a datatype that can handle huge numbers, or switch to an extended precision mathematics library like GMP.

Or use Ruby or Python that do not have these narrow limits.

bumsfeld 413 Nearly a Posting Virtuoso

A somewhat strange find in the Pyton Code Snippets here on this site. Is the BOO language very much like Python?

It seems nice that one can compile and interpret the same language. Will it be worth to translate Python code to BOO just to get a nice small exe file?

Does it have something like wxPython?

bumsfeld 413 Nearly a Posting Virtuoso

I did find the Python code snippet on PMIDI module here. It works fine and I have made some interesting sounds with it. Is there way to save this as sound file?

bumsfeld 413 Nearly a Posting Virtuoso

That looks good. Many countries in Europe have day/month/year format, but that doesn't make much sense for what I may want to do. I am thinking about a date and time stamp starting each data line where the line could be sorted. It could have to look something like year/month/day hour:minute:second to do this rightly.

The tuple_time almost has this sorting format.

bumsfeld 413 Nearly a Posting Virtuoso

I have played around with SDL that can do both sounds files and graphics things. It is used by gamers a lot and is free for DevC++. Much information availabel.

bumsfeld 413 Nearly a Posting Virtuoso

That would do it - but maybe a little shorter is even better.

bumsfeld 413 Nearly a Posting Virtuoso

I want to creat file with each line having date + time + data so I can append more data as need be and know when it was added. What date+time function would be best?

bumsfeld 413 Nearly a Posting Virtuoso

Is there a function in wxPython or anything that can creat a variable frequency sounds?

bumsfeld 413 Nearly a Posting Virtuoso

Wow Peter ClearBackground() did the trick and without it the colour would not chnage at all. Looks like you have to clear the old colour out first.

I could not find ClearBackground() at all in any information I have so far about wxPython! I do wonder where things like that are hidden at? Anyway thanks!

bumsfeld 413 Nearly a Posting Virtuoso

Nice code, I will have to remember that!

bumsfeld 413 Nearly a Posting Virtuoso

Peter thank you much,

I am just learning Python and need some handholding please! Can you give more detail?


Why do I use panel in bind?

What do I code in function "def OnEraseBackground(self, evt):"?

bumsfeld 413 Nearly a Posting Virtuoso

This how far I am with the program. It does flicker so and needs more work:

# Colour Matching Skill Tester    first version
# Colour the label1 with random RGB values
# Colour the label2 with RGB values from sliders
# Needs exposition of result closeness and possible file saving

import random
import wx

class MyPanel(wx.Panel):
    """ class MyPanel creates a panel with 2 labels, 3 sliders, inherits wx.Panel """
    def __init__(self, parent, id):
        wx.Panel.__init__(self, parent, id)
        self.SetBackgroundColour("white")
        str1 = ""
        
        self.Red1 = random.randrange(256)
        self.Green1 = random.randrange(256)
        self.Blue1 = random.randrange(256)
        # label1 with random RGB colour values
        self.label1 = wx.StaticText(self, -1, str1 , (10, 10), (120, 100))
        self.label1.SetBackgroundColour((self.Red1, self.Green1, self.Blue1))
        
        self.Red2 = 125
        self.Green2 = 125
        self.Blue2 = 125
        # label2 with RGB colour values from sliders
        self.label2 = wx.StaticText(self, -1, str1 , (10, 120), (120, 100))
        self.label2.SetBackgroundColour((self.Red2, self.Green2, self.Blue2))
        
        # init value = 125, min value = 0, max value = 255 for colours
        self.sliderR = wx.Slider(self, -1, self.Red2, 0, 255, (140, 10), (50, 200),
            wx.SL_VERTICAL | wx.SL_AUTOTICKS | wx.SL_LABELS)
        wx.StaticText(self, -1, "Red" , (160, 205))
        self.sliderG = wx.Slider(self, -1, self.Green2, 0, 255, (200, 10), (50, 200),
            wx.SL_VERTICAL | wx.SL_AUTOTICKS | wx.SL_LABELS)
        wx.StaticText(self, -1, "Green" , (220, 205))
        self.sliderB = wx.Slider(self, -1, self.Blue2, 0, 255, (260, 10), (50, 200),
            wx.SL_VERTICAL | wx.SL_AUTOTICKS | wx.SL_LABELS)
        wx.StaticText(self, -1, "Blue" , (280, 205))
        
        # result label
        self.label3 = wx.StaticText(self, -1, "", (160, 230))

        # all three sliders ...
        self.Bind(wx.EVT_SCROLL, self.slideColour)
       
        # button click
        self.button1 = wx.Button(self, -1, "Evaluate", (10, 230))
        self.button1.Bind(wx.EVT_BUTTON, …
bumsfeld 413 Nearly a Posting Virtuoso

I copied the snippet onto my IDE editor and it works well. Then I made three of vertically sliders and just chnaged the upper left corner x,y of each so now I have three sliders next to each other in the right side of frame or panel for RGB selection. Looks like good start of project.

What would you recommend to use for a colour area. I need two of them one for computer select colour and one for slider select colour.

bumsfeld 413 Nearly a Posting Virtuoso

I googled and found something in a old code at:
http://aspn.activestate.com/ASPN/Mail/Message/wxPython-users/1908355

Still not shure!

bumsfeld 413 Nearly a Posting Virtuoso

I have run the slider demo that come with wxPython docs. It is rather stupid, as it puts slider on a panel using many unexplained numbers, never tells how to get position of slider or what to do next if the slider is moved. I am much lost, does anyone have a actual usefull example?

bumsfeld 413 Nearly a Posting Virtuoso

Similar to the color project but with frequency of a tone. The computer plays a tone with random audible frequency. The user tries to match this frequency. In a GUI project can use a slider. Buttons allow replay of either tone. At end evaluate closeness.

bumsfeld 413 Nearly a Posting Virtuoso

Is file you want delete still on your editor?

bumsfeld 413 Nearly a Posting Virtuoso

Looking at the last three digit only, guess would be number2 is random.

Fuzzy Logic?

bumsfeld 413 Nearly a Posting Virtuoso

Since I can reverse dictionary, then anything that can be value can also be key?

bumsfeld 413 Nearly a Posting Virtuoso

This project takes wxPython or maybe Tkinter for GUI. Let the computer pick random color selecting random RGB value. The user has to match the color picking RGB (red, green, blue) values that colours a area next to the one of the computer color pick.

bumsfeld 413 Nearly a Posting Virtuoso

I remember in school they talked about DIB (device indepentant bitmaps) to be best for stretching/enlarging. Was C class for graph artists.

bumsfeld 413 Nearly a Posting Virtuoso

Now it all makes more sense, the two have each a very much definite purpose. In your tutorial on integrs you talk about pointers to memory, have tuples then just pointers to objects?

bumsfeld 413 Nearly a Posting Virtuoso

Thanks G-do for informing us over the interesting medical work you are doing! Orange sounds like Python based data mining module, things that should be explored. Slovenia is just like Austria, very nice with much history and great people.

bumsfeld 413 Nearly a Posting Virtuoso

Now I know which demo mawe was meaning. I downloaded the extra file and instaled it. There are nice examples now!

The project I am working with is a color match skill program. I have a frame, 2 panels, 3 sliders, label and buttons. One panel is colored with random (R,G,B) by the program, then I use sliders R,G, and B to try to match. When done I press button to evaluate and program tells me how close I was, some kind of rating will be done. Supposed to help eye patients.

bumsfeld 413 Nearly a Posting Virtuoso

You right! Documentation is for C++ and no examples. So I hope you and others will be posting good examples, right?

Are any good tutorials out?

bumsfeld 413 Nearly a Posting Virtuoso

A good idea for a developing country which has lots of powerlines already but not much highspeed cables. Places like India, China, Russia, South Africa and such.

Imagine all these poor people exposed to spyware and idiot popups!

bumsfeld 413 Nearly a Posting Virtuoso

Why is there a tuple and list in Python. They seemed to perform similar things.

bumsfeld 413 Nearly a Posting Virtuoso

Thanks you much wally,

I downloaded wxPython2.6-win32-unicode-2.6.1.0-py24.exe from
http://www.wxpython.org/download.php#binaries and installed it. The code works greatly.

I was looking through the files it instaled, but could not find a file wx.py. I thought when I import one module it is such a file. How does it work here?

bumsfeld 413 Nearly a Posting Virtuoso

Okay I have copy and pasted the code from the tutorial on the jpg image http://daniweb.com/techtalkforums/thread33791.html onto my IDE editor. This time no problem with indents!

Now I need to know how to instal required wxPython. I have Windows XP, also Python 2.4. Where do I best get free wxPython and which version?

bumsfeld 413 Nearly a Posting Virtuoso

Nice project c_shaft05 you do much thinking here!

bumsfeld 413 Nearly a Posting Virtuoso

Can you figure results?

a, b, c, d, e = range(100, 1000, 200)

print a, b, c, d, e
bumsfeld 413 Nearly a Posting Virtuoso

I know VegaSeat has put some wxPython code examples in the snippet part of this forums. Like:
http://daniweb.com/code/snippet227.html

bumsfeld 413 Nearly a Posting Virtuoso

I copy/paste the code onto my IDE, also downloaded the test jpg and unzipped onto work directory. Code gives me indentation error!

bumsfeld 413 Nearly a Posting Virtuoso

If you know Windows/DOS batch language you can create and save batch file from within Python program, than run it with os.system("mybatfile.bat")

bumsfeld 413 Nearly a Posting Virtuoso

I think an empty dictionary can be created with:

emptyD1 = {}
emptyD2 = dict()
print emptD1, emptyD2

Then is the normal perhaps called direct way:

dict1 = {'a':1, 'b':2, 'c':3, 'd':4}  # etc.
print dic1

Does this way have a name?

dic2 = {}
dic2['Linux'] = 'software'
dic2['floppy'] = 'accessory'
dic2['floppy drive'] = 'hardware'
dic2['CPU'] = 'hardware'     # etc.
print dic2
bumsfeld 413 Nearly a Posting Virtuoso

Now my question is what kind of things can be used as key?

bumsfeld 413 Nearly a Posting Virtuoso

I think I get it! It is sinking in slowly into my yellow brains! So key is something more meaningfull then a just number.

bumsfeld 413 Nearly a Posting Virtuoso

Thank you much again mawe,

I slowly getting to know what dictionaries are about. Looks like they are very usefull. Sorry I am asking so many naive questions.

bumsfeld 413 Nearly a Posting Virtuoso

How can you handle the wrong symbol? Like someone uses '**' and not '*'

bumsfeld 413 Nearly a Posting Virtuoso

So there is some order, but we don't know what Python uses to create this order?

That is muchly confusing!

bumsfeld 413 Nearly a Posting Virtuoso

Thanks much mawe!

All these >>> and ....... mess me up, so I always take time to remove them so I can use my IDE editior to run the code.

It looks like its workoing so.

How would invert a dictionary like:

{'A':, 'B':}

bumsfeld 413 Nearly a Posting Virtuoso

Windows supplies most of the fonts as "true type fonts" ( .TTF ). Don't know what Linux uses?

bumsfeld 413 Nearly a Posting Virtuoso

Is there a good way to invert dictionary so key:value gets to be value:key?

bumsfeld 413 Nearly a Posting Virtuoso

There seems to be many ways to create a dictionary, which one do you prefer?

abdi1 commented: i need the best and easy one from those +0
kindo commented: Good! This Question made me to Join this forum.Good +0
bumsfeld 413 Nearly a Posting Virtuoso

Thank you much!
I like G-Do's interesting way to create the dictionaries.
I also prefer mawe's second way to merge the dictionaries so nothing gets lost on collision.

bumsfeld 413 Nearly a Posting Virtuoso

Here are a bunch of impel dictionaries that surprise me:

dic1 = {'a':1, 'b':2, 'c':3, 'd':4}

print dic1  # {'a': 1, 'c': 3, 'b': 2, 'd': 4}

dic2 = {1:'a', 2:"b", 3:'c', 4:'d'}

print dic2  # {1: 'a', 2: 'b', 3: 'c', 4: 'd'}

dic3 = {11:'a', 22:"b", 3:'c', 4:'d'}

print dic3  # {3: 'c', 11: 'a', 4: 'd', 22: 'b'}

dic2 seems to behave as expected but dic1 and dic3 are surprise me.

bumsfeld 413 Nearly a Posting Virtuoso

Thanks G-Do! I think you gave me a good hint where i went wrong. Here is my error prone code:

# a dictionary of functions by bumsfeld
# get errors = TypeError: 'int' object is not callable

def add(a, b):
    return a + b

def sub(a, b):
    return a - b

def mul(a, b):
    return a * b

def div(a, b):
    return a / b

a = b = 1

mathD = {
'+' : add(a, b),
'-' : sub(a, b),
'*' : mul(a, b),
'/' : div(a, b)
}

f = mathD['+']
print f(99, 13)
bumsfeld 413 Nearly a Posting Virtuoso

I was trying to come up with a dictionary of functions, but get it not to work.