{"id":357,"date":"2019-01-16T09:35:44","date_gmt":"2019-01-16T01:35:44","guid":{"rendered":"https:\/\/www.yinyubo.cn\/?p=357"},"modified":"2022-05-17T09:44:02","modified_gmt":"2022-05-17T01:44:02","slug":"wxpython","status":"publish","type":"post","link":"https:\/\/www.yinyubo.com\/?p=357","title":{"rendered":"wxpython \u4ece\u526a\u8d34\u677f\u8bfb\u53d6\u6587\u4ef6\uff0c\u8bfb\u53d6\u6587\u5b57\uff0c\u8bfb\u53d6\u56fe\u50cf"},"content":{"rendered":"<h1>\u9700\u6c42<\/h1>\n<p>\u524d\u6bb5\u65f6\u95f4\u6709\u8fd9\u6837\u4e00\u4e2a\u9700\u6c42\uff0c\u8981\u8bfb\u53d6\u7528\u6237\u7684\u526a\u8d34\u677f\u7684\u5185\u5bb9\uff0c\u7136\u540e\u628a\u526a\u8d34\u677f\u7684\u4fe1\u606f\u590d\u5236\u5230\u53e6\u4e00\u4e2a\u5730\u65b9\u3002\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>\u5f53\u7528\u6237\u590d\u5236\u7684\u662f\u56fe\u7247\u65f6\uff0c\u628a\u56fe\u7247\u590d\u5236\u5230\u4e00\u4e2a\u6307\u5b9a\u4f4d\u7f6e\u3002<\/li>\n<li>\u5f53\u7528\u6237\u590d\u5236\u7684\u662ftxt\u4e2d\u7684\u4e00\u6bb5\u6587\u5b57\u65f6\uff0c\u83b7\u5f97\u590d\u5236\u7684\u6587\u5b57\u5185\u5bb9\u3002<\/li>\n<li>\u5f53\u7528\u6237\u590d\u5236\u7684\u662f\u4e00\u4e2a\u6587\u4ef6\u65f6\uff0c\u83b7\u5f97\u590d\u5236\u7684\u6587\u4ef6\u540d\u548c\u8def\u5f84\uff0c\u7136\u540e\u590d\u5236\u5230\u4e00\u4e2a\u6307\u5b9a\u4f4d\u7f6e\u3002<\/li>\n<\/ul>\n<h1>\u8bbe\u8ba1<\/h1>\n<p>1.\u901a\u8fc7wx\u81ea\u5e26\u7684\u68c0\u67e5\u526a\u8d34\u677f\u529f\u80fd\u3002<br \/>\nwx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_BITMAP)) \u8fd9\u6837\u7684\u65b9\u5f0f\uff0c\u5224\u65ad\u662f\u4e0d\u662f\u56fe\u7247\u3002<br \/>\n\u6587\u5b57\u548c\u6587\u4ef6\u7684\u65b9\u6cd5\u7c7b\u4f3c\uff0c\u53ef\u4ee5\u5728\u4e0b\u9762\u7684\u4ee3\u7801\u91cc\u770b\u5230\u3002<br \/>\n2.\u901a\u8fc7wx.TheClipboard.GetData(file_obj)\u7684\u65b9\u6cd5\u83b7\u5f97\u526a\u8d34\u677f\u7684\u5185\u5bb9<br \/>\n3.\u5982\u679c\u662f\u56fe\u7247\uff0c\u901a\u8fc7wx.BitmapDataObject()\u7684GetBitmap()\u65b9\u6cd5\u83b7\u5f97\u56fe\u7247\u4fe1\u606f\u3002\u518d\u901a\u8fc7SaveFile(name=filename, type=wx.BITMAP_TYPE_BMP)\u65b9\u6cd5\u4fdd\u5b58\u56fe\u7247<br \/>\n4.\u5982\u679c\u662f\u6587\u5b57\u3002\u901a\u8fc7wx.TextDataObject()\u7684GetText()\u65b9\u6cd5\u83b7\u5f97\u6587\u5b57\u5185\u5bb9\u3002<br \/>\n5.\u5982\u679c\u662f\u6587\u4ef6\u3002\u901a\u8fc7wx.FileDataObject()\u7684GetFilenames()\u83b7\u5f97\u590d\u5236\u7684\u6587\u4ef6\u5217\u8868\u3002\u7136\u540e\u53ef\u4ee5\u901a\u8fc7shutil\u5e93\u7684copy2\u65b9\u6cd5\u590d\u5236\u6587\u4ef6\u5230\u6307\u5b9a\u4f4d\u7f6e<\/p>\n<h1>wxpython\u7a97\u4f53\u7684\u90e8\u5206\u4ee3\u7801<\/h1>\n<pre class=\"lang:python decode:true EnlighterJSRAW\" data-enlighter-language=\"golang\"><code class=\"EnlighterJSRAW\" data-enlighter-language=\"golang\">#!\/usr\/bin\/env python\nimport wx\nclass MyFrame(wx.Frame):\n    def __init__(self, parent):\n        wx.Frame.__init__(self, parent, title=\"Paste Button Demo\")\n        self.text = wx.TextCtrl(self, style=wx.TE_MULTILINE | wx.HSCROLL)\n        self.count = 4  # gets incremented\n        menu = wx.MenuBar()\n        edit = wx.Menu()\n        paste = edit.Append(wx.ID_PASTE, \"&amp;Paste\", \"Paste from the clipboard\")\n        menu.Append(edit, \"&amp;Edit\")\n        self.SetMenuBar(menu)\n        self.toolbar = self.CreateToolBar()\n        bmp = wx.ArtProvider.GetBitmap(wx.ART_PASTE, wx.ART_TOOLBAR)\n        self.toolbar.AddTool(wx.ID_PASTE,\"1234\",bmp)\n        self.toolbar.Realize()\n        self.Bind(wx.EVT_IDLE, self.update_ui)\n        self.Bind(wx.EVT_UPDATE_UI, self.update_ui, id=wx.ID_PASTE)\n        wx.UpdateUIEvent.SetUpdateInterval(75)\n        self.UpdateWindowUI()\n    def update_ui(self, event):\n        if event.GetId() == wx.ID_PASTE:  # check this less frequently, possibly expensive\n            self.count += 1\n            if self.count &lt; 5:\n                return\n            if not wx.TheClipboard.IsOpened():\n                self.count = 0\n                wx.TheClipboard.Open()\n                success = wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_BITMAP))\n                success2 = wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_TEXT))\n                success3 = wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_ENHMETAFILE))\n                success4 = wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_FILENAME))\n                success5 = wx.TheClipboard.IsSupported(wx.DataFormat(wx.DF_LOCALE))\n                print(\"success\"+str(success))\n                print(\"success2\"+str(success2))\n                print(\"success3\" + str(success3))\n                print(\"success4\" + str(success4))\n                print(\"success5\" + str(success5))\n                if success2:\n                    text_obj = wx.TextDataObject()\n                    if wx.TheClipboard.IsOpened() or wx.TheClipboard.Open():\n                        if wx.TheClipboard.GetData(text_obj):\n                            value = text_obj.GetText()\n                        wx.TheClipboard.Close()\n                    self.text.SetValue(value)\n                elif success4:\n                    file_obj = wx.FileDataObject()\n                    if wx.TheClipboard.IsOpened() or wx.TheClipboard.Open():\n                        if wx.TheClipboard.GetData(file_obj):\n                            value = file_obj.GetFilenames()\n                            print(value[0])\n                        wx.TheClipboard.Close()\n                    self.text.SetValue(value[0])\n                else:\n                    event.Enable(False)\n                    self.text.SetValue(\"You can't paste. :(\")\napp = wx.App(False)\nf = MyFrame(None)\nf.Show()\napp.MainLoop()<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u9700\u6c42 \u524d\u6bb5\u65f6\u95f4\u6709\u8fd9\u6837\u4e00\u4e2a\u9700\u6c42\uff0c\u8981\u8bfb\u53d6\u7528\u6237\u7684\u526a\u8d34\u677f\u7684\u5185\u5bb9\uff0c\u7136\u540e\u628a\u526a\u8d34\u677f\u7684\u4fe1\u606f\u590d\u5236\u5230\u53e6\u4e00\u4e2a\u5730\u65b9\u3002\u4f8b\u5982\uff1a \u5f53\u7528\u6237\u590d\u5236 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-357","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=357"}],"version-history":[{"count":1,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/357\/revisions"}],"predecessor-version":[{"id":923,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=\/wp\/v2\/posts\/357\/revisions\/923"}],"wp:attachment":[{"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yinyubo.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}