Commits

afief sholichuddin committed ce261aa

fisrt commit

Comments (0)

Files changed (2)

+Aplikasi client untuk rhythmbox menggunakan bahasa python dan wxPython

src/rhythmswitch.py

+#!/usr/bin/env python
+
+import wx
+import os
+import commands
+
+
+class Frame(wx.Frame):
+    def __init__(self, *args, **kwargs):
+        super(Frame, self).__init__(*args, **kwargs)
+
+        self.SetSize((400, 300))
+
+        vbox = wx.BoxSizer(wx.VERTICAL)
+        self.SetSizer(vbox)
+
+        self.label_judul = wx.StaticText(self, label=self.GetCurrentSong())
+        vbox.Add(self.label_judul, 1, wx.EXPAND|wx.ALL|wx.ALIGN_CENTER, 10)
+        
+        panel_btn = wx.Panel(self)
+        
+        btn_prev = wx.Button(panel_btn, label="Prev")
+        btn_pp = wx.Button(panel_btn, label="Play/Pause")
+        btn_next = wx.Button(panel_btn, label="Next")
+
+        hbox = wx.BoxSizer()
+        panel_btn.SetSizer(hbox)
+        vbox.Add(panel_btn, 0, wx.EXPAND|wx.ALL, 10)
+        
+        panel_btn.GetSizer().AddMany([(btn_prev, 1, wx.EXPAND),
+                                 (btn_pp, 2, wx.EXPAND),
+                                 (btn_next, 1, wx.EXPAND)])
+        self.Bind(wx.EVT_BUTTON, self.OnBtnClicked, btn_prev)
+        self.Bind(wx.EVT_BUTTON, self.OnBtnClicked, btn_pp)
+        self.Bind(wx.EVT_BUTTON, self.OnBtnClicked, btn_next)
+
+    def GetCurrentSong(self, evt=None):
+        c_song = commands.getoutput("rhythmbox-client --print-playing")
+        return c_song
+        
+    def OnBtnClicked(self, evt):
+        obj_btn = evt.GetEventObject()
+
+        if obj_btn.GetLabel() == "Prev":
+            os.system("rhythmbox-client --previous")
+        elif obj_btn.GetLabel() == "Play/Pause":
+            os.system("rhythmbox-client --play-pause")
+        elif obj_btn.GetLabel() == "Next":
+            os.system("rhythmbox-client --next")
+        else:
+            pass # do nothing :)
+
+        # update info lagu
+        self.label_judul.SetLabel(self.GetCurrentSong())
+
+if __name__ == "__main__":
+    app = wx.App()
+    fr = Frame(None)
+    fr.Show()
+    app.MainLoop()