Stefano Mtangoo 455 Senior Poster

Missing Modules in Python 3.0 will defame it. If developers will develop the modules for Python 3, it will boost it with already said modernism and others stuffs like sneekula thing. Who will go for 3k and miss those valuable modules like wxpython, and many other non standard modules??

Stefano Mtangoo 455 Senior Poster

Hello Dev,
I want to change font colour in wx.RichTextCrtl, but I find the way it is used in wxDemo is complicated with no code to explain. Is there simple way to do it? If there is no other way, can someone explain the way it is done in demo TALKally (with comments)?
Thanks alot!
Steve

Stefano Mtangoo 455 Senior Poster

Thanks HoustonIT,
I'm Going to try it out
Great!

Stefano Mtangoo 455 Senior Poster

I have not used python 3k because I'm still learning under 2.5
Anyway I will be excite for those already are playing with it to tell me what is new and what is better about 3k, which excite them Like what Gribouillis said

Stefano Mtangoo 455 Senior Poster

What error do you get friend? Can you post every angle of the problem? Can you access mysql via commandline

Stefano Mtangoo 455 Senior Poster

I have Ubuntu/Vista Multiboot. While in Ubuntu I can access all my NTFS vista partition but not vice versa. Is there a legal hacking to get vista read the ubuntu file system?

Stefano Mtangoo 455 Senior Poster

open python shell and type in:
Python 2.5.2 (r252:60911, Feb 21 2008, 13:11:45) [MSC v.1310 32 bit (Intel)]
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb

if nothing happens and interpreter gives >>> then behold it is up and running othewise you will get traceback:
Traceback (most recent call last):
File "<string>", line 1, in <string>
ImportError: No module named MySQLdb

Stefano Mtangoo 455 Senior Poster

Finally solved. Codes are roughly arranged and are not in order because I was learning the bass.dll & ctypes basics

#Play audio with bass.dll and python ctypes
#Code By Steve
#import ctypes module
import ctypes as ct
#import OS
import os
#get BOOL C++ value from ctypes
from ctypes.wintypes import BOOL
from ctypes.wintypes import HANDLE
#Loading the DLL see: http://www.daniweb.com/forums/thread160430.html
bass_dll = ct.windll.bass
#initialize the DLL 
# sample I got somehwere: BASS_Init(-1,44100,0,win,NULL) win The application's main window... 0 = the current foreground window (use this for console applications). 
#function to intialize the DLL

def onInit_Lib():
    #define arg types
    bass_dll.BASS_Init.argtypes = [ct.c_int, ct.c_uint, ct.c_uint, ct.c_uint, ct.c_uint]
    #define result types
    bass_dll.BASS_Init.restype = ct.c_int
    #call function with args
    c= bass_dll.BASS_Init(-1, 44100, 0,0, 0)
    print c

def onStream():
    #arg definitions
    #HSTREAM BASS_StreamCreateFile(BOOL mem, void *file, QWORD offset, QWORD length, DWORD flags);
    bass_dll.BASS_StreamCreateFile.argtypes = [BOOL, ct.c_char_p, ct.c_int64 , ct.c_int64, ct.c_uint]
    #defining restypes
    bass_dll.BASS_StreamCreateFile.restype = ct.c_uint
    path = os.getcwd()
    full = os.path.join(path, "test.mp3")
    print full
    stream = bass_dll.BASS_StreamCreateFile(False, full, 0, 0, 0)
    print stream
    return stream
    
def onPlay(stream):
    #define args
    #BASS_ChannelPlay(stream, FALSE); // play the stream
    bass_dll.BASS_ChannelPlay.argtypes = [ct.c_uint, BOOL]
    #call function
    bass_dll.BASS_ChannelPlay(stream, False)
    
onInit_Lib()
print bass_dll.BASS_ErrorGetCode()
stream = onStream()
print bass_dll.BASS_ErrorGetCode()
onPlay(stream)
print bass_dll.BASS_ErrorGetCode()
while True:
    print "Playing"
Stefano Mtangoo 455 Senior Poster

I am from India

Mhh India Leads in this!

Stefano Mtangoo 455 Senior Poster

Try something like this

f= open("test.txt", "r")
s = f.readlines()
for name in s: 
    name = name.lower()    
    if name == "steve":
        print name
        print "found name %s" %(name, )
    else:
        print name
        print "No such Name!"
        
f.close()
Stefano Mtangoo 455 Senior Poster

my friend, use code blocks when posting codes so as to preserve the most valuable indentation

Stefano Mtangoo 455 Senior Poster

My friend, I propose you start with this:
http://www.greenteapress.com/thinkpython/thinkpython.pdf

Stefano Mtangoo 455 Senior Poster

I enjoy multibooting Vista Home with Ubuntu *nix
Yu might think about it, no pain!

