惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog RSS Feed
B
Blog
N
Netflix TechBlog - Medium
量子位
月光博客
月光博客
博客园_首页
博客园 - Franky
酷 壳 – CoolShell
酷 壳 – CoolShell
Last Week in AI
Last Week in AI
T
The Blog of Author Tim Ferriss
Hugging Face - Blog
Hugging Face - Blog
雷峰网
雷峰网
M
MIT News - Artificial intelligence
J
Java Code Geeks
大猫的无限游戏
大猫的无限游戏
D
DataBreaches.Net
腾讯CDC
Engineering at Meta
Engineering at Meta
云风的 BLOG
云风的 BLOG
L
LangChain Blog
GbyAI
GbyAI
IT之家
IT之家
Y
Y Combinator Blog
人人都是产品经理
人人都是产品经理

夜行人

回家路上 第一期的直播演示项目 震动检测器 正能量 在线参观CodeLab Neverland 发布 CodeLab Adapter 3.3.1 DynamicTable 之 纸糊方向盘 CodeLab DynamicTable: 一个可实施的技术方案 CodeLab Insight 发布 Alpha 版 情人节 Home Assistant 周报 && IoT 周报 (02) Joplin: 关注隐私的 Evernote 开源替代软件 浏览器的未来与 Web 传感器 Home Assistant 周报 && IoT 周报 (01) 百宝箱(01) 论自由 介绍 WebThings Home Assistant 周报 && iot 周报 (00) 百宝箱(00) 毛姆读书心得 传世之作 周末徒步 CodeLab Adapter ❤️ Jupyter/Python 航班 躲雨 夏令营途中 [译]思想--作为一种技术 The future of coding 美国之行 三门问题的程序模拟
为mpv写一个简单的图形界面
2016-07-31 · via 夜行人

文章目录

缘起

几个月前给朋友推荐过mpv,朋友非技术人员,而mpv只提供命令行工具,没有图形界面,周末下午逛github看到Gooey,觉得简单有趣,决定用它给mpv写一个简单的图形界面

需求

需求很简单,通过点击桌面图标,之后选择电影文件,就能播放,而不需要使用图形界面,这应该是大多非技术用户习惯的操作。

一些介绍

mpv

mac下常见播放器有QuickTime,MplayerX,VLC。我之前用MplayerX居多,mpv 是 Mplayer 和 Mplayer2 项目的分支,目前活跃的开发者都转向开发 mpv。mpv基本可以满足一般用户的需要

mac下不同播放器的比较参考这里

Gooey

Turn (almost) any Python command line program into a full GUI application with one line

Gooey能轻易地把python命令行工具变为GUI应用,通过极少的代码

安装

mpv

1
2
3
brew tap mpv-player/mpv
brew install mpv
which mpv # /usr/local/bin/mpv

使用:mpv /your/folder/yourfile.mp4

mpv在mac目前没有图形界面

Gooey

pip install Gooey //需要在sudo pip下安装,wxpython要求比较多,virtuanenv下比较麻烦,具体可以参考wxPythonVirtualenvOnMac

依赖wxpython,安装wxpython

1
2
3
brew install wxpython
cd /Library/Python/2.7/site-packages    
ln -s /usr/local/Cellar/wxpython/3.0.2.0/lib/python2.7/site-packages/wx-3.0-osx_cocoa/wx/ wx

上源码

cat mpv_gui.py

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env python
# encoding: utf-8
#import argparse
from gooey import Gooey, GooeyParser
import subprocess
import sys

def handle(args):
    filename = args.filename
    # 播放,调用系统服务(mpv)
    mpv = "/usr/local/bin/mpv"
    # todo:变为独立进程
    subprocess.Popen([mpv,filename])

@Gooey(language="chinese")
def main():
  parser = GooeyParser(description=u'mpv_gui')
  parser.add_argument('filename', help=u"请选择电影文件", widget='FileChooser')
  args = parser.parse_args()
  handle(args)

if __name__ == '__main__':
  main()

点击执行

1
2
mv mpv_gui.py mpv_gui
chmod +x mpv_gui

之后点击mpv_gui文件即可选择播放电影

如果你想把这个工具打包成无依赖的系统软件,可以试试pyinstaller

todo

Gooey安装不方便,文件选择用tkinter的tkFileDialog就好了

1
2
3
4
5
6
from Tkinter import Tk
from tkFileDialog import askopenfilename

Tk().withdraw() # we don't want a full GUI, so keep the root window from appearing
filename = askopenfilename() # show an "Open" dialog box and return the path to the selected file , 在命令行下层?
print(filename)

后记

后来发现可以直接安装mpv.app,之后绑定格式和播放工具 (参考 全能高效的播放器 mpv

1
2
brew install mpv --with-bundle
brew linkapps mpv

文章作者 种瓜

上次更新 2016-07-31