zoukankan      html  css  js  c++  java
  • Using PyQt first procedurebupt IPTV client

    blog.sina.com.cn/s/blog_5a3640220100b0se.html - Translator


    Using PyQt first procedure-bupt IPTV client
    [此博文包含图片] (2008-11-11 14:59:14)
    Reprint▼
    Tags:
    qt
    iptv
    it
        Category: Python
        To practice how to write a Gui program that is relatively simple, is to link hold down on your Web site, and then double-click called MPlayer for playback:
    使用pyqt的第一个程序--北邮人IPTV客户端
       (1) get the link code (uses urllib and sgmllib library):
    #! /usr/bin/env python
    # -*- coding: utf-8 -*-

    import urllib
    import sys
    from sgmllib import SGMLParser
    class URLLister(SGMLParser):
        def reset(self):
            SGMLParser.reset(self)
            self.pieces=[]
            self.urls=[]
            self.data=[]
            self.flag = 0

        def start_a(self,attrs):
            href=[v for k,v in attrs if k=="href"]
            if "mms" in str(href):
                self.pieces.extend(href)
                self.flag = 1

        def end_a(self):
            self.flag = 0

        def handle_data(self,text):
            if(self.flag == 1):
                self.pieces.extend([text.decode('GB2312').encode('UTF-8')]) # (sys.stdin.encoding)])

    def getplaylist():
        playlist = []
        usock=urllib.urlopen("http://iptv.bupt.edu.cn/")
        parser=URLLister()
        parser.feed(usock.read())
        usock.close()
        parser.close()

        length = len(parser.pieces)/2
        for i in range(length) :
                playlist.extend(["%s %s" % (parser.pieces[i*2+1],parser.pieces[i*2])])
        return playlist

        (2) Gui part of the code:
    #! /usr/bin/env python
    # -*- coding: utf-8 -*-

    import sys
    from PyQt4 import QtCore, QtGui
    from iptv import Ui_iptv
    import playlist
    import string

    class StartQt4(QtGui.QMainWindow):
        def __init__(self, parent=None):
            QtGui.QWidget.__init__(self, parent)
            self.ui = Ui_iptv()
            self.ui.setupUi(self)
            self.codec = QtCore.QTextCodec.codecForName('UTF-8')
            self.tvlist = playlist.getplaylist()
            self.ui.listTable.clear()
            for url in self.tvlist:
                item = QtGui.QListWidgetItem(self.ui.listTable)
                item.setText(QtGui.QApplication.translate("iptv", url, None, QtGui.QApplication.UnicodeUTF8))            
           QtCore.QObject.connect(self.ui.listTable,QtCore.SIGNAL("itemDoubleClicked(QListWidgetItem*)"),
    self.play)
            QtCore.QMetaObject.connectSlotsByName(self)


        def play(self):
            import subprocess
            signalList = self.sender()
            Itemcount = signalList.currentRow()
            Itemtext = self.tvlist[Itemcount]
            url = string.split(Itemtext)[1]
            subprocess. Popen(["smplayer",url])
       
    if __name__ == "__main__":
        app = QtGui.QApplication(sys.argv)
        myapp = StartQt4()
        myapp.show()
        sys.exit(app.exec_())

  • 相关阅读:
    7.Ubuntu16.04安装Jenkins
    5.在Gitlab创建一个基于Sping Boot Maven项目
    4.ubuntu 16.04.6 离线安装 Git
    CNN注意事项_七月算法5月深度学习班第5次课程笔记
    Github 文件选择性上传
    一个Velocity Template Language学习的框架
    设计模式学习之代理模式(Proxy)
    ibatis入门教程一
    SimpleDataFormat详解
    使用Qmake在树莓派上开发Opencv程序
  • 原文地址:https://www.cnblogs.com/lexus/p/2819543.html
Copyright © 2011-2022 走看看