Stefano Mtangoo 455 Senior Poster

here is modified code that fix the error but no sound

#import ctypes module
import ctypes as ct
#import OS
import os
#get BOOL C++ value from ctypes
from ctypes.wintypes import BOOL
from ctypes.wintypes import HANDLE
#Loading the DLL see: http://www.daniweb.com/forums/thread160430.html
bass_dll = ct.windll.bass
#initialize the DLL 
# sample I got somehwere: BASS_Init(-1,44100,0,win,NULL) win The application's main window... 0 = the current foreground window (use this for console applications). 
#function to intialize the DLL

def onInit_Lib():
    #define arg types
    bass_dll.BASS_Init.argtypes = [ct.c_int, ct.c_int, ct.c_int, ct.c_int, ct.c_int]
    #define result types
    bass_dll.BASS_Init.restype = ct.c_int
    #call function with args
    c= bass_dll.BASS_Init(-1, 44100, 0,0, 0)
    print c

def onStream():
    #arg definitions
    #HSTREAM BASS_StreamCreateFile(BOOL mem, void *file, QWORD offset, QWORD length, DWORD flags);
    bass_dll.BASS_StreamCreateFile.argtypes = [BOOL, ct.c_char_p, ct.c_longlong , ct.c_longlong, ct.c_int]
    #defining restypes
    bass_dll.BASS_StreamCreateFile.restype = HANDLE
    path = os.getcwd()
    full = os.path.join(path, "test.mp3")
    print full
    stream = bass_dll.BASS_StreamCreateFile(False, full, 0, 0, 0)
    print stream
    return stream
    
def onPlay(stream):
    #define args
    #BASS_ChannelPlay(stream, FALSE); // play the stream
    bass_dll.BASS_ChannelPlay.argtypes = [HANDLE, BOOL]
    #call function
    bass_dll.BASS_ChannelPlay(stream, False)
    
onInit_Lib()
stream = onStream()
onPlay(stream)
Stefano Mtangoo 455 Senior Poster

I use ctypes to play AUDIO using bass.dll found here:
http://www.un4seen.com/
I have gone so far and tried as they advised me at their forum entry here:
http://www.un4seen.com/forum/?topic=9257.0
But I still get errors. Can anyone take code and analyze to point out source of error?
Here is the code, pse ignore any useless comment, I was using the editor as scratch pad too :D

#import ctypes module
import ctypes as ct
#import OS
import os
#get BOOL C++ value from ctypes
from ctypes.wintypes import BOOL
from ctypes.wintypes import HANDLE
#Loading the DLL see: http://www.daniweb.com/forums/thread160430.html
bass_dll = ct.windll.bass
#initialize the DLL 
# sample I got somehwere: BASS_Init(-1,44100,0,win,NULL) win The application's main window... 0 = the current foreground window (use this for console applications). 
#function to intialize the DLL

def onInit_Lib():
    #define arg types
    bass_dll.BASS_Init.argtypes = [ct.c_int, ct.c_int, ct.c_int, ct.c_int, ct.c_int]
    #define result types
    bass_dll.BASS_Init.restype = ct.c_int
    #call function with args
    c= bass_dll.BASS_Init(-1, 44100, 0,0, 0)
    print c

def onStream():
    #arg definitions
    #HSTREAM BASS_StreamCreateFile(BOOL mem, void *file, QWORD offset, QWORD length, DWORD flags);
    bass_dll.BASS_StreamCreateFile.argtypes = [BOOL, ct.c_char_p, ct.c_int , ct.c_int, ct.c_int]
    #defining restypes
    bass_dll.BASS_StreamCreateFile.restype = HANDLE
    path = os.getcwd()
    full = os.path.join(path, "test.mp3")
    print full
    stream = bass_dll.BASS_StreamCreateFile(False, full, 0, 0, 0)
    print stream
    return stream
    
def onPlay(stream):
    #define args
    #BASS_ChannelPlay(stream, FALSE); // play the stream
    bass_dll.BASS_ChannelPlay.argtypes = [HANDLE, BOOL]
    #call function
    bass_dll.BASS_ChannelPlay(stream, False)
    
onInit_Lib()
stream = onStream()
onPlay(stream)

With thanks,

Stefano Mtangoo 455 Senior Poster

wxpython is exactly what you need. It looks native in the platform take a look at wxpython.org for docs and API plus zetcode.com for tutorial

Stefano Mtangoo 455 Senior Poster
Stefano Mtangoo 455 Senior Poster

Or you can use Revo Uninstaller. It hav Got special feature for startup. Also Anvir Task manager should be able to do it

Stefano Mtangoo 455 Senior Poster
Stefano Mtangoo 455 Senior Poster
Stefano Mtangoo 455 Senior Poster

