class AutoRemoteServer(object): def __init__(self, triggers): self.wifi_location = None self.triggers = triggers def main(self): self.device_mgr = UPnPDeviceManager() self.device_mgr.connect("device-available", self.device_available) self.device_mgr.connect("device-unavailable", self.device_unavailable) self.world = WorldData() triggerfile = os.path.expanduser("~/.triggers.json") if not os.path.exists(triggerfile): f = open(triggerfile, 'w') f.write('[]') f.close() self.triggermaster = TriggerMaster(simplejson.load( open(triggerfile)), self.device_mgr) GObject.timeout_add(1000, self.process_triggers) GObject.timeout_add(5000, self.device_mgr.list_cur_devices) import gtk gtk.main() def process_triggers(self): print "Processing Triggers / Advancing Time" self.world.advance_time() self.triggermaster.run_triggers(self.world) return True def device_available(self, manager, device): print "Device available", device.get_friendly_name() def device_unavailable(self, manager, device): print "Device unavailable", device.get_friendly_name()
def main(self): self.device_mgr = UPnPDeviceManager() self.device_mgr.connect("device-available", self.device_available) self.device_mgr.connect("device-unavailable", self.device_unavailable) self.world = WorldData() triggerfile = os.path.expanduser("~/.triggers.json") if not os.path.exists(triggerfile): f = open(triggerfile, 'w') f.write('[]') f.close() self.triggermaster = TriggerMaster(simplejson.load( open(triggerfile)), self.device_mgr) GObject.timeout_add(1000, self.process_triggers) GObject.timeout_add(5000, self.device_mgr.list_cur_devices) import gtk gtk.main()
def build_trigger_creation_window(self, button=None): self.actions = [] trigger_types = TriggerMaster.getTriggerTypes() liststore = gtk.ListStore(str, object) trigger_list = gtk.ComboBox(liststore) cellpb = gtk.CellRendererPixbuf() cell = gtk.CellRendererText() trigger_list.pack_start(cellpb, False) trigger_list.pack_start(cell, True) trigger_list.add_attribute(cell, 'text', 0) trigger_list.get_model().append(["Select a Trigger Type", None]) for trigger_type in TriggerMaster.getTriggerTypes(): trigger_list.get_model().append([trigger_type.__name__, trigger_type]) trigger_list.set_active(0) trigger_list.connect("changed", self.trigger_type_changed) trigger_type = gtk.Label("Trigger Type:") trigger_type.show() trigger_list.show() self.trigger_list = trigger_list self.trigger_form = gtk.Table(rows=1, columns=2) self.trigger_form.attach(trigger_type, 0, 1, 0, 1) self.trigger_form.attach(trigger_list, 1, 2, 0, 1) self.trigger_form.show() (label, input) = inpututils.Entry("Name").draw() self.trigger_name = input self.trigger_form.attach(label, 0, 1, 1, 2) self.trigger_form.attach(input, 1, 2, 1, 2) self.action_form = gtk.Table(rows=1, columns=2) self.action_form.show() add_action = gtk.Button("Add Another Action") add_action.show() add_action.connect("clicked", self.add_action) submit = gtk.Button("Save") submit.show() submit.connect("clicked", self.save_trigger) buttons = gtk.HBox() buttons.pack_start(add_action) buttons.pack_start(submit) buttons.show() form_holder = gtk.VBox() form_holder.pack_start(self.trigger_form, False) form_holder.pack_start(self.action_form, False) form_holder.pack_end(buttons, False) form_holder.show() # if self.add_action_by_default: # self.add_action(None) return form_holder