Quantcast

a question about word addin , IRibbonExtensibility, GetCustomUI, getImage, IPicture

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

a question about word addin , IRibbonExtensibility, GetCustomUI, getImage, IPicture

shuwj-2
hi,

I'm writing an addin for ms word 2010.  It will show a tab named JJ in
which there are  two buttons. one labels doo, the other labels doo2.
doo2 should be displayed with customization image(edit.png) but don't
show as expected.

debugging  with pythonwin trace collector debugging tool.  there's a
exception as following:
--------------------------------------------
in _GetIDsOfNames_ with '(u'GetImage',)' and '2048'

in _Invoke_ with 1001 2048 1 (<PyIDispatch at 0x07052048 with obj at 0x03D51050>,)
0
0
0
c_void_p(111734808) ddd
pythoncom error: Python error invoking COM method.

TypeError: Objects of type 'c_void_p' can not be converted to a COM VARIANT (but obtaining the buffer() of this object could)
---------------------------------------------

can anybody give me some helps?

Thanks.
--
shuwj <[hidden email]>

_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32

edit.png (968 bytes) Download Attachment
wordaddin-example.py (6K) Download Attachment
gdiplus.py (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: a question about word addin , IRibbonExtensibility, GetCustomUI, getImage, IPicture

Mark Hammond-4
On 24/03/2012 6:24 PM, shuwj wrote:

> hi,
>
> I'm writing an addin for ms word 2010.  It will show a tab named JJ in
> which there are  two buttons. one labels doo, the other labels doo2.
> doo2 should be displayed with customization image(edit.png) but don't
> show as expected.
>
> debugging  with pythonwin trace collector debugging tool.  there's a
> exception as following:
> --------------------------------------------
> in _GetIDsOfNames_ with '(u'GetImage',)' and '2048'
>
> in _Invoke_ with 1001 2048 1 (<PyIDispatch at 0x07052048 with obj at 0x03D51050>,)
> 0
> 0
> 0
> c_void_p(111734808) ddd
> pythoncom error: Python error invoking COM method.
>
> TypeError: Objects of type 'c_void_p' can not be converted to a COM VARIANT (but obtaining the buffer() of this object could)
> ---------------------------------------------
>
> can anybody give me some helps?

I believe a c_void_p is a ctypes construct which aren't supported by
pywin32.  You need to convert it to a "normal" Python type.  I'm
guessing it is binary data, so in py2k, you should be able to simply use
buffer(some_string_object).  The error message seems to imply you may
even be able to use buffer(c_void_p_object), but I don't know how they
work well enough to suggest that will actually work.

Mark
_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: a question about word addin , IRibbonExtensibility, GetCustomUI, getImage, IPicture

shuwj-2
In reply to this post by shuwj-2

> I believe a c_void_p is a ctypes construct which aren't supported by
> pywin32.  You need to convert it to a "normal" Python type.  I'm
> guessing it is binary data, so in py2k, you should be able to simply use
> buffer(some_string_object).  The error message seems to imply you may
> even be able to use buffer(c_void_p_object), but I don't know how they
> work well enough to suggest that will actually work.
>
> Mark
>

Hi Mark,
Thanks for your reply. I use buffer() in GetImage method and there's no
exception now,  but they don't work as expected.


-----------------------------------------
class wordaddin:
    def GetImage(self,ctrl):
        from gdiplus import LoadImage
        i = LoadImage( 'c:/edit.png' )
        i = buffer(i)
        print i, 'ddd'
        return i
-----------------------------------------


gdiplus.py  is as following:
-----------------------------------------
#coding: gbk

from ctypes import *
from ctypes.wintypes import *
from comtypes import GUID

oleaut32 = windll.oleaut32
gdiplus = windll.gdiplus


class GdiplusStartupInput(Structure):
    _fields_ = [
        ('GdiplusVersion', c_uint32),
        ('DebugEventCallback', c_void_p),
        ('SuppressBackgroundThread', BOOL),
        ('SuppressExternalCodecs', BOOL)
    ]

class GdiplusStartupOutput(Structure):
    _fields = [
        ('NotificationHookProc', c_void_p),
        ('NotificationUnhookProc', c_void_p)
    ]


class PicDesc(Structure):
    _fields_ = [
        ('Size', UINT),
        ('Type', UINT),
        ('hPic', HBITMAP),
        ('hPal', HPALETTE)
    ]

PICTYPE_BITMAP = 1

def LoadImage(filename):
    '''Load an image from a file.
    '''

    #Initaialize GDI+
    token = c_ulong()
    startup_in = GdiplusStartupInput()
    startup_in.GdiplusVersion = 1
    startup_out = GdiplusStartupOutput()
    u = gdiplus.GdiplusStartup( byref(token), byref(startup_in), byref(startup_out))

    fname = LPOLESTR( filename )
    bitmap = c_void_p()
    gdiImage = c_void_p()
    x = LPVOID()
       
    if u == 0:
        print u
        #Load the image
        v = gdiplus.GdipCreateBitmapFromFile( fname, byref(gdiImage) )
        if v == 0:
            print v

            #Create a bitmap handle from the GDI image
            gdiplus.GdipCreateHBITMAPFromBitmap( gdiImage, byref(bitmap), 0 )

            #Create the IPicture object from the bitmap handle
            IID_IPicture = GUID('{7BF80980-BF32-101A-8BBB-00AA00300CAB}' )
            picinfo = PicDesc( Type=PICTYPE_BITMAP, hPic=bitmap, hPal=0  )
            picinfo.Size = picinfo.__sizeof__()
           
            print oleaut32.OleCreatePictureIndirect( byref(picinfo), byref(IID_IPicture), True, byref(x) )
           
            gdiplus.GdipDisposeImage( gdiImage)

        gdiplus.GdiplusShutdown( token )
       
   
    return x
   
   
   
   
   

--
shuwj <[hidden email]>


_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: a question about word addin , IRibbonExtensibility, GetCustomUI, getImage, IPicture

Mark Hammond-4
I'm not familiar enough with ctypes to know if that makes sense, but I
doubt it - nothing would seem to know the size of the buffer pointed at
by 'x'.  You probably need to stick with using a python string object -
ensure the string contains exactly the bytes of the metafile.

Mark

On 25/03/2012 10:33 PM, shuwj wrote:

>
>> I believe a c_void_p is a ctypes construct which aren't supported by
>> pywin32.  You need to convert it to a "normal" Python type.  I'm
>> guessing it is binary data, so in py2k, you should be able to simply use
>> buffer(some_string_object).  The error message seems to imply you may
>> even be able to use buffer(c_void_p_object), but I don't know how they
>> work well enough to suggest that will actually work.
>>
>> Mark
>>
>
> Hi Mark,
> Thanks for your reply. I use buffer() in GetImage method and there's no
> exception now,  but they don't work as expected.
>
>
> -----------------------------------------
> class wordaddin:
>      def GetImage(self,ctrl):
>          from gdiplus import LoadImage
>          i = LoadImage( 'c:/edit.png' )
>          i = buffer(i)
>          print i, 'ddd'
>          return i
> -----------------------------------------
>
>
> gdiplus.py  is as following:
> -----------------------------------------
> #coding: gbk
>
> from ctypes import *
> from ctypes.wintypes import *
> from comtypes import GUID
>
> oleaut32 = windll.oleaut32
> gdiplus = windll.gdiplus
>
>
> class GdiplusStartupInput(Structure):
>      _fields_ = [
>          ('GdiplusVersion', c_uint32),
>          ('DebugEventCallback', c_void_p),
>          ('SuppressBackgroundThread', BOOL),
>          ('SuppressExternalCodecs', BOOL)
>      ]
>
> class GdiplusStartupOutput(Structure):
>      _fields = [
>          ('NotificationHookProc', c_void_p),
>          ('NotificationUnhookProc', c_void_p)
>      ]
>
>
> class PicDesc(Structure):
>      _fields_ = [
>          ('Size', UINT),
>          ('Type', UINT),
>          ('hPic', HBITMAP),
>          ('hPal', HPALETTE)
>      ]
>
> PICTYPE_BITMAP = 1
>
> def LoadImage(filename):
>      '''Load an image from a file.
>      '''
>
>      #Initaialize GDI+
>      token = c_ulong()
>      startup_in = GdiplusStartupInput()
>      startup_in.GdiplusVersion = 1
>      startup_out = GdiplusStartupOutput()
>      u = gdiplus.GdiplusStartup( byref(token), byref(startup_in), byref(startup_out))
>
>      fname = LPOLESTR( filename )
>      bitmap = c_void_p()
>      gdiImage = c_void_p()
>      x = LPVOID()
>
>      if u == 0:
>          print u
>          #Load the image
>          v = gdiplus.GdipCreateBitmapFromFile( fname, byref(gdiImage) )
>          if v == 0:
>              print v
>
>              #Create a bitmap handle from the GDI image
>              gdiplus.GdipCreateHBITMAPFromBitmap( gdiImage, byref(bitmap), 0 )
>
>              #Create the IPicture object from the bitmap handle
>              IID_IPicture = GUID('{7BF80980-BF32-101A-8BBB-00AA00300CAB}' )
>              picinfo = PicDesc( Type=PICTYPE_BITMAP, hPic=bitmap, hPal=0  )
>              picinfo.Size = picinfo.__sizeof__()
>
>              print oleaut32.OleCreatePictureIndirect( byref(picinfo), byref(IID_IPicture), True, byref(x) )
>
>              gdiplus.GdipDisposeImage( gdiImage)
>
>          gdiplus.GdiplusShutdown( token )
>
>
>      return x
>
>
>
>
>
>


_______________________________________________
python-win32 mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/python-win32
Loading...