Ok, does any other wxpy program run successful? I ask because may be version is wrong (I always prefer unicode). Another problem is installing wxpy with less admin rights. Try to re-install wxpy in Admin level. Try same code but compile with 2.5

Stefano Mtangoo 455 Senior Poster

so, now; what is the cause of error:
TypeError: list objects are unhashable

Stefano Mtangoo 455 Senior Poster

so you say that when created, prototype calls the required arguments? I mean, I haven't passed any arg as you can see. I have just defined it. Should I pass all the arguments before call CFUNCTYPE??

Stefano Mtangoo 455 Senior Poster

don't use a list when assigning restype: res = bass_dll.BASS_SampleLoad.restype = ct.c_int But I suspect you're in for a spot of trouble.

a FILE * is NOT a char * fname;

What do you mean?

Stefano Mtangoo 455 Senior Poster

tried but this error poped:
TypeError: list objects are unhashable

What does it try to tell me?

Stefano Mtangoo 455 Senior Poster

I'm learning ctypes right now and have made simple function and here is the code

#import ctypes module
import ctypes as ct
#get BOOL C++ value from ctypes
from ctypes.wintypes import BOOL
#Loading the DLL see: http://www.daniweb.com/forums/thread160430.html
bass_dll = ct.cdll.bass
#here is function description on the function
""" Loads a WAV, AIFF, MP3, MP2, MP1, OGG or plugin supported sample.
     HSAMPLE BASS_SampleLoad(
     BOOL mem,
         void *file,
         QWORD offset,
         DWORD length,
         DWORD max,
         DWORD flags
     );  
     
     CFUNCTYPE(restype, *argtypes)
     """
#The rguments list
res = bass_dll.BASS_SampleLoad.restype = [ct.c_int]        
args = bass_dll.BASS_SampleLoad.argtypes = [BOOL, ct.c_char_p, ct.c_int, ct.c_int, ct.c_int, ct.c_char_p]
prototype = ct.CFUNCTYPE(res, args)
print prototype

when I run I get error:
TypeError: restype must be a type, a callable, or None
I dont know what is wrong, so need help!

Stefano Mtangoo 455 Senior Poster

if wxpython, then Show(True) method is to show widgets and by default is True so you don't need to add it. figure()?? Not sure what it is! Which modules are you using?

Stefano Mtangoo 455 Senior Poster

I got it!

from ctypes.wintypes import BOOL
#then you can use BOOL anywhere in your code
Stefano Mtangoo 455 Senior Poster

What is ctypes data for BOOL?
I mean in C++ to ctypes we have:
int--> c_int
float--> c_float
what about BOOL?

Stefano Mtangoo 455 Senior Poster

have you checked those garbages? Many times these ready made PC/Laps comes with garbage of softs and you need to uninstall them manually. If you want to make it easy: Use revo uninstaller for free or Uninstaller! 2006 for $

Stefano Mtangoo 455 Senior Poster

Check for garbage programs that might be installed and startup withsystem

Stefano Mtangoo 455 Senior Poster

I suggest pure HTML for such application. Python can do it, may be check here:
http://wiki.python.org/moin/WebProgramming

Stefano Mtangoo 455 Senior Poster

break and continue might be what you need
if x==0 break --> this stops the Loop
y==1 continue --> this makes loop running

this might help:
http://www.network-theory.co.uk/docs/pytut/breakandcontinueStatements.html

Stefano Mtangoo 455 Senior Poster

O2 - BHO: (no name) - {A3A641C8-7F6F-470E-8328-C28717500A65} - C:\WINDOWS\system32\geBtRigg.dll

O4 - HKLM\..\Run: [nwiz] nwiz.exe /install

I susspect these programs were the stubborn ones
They are unIdentified, yet install themselves at startup :-O

Stefano Mtangoo 455 Senior Poster

okay so i have the same acer 6920 and i have the same problems basically but i cannot open an internet window? any ideas?

How did it start to misbehave? Can you provide details

Stefano Mtangoo 455 Senior Poster

? what?

I sometimes wish to shut it up (I have done some time ago) due to those annoying behaviours. What do you reckon?

Stefano Mtangoo 455 Senior Poster

Anyone who knows QWORD, DWORD and BOOL ctypes Equivalents. I find c_int, c_float etc but not the Equivalent above!

Stefano Mtangoo 455 Senior Poster

I have failed to re-write the function in python because I don't know how to convert QWORD offset, and BOOLto ctypes. Someone help me please!

Stefano Mtangoo 455 Senior Poster

I have problems with the MS updates. They sometimes cause great problems. I have recently rolled back using sys restore and Lost my Anvil Taskmanager I got from giveaway! It messed up with my HDSPA huawei E220 and my Wing IDE. It have done before and my Laptop became Unstable

