精华内容
下载资源
问答
  • pywebview 3.0

    2020-12-02 01:51:23
    <div><p>Will be the next version of <em>pywebview</em>. This will be the first <em>pywebview</em> release introducing breaking API changes. The release will feature at least the following issues and ...
  • pywebview 2

    2020-12-02 10:26:03
    <div><p>It is time for a new release. Let's call it 2.0 due the sheer amount of changes. <p>In addition to the merged features, I would like to include ...r0x0r/pywebview</p></div>
  • pywebview初探

    2019-08-15 15:06:00
      最近看python123的GUI项目推荐的时候,看到这个项目pywebviewpywebview 是一个轻量级的跨平台包装器,允许在自己的原生 GUI 窗口中展示HTML 内容。它使得你能在桌面应用程序中使用 web 技术,隐藏了 GUI 是...

      最近看python123的GUI项目推荐的时候,看到这个项目pywebview。pywebview 是一个轻量级的跨平台包装器,允许在自己的原生 GUI 窗口中展示HTML 内容。它使得你能在桌面应用程序中使用 web 技术,隐藏了 GUI 是基于浏览器的事实。你可以在 Flask 或 Bottle 这样的轻量级web框架中使用 pywebview,也可以在 Python 和 DOM 之间单独使用。

      可以看出pywebview具有以下特性的:跨平台的,web技术,还可以直接与js交互。
      对于有全干开发经验的pythoneer来说,这个库应该是极大的便利了GUI的编程实现。通过前端的组件和框架能够实现很好的界面效果,后台flask编写接口简单易用,搭配起来完美。
      然后,开始下载源码,测试例子。各个过程都很完美。然而,我还是太天真了。too yang too simple!在打包exe文件的时候就遇到问题了。

    1. 找不到dll文件。(这个还好解决,在GitHub上的issue找到了解决方案,直接把源码lib里面的dll复制到项目文件下。然后使用pyinstaller -w -F --add-data "WebBrowserInterop.x86.dll;./" --add-data "Microsoft.Toolkit.Forms.UI.Controls.WebView.dll;./" --add-data "Microsoft.Toolkit.Forms.UI.Controls.WebView.LICENSE.md;./" --onefile -y app.py 这条命令来打包项目。)
    2. 打包完成后,有50M这么大。(这个是环境包太多的问题,再开一个虚拟环境只安装需要的第三方包,打包后有6M)
    3. 在别的电脑不能打开。(打包后,在我的电脑上运行成功,但是在朋友的电脑上运行失败了,同样是win10 64位系统)

    打包官方的demo flask_app

      使用官方推荐的venv创建环境,打包出来的项目只有8M。这个大小还是可以接受的。但是遇到一个小问题,在pyinstaller打包项目的时候,添加-w参数隐藏控制台,打包出来的exe不能正常运行了。没有显示界面,只有在管理器上留下名字。找了百度、谷歌都是没有找到解决方案。就去了GitHub上,提了issue。这还是一个很活跃的项目。作者给我反馈了,一个相似问题的issue。这个issue很长,看得我都快蒙圈了。大概内容就是win10的安全机制导致,pyinstaller没有监控到控制台输出,直接结束控制台,把flask后台关闭了。作者认为这个问题应该是pyinstaller修复的,然后给了个代码,去绕过这个问题。以下代码,添加到运行文件开头就可以了。

    from contextlib import redirect_stdout
    from io import StringIO
    stream = StringIO()
    with redirect_stdout(stream):
            # something

      总的来说,这个库是值得去关注的。对于全干的pythoneer来说,提供了很大的便利。同时作者也是一个牛人,我会继续持续关注这个项目的。

    转载于:https://www.cnblogs.com/aaronhua/p/11358051.html

    展开全文
  • Import pywebview?

    2020-12-02 05:10:53
    <div><p>How i can import pywebview library?</p><p>该提问来源于开源项目:exodrifter/unity-python</p></div>
  • Pywebview with dev tools

    2020-11-30 11:45:47
    <div><p>I am wondering that is there a way to add dev tools for pywebview just like in electron?</p><p>该提问来源于开源项目:r0x0r/pywebview</p></div>
  • Flask issues with pywebview

    2020-12-08 18:23:35
    <ul><li>pywebview version: 3.2</li><li>platform / version: OS X Catalina 10.15.4</li></ul> <h3>Description <p>I'm trying to work with Flask and Pywebview from the example of the repository. My ...
  • Question about CEF/Pywebview

    2020-12-01 11:33:42
    <p>In the current version, embedding CEF with Pywebview, offers advantages over embedding CEF with wxPython? <p>I really need to be able to deploy serverless apps, with the main interface in ...
  • <div><h3>Specification <ul><li>Platform: MacOS High Sierra</li><li>...<p>Need pywebview window to start minimized. Cannot find a way to do it. </p><p>该提问来源于开源项目:r0x0r/pywebview</p></div>
  • PyWebView 2.0.3 简单了解

    千次阅读 2018-05-21 15:33:09
    学习一下pywebview,很方便的前后台交互技术。 近日,Pywebview发布了2.0的新版本。Pywebview允许您使用Web技术和Python相结合创建GUI应用程序。 使你可以用Python进行应用程序逻辑控制,使用Javascript和CSS生成...

    学习一下pywebview,很方便的前后台交互技术。

    近日,Pywebview发布了2.0的新版本。Pywebview允许您使用Web技术和Python相结合创建GUI应用程序。 使你可以用Python进行应用程序逻辑控制,使用Javascript和CSS生成GUI。 Pywebview对freeze支持良好从而实现了程序的可执行封装。
    Pywebview2.0中最大的变化是Python和Javascript之间的双向通信,它完全消除了对Python Web服务器的需求。

    import webview
    from threading import Thread
    
    class Api():
        def helloWorld(self,param):
            # 可执行业务逻辑
            return 'return result'
    
    def load_html():
        webview.load_html("""
            <style>
                #hdl_id{
                    height:25%;
                    width:100%;
                    font-size: 30px;
                    background-color:skyblue;
                }
            </style>
            <!-- 也可以引入css文件-->
            <!-- <link rel="stylesheet" type="text/css" href="test.css"/> -->
    
            <table style="border:1px solid #cccaca;background:red;">
                <tr>
                    <td>11</td>
                    <td>12</td>
                </tr>
                <tr>
                    <td>21</td>
                    <td>22</td>
                </tr>
            </table> 
            <div id="hdl_id" onclick="hdl_function_test()">enene</div> 
    
            <script>
                function hdl_function_test(){
                    alert('be clicked!')
                } 
            </script>
            <!-- 也可以引入js文件-->
            <!-- <script type="text/javascript" src="test.js"></script> -->
        """)
        # 新增的加载自定义CSS的load_css函数
        # 按如下使用时 TypeError: evaluate_js() takes exactly 2 arguments (1 given) 
        # webview.load_css(stylesheet="""
        #     #hdl_id{
        #         height:25%;
        #         width:100%;
        #         font-size: 30px;
        #         background-color:skyblue;
        #     }
        # """,uid="master")
    
        #创建窗口  
        second_window = webview.create_window('second  window')
        #指定WebView并添加内容
        webview.load_html("""
            <span>this is a test</span><br>
            <div style="background-color:grey;">gegegeg</div>
            <input type="button" id="test" value="click it" onclick="test()">
        """,uid=second_window)
        #回调后台业务逻辑
        webview.evaluate_js(script="""
            pywebview.api.helloWorld().then(function(response){
                alert(response)
            })
        """)
    
    if __name__ == '__main__':
        api = Api()
        t = Thread(target=load_html)
        t.start()
        test = webview.create_window('first  window', js_api=api)
    

    pywebview 2.0 released
    http://www.myegotraps.com/pywebview-2-0-released/
    说明文档
    https://github.com/r0x0r/pywebview

    执行结果:

    这里写图片描述

    这里写图片描述

    展开全文
  • <p>When using <a href="https://github.com/sdispater/poetry">poetry</a> for project management, trying to add pywebview to the project using the command <code>poetry add pywebview --extras qt</code> ...
  • 您可以将pywebview与轻量级的Web框架(例如或一起使用,也可以单独使用python和DOM之间的双向桥梁。 pywebview使用本机GUI创建Web组件窗口:Windows上的WinForms,macOS上的Cocoa和Linux上的QT或GTK。 如果选择...
  • <div><ul><li>pywebview version: 3.2</li><li>platform / version: 32-bit Linux</li></ul> <p>Trying to build a very basic web browser with pywebview, most websites render find except for Discord, which ...
  • 1年前研究了用pywebview做桌面应用的开发:Python使用pywebview开发桌面应用 当时只是浅尝辄止了下, 没有完整的实现过什么项目, 时间长了也有点生疏了, 最近正好有时间, 再复习一下顺带记录实现一个完整的小应用的...

    上集回顾

    1年前研究了用pywebview做桌面应用的开发:Python使用pywebview开发桌面应用
    当时只是浅尝辄止了下, 没有完整的实现过什么项目, 时间长了也有点生疏了, 最近正好有时间, 再复习一下顺带记录实现一个完整的小应用的过程, 好了,唠叨结束开始撸~🔨🔨🔨

    实现目标

    目标是实现一个单机通讯录桌面程序, 界面和功能部分用flask和layui来实现, 这一块内容涉及到的主要是flask做web开发, 就不展开描述了, 完整的项目代码开源到gitee上了, 可以自行围观, ps:写的比较烂, 没做太细的功能实现, 主要是记录后面加壳和打包的过程.
    https://gitee.com/lpwm/contracts_pywebview

    涉及技术

    flask处理后台业务
    layui做前端(简单粗暴有效,关键是兼容IE)
    sqlite本地数据库
    pywebview套壳成WinForm
    pyinstaller打包成exe

    pywebview加壳

    创建main.py用来作为程序的主入口:

    import webview
    from com.application import create_app	# flask实例工厂函数
    
    if __name__ == '__main__':
        app = create_app(__name__)
        window = webview.create_window(
            title='通讯录',
            url=app,		# 这里直接将实例化后的flask对象传给url参数就可以自动启动web服务了
            confirm_close=True		# 退出时提示
        )
        # 自定义退出提示的中文内容
        cn = {
            'global.quitConfirmation': u'确定关闭?'
        }
        webview.start(localization=cn, gui='mshtml')
    
    

    这里再解释一下webview.create_window函数的参数url=后面直接传入的是实例化后的flask对象, 官方文档上写的比较详细:

    url - URL to load. If the URL does not have a protocol prefix, it is resolved as a path relative to the application entry point. Alternatively a WSGI server object can be passed to start a local web server.

    gui='mshtml'指定使用IE进行渲染, 好处是可以通吃Win7到Win10所有平台, 就是需要注意使用老一点的web前端技术, 如果目标客户端都是Win10的话可以不加这个参数, 会自动匹配根据顺序尝试可用的浏览器渲染引擎, 优先使用Edge渲染, IE兜底, 官方的说明:

    On Windows renderer is chosen in the following order: edgechromium, edgehtml, mshtml. mshtml is the only renderer that is guaranteed to be available on any system.

    到这里直接运行main.py就可以跑出来效果了:
    在这里插入图片描述

    pyinstaller打包

    pyinstaller版本>=3.6以后打包变得简单了, 自动钩子分析依赖调用, 不用再手工添加dll动态库了.

    pyinstaller --onefile --windowed --noconfirm --icon Chat.ico main.py
    

    参数解释:
    --onefile打包成单个exe文件
    --windowed隐藏控制台窗口
    --noconfirm如果有之前打包的dist文件就自动覆盖
    --icon指定exe的图标.ico文件

    打包完成后会在项目路径下创建dist文件夹, 这时候还需要手工将templates文件夹和sqlite数据库文件复制到exe相同路径下

    尝试了用--add-data把templates和sqlite数据文件打包结果发现不行, 运行会报错找不到模板和数据库文件

    双击exe文件就可以正常运行了
    在这里插入图片描述

    展开全文
  • Python使用pywebview开发桌面应用

    千次阅读 2019-11-10 15:28:35
    前言 之前用了Eel做的桌面应用觉得已经够屌了,不过由于Eel是调用Chrome,时常出现各种小问题,比如窗口大小设置后有时候不管用,鼠标右键菜单无法禁用(一眼就...由于pywebview是直接调用系统自身的浏览器(Win10调用Edge...

    前言

    之前用了Eel做的桌面应用觉得已经够屌了,不过由于Eel是调用Chrome,时常出现各种小问题,比如窗口大小设置后有时候不管用,鼠标右键菜单无法禁用(一眼就能看出来是个web).而且尝试了用pyinstaller打包后文件好大,昨天晚上闲逛又发现了个比Eel更好的解决方案pywebview,更轻量,可自定义的设置更多.
    由于pywebview是直接调用系统自身的浏览器(Win10调用Edge,Win7调用IE),因此很适合打包发布.
    官网:https://pywebview.flowrl.com/

    最简单应用上手

    先装上轮子

    pip install pywebview
    

    实现一个内嵌百度首页的winform程序,固定窗口大小,禁止选择文字

    """
    main.py
    """
    import webview
    
    window = webview.create_window(
        title='百度一下,全是广告',
        url='http://www.baidu.com',
        width=850,
        height=600,
        resizable=False,    # 固定窗口大小
        text_select=False,   # 禁止选择文字内容
        confirm_close=True   # 关闭时提示
    )
    webview.start()
    
    

    在这里插入图片描述
    无论是启动速度,还是显示效果都要比Eel好很多.
    退出提示的窗口默认显示的是英文,可以本地化一下,定义个字典传给webview.start()当启动参数就行了.

    chinese = {
        'global.quitConfirmation': u'确定关闭?',
    }
    webview.start(localization=chinese)
    

    在这里插入图片描述

    高阶应用

    在HTML前端界面中调用Python中的函数并返回结果

    基本流程:

    1. 定义一个类,这里叫Api
    2. Api类中定义要被前端调用的各种函数
    3. 定义一个window对象的时候加入参数js_api=api,api是实例化的Api类对象,将上面定义的Api类传给window以供js调用
    4. 前端js调用的语法为pywebview.api.函数名(参数).then(回调js函数)
      直接上代码吧:

    Python

    Http是由Flask提供的,这里不介绍了

    """
    main.py
    """
    import webview
    
    chinese = {
        'global.quitConfirmation': u'确定关闭?',
    }
    
    class Api:
    
        def func(self, txt):
            response = {
                'message': '从Python调用函数返回内容:' + txt
            }
            return response
    
    
    if __name__ == '__main__':
        api = Api()
        window = webview.create_window(
            title='天涯海角',
            url='http://127.0.0.1:5000/demo',
            width=760,
            height=390,
            # resizable=False,  # 固定窗口大小
            text_select=False,  # 禁止选择文字内容
            # confirm_close=True,  # 关闭时提示
            js_api=api  # 将上面实例化后的Api对象传给前端js调用
        )
        webview.start(localization=chinese)
    
    
    

    HTML

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
    	<meta charset="UTF-8">
    	<meta name="viewport" content="width=device-width, initial-scale=1.0">
    	<meta http-equiv="X-UA-Compatible" content="ie=edge">
    	<title>Document</title>
    	<link rel="stylesheet" type="text/css" href="https://www.layuicdn.com/layui/css/layui.css" />
    	<style>
    		.setting-label {
    			width: 150px;
    		}
    	</style>
    </head>
    
    <body>
    	<div class="layui-container">
    		<div class="layui-form">
    			<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    				<legend>商品信息采集</legend>
    			</fieldset>
    			<div class="layui-form-item">
    				<label class="layui-form-label">请粘贴网址</label>
    				<div class="layui-input-block">
    					<input type="text" id="url" lay-verify="title" autocomplete="off"
    						placeholder="支持淘宝/速卖通搜索结果与单独详情页面地址" class="layui-input">
    				</div>
    			</div>
    			<div class="layui-form-item">
    				<div class="layui-input-block">
    					<button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1"
    						onclick="startJob()">开始采集</button>
    					<button type="reset" class="layui-btn layui-btn-primary">重置</button>
    					<button type="button" class="layui-btn layui-btn-danger layui-btn-radius layui-layout-right"
    						onclick="openSetting()" style="display:none"><i class="layui-icon layui-icon-set"></i></button>
    				</div>
    			</div>
    			<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    				<legend>任务控制台</legend>
    			</fieldset>
    			<div class="layui-form-item layui-form-text">
    				<label class="layui-form-label">输出信息:</label>
    				<div class="layui-input-block">
    					<textarea id="console" placeholder="开始采集后会在这里显示任务详细状态信息" class="layui-textarea" rows="6"></textarea>
    				</div>
    			</div>
    		</div>
    	</div>
    
    	<!-- 设置弹出层 -->
    	<div id="setting" class="layui-fluid" style="display:none">
    
    		<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
    			<legend>批量抓取任务参数</legend>
    		</fieldset>
    		<div class="layui-form-item">
    			<label class="layui-form-label setting-label">并发任务数量:</label>
    			<div class="layui-input-inline">
    				<input type="number" name="task_num" lay-verify="required" placeholder="请输入" autocomplete="off"
    					class="layui-input">
    			</div>
    		</div>
    		<div class="layui-form-item">
    			<label class="layui-form-label setting-label">商品详情采集图片数量:</label>
    			<div class="layui-input-inline">
    				<input type="number" name="pic_num" lay-verify="required" placeholder="请输入" autocomplete="off"
    					class="layui-input">
    			</div>
    		</div>
    		<div class="layui-form-item">
    			<div class="layui-input-block">
    				<button type="submit" class="layui-btn" lay-submit="">保存</button>
    				<button type="reset" class="layui-btn layui-btn-primary">取消</button>
    			</div>
    		</div>
    
    
    	</div>
    	<script src="https://cdn.bootcss.com/jquery/1.9.1/jquery.min.js"></script>
    	<script src="https://www.layuicdn.com/layui/layui.all.js"></script>
    	<script>
    		var layer = layui.layer;
    		var form = layui.form;
    		
    		function output(res) {
    				$("#console").val(res.message)
    			}
    
    		function startJob() {
    			var url = $("#url").val();
    			pywebview.api.startJob(url).then(output);
    		}
    
    		function openSetting() {
    			// 打开弹出遮罩层
    			layer.open({
    				type: 1,
    				title: '参数设置',
    				area: ['600px', '300px'],
    				shadeClose: true,
    				content: $('#setting')
    			});
    		}
    	
    	</script>
    </body>
    
    </html>
    

    打包成单个EXE文件

    打包需要将关键的三个DLL文件一并打进去,所以首先需要复制这几个文件到Python代码根目录下:

    .\venv\Lib\site-packages\webview\lib\WebBrowserInterop.x64.dll
    .\venv\Lib\site-packages\webview\lib\WebBrowserInterop.x86.dll
    .\venv\Lib\site-packages\webview\lib\Microsoft.Toolkit.Forms.UI.Controls.WebView.dll
    

    如果是跑了Flask应用提供HTTP服务,那么还需要额外将templatesstatic文件夹也打包进去,完整的命令如下:

    pyinstaller -windowed --onefile -y -i myicon.ico --add-data "templates;templates" --add-data "static;static" --add-data "WebBrowserInterop.x86.dll;./" --add-data "WebBrowserInterop.x64.dll;./" --add-data
     "Microsoft.Toolkit.Forms.UI.Controls.WebView.dll;./" main.py
    

    实现目标
    在服务器端设计好界面,用webview封装成一个exe文件,运行后加载服务器端的html界面,点击界面上的按钮通过js和python函数进行互动.

    2020.3.8 更新pyinstaller打包遇到的坑

    忘了之前写这篇文章的时候是咋直接用pyinstaller打包还成功了,最近又撸了个项目打包的时候各种报错,后来才想起来新项目中指定了使用的是cef作为pywebview的渲染引擎,打包的时候还得做一下修改:

    由于引入了cefpython3包,所以在使用pyinstaller之前需要先将
    venv\Lib\site-packages\cefpython3\examples\pyinstaller\hook-cefpython3.py
    这个文件复制到pyinstaller的hooks文件夹中:
    venv\Lib\site-packages\PyInstaller\hooks\
    这样再使用之前记录的打包命令的时候,pyinstaller会自动根据hooks下面的这个钩子文件加载cef相关的数据打包


    再遇坑,直接用上面的hook-cefpython3.py居然还会报错

    AssertionError: Missing cefpython3 Cython modules
    

    用了以前项目中保存的老版本的这个hook文件正常了,贴上来存个档:
    可用的hook-cefpython3.py

    """
    This is PyInstaller hook file for CEF Python. This file
    helps PyInstaller find CEF Python dependencies that are
    required to run final executable.
    See PyInstaller docs for hooks:
    https://pyinstaller.readthedocs.io/en/stable/hooks.html
    """
    
    import glob
    import os
    import platform
    import re
    import sys
    import PyInstaller
    from PyInstaller.utils.hooks import is_module_satisfies, get_package_paths
    from PyInstaller.compat import is_win, is_darwin, is_linux, is_py2
    from PyInstaller import log as logging
    
    # Constants
    CEFPYTHON_MIN_VERSION = "57.0"
    PYINSTALLER_MIN_VERSION = "3.2.1"
    
    # Makes assumption that using "python.exe" and not "pyinstaller.exe"
    # TODO: use this code to work cross-platform:
    # > from PyInstaller.utils.hooks import get_package_paths
    # > get_package_paths("cefpython3")
    
    CEFPYTHON3_DIR = get_package_paths("cefpython3")[1]
    
    CYTHON_MODULE_EXT = ".pyd" if is_win else ".so"
    
    # Globals
    logger = logging.getLogger(__name__)
    
    
    # Functions
    def check_platforms():
        if not is_win and not is_darwin and not is_linux:
            raise SystemExit("Error: Currently only Windows, Linux and Darwin "
                             "platforms are  supported, see Issue #135.")
    
    
    def check_pyinstaller_version():
        """Using is_module_satisfies() for pyinstaller fails when
        installed using 'pip install develop.zip' command
        (PyInstaller Issue #2802)."""
        # Example version string for dev version of pyinstaller:
        # > 3.3.dev0+g5dc9557c
        version = PyInstaller.__version__
        match = re.search(r"^\d+\.\d+(\.\d+)?", version)
        if not (match.group(0) >= PYINSTALLER_MIN_VERSION):
            raise SystemExit("Error: pyinstaller %s or higher is required"
                             % PYINSTALLER_MIN_VERSION)
    
    
    def check_cefpython3_version():
        if not is_module_satisfies("cefpython3 >= %s" % CEFPYTHON_MIN_VERSION):
            raise SystemExit("Error: cefpython3 %s or higher is required"
                             % CEFPYTHON_MIN_VERSION)
    
    
    def get_cefpython_modules():
        """Get all cefpython Cython modules in the cefpython3 package.
        It returns a list of names without file extension. Eg.
        'cefpython_py27'. """
        pyds = glob.glob(os.path.join(CEFPYTHON3_DIR,
                                      "cefpython_py*" + CYTHON_MODULE_EXT))
        assert len(pyds) > 1, "Missing cefpython3 Cython modules"
        modules = []
        for path in pyds:
            filename = os.path.basename(path)
            mod = filename.replace(CYTHON_MODULE_EXT, "")
            modules.append(mod)
        return modules
    
    
    def get_excluded_cefpython_modules():
        """CEF Python package includes Cython modules for various Python
           versions. When using Python 2.7 pyinstaller should not
           bundle modules for eg. Python 3.6, otherwise it will
           cause to include Python 3 dll dependencies. Returns a list
           of fully qualified names eg. 'cefpython3.cefpython_py27'."""
        pyver = "".join(map(str, sys.version_info[:2]))
        pyver_string = "py%s" % pyver
        modules = get_cefpython_modules()
        excluded = []
        for mod in modules:
            if pyver_string in mod:
                continue
            excluded.append("cefpython3.%s" % mod)
            logger.info("Exclude cefpython3 module: %s" % excluded[-1])
        return excluded
    
    
    def get_cefpython3_datas():
        """Returning almost all of cefpython binaries as DATAS (see exception
        below), because pyinstaller does strange things and fails if these are
        returned as BINARIES. It first updates manifest in .dll files:
        >> Updating manifest in chrome_elf.dll
        And then because of that it fails to load the library:
        >> hsrc = win32api.LoadLibraryEx(filename, 0, LOAD_LIBRARY_AS_DATAFILE)
        >> pywintypes.error: (5, 'LoadLibraryEx', 'Access is denied.')
        It is not required for pyinstaller to modify in any way
        CEF binaries or to look for its dependencies. CEF binaries
        does not have any external dependencies like MSVCR or similar.
        The .pak .dat and .bin files cannot be marked as BINARIES
        as pyinstaller would fail to find binary depdendencies on
        these files.
        One exception is subprocess (subprocess.exe on Windows) executable
        file, which is passed to pyinstaller as BINARIES in order to collect
        its dependecies.
        DATAS are in format: tuple(full_path, dest_subdir).
        """
        ret = list()
    
        if is_win:
            cefdatadir = "."
        elif is_darwin or is_linux:
            cefdatadir = "."
        else:
            assert False, "Unsupported system {}".format(platform.system())
    
        # Binaries, licenses and readmes in the cefpython3/ directory
        for filename in os.listdir(CEFPYTHON3_DIR):
            # Ignore Cython modules which are already handled by
            # pyinstaller automatically.
            if filename[:-len(CYTHON_MODULE_EXT)] in get_cefpython_modules():
                continue
    
            # CEF binaries and datas
            extension = os.path.splitext(filename)[1]
            if extension in \
                    [".exe", ".dll", ".pak", ".dat", ".bin", ".txt", ".so", ".plist"] \
                    or filename.lower().startswith("license"):
                logger.info("Include cefpython3 data: {}".format(filename))
                ret.append((os.path.join(CEFPYTHON3_DIR, filename), cefdatadir))
    
        if is_darwin:
            # "Chromium Embedded Framework.framework/Resources" with subdirectories
            # is required. Contain .pak files and locales (each locale in separate
            # subdirectory).
            resources_subdir = \
                os.path.join("Chromium Embedded Framework.framework", "Resources")
            base_path = os.path.join(CEFPYTHON3_DIR, resources_subdir)
            assert os.path.exists(base_path), \
                "{} dir not found in cefpython3".format(resources_subdir)
            for path, dirs, files in os.walk(base_path):
                for file in files:
                    absolute_file_path = os.path.join(path, file)
                    dest_path = os.path.relpath(path, CEFPYTHON3_DIR)
                    ret.append((absolute_file_path, dest_path))
                    logger.info("Include cefpython3 data: {}".format(dest_path))
        elif is_win or is_linux:
            # The .pak files in cefpython3/locales/ directory
            locales_dir = os.path.join(CEFPYTHON3_DIR, "locales")
            assert os.path.exists(locales_dir), \
                "locales/ dir not found in cefpython3"
            for filename in os.listdir(locales_dir):
                logger.info("Include cefpython3 data: {}/{}".format(
                    os.path.basename(locales_dir), filename))
                ret.append((os.path.join(locales_dir, filename),
                            os.path.join(cefdatadir, "locales")))
    
            # Optional .so/.dll files in cefpython3/swiftshader/ directory
            swiftshader_dir = os.path.join(CEFPYTHON3_DIR, "swiftshader")
            if os.path.isdir(swiftshader_dir):
                for filename in os.listdir(swiftshader_dir):
                    logger.info("Include cefpython3 data: {}/{}".format(
                        os.path.basename(swiftshader_dir), filename))
                    ret.append((os.path.join(swiftshader_dir, filename),
                                os.path.join(cefdatadir, "swiftshader")))
        return ret
    
    
    # ----------------------------------------------------------------------------
    # Main
    # ----------------------------------------------------------------------------
    
    # Checks
    check_platforms()
    check_pyinstaller_version()
    check_cefpython3_version()
    
    # Info
    logger.info("CEF Python package directory: %s" % CEFPYTHON3_DIR)
    
    # Hidden imports.
    # PyInstaller has no way on detecting imports made by Cython
    # modules, so all pure Python imports made in cefpython .pyx
    # files need to be manually entered here.
    # TODO: Write a tool script that would find such imports in
    #       .pyx files automatically.
    hiddenimports = [
        "codecs",
        "copy",
        "datetime",
        "inspect",
        "json",
        "os",
        "platform",
        "random",
        "re",
        "sys",
        "time",
        "traceback",
        "types",
        "urllib",
        "weakref",
    ]
    if is_py2:
        hiddenimports += [
            "urlparse",
        ]
    
    # Excluded modules
    excludedimports = get_excluded_cefpython_modules()
    
    # Include binaries requiring to collect its dependencies
    if is_darwin or is_linux:
        binaries = [(os.path.join(CEFPYTHON3_DIR, "subprocess"), ".")]
    elif is_win:
        binaries = [(os.path.join(CEFPYTHON3_DIR, "subprocess.exe"), ".")]
    else:
        binaries = []
    
    # Include datas
    datas = get_cefpython3_datas()
    
    # Notify pyinstaller.spec code that this hook was executed
    # and that it succeeded.
    os.environ["PYINSTALLER_CEFPYTHON3_HOOK_SUCCEEDED"] = "1"
    

    2020.4.3更新-判断页面中pywebview.api对象是否加载成功

    今天又写了个小应用,调用的本地的html文件,想要在页面打开的时候直接调用pywebview.api中关联的python函数,但是由于页面中直接用js访问pywebview.api对象的话会报错找不到对象,又翻了下官方文档,发现需要给window对象添加个事件监听pywebviewready,示例代码:

    <script>
      window.addEventListener('pywebviewready', function () {
        pywebview.api.hl('aaa').then(function (res) {
          document.querySelector('#hl').textContent = res.rate
        })
      })
    </script>
    
    展开全文
  • <ul><li>pywebview version: 3.0</li><li>platform / version: Windows 8.1 64-bits</li></ul> <h3>Description <p>Describe your issue: <p>Hello, I've been trying to use pywebview for around 3 days.. I&#...
  • ve been working on a production level project for a while now involving pywebview. The client and I recently noticed that one of the ...
  • <ul><li>pywebview version: Version: 3.4</li><li>platform / version: 5.20.4 Operating System: Manjaro Linux </li></ul> <h3>Description <p>JavaScript API <pre><code> $(document).ready(function () { $(&...
  • <div><p>It's possible to create a bridge between the webview and python without depending on sockets. The problem of starting a server on windows is that the firewall can ...r0x0r/pywebview</p></div>
  • <div><h3>Specification <ul><li>Platform: Windows/Mac</li><li>Version: 1.8</li></ul> <h3>Description <p>Hi, I'm trying to use webview inside my pyqt GUI application....r0x0r/pywebview</p></div>
  • , and the pywebview variable disappeared on the '/home' page, as you've noted. <p>The fix was instead of redirecting from '/' to 'home', I would AJAX fetch the content of &...
  • <div><p>该提问来源于开源项目:r0x0r/pywebview</p></div>
  • <ul><li>pywebview version: pip version 3.2</li><li>platform / version: MacOS 10.14.6</li></ul> <h3>Description <p>Example for flask-based app does not work using pip install of pywebview (3.2). using ...
  • 1.2 pywebview是一个轻量级跨平台的 HTML 浏览器控件,可以在 GUI 应用中显示 HTML 内容。 华为笔记本+深度deepin-linux操作系统:pywebview调用html 2 加载html部分: 2.1 加载html的部分文字法 #官网例子 import ...
  • 一.pywebview简介 pywebview是围绕webview组件的轻型跨平台包装器,它允许在其自己的本机GUI窗口中显示HTML内容。您可能会想到Python的Electron,但是pywebview打包的执行文件小很多。 它为您提供了桌面应用程序...
  • <ul><li>python version: 3.7.4</li><li>pywebview version: 3.0</li><li>pyinstaller version: 3.5</li><li>platform / version: Window 10 64-bit + Windows 7 32-bit</li></ul> <h3>Description <p>pywebview...
  • pywebview是webview组件的轻量级跨平台原生封装,实现利用Web技术开发GUI应用
  • 本文介绍pywebview+vue实现一个系统的登录页面,效果图如下: 一、python代码 创建test_pywebview.py文件 import webview def on_closed(): print('pywebview window is closed') def on_closing(): print('...
  • m trying to use the Python module <a href="https://github.com/r0x0r/pywebview">pywebview</a> with Nuitka and I'm not able to to get it to work. I've tried to manually copy over the <code>...
  • pywebview构建应用程序与构建Web应用程序非常相似,但有一些主要区别: 数据库可选 访问本地用户的文件系统 几乎没有延迟(在JavaScript和Python之间) 默认情况下为离线(无需使用互联网)。 使用pywebview的...
  • Pywebview,这种类似于Electron的Python库已经发布了2.0版本。Pywebview允许您使用Web技术和Python相结合创建GUI应用程序。 使你可以用Python进行应用程序逻辑控制,使用Javascript和CSS生成GUI。 Pywebview对freeze...

空空如也

空空如也

1 2 3 4 5 ... 17
收藏数 324
精华内容 129
关键字:

pywebview