Aaaarrrrrggggghhhhhhhh!!!! (But not directed at you, Robin, I promise. And
not Neil, either.)
What I'd really like (I think) is:
EVT_STC_CUT()
EVT_STC_COPY()
EVT_STC_PASTE()
As long as the passed in functions were *always* called.
What I'm trying to do is make everything in the PyCrust shell prior to the
most recent prompt read only (no cut and no paste). Removing or inserting
text in any fashion messes me up. So I want my methods called no matter how
a cut or paste is initiated, whether from dragging or a menu operation or
some other program even. Here are the methods as they stand, in case they
help the discussion:
def CanCut(self):
"""Return true if text is selected and can be cut."""
if self.GetSelectionStart() != self.GetSelectionEnd() \
and self.GetSelectionStart() >= self.prompt1Pos[1] \
and self.GetSelectionEnd() >= self.prompt1Pos[1]:
return 1
else:
return 0
def CanCopy(self):
"""Return true if text is selected and can be copied."""
return self.GetSelectionStart() != self.GetSelectionEnd()
def CanPaste(self):
"""Return true if a paste should succeed."""
if self.CanEdit() and wxStyledTextCtrl.CanPaste(self):
return 1
else:
return 0
def CanEdit(self):
"""Return true if editing should succeed."""
return self.GetCurrentPos() >= self.prompt1Pos[1]
def Cut(self):
"""Remove selection and place it on the clipboard."""
if self.CanCut() and self.CanCopy():
if self.AutoCompActive(): self.AutoCompCancel()
if self.CallTipActive: self.CallTipCancel()
self.Copy()
self.ReplaceSelection('')
def Copy(self):
"""Copy selection and place it on the clipboard."""
if self.CanCopy():
command = self.GetSelectedText()
command = command.replace(os.linesep + sys.ps2, os.linesep)
data = wxTextDataObject(command)
if wxTheClipboard.Open():
wxTheClipboard.SetData(data)
wxTheClipboard.Close()
def Paste(self):
"""Replace selection with clipboard contents."""
if self.CanPaste():
if wxTheClipboard.Open():
if wxTheClipboard.IsSupported(wxDataFormat(wxDF_TEXT)):
data = wxTextDataObject()
if wxTheClipboard.GetData(data):
command = data.GetText()
command = self.fixLineEndings(command)
command = command.replace(os.linesep + sys.ps2,
'\n')
command = command.replace(os.linesep, '\n')
command = command.replace('\n', os.linesep +
sys.ps2)
self.ReplaceSelection('')
self.write(command)
wxTheClipboard.Close()
···
---
Patrick K. O'Brien
Orbtech
"I am, therefore I think."
-----Original Message-----
From: wxpython-users-admin@lists.wxwindows.org
[mailto:wxpython-users-admin@lists.wxwindows.org]On Behalf Of Robin Dunn
Sent: Tuesday, October 23, 2001 12:11 PM
To: wxpython-users@lists.wxwindows.org
Subject: Re: [wxPython] Capturing Cut/Copy/Paste in wxSTC
How do I do this in a platform-neutral fashion? Am I to assume Ctrl-X,
Ctrl-C, Ctrl-V?
I've seen an increasing number of *nix applications use these keys, so it's
probably pretty safe to use them. The Mac uses the same ascii chars in
confunction with the "apple" key instead of Control, but I'm not sure yet
how that will appear in wx.
Or are there wx constants that I should use instead?
There are standard menu IDs for them, but I don't see anything for keysyms.
What
about drap and drop? Right now dragging a selection from wxSTC does a cut,
bypassing my Cut() method.
(And holding down the Ctrl should turn it into a Copy.)
I need absolute control in all circumstances.
I've read all the docs and previous messages and can't find anything that
makes this clear to me.
Currently you would have to intercept the mouse events and check for the
dragging from the selected text range, and do your own drag/drop operations,
but I think I can make it easier... Would it work for you if there was an
event at the begining of the drag opperation that give you the default text
to be dragged and allow you to change it?
--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users