This forum has been archived. All content is frozen. Please use KDE Discuss instead.

interaction with katepart

Tags: None
(comma "," separated)
User avatar
flying sheep
Registered Member
Posts
56
Karma
0
OS

interaction with katepart

Sat Jan 30, 2010 1:00 am
hi, i have successfully created a katepart and added it’s widget to a window.

now i want to know how to…
  • set the text it contains to a string (like qtextedit::setplaintext)
  • get the text back as a string
  • get and set the cursor position
  • insert text at the cursor position/left or right of the text selection
  • set the syntax higlighting to “HTML”

here the code i used so far on the part. it’s in python, but c++ answers are welcome.
Code: Select all
sced = KLibLoader.self().factory("katepart").create(self, "KatePart")
sced.setReadWrite(True)
#now i add sced.widget() where i want it
User avatar
anda_skoa
KDE Developer
Posts
783
Karma
4
OS

Re: interaction with katepart

Sat Jan 30, 2010 5:20 pm
KatePart implements the KTextEditor interfaces
http://api.kde.org/4.x-api/kdelibs-apid ... index.html

Cheers,
_


anda_skoa, proud to be a member of KDE forums since 2008-Oct.
User avatar
flying sheep
Registered Member
Posts
56
Karma
0
OS

Re: interaction with katepart

Sat Jan 30, 2010 5:48 pm
thank you, but i don’t know how to access this functionality, since
Code: Select all
type(sced) == <class 'PyKDE4.kparts.ReadWritePart'> and
type(sced.widget()) == <class 'PyQt4.QtGui.QWidget'>

and nothing of these implements it.

there seems to be a problem with casting. python is dynamically typed, so how do i convince it that sced.widget() is indeed a katepart?
User avatar
anda_skoa
KDE Developer
Posts
783
Karma
4
OS

Re: interaction with katepart

Tue Feb 02, 2010 1:11 pm
I don't think that the widget is a KatePart, at least it isn't in C++

In C++ one would cast sced to KatePart*
Since Python does duck typing, maybe you can just call KatePart of KTextInterface methods on sced?

Cheers,
_


anda_skoa, proud to be a member of KDE forums since 2008-Oct.
User avatar
flying sheep
Registered Member
Posts
56
Karma
0
OS

Re: interaction with katepart  Topic is solved

Tue Feb 02, 2010 1:26 pm
nope, but i was told yesterday evening that KTextEdit != KTextEditor. The latter is the Katepart i was searching for:
Code: Select all
self.sced = kate.createDocument(self).createView(self)
self.sced.setContextMenu(self.sced.defaultContextMenu())
self.sced.document().setText("Hello Katepart")
the only thing missing now is a clue how to add specific syntax highlighting (since the only language i want to highlight is (x)html, i don’t want the user to manually select a scheme)


Bookmarks



Who is online

Registered users: abc72656, Bing [Bot], daret, Google [Bot], Sogou [Bot], Yahoo [Bot]