I'm not sure If it is right to install it or disable completly the updates!

Stefano Mtangoo 455 Senior Poster

No problem! Misunderstanding that ends with understanding is not.....bad haaah

Stefano Mtangoo 455 Senior Poster

Not only Run, but also debug, which is missing in IDLE. There is also browser for classes and methods if you have long code. I used for sometime 101 version before I bought the personal Edition. After I master well the Language I will go for Pro version. From my point of view, 101 verion is best than many free IDE available and too superior to compare with IDLE

Dont take me at my word, do it yourself
www.wingware.com

Stefano Mtangoo 455 Senior Poster

I have started the mission!
I have already the CDs and it allows Once,
so once created, not worthy to fill my HDD
Thanks

Stefano Mtangoo 455 Senior Poster

I meant give up in the forum and not Quit the programming deal
Anyway I don't know what he mean exactly unless he explains lol:

Stefano Mtangoo 455 Senior Poster

why not use Wing IDE? It have been my IDE for python. I have tried many; SPE, Pyscripter BOA, etc and found Wing IDE both easy and Powerful. If you don't Like to pay $ there is 101 version with stripped feature but have Editor, Run/Debug, Methoda/Class browser!

I suggest it, but again it is a matter of preference!

Stefano Mtangoo 455 Senior Poster

wx.ListCtrl is the best choice in my Opinion,
as Shadwick i suggest using style flag to get thing done

Stefano Mtangoo 455 Senior Poster

Why Painful? Yes thing aren't easy but possible!
You have to state clearly everything where have you failed or what you want to do but have no Idea where to start. From there it is simple to help you! Don't give up so easily!

Stefano Mtangoo 455 Senior Poster

sample code??
Are you using TextCtrl or what?

Stefano Mtangoo 455 Senior Poster

Proportionality is missing. Also you can add wx.EXPAND for widgets to fit your sizer better

import wx

class MainWindow(wx.Frame):
	def __init__(self, parent, id, title):
		wx.Frame.__init__(self, parent, wx.ID_ANY, title, size=(400,200), style = wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE)
		
		#-- I think you need a panel if you're going to have more than one control in your frame.
		panel = wx.Panel(self, -1)
		
		#--- Create the Username label and text box and add them to the panel
		#--- I think the TextCtrl needs to have self. at the front for the value to be used by
		#--- the Process() function below.  There must be a better way.
		
		self.txt_Username = wx.TextCtrl(panel, 1, size=(125, -1))
		lbl_Username = wx.StaticText(panel, -1, "Username:")
		
		#-- Create the Password label and text box and add them to the panel
		self.txt_Password = wx.TextCtrl(panel, 1, size=(125, -1), style=wx.TE_PASSWORD)
		lbl_Password = wx.StaticText(panel, -1, "Password:")
		
		#-- Create the processing button, add it to the panel and wire it up to a function in the class
		btn_Process = wx.Button(panel, -1, "&Process")
		self.Bind(wx.EVT_BUTTON, self.Process, btn_Process)
		
		#-- Create the close button, add it to the panel and wire it up to a function in the class
		btn_Close = wx.Button(panel, -1, "&Close")
		self.Bind(wx.EVT_BUTTON, self.onExit, btn_Close)
		
		#-- Now we have to create a grid to layout our controls
		#format--> sizer.Add(widget_to_add, proportion,spacing btn widgets )
		#Also using Flexigrid sizer use AddMany for simplicity
		sizer = wx.FlexGridSizer(rows=3, cols=2, hgap=5, vgap=10)
		sizer.Add(lbl_Username,0, wx.LEFT|wx.TOP| wx.RIGHT, 5)
		sizer.Add(self.txt_Username,0, wx.TOP| wx.RIGHT, 5)
		sizer.Add(lbl_Password,0, wx.LEFT|wx.TOP| wx.RIGHT, 5)
		sizer.Add(self.txt_Password,0, wx.TOP| wx.RIGHT, 5)
		sizer.Add(btn_Process,0, wx.LEFT|wx.TOP| wx.RIGHT, 5)
		sizer.Add(btn_Close,0, wx.TOP| wx.RIGHT, …
Stefano Mtangoo 455 Senior Poster

I have problems too in learning ctypes. They are powerful way to port C++ power into python, but seems to lack begginers tutorial which is very sad. For man like me with little knowledge in c++, it is big burded.

Anyway, so far what I know is that, in order to rightly call any function in Python using ctypes are
1. define result type using restype
2. define arguments types using argtype
3. call the function with right arguments

But so far I haven't been successful to do anything useful with ctypes. I believe sometimes I will do!

Stefano Mtangoo 455 Senior Poster

I give up...Is this problem fixed now???

which problem?