Using RichTextEdit control with pythonwin - seems to fail

Brad Clements bkc at Murkworks.com
Fri May 21 13:48:37 EDT 1999


Being the non-mfc person that I am, I'm trying to find a cheap way to print
some text to a Windows printer.

I thought I'd use a RichTextEdit control, put some text on it, then tell it
to print.

Unfortunately, I can't even put the text into the control..

Here's what I'm trying in interactive mode.

>>> import win32com

>>> a = win32com.client.Dispatch('RICHTEXT.RichtextCtrl.1')
>>> print a
<win32com.gen_py.Microsoft Rich Textbox Control 6.0.IRichText>

So far, so good.

>>> a.Text = 'Hi there'
Traceback (innermost last):
  File "<interactive input>", line 1, in ?
  File "d:\Program
Files\Python\win32com\gen_py\3B7C8863-D78F-101B-B9B5-04021C009402x0x1x2.py",
line 214, in __setattr__
    apply(self._oleobj_.Invoke, args + (value,) + defArgs)
com_error: (-2146827901, 'CTL_E_SETNOTPERMITTED', (0, 'RichtextCtrl',
'Property cannot be set', 'RTFBox98.CHM', 387, -2146827901), None)


According to rtfbox98.chm, Text and TextRTF can both be set and read.

>>> a.LoadFile("c:\autoexec.bat",1)
>>> a.Text
''

Funny, no error loading the file, but can't get any text from it..

>>> a.TextRTF = "hi there"
Traceback (innermost last):
  File "<interactive input>", line 1, in ?
  File "d:\Program
Files\Python\win32com\gen_py\3B7C8863-D78F-101B-B9B5-04021C009402x0x1x2.py",
line 214, in __setattr__
    apply(self._oleobj_.Invoke, args + (value,) + defArgs)
com_error: (-2146827901, 'CTL_E_SETNOTPERMITTED', (0, 'RichtextCtrl',
'Property cannot be set', 'RTFBox98.CHM', 387, -2146827901), None)
>>>

Any suggestions?


--
Brad Clements,
bkc at murkworks.com






More information about the Python-list mailing list