Skip to content

Instantly share code, notes, and snippets.

@thefinn93
Created July 4, 2012 09:23
Show Gist options
  • Save thefinn93/3046320 to your computer and use it in GitHub Desktop.
Save thefinn93/3046320 to your computer and use it in GitHub Desktop.
CJDNS GUI
#!/usr/bin/env python
import wx
import os
class MainWindow(wx.Frame):
def __init__(self, parent, title):
self.dirname = ''
# A "-1" in the size parameter instructs wxWidgets to use the default size.
# In this case, we select 200px width and the default height.
wx.Frame.__init__(self, parent, title=title, size=(200, -1))
self.control = wx.Panel(self)
self.wangs = wx.StaticText(self.control, label="wangs", pos=(0, 0))
self.CreateStatusBar() # A Statusbar in the bottom of the window
# Setting up the menu
filemenu = wx.Menu()
menuAbout = filemenu.Append(wx.ID_ABOUT, "&About", " Information about this program")
menuExit = filemenu.Append(wx.ID_EXIT, "E&xit", " Terminate the program")
# Creating the menubar.
menuBar = wx.MenuBar()
menuBar.Append(filemenu, "&File") # Adding the "filemenu" to the MenuBar
self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content.
# Events.
# self.Bind(wx.EVT_MENU, self.OnOpen, menuOpen)
self.Bind(wx.EVT_MENU, self.OnExit, menuExit)
self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)
self.sizer2 = wx.BoxSizer(wx.HORIZONTAL)
self.buttons = []
for i in range(0, 6):
self.buttons.append(wx.Button(self, -1, "Button &" + str(i)))
self.sizer2.Add(self.buttons[i], 1, wx.EXPAND)
# Use some sizers to see layout options
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.control, 1, wx.EXPAND)
self.sizer.Add(self.sizer2, 0, wx.EXPAND)
#Layout sizers
self.SetSizer(self.sizer)
self.SetAutoLayout(1)
self.sizer.Fit(self)
self.Show()
def OnAbout(self, e):
# Create a message dialog box
dlg = wx.MessageDialog(self, " A sample editor\nin wxPython", "About Sample Editor", wx.OK)
dlg.ShowModal() # Shows it
dlg.Destroy() # finally destroy it when finished.
def OnExit(self, e):
self.Close(True) # Close the frame.
def OnOpen(self, e):
""" Open a file"""
dlg = wx.FileDialog(self, "Choose a file", self.dirname, "", "*.*", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
self.filename = dlg.GetFilename()
self.dirname = dlg.GetDirectory()
f = open(os.path.join(self.dirname, self.filename), 'r')
self.control.SetValue(f.read())
f.close()
dlg.Destroy()
app = wx.App(False)
frame = MainWindow(None, "Sample editor")
app.MainLoop()
#! /usr/bin/env python
import ConfigParser
import sys
import json
import pynotify
pynotify.init("Hyperboria Node Finder")
def new(ip, link, path):
n = pynotify.Notification("New Hyperboira Node!", ip)
n.show()
# print "Got a new one! " + ip
path = "/home/finn/Dropbox/projects/hyperboria/NewNode/"
parser = ConfigParser.SafeConfigParser()
parser.read([path + 'config.ini'])
adminPassword = parser.get('cjdns', 'adminPassword')
adminPort = parser.getint('cjdns', 'adminPort')
importpath = parser.get("cjdns", "importpath")
sys.path.append(importpath)
from cjdns import cjdns_connect
cjdns = cjdns_connect("127.0.0.1", adminPort, adminPassword)
knownnodes = json.load(open(path + "known_nodes.json"))
#print "Loaded " + str(len(knownnodes)) + " nodes"
more = True
i = 0
while more:
# print ">Loading page " + str(i)
dump = cjdns.NodeStore_dumpTable(i)
more = "more" in dump
for node in dump["routingTable"]:
if not node['ip'] in knownnodes:
new(node['ip'], node['link'], node['path'])
knownnodes.append(node['ip'])
i = i + 1
json.dump(path + "known_nodes.json", open(nodefile, "w"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment