Python and Com Question

John Underwood johnwadeunderwood at yahoo.com
Wed Feb 26 11:55:06 EST 2003


Here's the Com Server code.. after this code is a sample code of the
client piece.

I'm trying to get some direction. This commented out line in the com
server gives an error.

#self.bmpPic = wxStaticBitmap(self, -1, bmp, wxPoint(10, 10),
wxSize(bmp.GetWidth(), bmp.GetHeight()))

. does not work because the argument 1, self is not passed... I'm
trying to figure out how to pass that information from the client, and
was hoping for some direction.. below the com server code i have an
example of my client code..  Basically want i'm trying to do is have a
little com piece which receives a bitmap file name, sets everything up
and returns it.. just not sure how to handle it yet.. thanks for any
help.


--------------Com Server Code-----------------------------------
from wxPython.wx import *
        
class PythonUtilities:
    _public_methods_ = [ 'showText' ]
    _reg_progid_ = "app.ShowBitmap"
    _reg_clsid_ = "{AF4E3237-72DE-49CA-A29D-CEA4BCCA7F77}"
    
    def showBitmap(self, val, item=None):
        
        bmp = wxImage('somepicture.bmp',
wxBITMAP_TYPE_BMP).ConvertToBitmap()
      
        print self.aTest
        #self.bmpPic = wxStaticBitmap(self, -1, bmp, wxPoint(10, 10),
wxSize(bmp.GetWidth(), bmp.GetHeight()))
        return self.bmpPic # ?? unsure how do return this correctly

if __name__=='__main__':
    print "Registering COM server..."
    import win32com.server.register
    win32com.server.register.UseCommandLine(PythonUtilities)

--------------Client Code-----------------------------------
from wxPython.wx import *
import win32com.client
rsBMP = win32com.client.Dispatch("app.ShowBitmap") # open the com
server


class MyFrame(wxFrame):
    def __init__(self, parent, id, log):
        wxFrame.__init__(self, parent, id, 'DnD', size=(410, 450))
        self.log = log

        panel = wxPanel(self, -1)
        
        sizer = wxBoxSizer(wxVERTICAL)
        # following line calls the com def showBitmap
        self.rsShowBitmap = rsBMP.showBitmap("redstone.bmp")
        print self.rsShowBitmap
        #sizer.Add(self.rsShowBitmap,wxALIGN_CENTER) # ? unsure about
this
        
        panel.SetAutoLayout(true)
        panel.SetSizer(sizer)        
        
    def TimeToQuit(self, event):
        self.Close(true)

class MyApp(wxApp):
    def OnInit(self):
        
        frame = MyFrame(NULL, -1, Log)
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

app = MyApp(0)
app.MainLoop()



John Underwood
Johnwadeunderwood at yahoo.com




More information about the Python-list mailing list