2013-12-01, 07:48
I'm currently in the process of taking up Python and getting familiar with it. I've been sifting through documentation and online references to make a script that can send commands to a DD-WRT based router via telnet commands. At this stage the script loads, goes to a black screen and displays the output from the telnet session. It's very rough and ugly but so far so good . At this stage I'm just having troubles with how to get the output to display correctly. I'm using ControlLabel (xbmcgui.ControlLabel) to display output but I'm starting to get the feeling that it's only meant for titles because there appears to be a width limit.
Background: I'm building a custom Xbox with a stripped down Belkin wireless router with DD-WRT installed inside of it, and I need to set it up as a Repeater Bridge (already done, works fine). But the thing is, there will be times where I'll need to connect it to other wifi networks or change the way the router behaves through a set of predefined commands. Later on it will eventually scan for nearby access points, return a list of SSID's (and ask for a passkey if required), but baby steps first, right?
Anyways, so main question: What's the best way to display (and later update) text on screen?
Current code (works)
Which shows up as:
Background: I'm building a custom Xbox with a stripped down Belkin wireless router with DD-WRT installed inside of it, and I need to set it up as a Repeater Bridge (already done, works fine). But the thing is, there will be times where I'll need to connect it to other wifi networks or change the way the router behaves through a set of predefined commands. Later on it will eventually scan for nearby access points, return a list of SSID's (and ask for a passkey if required), but baby steps first, right?
Anyways, so main question: What's the best way to display (and later update) text on screen?
Current code (works)
Code:
import xbmc, xbmcgui
import sys
import telnetlib
host = "192.168.1.2"
user = "root"
password = "admin"
tn = telnetlib.Telnet(host)
tn.read_until("login: ")
tn.write(user + "\n")
if password:
tn.read_until("Password: ")
tn.write(password + "\n")
tn.write("nvram show\n")
tn.write("exit\n")
nvram_result = tn.read_all()
ACTION_PREVIOUS_MENU = 10
class toolsmain(xbmcgui.Window):
def __init__(self):
self.strActionInfo = xbmcgui.ControlLabel(20, 20, 200, 600, '', 'font13', '0xFF00FF00')
self.addControl(self.strActionInfo)
self.strActionInfo.setLabel('DD-WRT Tools')
def onAction(self, action):
if action == ACTION_PREVIOUS_MENU:
self.confirmexit()
def confirmexit(self):
dialog = xbmcgui.Dialog()
if dialog.yesno("Confirm Exit", "Are you sure you want to exit?"):
self.close()
mydisplay = toolsmain()
mydisplay.strActionInfo.setLabel(nvram_result)
mydisplay .doModal()
del mydisplay
Which shows up as: