diff options
author | Slávek Banko <slavek.banko@axis.cz> | 2023-01-17 20:07:45 +0100 |
---|---|---|
committer | Slávek Banko <slavek.banko@axis.cz> | 2023-01-18 22:24:25 +0100 |
commit | 9be5499101c28522c831605d603bc7a3dcc01edb (patch) | |
tree | 6e6d1099f48a12ace9a1fac87a0bfdc57d871cee /amarok/src/scripts/webcontrol | |
parent | 5f01cbb7f8a9150311188e11279b7592eb284b6b (diff) | |
download | amarok-9be5499101c28522c831605d603bc7a3dcc01edb.tar.gz amarok-9be5499101c28522c831605d603bc7a3dcc01edb.zip |
Drop python2 support.
Update for PyTQt.
Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
Diffstat (limited to 'amarok/src/scripts/webcontrol')
-rw-r--r-- | amarok/src/scripts/webcontrol/Playlist.py | 10 | ||||
-rw-r--r-- | amarok/src/scripts/webcontrol/RequestHandler.py | 25 | ||||
-rwxr-xr-x | amarok/src/scripts/webcontrol/WebControl.py | 123 | ||||
-rw-r--r-- | amarok/src/scripts/webcontrol/WebPublisher.py | 8 |
4 files changed, 82 insertions, 84 deletions
diff --git a/amarok/src/scripts/webcontrol/Playlist.py b/amarok/src/scripts/webcontrol/Playlist.py index e2d888c6..a049abab 100644 --- a/amarok/src/scripts/webcontrol/Playlist.py +++ b/amarok/src/scripts/webcontrol/Playlist.py @@ -30,7 +30,7 @@ class Track(object): max_field_value_lengths = [(0,"")] * len(FIELDS) def __init__(self, **kwargs): - for key,value in kwargs.iteritems(): + for key,value in kwargs.items(): setattr(self, key, value) @@ -53,14 +53,14 @@ class Track(object): index = 0 # for f in self.__Q_SLOTS__ : -# print string.strip(f) +# print f.strip() for i in [getattr(self,f) for f in self.__Q_SLOTS__ ]: - if len(string.strip(i)) > Track.max_field_value_lengths[index][0]: - Track.max_field_value_lengths[index] = (len(string.strip(i)),i) + if len(i.strip()) > Track.max_field_value_lengths[index][0]: + Track.max_field_value_lengths[index] = (len(i.strip()),i) index += 1 - tr_style = '' + tr_style = '' tr_id = '' if style: diff --git a/amarok/src/scripts/webcontrol/RequestHandler.py b/amarok/src/scripts/webcontrol/RequestHandler.py index 8519ef35..2d0b2cb3 100644 --- a/amarok/src/scripts/webcontrol/RequestHandler.py +++ b/amarok/src/scripts/webcontrol/RequestHandler.py @@ -11,8 +11,8 @@ License: GPL """ -import SimpleHTTPServer -import BaseHTTPServer +import http.server +import http.server from Playlist import Playlist import Globals @@ -63,8 +63,7 @@ class AmarokStatus: if self.playState != -1: res = self.playState == self.EnginePlay else: - res = string.find(self.dcop_isplaying.result(), "true") >= 0 - if res: + if "true" in self.dcop_isplaying.result(): self.playState = self.EnginePlay else: self.playState = self.EnginePause @@ -85,7 +84,7 @@ class AmarokStatus: def controlsEnabled(self): return self.allowControl -class RequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): +class RequestHandler(http.server.SimpleHTTPRequestHandler): """We need our own 'RequestHandler, to handle the requests, that arrive at our server.""" @@ -144,10 +143,10 @@ class RequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): # abort a request that has already been completed # probably a refresh from the users browser - if qmap.has_key("reqid") and req_id == int(qmap["reqid"]): + if "reqid" in qmap and req_id == int(qmap["reqid"]): return 0 - if qmap.has_key("action"): + if "action" in qmap: a = qmap["action"] if a == "stop": self._amarokStop() @@ -193,9 +192,9 @@ class RequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): # get the sessions last reqid last_req_id = 0 session_id = None - if qmap.has_key("sesid"): + if "sesid" in qmap: session_id = qmap["sesid"] - if REQ_IDS.has_key(session_id): + if session_id in REQ_IDS: last_req_id = REQ_IDS[session_id] else: REQ_IDS[session_id] = last_req_id @@ -229,15 +228,15 @@ class RequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): # Surely there must be a better way that this:) # self.send_response(200) - if string.find(self.path, ".png") >= 0: + if ".png" in self.path: self.send_header("content-type","image/png") self.end_headers() self._sendFile(self.path) - elif string.find(self.path, ".js") >= 0: + elif ".js" in self.path: self.send_header("content-type","text/plain") self.end_headers() self._sendFile(self.path) - elif string.find(self.path, ".css") >= 0: + elif ".css" in self.path: self.send_header("content-type","text/css") self.end_headers() self._sendFile(self.path) @@ -257,7 +256,7 @@ def main(): """main is the starting-point for our script.""" global PLIST PLIST = Playlist() - srv = BaseHTTPServer.HTTPServer(('',Globals.PORT),RequestHandler) + srv = http.server.HTTPServer(('',Globals.PORT),RequestHandler) srv.serve_forever() diff --git a/amarok/src/scripts/webcontrol/WebControl.py b/amarok/src/scripts/webcontrol/WebControl.py index e172a157..03f97e7f 100755 --- a/amarok/src/scripts/webcontrol/WebControl.py +++ b/amarok/src/scripts/webcontrol/WebControl.py @@ -4,11 +4,11 @@ # (c) 2005 Jonas Drewsen <kde@xspect.dk> # (c) 2006 Peter C. Ndikuwera <pndiku@gmail.com> # -# Depends on: Python 2.2, PyQt +# Depends on: Python 3, PyTQt # ############################################################################ # Based on -# Python-Qt template script for Amarok +# PyTQt template script for Amarok # (c) 2005 Mark Kretschmann <markey@web.de> # ############################################################################ @@ -20,7 +20,7 @@ # ############################################################################ -import ConfigParser +import configparser import os import sys import socket @@ -31,7 +31,7 @@ from time import sleep import Globals from Playlist import Playlist import RequestHandler -import BaseHTTPServer +import http.server from WebPublisher import * import time @@ -40,9 +40,9 @@ import time import string try: - from qt import * + from PyTQt.qt import * except: - os.popen( "kdialog --sorry 'PyQt (Qt bindings for Python) is required for this script.'" ) + os.popen( "kdialog --sorry 'PyTQt (TQt bindings for Python) is required for this script.'" ) raise @@ -50,47 +50,47 @@ except: debug_prefix = "[WebControl Script]" -class ConfigDialog( QDialog ): +class ConfigDialog( TQDialog ): """ Configuration widget """ def __init__( self ): - QDialog.__init__( self ) - self.setWFlags( Qt.WDestructiveClose ) + TQDialog.__init__( self ) + self.setWFlags( TQt.WDestructiveClose ) self.setCaption( "WebControl - Amarok" ) - self.config = ConfigParser.ConfigParser() + self.config = configparser.ConfigParser() allowControl = RequestHandler.AmarokStatus.allowControl - publish = RequestHandler.AmarokStatus.publish + publish = RequestHandler.AmarokStatus.publish try: - config = ConfigParser.ConfigParser() + config = configparser.ConfigParser() config.read( "webcontrolrc" ) - allowControl = string.find(config.get( "General", "allowcontrol" ), "True") >= 0 - publish = string.find(config.get( "General", "publish" ), "True") >= 0 + allowControl = "True" in config.get( "General", "allowcontrol" ) + publish = "True" in config.get( "General", "publish" ) except: pass - self.lay = QHBoxLayout( self ) + self.lay = TQHBoxLayout( self ) - self.vbox = QVBox( self ) + self.vbox = TQVBox( self ) self.lay.addWidget( self.vbox ) - self.hbox1 = QHBox( self.vbox ) + self.hbox1 = TQHBox( self.vbox ) - self.allowControl = QCheckBox( QString("Allow control"), self.hbox1 ) + self.allowControl = TQCheckBox( TQString("Allow control"), self.hbox1 ) self.allowControl.setChecked(allowControl) - self.hbox1 = QHBox( self.vbox ) + self.hbox1 = TQHBox( self.vbox ) - self.publish = QCheckBox( QString("Publish"), self.hbox1 ) + self.publish = TQCheckBox( TQString("Publish"), self.hbox1 ) self.publish.setChecked(publish) - self.hbox = QHBox( self.vbox ) + self.hbox = TQHBox( self.vbox ) - self.ok = QPushButton( self.hbox ) + self.ok = TQPushButton( self.hbox ) self.ok.setText( "Ok" ) - self.cancel = QPushButton( self.hbox ) + self.cancel = TQPushButton( self.hbox ) self.cancel.setText( "Cancel" ) self.cancel.setDefault( True ) @@ -104,7 +104,7 @@ class ConfigDialog( QDialog ): self.file = file( "webcontrolrc", 'w' ) - self.config = ConfigParser.ConfigParser() + self.config = configparser.ConfigParser() self.config.add_section( "General" ) self.config.set( "General", "allowcontrol", self.allowControl.isChecked() ) self.config.set( "General", "publish", self.publish.isChecked() ) @@ -114,17 +114,17 @@ class ConfigDialog( QDialog ): self.accept() -class Notification( QCustomEvent ): - __super_init = QCustomEvent.__init__ +class Notification( TQCustomEvent ): + __super_init = TQCustomEvent.__init__ def __init__( self, str ): - self.__super_init(QCustomEvent.User + 1) - self.string = str + self.__super_init(TQCustomEvent.User + 1) + self.eventStr = str -class WebControl( QApplication ): - """ The main application, also sets up the Qt event loop """ +class WebControl( TQApplication ): + """ The main application, also sets up the TQt event loop """ def __init__( self, args ): - QApplication.__init__( self, args ) + TQApplication.__init__( self, args ) debug( "Started." ) self.readSettings() @@ -138,15 +138,15 @@ class WebControl( QApplication ): while p_incr < 10: try: - p_i=p_incr+Globals.PORT - self.srv = BaseHTTPServer.HTTPServer(('',p_i),RequestHandler.RequestHandler) - publisher.port = p_i - break - except socket.error: - p_incr+=1 - + p_i=p_incr+Globals.PORT + self.srv = http.server.HTTPServer(('',p_i),RequestHandler.RequestHandler) + publisher.port = p_i + break + except socket.error: + p_incr+=1 + self.zeroconfPublishing() - self.snsrv = QSocketNotifier(self.srv.fileno(), QSocketNotifier.Read) + self.snsrv = TQSocketNotifier(self.srv.fileno(), TQSocketNotifier.Read) self.snsrv.connect( self.snsrv, SIGNAL('activated(int)'), self.readSocket ) def readSocket( self ): @@ -155,15 +155,15 @@ class WebControl( QApplication ): def readSettings( self ): """ Reads settings from configuration file """ - config = ConfigParser.ConfigParser() + config = configparser.ConfigParser() config.read( "webcontrolrc" ) try: - RequestHandler.AmarokStatus.allowControl = string.find(config.get( "General", "allowcontrol" ), "True") >= 0 - RequestHandler.AmarokStatus.publish = string.find(config.get( "General", "publish" ), "True") >= 0 + RequestHandler.AmarokStatus.allowControl = "True" in config.get( "General", "allowcontrol" ) + RequestHandler.AmarokStatus.publish = "True" in config.get( "General", "publish" ) except: debug( "No config file found, using defaults." ) - + def postConfigure( self ): self.readSettings() @@ -195,32 +195,32 @@ class WebControl( QApplication ): def customEvent( self, notification ): """ Handles the notifications """ - string = QString(notification.string) - debug( "Received notification: " + str( string ) ) + eventStr = TQString(notification.eventStr) + debug( "Received notification: " + str( eventStr ) ) - if string.contains( "configure" ): + if eventStr.contains( "configure" ): self.configure() - elif string.contains( "exit" ): + elif eventStr.contains( "exit" ): cleanup(None,None) - elif string.contains( "engineStateChange: play" ): + elif eventStr.contains( "engineStateChange: play" ): self.engineStatePlay() - elif string.contains( "engineStateChange: idle" ): + elif eventStr.contains( "engineStateChange: idle" ): self.engineStateIdle() - elif string.contains( "engineStateChange: pause" ): + elif eventStr.contains( "engineStateChange: pause" ): self.engineStatePause() - elif string.contains( "engineStateChange: empty" ): + elif eventStr.contains( "engineStateChange: empty" ): self.engineStatePause() - elif string.contains( "trackChange" ): + elif eventStr.contains( "trackChange" ): self.trackChange() else: - debug( "Unknown notification: " + str(string) + " -> ignoring") + debug( "Unknown notification: " + str(eventStr) + " -> ignoring") # Notification callbacks. Implement these functions to react to specific notification # events from Amarok: @@ -260,7 +260,6 @@ class WebControl( QApplication ): RequestHandler.AmarokStatus.dcop_trackcurrenttime.result() RequestHandler.AmarokStatus.dcop_tracktotaltime = Globals.PlayerDcop("trackTotalTime") RequestHandler.AmarokStatus.dcop_tracktotaltime.result() - @@ -269,21 +268,21 @@ class WebControl( QApplication ): def debug( message ): """ Prints debug message to stdout """ - print debug_prefix + " " + message + print(debug_prefix + " " + message) def cleanup(sig,frame): publisher.shutdown() - os._exit(0) + os._exit(0) def guithread(): - app = WebControl( sys.argv ) - app.exec_loop() + app = WebControl( sys.argv ) + app.exec_loop() if __name__ == "__main__": Globals.EXEC_PATH = os.path.abspath(sys.path[0]) - gui = threading.Thread(target=guithread) - gui.start() - signal.signal(signal.SIGTERM,cleanup) + gui = threading.Thread(target=guithread) + gui.start() + signal.signal(signal.SIGTERM,cleanup) # just wait quietly for the end - while 1: sleep(120) + while 1: sleep(120) diff --git a/amarok/src/scripts/webcontrol/WebPublisher.py b/amarok/src/scripts/webcontrol/WebPublisher.py index 2cb649de..38eadc08 100644 --- a/amarok/src/scripts/webcontrol/WebPublisher.py +++ b/amarok/src/scripts/webcontrol/WebPublisher.py @@ -20,15 +20,15 @@ import string temp=sys.path[:] sys.path.insert(0,os.path.abspath(os.path.dirname(sys.argv[0])+'/../common')) if not os.getenv("TDEDIR") is None: sys.path.insert(0,os.getenv("TDEDIR")+"/share/apps/amarok/scripts/common") -if not os.getenv("TDEDIRS") is None: sys.path=[p+"/share/apps/amarok/scripts/common" for p in string.split(os.getenv("TDEDIRS"),os.pathsep)]+sys.path +if not os.getenv("TDEDIRS") is None: sys.path=[p+"/share/apps/amarok/scripts/common" for p in os.pathsep.split(os.getenv("TDEDIRS"))]+sys.path from Publisher import * sys.path=temp class WebPublisher(Publisher): - + port = None def services(self): return [{ "name" : "Amarok WebControl for "+getpass.getuser(), "port": self.port, "type": "_http._tcp", "properties": {}}] - -publisher = WebPublisher()
\ No newline at end of file + +publisher = WebPublisher() |