Guest User

Guilherme de Sousa - lircrcMaker

a guest
Jul 31st, 2010
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.90 KB | None | 0 0
  1. import wx
  2. import os
  3. import fileinput
  4. import re
  5. import types
  6. import ctypes
  7.  
  8.  
  9. bindslist = []
  10. module = ""
  11.  
  12. configfile = os.getenv("HOME")
  13. configfile = configfile + "/.lircrc"
  14.  
  15. class Binds:
  16.     def __init__(self, remote, button, config):
  17.         self._remote = remote
  18.         self._button = button
  19.         self._config = config
  20.  
  21. class MyFrame(wx.Frame):
  22.    
  23.     def __init__(self,parent, id, title):
  24.         wx.Frame.__init__(self,parent,id,title,size=(370, 350), style=wx.DEFAULT_FRAME_STYLE & ~ (wx.RESIZE_BORDER | wx.RESIZE_BOX | wx.MAXIMIZE_BOX))
  25.        
  26.         menuBar = wx.MenuBar()
  27.         menu = wx.Menu()
  28.         helpMenu = wx.Menu()
  29.  
  30.         menu.Append(101, "Start Lirc Daemon")
  31.         menu.Append(102, "Stop Lirc Daemon")
  32.         menu.Append(103, "Exit")
  33.        
  34.         helpMenu.Append(104, "About")
  35.         menuBar.Append(menu, "Options")
  36.         menuBar.Append(helpMenu, "Help")
  37.         self.SetMenuBar(menuBar)
  38.  
  39.  
  40. #listctrl
  41.  
  42.  
  43.         self.lstctrl = wx.ListCtrl(self, 150, pos=(10, 140), style=wx.LC_REPORT, size=(360, 135))
  44.         self.lstctrl.InsertColumn(0, 'Remote')
  45.         self.lstctrl.InsertColumn(1, 'Button')
  46.         self.lstctrl.InsertColumn(2, 'Execute')
  47.         self.lstctrl.SetColumnWidth(0, 125)
  48.         self.lstctrl.SetColumnWidth(1, 125)
  49.         self.lstctrl.SetColumnWidth(2, 125)
  50.  
  51.  
  52. #Buttons
  53.  
  54.  
  55.         okButton = wx.Button(self, id=131, pos=(270, 90), name="Add Bind", label="Add Bind")
  56.         self.Bind(wx.EVT_BUTTON, self.WriteNewBind, id=131)
  57.         removeButton = wx.Button(self, id=132, pos=(270, 290), name="Remove", label="Remove")
  58.         self.Bind(wx.EVT_BUTTON, self.RemoveBind, id=132)
  59.  
  60.        
  61. #Static text labels
  62.  
  63.        
  64.         stRemote = wx.StaticText(self, 111, "Remote Module", pos=(10, 10))
  65.         stButton = wx.StaticText(self, 112, "Button", pos=(10, 40))
  66.         stConfig = wx.StaticText(self, 113, "Execute This", pos=(10, 70))
  67.  
  68.  
  69. #ComboBox's for getting the input from user
  70.  
  71.  
  72.         self.remote = wx.ComboBox(self, 121, pos=(100, 10), size=(150, 20))
  73.         self.remote.Append("lirc-mceusb2")
  74.  
  75.         self.button = wx.ComboBox(self, id=122, pos=(100, 40), size=(150, 20))
  76.         self.button.Append("Play")
  77.         self.button.Append("Stop")
  78.         self.button.Append("Skip")
  79.         self.button.Append("Replay")
  80.         self.config = wx.TextCtrl(self, 123, pos=(100, 70), size=(150, 20))
  81.  
  82.  
  83. #Menu Binds
  84.  
  85.  
  86.         self.Bind(wx.EVT_MENU, self.StartLirc, id=101)
  87.         self.Bind(wx.EVT_MENU, self.StopLirc, id=102)
  88.         self.Bind(wx.EVT_MENU, self.QuitApp, id=103)
  89.         self.Bind(wx.EVT_MENU, self.About, id=104)
  90.  
  91.  
  92. #Menu Actions
  93.  
  94.  
  95.     def StartLirc(self, event):
  96.         global module
  97.         dialog = MyDialog(self, 161, "Choose Module")
  98.         dialog.ShowModal()
  99.         dialog.Destroy()
  100.         print "\n\n MODULE:" + module
  101.         print "Starting Lirc"
  102.         os.system("gksudo /etc/rc.d/lircd start")
  103.         os.system("gksudo modprobe "+ module)
  104.         os.system("irexec &")
  105.  
  106.     def StopLirc(self, event):
  107.         os.system("gksudo killall lircd")
  108.  
  109.     def QuitApp(self, event):
  110.         self.Close()
  111.  
  112.  
  113.     def About(self, event):
  114.         about = wx.AboutDialogInfo()
  115.        
  116.         about.AddDeveloper("Guilherme de Sousa")
  117.         about.SetDescription("A simple Lircrc wizzard to add new Binds to your IR Remote")
  118.         about.SetVersion("v 1.0")
  119.         about.SetName("LircrcMaker")
  120.         aboutBox = wx.AboutBox(about)
  121.        
  122.     def ChooseModule(self, event):
  123.         print "\n\nCHOOSE MODULE\n\n"
  124.         self.module = self.choosemodule.GetValue()
  125.         self.dialog.Show(False)
  126.         print self.module
  127.        
  128.        
  129. #File Handling
  130.  
  131.  
  132.     def WriteNewBind(self, event):
  133.         global configfile
  134.         fileHandle = open(configfile, "a")
  135.  
  136.         _remote = self.remote.GetValue()
  137.         _button = self.button.GetValue()
  138.         _config = self.config.GetLineText(0)
  139.        
  140.         fileHandle.write("\tbegin\n\t\tremote = " + _remote + "\n\t\tbutton = " + _button + "\n\t\tprog = irexec\n\t\trepeat = 0\n\t\tconfig = " + _config + "\n\tend\n")
  141.         fileHandle.close()
  142.         self.lstctrl.Append((_remote, _button, _config))
  143.  
  144.     def RemoveBind(self, event):
  145.         global configfile
  146.         item = self.lstctrl.GetNextItem(-1, wx.LIST_NEXT_ALL, wx.LIST_STATE_FOCUSED)
  147.        
  148.            
  149.         self.lstctrl.DeleteItem(item)
  150.  
  151.         size = self.lstctrl.GetItemCount()
  152.        
  153.         os.remove(configfile)
  154.            
  155.         os.system("touch " + configfile)
  156.         fileHandle = open(configfile , "a")
  157.         for i in range(0, size):
  158.             _remote = self.lstctrl.GetItem(i, 0).GetText()
  159.             _button = self.lstctrl.GetItem(i, 1).GetText()
  160.             _config = self.lstctrl.GetItem(i, 2).GetText()
  161.             fileHandle.write("\tbegin\n\t\tremote = " + _remote + "\n\t\tbutton = " + _button + "\n\t\tprog = irexec\n\t\trepeat = 0\n\t\tconfig = " + _config +"\n\tend\n")
  162.         fileHandle.close()
  163.  
  164. # Dialog for choosing remote module
  165.  
  166. class MyDialog(wx.Dialog):
  167.     def __init__(self, parent, id, title):
  168.         wx.Dialog.__init__(self, parent, id, title, size=(250,130))
  169.  
  170.         stChooseModule = wx.StaticText(self, 162, "Choose the module for your remote control:", pos=(10, 20))
  171.         self.choosemodule = wx.ComboBox(self, 163, pos=(10, 50), size=(230, 20))
  172.         self.choosemodule.Append("lirc-mceusb2")
  173.         dialogOK = wx.Button(self, 164, pos=(150, 90), label="OK")
  174.         self.Bind(wx.EVT_BUTTON, self.ChooseModule, id=164)
  175.        
  176.     def ChooseModule(self, event):
  177.         global module
  178.         module = self.choosemodule.GetValue()
  179.         self.Show(False)
  180.         print self.module
  181.  
  182. class MyApp(wx.App):
  183.    
  184.     global bindslist
  185.  
  186.    
  187.     def MyParser(self):
  188.     global configfile
  189.    
  190.     os.system("touch " + configfile)
  191.        
  192.     file = open(configfile, "r")
  193.        
  194.         for line in file:
  195.             if "remote" in line:
  196.                 _split = line.split("=")
  197.                 _remote = _split[1]
  198.             elif "button" in line:
  199.                 _split = line.split("=")
  200.                 _button = _split[1]
  201.             elif "config" in line:
  202.                 _split = line.split("=")
  203.                 _config = _split[1]
  204.             elif "end" in line:
  205.                 bindslist.append(Binds(_remote, _button, _config))
  206.  
  207.     def InsertListCtrl(self):
  208.         for i in bindslist:
  209.            self.frame.lstctrl.Append((i._remote, i._button, i._config))
  210.  
  211.  
  212.     def PrintParser(self):
  213.         for b in bindslist:
  214.             print b._config
  215.             print b._button
  216.             print b._remote
  217.  
  218.  
  219.  
  220.     def OnInit(self):
  221.         self.frame = MyFrame(None, -1, "LircrcMaker")
  222.         self.frame.Show(True)
  223.         self.SetTopWindow(self.frame)
  224.         os.system("touch " + configfile)
  225.         self.MyParser()
  226.         self.InsertListCtrl()
  227.         return True
  228.  
  229. app = MyApp(0)
  230. app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment