Richard Procter wrote: >> >> Hi all, >> >> I'm also having some issues with the default cut and paste which is that >> my application can also cut and paste files. These file actions have >> naturally been assigned the accelerators Ctrl+X, Ctrl+V etc but this >> naturally means that currently these accelerators don't work for >> selected text in the TextView widgets. What I'd like is for Ctrl+C to >> copy a file if a file is selected and copy some text (as the default) if >> some text is selected. >> >> What's the easiest or "normal" way of fixing something like this? > > Hi Geoff, > > I've also come up against this problem with glade. I couldn't find a > canonical way to fix it. > > My approach has been to create custom accelerator handlers which > return False if a global copy/paste is not appropiate for the focused > widget, allowing the keypress event to percolate to the TextView > widget and trigger its keybindings. > > I've included the relevant code below. > > The wrinkle is that, as glade is no longer handling their bindings, > the glade-created copy/paste menu items no longer show > "CTRL-C"/"CTRL-V". So I kludge it by giving them fake accelerators. > There may well be a cleaner way to do this. > > best, > Richard. > Hi Richard,
Thanks for your response. I've also implemented a solution to this now, which works a bit differently. I'll also paste it below and then others can decide what the canonical solution should be... The basic plan is to make the "file cut, copy and paste" actions insensitive when a textual widget is in focus, which also has the effect of disabling their accelerators and hence unblocking the default ones. It doesn't cause any trouble as it isn't possible to execute these actions anyway without moving the focus away from the text widget again. So I inherit these actions from the following class. (The isActiveOnCurrent method is filled in by the derived classes to determine whether these actions should otherwise be sensitive) Regards, Geoff # Cut, copy and paste class FocusDependentAction: def connectFocus(self): self.widget.get_toplevel().connect("set-focus", self.focusChanged) def focusChanged(self, window, widget): freeTextWidget = isinstance(widget, gtk.Entry) or isinstance(widget, gtk.TextView) if freeTextWidget: self.widget.set_sensitive(False) elif self.isActiveOnCurrent(): self.widget.set_sensitive(True) _______________________________________________ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/