) print() if x == 'p': state = 1 break elif x == 'b': state = 2 break elif x == 's': state = 0 break else: print("Please just input (p)ing, (b)link or (s)top.\n") s = "Where to send ? " for name in lamp_dict.values(): y = name[5:] s = s + "%s " % y.replace(y[0], "(%s)" % y[0], 1) if len(lamp_dict) > 1: s = s + "or (a)ll : " else: s = s + " : " while True: kbd_inp = input(s) print() first_letter_list = [y[5] for y in lamp_dict.values()] if kbd_inp in first_letter_list: k = [y for y in lamp_dict.values() if kbd_inp == y[5]] globals()[k[0]].alert_set(state) break
cyan = (0x01, 0x00, 0x7f, 0x7f) blue = (0x01, 0x00, 0xfe, 0x01) magenta = (0x01, 0x7f, 0x7f, 0x00) my_colors = (red, yellow, green, cyan, blue, magenta) it = 0 pos = 0 while it < 10: print("loop # %s" % it) pos = 0 while pos <= 5: color = my_colors[pos] for lamp in lamp_dict.values(): hl_obj = globals()[lamp] hl_obj.color_set(color) print("%s got translated in the bulb to %s!" % (colored( color, 'green'), colored(hl_obj.color_get(), 'green'))) pos += 1 sleep(0.4) it += 1 for lamp in lamp_dict.values(): hl_obj = globals()[lamp] hl_obj.prop_chg_notify.kill()
def __init__(self, app): Gtk.Window.__init__(self, title="Box Test", application=app) #self.set_default_size(40, 40) self.set_border_width(10) self.set_position(Gtk.WindowPosition.CENTER) self.settings = Gtk.Settings.get_default() self.hb = Gtk.HeaderBar() self.hb.set_show_close_button(True) self.hb.set_title("Philips Hue Drive") self.set_titlebar(self.hb) hue_button = Gtk.MenuButton() pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( os.path.join(pwd, "bulb_icon.jpg"), 40, 40, preserve_aspect_ratio=True) image = Gtk.Image.new_from_pixbuf(pixbuf) hue_button.add(image) main_menu = Gtk.Menu() hue_button.set_popup(main_menu) self.hb.pack_start(hue_button) fun_menu_item = Gtk.MenuItem(label="Hue Fun") main_menu.append(fun_menu_item) fun_submenu = Gtk.Menu() fun_menu_item.set_submenu(fun_submenu) dark_theme_cmi = Gtk.CheckMenuItem(label="dark-theme") dark_theme_cmi.connect("activate", self.dark_theme_cmi_selected) dark_theme_cmi.set_active(True) fun_submenu.append(dark_theme_cmi) menuitem = Gtk.MenuItem(label="pass") fun_submenu.append(menuitem) menuitem = Gtk.MenuItem(label="pass") fun_submenu.append(menuitem) menuitem = Gtk.MenuItem(label="pass") fun_submenu.append(menuitem) admin_menu_item = Gtk.MenuItem(label="Hue Admin") main_menu.append(admin_menu_item) admin_submenu = Gtk.Menu() admin_menu_item.set_submenu(admin_submenu) menuitem = Gtk.MenuItem(label="import new Bulb") admin_submenu.append(menuitem) lamp_dict_mi = Gtk.MenuItem(label="show lamp_dict") lamp_dict_mi.connect('activate', self.lamp_dict_mi_selected) admin_submenu.append(lamp_dict_mi) quit_mi = Gtk.MenuItem(label="Quit") quit_mi.connect('activate', self.quit_menuitem_selected) admin_submenu.append(quit_mi) main_menu.show_all() self.vbox = Gtk.VBox(spacing=10) for lamp in lamp_dict.values(): hl_obj = globals()[lamp] dynamic_grid = Gtk.Grid() mir_adjust = Gtk.Adjustment(value=326, lower=153, upper=500, step_increment=20, page_increment=20, page_size=0) mir_scale = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL, adjustment=mir_adjust) mir_scale.set_value_pos(Gtk.PositionType.RIGHT) mir_scale.set_value(hl_obj.mired_get()) mir_scale.set_digits(0) mir_scale.set_hexpand(True) mir_scale.set_vexpand(False) mir_scale.connect("value-changed", self.mir_scale_moved, hl_obj) col_adjust = Gtk.Adjustment(value=3, lower=0, upper=5, step_increment=1, page_increment=1, page_size=0) col_scale = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL, adjustment=col_adjust) col_scale.set_value_pos(Gtk.PositionType.RIGHT) #col_scale.set_value(hl_obj.color_get()) col_scale.set_digits(0) col_scale.set_hexpand(True) col_scale.set_vexpand(False) col_scale.connect("value-changed", self.col_scale_moved, hl_obj) bri_label = Gtk.Label() bri_label.set_text("brightness") bri_adjust = Gtk.Adjustment(value=126, lower=1, upper=254, step_increment=10, page_increment=10, page_size=0) bri_scale = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL, adjustment=bri_adjust) bri_scale.set_value_pos(Gtk.PositionType.RIGHT) bri_scale.set_value(hl_obj.brightness_get()) bri_scale.set_digits(0) bri_scale.set_hexpand(True) bri_scale.set_vexpand(False) bri_scale.connect("value-changed", self.bri_scale_moved, hl_obj) tra_label = Gtk.Label() tra_label.set_text("transitiontime") tra_adjust = Gtk.Adjustment(value=1, lower=0, upper=4, step_increment=1, page_increment=1, page_size=0) tra_scale = Gtk.Scale(orientation=Gtk.Orientation.HORIZONTAL, adjustment=tra_adjust) tra_scale.set_value_pos(Gtk.PositionType.RIGHT) tra_scale.set_value(hl_obj.transitiontime_get()) tra_scale.set_digits(0) tra_scale.set_hexpand(True) tra_scale.set_vexpand(False) tra_scale.connect("value-changed", self.tra_scale_moved, hl_obj) bulb_name_entry = Gtk.Entry() bulb_name_entry.set_placeholder_text( "Please input a new lamp name:") bulb_name_entry.set_max_length(20) bulb_name_entry.connect("activate", self.bulb_name_entry_input, hl_obj) #bulb_name_entry.set_activates_default(True) #bulb_name_entry.grab_focus_without_selecting() lamp_label = Gtk.Label() lamp_label.props.halign = Gtk.Align.START lamp_label.set_text(lamp) #lamp_label.set_text(hl_obj.name_get()) on_off_switch = Gtk.Switch() on_off_switch.props.valign = Gtk.Align.CENTER on_off_switch.props.halign = Gtk.Align.END on_off_switch.set_tooltip_text("Off <> On") if hl_obj.on_off_state() == "on": on_off_switch.set_active(True) else: on_off_switch.set_active(False) on_off_switch.connect("notify::active", self.on_off_switch_activated, hl_obj) mir_col_tb = Gtk.ToggleButton() mir_col_tb.connect("toggled", self.mir_col_tb_toggled, hl_obj, dynamic_grid, lamp_label, mir_col_tb, mir_scale, col_scale) mir_col_tb.set_active(True) lamp_menu_button = Gtk.MenuButton() pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale( os.path.join(pwd, "bulb_icon.jpg"), 28, 28, preserve_aspect_ratio=True) image = Gtk.Image.new_from_pixbuf(pixbuf) lamp_menu_button.add(image) lamp_menu_button.props.halign = Gtk.Align.START lamp_menu = Gtk.Menu() lamp_menu_button.set_popup(lamp_menu) bulb_name_cmi = Gtk.CheckMenuItem(label="set bulb name") transitiontime_cmi = Gtk.CheckMenuItem(label="transitiontime") transitiontime_cmi.connect("activate", self.transitiontime_cmi_selected, hl_obj, dynamic_grid, tra_label, tra_scale, bulb_name_cmi) lamp_menu.append(transitiontime_cmi) bulb_name_cmi.connect("activate", self.bulb_name_cmi_selected, hl_obj, dynamic_grid, bulb_name_entry, transitiontime_cmi) lamp_menu.append(bulb_name_cmi) lamp_menu.show_all() dynamic_grid.set_border_width(0) dynamic_grid.set_column_homogeneous(True) #dynamic_grid.set_row_homogeneous(False) dynamic_grid.set_column_spacing(5) #dynamic_grid.set_row_spacing(40) dynamic_grid.attach(on_off_switch, 0, 1, 1, 1) dynamic_grid.attach(lamp_menu_button, 0, 1, 1, 1) dynamic_grid.attach(bri_label, 1, 1, 1, 1) dynamic_grid.attach(bri_scale, 2, 1, 1, 1) self.vbox.pack_start(dynamic_grid, False, False, 0) self.add(self.vbox)
for lamp in hl: hl_obj = globals()[lamp] hl_obj.brightness_set(bri) already_send = "no" elif key == "q": print("\nbye bye (;-)\n") break else: print("Please just use + or - or (q)uit.") print("\n###### Alter the lamp's brightness ######\n") s = "Where to send ? " for name in lamp_dict.values(): y = name[5:] s = s + "%s " % y.replace(y[0], "(%s)" % y[0], 1) if len(lamp_dict) > 1: s = s + "or (a)ll : " else: s = s + " : " while True: kbd_inp = input(s) print() first_letter_list = [y[5] for y in lamp_dict.values()] if kbd_inp in first_letter_list: k = [y for y in lamp_dict.values() if kbd_inp == y[5]] brightness_alter(k) break