python:wxpython

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
python:wxpython [2020/03/07 18:42] – [WebView] ともやんpython:wxpython [2021/06/12 12:32] (現在) – [distutils.msvc9compiler の find_vcvarsall() の実装 (Python 3.8)] ともやん
行 1: 行 1:
-<html> 
-  <style> 
-    #result pre { 
-      overflow: scroll; 
-      overflow-x: hidden; 
-      font-size: 12px; 
-    } 
-    #result_long pre { 
-      height: 300px; 
-      overflow: scroll; 
-      overflow-x: hidden; 
-      font-size: 12px; 
-    } 
-    #source_code pre { 
-      overflow: scroll; 
-      overflow-x: hidden; 
-      font-size: 12px; 
-    } 
-  </style> 
-</html> 
 ====== wxPython ====== ====== wxPython ======
-{{:python:wxpython_logo.png?309|wxPython Logo}}\\+{{python:wxpython_logo.png?309|wxPython Logo}}\\
 本家: [[https://wxpython.org/|Welcome to wxPython! | wxPython]]\\ 本家: [[https://wxpython.org/|Welcome to wxPython! | wxPython]]\\
 ソースコード: \\ ソースコード: \\
-・[[https://github.com/wxWidgets/Phoenix|wxWidgets/Phoenix: wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before.]] (wxPython Phoenix 4系)\\ +・[[git>wxWidgets/Phoenix|wxWidgets/Phoenix: wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before.]] (wxPython Phoenix 4系)\\ 
-・[[https://github.com/wxWidgets/wxPython-Classic|wxWidgets/wxPython-Classic: This is the repository for "Classic" wxPython. All new development is happening in the Phoenix project at https://github.com/wxWidgets/Phoenix]] (wxPython Classic 3系)\\+・[[git>wxWidgets/wxPython-Classic|wxWidgets/wxPython-Classic: This is the repository for "Classic" wxPython. All new development is happening in the Phoenix project at https://github.com/wxWidgets/Phoenix]] (wxPython Classic 3系)\\
 リリース: \\ リリース: \\
 ・[[https://pypi.org/project/wxPython/|wxPython · PyPI]] (wxPython Phoenix 4系)\\ ・[[https://pypi.org/project/wxPython/|wxPython · PyPI]] (wxPython Phoenix 4系)\\
-・[[https://sourceforge.net/projects/wxpython/files/wxPython/|wxPython - Browse /wxPython at SourceForge.net]] (wxPython Classic 3系)\\+・[[sf>wxpython/files/wxPython/|wxPython - Browse /wxPython at SourceForge.net]] (wxPython Classic 3系)\\
 \\ \\
- wxPythonは、wxWidgets C++ クラス ライブラリ(クロス プラットフォーム GUIライブラリ)のPython言語向けバインディングである。つまり、PythonからwxWidgetsを利用できるようにしたものである。\\ + wxPythonは、wxWidgets C++ クラス ライブラリ(クロス プラットフォーム GUI ライブラリ)の Python 言語向けバインディングである。つまり、Python から wxWidgets を利用できるようにしたものである。\\ 
- wxPythonを使いPythonでプログラムを記述すると、スクリプト言語でGUIアプリケーションを作成できる。さらに、そのプログラムはLinuxやWindows、Mac OS Xで同じように動作する。(PythonとwxPythonが利用できる様々なプラットフォームで動作する。)+ wxPython を使い Python でプログラムを記述すると、スクリプト言語で GUI アプリケーションを作成できる。さらに、そのプログラムは Linux や Windows、Mac OS Xで同じように動作する。(Python と wxPython が利用できる様々なプラットフォームで動作する。)
  
 ===== インストール ===== ===== インストール =====
 **wxPython Phoenix 4**系\\ **wxPython Phoenix 4**系\\
 <code powershell> <code powershell>
-PS > pip install wxpython+pip install wxpython
 </code> </code>
 <WRAP prewrap 100% #result> <WRAP prewrap 100% #result>
 <code> <code>
 Collecting wxpython Collecting wxpython
-  Downloading wxPython-4.0.7.post2-cp38-cp38-win_amd64.whl (22.MB) +  Downloading wxPython-4.1.1-cp39-cp39-win_amd64.whl (18.MB) 
-     |████████████████████████████████| 22.MB 819 kB/s+     |████████████████████████████████| 18.1 MB 2.MB/s
 Collecting six Collecting six
-  Downloading six-1.14.0-py2.py3-none-any.whl (10 kB) +  Downloading six-1.16.0-py2.py3-none-any.whl (11 kB)
-Collecting numpy; python_version >= "3.0" +
-  Downloading numpy-1.18.1-cp38-cp38-win_amd64.whl (12.8 MB) +
-     |████████████████████████████████| 12.8 MB 1.3 MB/s+
 Collecting pillow Collecting pillow
-  Downloading Pillow-7.0.0-cp38-cp38-win_amd64.whl (2.MB) +  Downloading Pillow-8.2.0-cp39-cp39-win_amd64.whl (2.MB) 
-     |████████████████████████████████| 2.MB 1.3 MB/s +     |████████████████████████████████| 2.MB 3.3 MB/s 
-Installing collected packages: six, numpy, pillow, wxpython +Collecting numpy; python_version >= "3.0" 
-Successfully installed numpy-1.18.pillow-7.0.0 six-1.14.0 wxpython-4.0.7.post2+  Downloading numpy-1.20.3-cp39-cp39-win_amd64.whl (13.7 MB) 
 +     |████████████████████████████████| 13.7 MB 3.3 MB/s 
 +Installing collected packages: six, pillow, numpy, wxpython 
 +Successfully installed numpy-1.20.pillow-8.2.0 six-1.16.0 wxpython-4.1.1
 </code> </code>
 </WRAP> </WRAP>
行 123: 行 103:
 <code> <code>
 > git clone https://github.com/wxWidgets/Phoenix.git wxPython-Phoenix > git clone https://github.com/wxWidgets/Phoenix.git wxPython-Phoenix
-> "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"+> cd wxPython-Phoenix 
 +> "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvarsall.bat" x64 -vcvars_ver=14.16
 ********************************************************************** **********************************************************************
 ** Visual Studio 2019 Developer Command Prompt v16.4.5 ** Visual Studio 2019 Developer Command Prompt v16.4.5
行 129: 行 110:
 ********************************************************************** **********************************************************************
 [vcvarsall.bat] Environment initialized for: 'x64' [vcvarsall.bat] Environment initialized for: 'x64'
 +> echo %VCToolsVersion%
 +14.16.27023
 +> git submodule update --init --recursive
 </code> </code>
  
行 200: 行 184:
 [[https://stackoverflow.com/questions/9233118/library-abi-compatibility-between-versions-of-visual-studio|c++ - Library ABI compatibility between versions of Visual Studio - Stack Overflow]]\\ [[https://stackoverflow.com/questions/9233118/library-abi-compatibility-between-versions-of-visual-studio|c++ - Library ABI compatibility between versions of Visual Studio - Stack Overflow]]\\
  
-===== 最小のwxPythonアプリケーション ===== +==== distutils.msvccompiler の get_build_version() の実装 (Python 3.8) ==== 
-UTF-8で保存すること。+<WRAP prewrap 100% #result_long> 
 +<code python> 
 +def get_build_version(): 
 +    """Return the version of MSVC that was used to build Python. 
 + 
 +    For Python 2.3 and up, the version number is included in 
 +    sys.version.  For earlier versions, assume the compiler is MSVC 6. 
 +    """ 
 +    prefix = "MSC v." 
 +    i = sys.version.find(prefix) 
 +    if i == -1: 
 +        return 6 
 +    i = i + len(prefix) 
 +    s, rest = sys.version[i:].split(" ", 1) 
 +    majorVersion = int(s[:-2]) - 6 
 +    if majorVersion >= 13: 
 +        # v13 was skipped and should be v14 
 +        majorVersion += 1 
 +    minorVersion = int(s[2:3]) / 10.0 
 +    # I don't think paths are affected by minor version in version 6 
 +    if majorVersion == 6: 
 +        minorVersion = 0 
 +    if majorVersion >= 6: 
 +        return majorVersion + minorVersion 
 +    # else we don't know what version of the compiler this is 
 +    return None 
 +</code> 
 +</WRAP> 
 +<WRAP prewrap 100% #result> 
 +<code python> 
 +>>> from distutils.msvccompiler import get_build_version 
 +>>> version = get_build_version(); version 
 +14.1 
 +>>> import sys 
 +>>> sys.version 
 +'3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)]' 
 +>>> s[:-2] 
 +'19'                                                                                                                    >>> majorVersion = int(s[:-2]) - 6 
 +>>> majorVersion 
 +13                                                                                                                      >>> majorVersion += 1 
 +>>> majorVersion 
 +14 
 +>>> s[2:3] 
 +'1' 
 +>>> minorVersion = int(s[2:3]) / 10.0 
 +>>> minorVersion 
 +0.1 
 +>>> majorVersion + minorVersion 
 +14.1 
 +</code> 
 +</WRAP> 
 + 
 +==== distutils.msvc9compiler の find_vcvarsall() の実装 (Python 3.8) ==== 
 +<WRAP prewrap 100% #result_long> 
 +<code python> 
 +def find_vcvarsall(version): 
 +    """Find the vcvarsall.bat file 
 + 
 +    At first it tries to find the productdir of VS 2008 in the registry. If 
 +    that fails it falls back to the VS90COMNTOOLS env var. 
 +    """ 
 +    vsbase = VS_BASE % version 
 +    try: 
 +        productdir = Reg.get_value(r"%s\Setup\VC" % vsbase, 
 +                                   "productdir"
 +    except KeyError: 
 +        log.debug("Unable to find productdir in registry"
 +        productdir = None 
 + 
 +    if not productdir or not os.path.isdir(productdir): 
 +        toolskey = "VS%0.f0COMNTOOLS" % version 
 +        toolsdir = os.environ.get(toolskey, None) 
 + 
 +        if toolsdir and os.path.isdir(toolsdir): 
 +            productdir = os.path.join(toolsdir, os.pardir, os.pardir, "VC"
 +            productdir = os.path.abspath(productdir) 
 +            if not os.path.isdir(productdir): 
 +                log.debug("%s is not a valid directory" % productdir) 
 +                return None 
 +        else: 
 +            log.debug("Env var %s is not set or invalid" % toolskey) 
 +    if not productdir: 
 +        log.debug("No productdir found"
 +        return None 
 +    vcvarsall = os.path.join(productdir, "vcvarsall.bat"
 +    if os.path.isfile(vcvarsall): 
 +        return vcvarsall 
 +    log.debug("Unable to find vcvarsall.bat"
 +    return None 
 +</code> 
 +</WRAP> 
 + 
 +===== 最小の wxPython アプリケーション ===== 
 +<wrap em>※ UTF-8 で保存すること。</wrap>\\ 
 + 
 +==== wx.Frame サンプル ==== 
 +{{:python:wxpython_minimum_app_001.png?276|wxPython minimum app 001}}\\ 
 <WRAP prewrap 100% #source_code> <WRAP prewrap 100% #source_code>
 <code python PyWxHelloMain.py> <code python PyWxHelloMain.py>
行 207: 行 288:
 # -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
 import wx import wx
 + 
 # PyWxHelloFrame クラス(wxFrame から派生) # PyWxHelloFrame クラス(wxFrame から派生)
 class PyWxHelloFrame(wx.Frame): class PyWxHelloFrame(wx.Frame):
行 215: 行 296:
         panel = wx.Panel(self, -1)         panel = wx.Panel(self, -1)
         # Panel に [閉じる] ボタンを追加         # Panel に [閉じる] ボタンを追加
-        btnClose = wx.Button(panel, wx.NewId(), u"閉じる")+        btnClose = wx.Button(panel, wx.NewIdRef(), u"閉じる")
         # ボタンの位置を設定         # ボタンの位置を設定
-        btnClose.SetPosition((50, 35))+        btnClose.SetPosition((100, 35))
         # クリックイベントにイベントハンドラをバインド         # クリックイベントにイベントハンドラをバインド
         self.Bind(wx.EVT_BUTTON, self.btnClose_Click, btnClose)         self.Bind(wx.EVT_BUTTON, self.btnClose_Click, btnClose)
 + 
     # [閉じる] ボタンクリック時     # [閉じる] ボタンクリック時
     def btnClose_Click(self, event):     def btnClose_Click(self, event):
         # 閉じる         # 閉じる
         self.Close(True)         self.Close(True)
 + 
 # PyWxHelloApp クラス(wxApp から派生) # PyWxHelloApp クラス(wxApp から派生)
 class PyWxHelloApp(wx.App): class PyWxHelloApp(wx.App):
     def OnInit(self):     def OnInit(self):
         # PyWxHelloFrame クラスを生成(タイトル、サイズを指定)         # PyWxHelloFrame クラスを生成(タイトル、サイズを指定)
-        mainFrame = PyWxHelloFrame(None, -1, "Hello wxPython!!", size=(200, 100))+        mainFrame = PyWxHelloFrame(None, -1, "Hello wxPython!!", size=(290, 100))
         # トップウインドウとして設定         # トップウインドウとして設定
         self.SetTopWindow(mainFrame)         self.SetTopWindow(mainFrame)
行 237: 行 318:
         # 正常終了         # 正常終了
         return True         return True
 + 
 # メイン処理 # メイン処理
 def main(): def main():
行 244: 行 325:
     # メインループを開始     # メインループを開始
     app.MainLoop()     app.MainLoop()
 + 
 # スクリプト起動時にmain()を実行 # スクリプト起動時にmain()を実行
 if __name__ == "__main__": if __name__ == "__main__":
行 250: 行 331:
 </code> </code>
 </WRAP> </WRAP>
 +
 +サンプルアプリケーションの実行。\\
 +<WRAP prewrap 100%>
 +<code>
 +$ python PyWxHelloMain.py
 +</code>
 +</WRAP>
 +
 +==== wx.html2.WebView サンプル ====
 +{{:python:wxpython_minimum_app_002.png?640|wxPython minimum app 002}}\\
  
 <WRAP prewrap 100% #source_code> <WRAP prewrap 100% #source_code>
行 257: 行 348:
 import wx import wx
 import wx.html2 import wx.html2
- +  
-# PyWxWebViewDialog クラス(wxDialog から派生)+# PyWxWebViewDialog (wxDialog )
 class PyWxWebViewDialog(wx.Dialog): class PyWxWebViewDialog(wx.Dialog):
     def __init__(self, *args, **kwds):     def __init__(self, *args, **kwds):
         wx.Dialog.__init__(self, *args, **kwds)         wx.Dialog.__init__(self, *args, **kwds)
-        # BoxSizer 生成+        # BoxSizer 
         sizer = wx.BoxSizer(wx.VERTICAL)         sizer = wx.BoxSizer(wx.VERTICAL)
-        # WebView 生成 +        # WebView  
-        self.browser = wx.html2.WebView.New(self) +        self.browser = wx.html2.WebView.New(self, backend=wx.html2.WebViewBackendIE) 
-        # BoxSizer に WebView を追加+        #self.browser = wx.html2.WebView.New(self, backend=wx.html2.WebViewBackendEdge
 +        # BoxSizer  WebView 
         sizer.Add(self.browser, 1, wx.EXPAND, 10)         sizer.Add(self.browser, 1, wx.EXPAND, 10)
-        # Dialog に BoxSizer レイアウトを適用+        # Dialog  BoxSizer 
         self.SetSizer(sizer)         self.SetSizer(sizer)
-        # Dialog サイズを設定+        # Dialog 
         self.SetSize((1024, 700))         self.SetSize((1024, 700))
-        # Dialog 最小サイズを設定+        # Dialog 
         self.SetMinSize((600,300))         self.SetMinSize((600,300))
-        # Dialog をディスプレイ中央に配置+        # Dialog 
         self.Center()         self.Center()
 + 
 if __name__ == '__main__': if __name__ == '__main__':
-    # wxApp クラスを生成+    # wxApp 
     app = wx.App()     app = wx.App()
-    # PyWxWebViewDialog クラスを生成+    # PyWxWebViewDialog 
     dialog = PyWxWebViewDialog(None, -1)     dialog = PyWxWebViewDialog(None, -1)
-    # WebView の URL を設定+    # WebView  URL 
     dialog.browser.LoadURL('https://html5test.com/')     dialog.browser.LoadURL('https://html5test.com/')
-    # Dialog を表示+    # Dialog 
     dialog.Show()     dialog.Show()
-    # メインループを開始+    # 
     app.MainLoop()     app.MainLoop()
 </code> </code>
 +</WRAP>
 +
 +サンプルアプリケーションの実行。\\
 +<WRAP prewrap 100%>
 +<code>
 +$ python PyWxWebView.py</code>
 </WRAP> </WRAP>
  
行 351: 行 449:
 [[https://github.com/windows-toolkit/WindowsCommunityToolkit|windows-toolkit/WindowsCommunityToolkit: The Windows Community Toolkit is a collection of helper functions, custom controls, and app services. It simplifies and demonstrates common developer tasks building UWP apps for Windows 10. The toolkit is part of the .NET Foundation.]]\\ [[https://github.com/windows-toolkit/WindowsCommunityToolkit|windows-toolkit/WindowsCommunityToolkit: The Windows Community Toolkit is a collection of helper functions, custom controls, and app services. It simplifies and demonstrates common developer tasks building UWP apps for Windows 10. The toolkit is part of the .NET Foundation.]]\\
 [[https://www.nuget.org/packages/Microsoft.Web.WebView2|NuGet Gallery | Microsoft.Web.WebView2 0.9.430]]\\ [[https://www.nuget.org/packages/Microsoft.Web.WebView2|NuGet Gallery | Microsoft.Web.WebView2 0.9.430]]\\
 +[[https://wiki.python.org/moin/WindowsCompilers#Which_Microsoft_Visual_C.2B-.2B-_compiler_to_use_with_a_specific_Python_version_.3F|WindowsCompilers - Python Wiki]]\\
 +
 +==== 付録 ====
 +[[tw>tomoyan596/status/1403202445094752264|wxPythonのWebViewはIEです😅💦💦💦 vue.jsなんて動きません🤤😇 $ pip install wxpython $ pip freeze wxPython==4.1.1 $ python / Twitter]]\\
 +
  
  • python/wxpython.1583574131.txt.gz
  • 最終更新: 2020/03/07 18:42
  • by ともやん