python - wxPython - implementing wx.EVT_TEXT_PASTE -


i'm creating wx.pyvalidator textboxes:

class ipvalidator(wx.pyvalidator):     "validator validating ip addresses"      def __init__(self):         super(ipvalidator, self).__init__()         self.bind(wx.evt_text_paste, self.onpaste)      def clone(self):         """cloning validator"""         return self.__class__()      def validate(self, win):         """the validate function"""         return self.onvalidate(self.getwindow().getvalue())      def onvalidate(self, text):         """returns true or false given text"""         return re.match(text, ip_pattern)      def onpaste(self, event): #######         text = event.getstring()         if self.onvalidate(text):             event.skip()      def transfertowindow(self):         return true      def transferfromwindow(self):         return true 

i have problem in onpaste method. how can string pasted before being pasted , make sure valid? event.getstring returns empty string

you need interface clipboard directly

def get_clipboard_text():     if not wx.theclipboard.isopened(): wx.theclipboard.open()     = wx.textdataobject()     success = wx.theclipboard.getdata(do)     if success:         return do.gettext()     return ""  class mywidget(...):     ....     def onpaste(self, event): #######         text = get_clipboard_text()         if self.onvalidate(text):             event.skip() 

is how can wx ... recommend using pyperclip easier deal with


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -