def game_loop(): panel_load = None parent = None while True: clock.tick(1) for event in pygame.event.get(): if event.type == pygame.KEYDOWN: if event.key == pygame.K_q: pygame.quit() quit() if event.type == pygame.QUIT: pygame.quit() quit() panel_time = os.stat(CONFIG_PATH).st_mtime_ns if panel_time != panel_load: parent = panel.Panel(lambda: pygame.Surface(SIZE), children=panel.load(CONFIG_PATH)) panel_load = panel_time screen.fill((0, 0, 0)) screen.blit(parent.surf, (0, 0)) pygame.display.flip()
def __init__(self, panelFile=None): # instantiate serial self.arduino = None try: self.arduino = arduino.Arduino() except Exception as e: print e.message if panelFile is None: # read from serial the panel id? pass else: self.panelFile = panelFile # build panel self.panels = dict() self.panels[1] = panel.Panel(self.panelFile, panelId=1) # the key is = to panelId self.currentPanelId = 1 # here the messages from Control will arrive # onOffQueue will contain string messages with 'on' and 'off' # panelQueue will contain panel that will be drawn # optionQueue will contain option that was selected self.onOffQueue = Queue.Queue() self.panelQueue = Queue.Queue() queues = (self.onOffQueue, self.panelQueue) # create GUI self.synchGUI = threading.Event() self.gui = GUI.GUI(queues, self.synchGUI) self.state = 'off'
def __init__(self, replace): pynotify.init("ibus") self.__bus = ibus.Bus() self.__bus.connect("disconnected", gtk.main_quit) self.__bus.connect("registry-changed", self.__registry_changed_cb) match_rule = "type='signal',\ sender='org.freedesktop.IBus',\ path='/org/freedesktop/IBus'" self.__bus.add_match(match_rule) self.__panel = panel.Panel(self.__bus) flag = ibus.BUS_NAME_FLAG_ALLOW_REPLACEMENT if replace: flag = flag | ibus.BUS_NAME_FLAG_REPLACE_EXISTING self.__bus.request_name(ibus.IBUS_SERVICE_PANEL, flag) self.__bus.get_dbusconn().add_signal_receiver( self.__name_acquired_cb, signal_name="NameAcquired") self.__bus.get_dbusconn().add_signal_receiver(self.__name_lost_cb, signal_name="NameLost") self.__notify = pynotify.Notification("IBus", \ _("Some input methods have been installed, removed or updated. " \ "Please restart ibus input platform."), \ "ibus") self.__notify.set_timeout(10 * 1000) self.__notify.add_action("restart", _("Restart Now"), self.__restart_cb, None) self.__notify.add_action("ignore", _("Later"), lambda *args: None, None)
def __init__(self, n=48, order='forward', saturation = 0, value = 0, rhost = '', subdivisions = 1, bordercolor = '', nodisplay = False): self.ecount = n self.rowmode = 'single' self.cgranularity = 1 self.mgranularity = 1 self.subdivisions = subdivisions if subdivisions > 1 and not bordercolor: bordercolor = '#000000' self.bordercolor = bordercolor self.rcount = n * 2 * self.subrectanglecount(True) * self.mgranularity self.perm = genperm(n, order=order) self.keys = range(0, n) self.lastorder = order cols = self.rcount/2 self.panel = panel.Panel(rows = 2, cols = cols, rwidth = int(1440/cols), nodisplay = nodisplay) if rhost: port = 8000 (host, s, p) = rhost.partition(':') if p: port = int(p) pn = panel.PanelClient(host, port) self.panel.addsubpanel(pn) if saturation > 0: self.spectrum_s = saturation if value > 0: self.spectrum_v = value self.colors = hsv.spectrum(n, self.spectrum_s, self.spectrum_v, granularity=self.colorgranularity(self.rowmode)) self.showsort()
def Pack(self): self._packed = 1 # useless, but included for compatibility if len(self.Children) == 1: import panel dummy = panel.Panel(self, size=(0,0)) dummy.Position = 0, 0 self.__dummy = dummy
def __init__(self): wx.Frame.__init__(self, None, wx.ID_ANY, "Threads Controlling a GUI", size=(500, 500)) # Add a panel so it looks the correct on all platforms panel.Panel(self)
def color(self, loc): "Get the color of a panel" # 1. If we don't have the current panel, create it if loc not in self.panels: self.panels[loc] = panel.Panel(loc=loc) # 2. Return the color of the panel return self.panels[loc].color()
def paint(self, loc, color): "Paint a panel" # 0. Preconditions assert color in panel.COLORS # 1. If we don't have the current panel, create it if loc not in self.panels: self.panels[loc] = panel.Panel(loc=loc) # 2. Pain the panel self.panels[loc].paint(color=color)
def __init__(self): self.body = body.Body() self.panel = panel.Panel(self.body) self.status = status.Status(self.body) self.edgepoint = None self.twinklers = [] self.shots = [] self.paused = False self.target = None self.healmode = False self.clearselections() self.clickat = None
def test_value_init(self): "Test Panel object creation with values" # 1. Create Panel object with values mypanel = panel.Panel(loc=(7, 11), color=panel.COLOR_WHITE) # 2. Make sure it has the specified values self.assertEqual(mypanel.loc, (7, 11)) self.assertEqual(mypanel.colored, panel.COLOR_WHITE) self.assertEqual(mypanel.history, [panel.COLOR_WHITE]) # 3. Check methods self.assertEqual(len(mypanel), 0) self.assertEqual(mypanel.painted(), False) self.assertEqual(mypanel.color(), panel.COLOR_WHITE) self.assertEqual(str(mypanel), '#')
def test_empty_init(self): """Test default Panel object creation""" # 1. Create default Panel object mypanel = panel.Panel() # 2. Make sure it has the default values self.assertEqual(mypanel.loc, (0, 0)) self.assertEqual(mypanel.colored, panel.COLOR_BLACK) self.assertEqual(mypanel.history, [panel.COLOR_BLACK]) # 3. Check methods self.assertEqual(len(mypanel), 0) self.assertEqual(mypanel.painted(), False) self.assertEqual(mypanel.color(), panel.COLOR_BLACK) self.assertEqual(str(mypanel), '.')
def run(name, args): rows = 2 cols = 40 port = 8000 rwidth = 0 rheight = 0 logging = False optimize = False nogetfqdn = False localhost = False optlist, args = getopt.getopt(args, 'hr:c:p:W:H:LOlf') for (opt,val) in optlist: if opt == '-h': usage(name) return elif opt == '-r': rows = int(val) elif opt == '-c': cols = int(val) elif opt == '-p': port = int(val) elif opt == '-W': rwidth = int(val) elif opt == '-H': rheight = int(val) elif opt == '-O': optimize = True elif opt == '-L': localhost = True elif opt == '-l': logging = True elif opt == '-f': nogetfqdn = True print 'Creating panel with rows = %d, cols = %d, rwidth = %d, rheight = %d' \ % (rows, cols, rwidth, rheight) if optimize: print 'Enabling socket optimization' if logging: print 'Enabling event logging' if nogetfqdn: print 'Disabling getfqdn' p = panel.Panel(rows, cols, rwidth, rheight) host = 'localhost' if localhost else socket.gethostname() print 'Running server on host %s, port %d' % (host, port) p.runserver(host, port, logging=logging, nodelay = optimize, nogetfqdn = nogetfqdn)
def __init__(self, title='', size=default_gui_size): """ Initialize the gr top block. Create the wx gui elements. @param title the main window title @param size the main window size tuple in pixels @param icon the file path to an icon or None """ #initialize gr.top_block.__init__(self) self._size = size #create gui elements self._app = wx.App() self._frame = wx.Frame(None, title=title) self._panel = panel.Panel(self._frame) self.Add = self._panel.Add self.GridAdd = self._panel.GridAdd self.GetWin = self._panel.GetWin
def __init__(self, n=48, order='forward', saturation=0, value=0, subdivisions=1, bordercolor='', nodisplay=False, rigBool=False, rig=[]): # just pass to panel self.rigBool = rigBool self.rig = rig print rigBool self.ecount = n self.rowmode = 'single' self.cgranularity = 1 self.mgranularity = 1 self.subdivisions = subdivisions if subdivisions > 1 and not bordercolor: bordercolor = '#000000' self.bordercolor = bordercolor self.rcount = n * 2 * self.subrectanglecount(True) * self.mgranularity self.perm = genperm(n, order=order) self.keys = range(0, n) self.lastorder = order cols = self.rcount / 2 self.panel = panel.Panel(rows=2, cols=cols, rwidth=int(1440 / cols), nodisplay=nodisplay, rigBool=self.rigBool, rig=self.rig) if saturation > 0: self.spectrum_s = saturation if value > 0: self.spectrum_v = value self.colors = hsv.spectrum(n, self.spectrum_s, self.spectrum_v, granularity=self.colorgranularity( self.rowmode)) self.showsort()
def test_painting(self): "Test painting the Panel object" # 1. Create default Panel object mypanel = panel.Panel() # 2. Paint it a couple of times mypanel.paint(panel.COLOR_WHITE) mypanel.paint(panel.COLOR_WHITE) mypanel.paint(panel.COLOR_BLACK) mypanel.paint(panel.COLOR_WHITE) mypanel.paint(panel.COLOR_WHITE) mypanel.paint(panel.COLOR_BLACK) # 3. Check the results self.assertEqual(len(mypanel), 6) self.assertEqual(mypanel.painted(), True) self.assertEqual(mypanel.color(), panel.COLOR_BLACK) self.assertEqual(str(mypanel), '.')
def do_ok(self): if self.state != 'off': option = self.panels[self.currentPanelId].currentOption if hasattr(option, 'turnOff'): self.onOffQueue.put_nowait('off') self.state = 'off' return 'OFF' if hasattr(option, 'deviceOperation') and not hasattr(option, 'objectId'): # operate a device and wait self._operate_device(self.panels[self.currentPanelId], option, option.deviceOperation) if hasattr(option, 'deviceOperation') and hasattr( option, 'objectId'): # the operation is about a device in another panel # the search in not efficient, but the number of panels and options is small for p in self.panels.values(): # loop through panels for o in p.options: # loop through option # is there an option with same id in the panel? if o.id == option.objectId: # so, the deviceOperation is about a device in the other panel self._operate_device(p, o, option.deviceOperation) if hasattr(option, 'panelId'): # create the new panel newPanelId = option.panelId if newPanelId in self.panels.keys(): p = self.panels[newPanelId] else: p = panel.Panel(self.panelFile, newPanelId) self.panels[newPanelId] = p self.currentPanelId = newPanelId self.panelQueue.put_nowait(p) # the GUI main loop will update the window automatically # wait a moment for the user to rest self.synchGUI.clear() time.sleep(2) # wait self.synchGUI.set()
def __init__(self): super().__init__() self.setFixedSize(600, 600) self.title = "Kółeczko - Serwer" self.setWindowTitle(self.title) self.menubar = self.menuBar() view = self.menubar.addMenu("Serwer") serwer = QAction("Uruchom serwer", self) serwer.setCheckable(True) view.addAction(serwer) view.triggered[QAction].connect(self.processSerwerAction) w = QWidget(self) l = QVBoxLayout() self.label = QLabel() self.label.setText("Serwer jest wyłączony") self.label.setFixedSize(600, 20) l.addWidget(self.label) l.addWidget(panel.Panel()) w.setLayout(l) self.setCentralWidget(w) self.show()
def __init__(self): pynotify.init("ibus") self.__bus = ibus.Bus() self.__bus.connect("disconnected", gtk.main_quit) self.__bus.connect("registry-changed", self.__registry_changed_cb) match_rule = "type='signal',\ sender='org.freedesktop.IBus',\ path='/org/freedesktop/IBus'" self.__bus.add_match(match_rule) self.__panel = panel.Panel(self.__bus) self.__bus.request_name(ibus.IBUS_SERVICE_PANEL, 0) self.__notify = pynotify.Notification("IBus", \ _("Some input methods have been installed, removed or updated. " \ "Please restart ibus input platform."), \ "ibus") self.__notify.set_timeout(10 * 1000) self.__notify.add_action("restart", _("Restart Now"), self.__restart_cb, None) self.__notify.add_action("ignore", _("Later"), lambda *args: None, None)
def __init__(self): super().__init__() self.setFixedSize(600, 600) self.title = "Kółeczko - Klient" self.setWindowTitle(self.title) self.menubar = self.menuBar() view = self.menubar.addMenu("Połączenie") polaczenie = QAction("Połącz z serwerem", self) view.addAction(polaczenie) w = QWidget(self) l = QVBoxLayout() self.slider = QSlider() self.slider.setOrientation(Qt.Horizontal) self.slider.setTickInterval(1) self.slider.setMinimum(10) self.slider.setMaximum(300) l.addWidget(self.slider) self.container = panel.Panel() l.addWidget(self.container) self.slider.valueChanged.connect(self.changedValue) w.setLayout(l) self.setCentralWidget(w) self.show()
def view(self): return pn.Panel(self.param)
self.update() # sleep a moment for the user to rest # and then wait for the command self.synch.wait() self.upFrame.aLabel.grid_forget() # Test class if __name__ == '__main__': from threading import Thread from time import sleep def simulate_control(arg): sleep(2) arg.next_option() sleep(2) arg.next_option() sleep(2) arg.switch() app = GUI(None) jsonFile = '../resources/sala.panel' panel = panel.Panel(jsonFile, 1) thread = Thread(target=simulate_control, args=(panel, )) thread.start() app.show_panel(panel) app.mainloop()
def __init__(self, master): self.master = master self.messages = { "add_main": False, "display_layers": False, "main_id": None, "add_part": False, "remove_main": False, "remove_part": False, "part_id": None, "draw_single": False, "draw_multiple": False, "spray": False, "which_button": 0, "event": None, "draw_release": False, "play_anim": False, "stop_anim": False, "anim_playing": False, "drawing_enabled": True, "colors": [PEN_INIT_LEFT_COLOR, PEN_INIT_RIGHT_COLOR, PEN_INIT_LEFT_COLOR], "fps": FPS_INIT, "change_tool": False, "tool": PEN, "tool_cursor": "pencil", "pen_hover": False, "circle_hover": False, "tool_hover_color": None, "hover_id": None, "tool_leave": False, "draw_circle": False, "cell_size": CELL_INIT_SIZE, "cells_x": CELLS_X_INIT, "cells_y": CELLS_Y_INIT, "grid_max_x": GRID_MAX, "grid_max_y": GRID_MAX, "cursor_x": 0, "cursor_y": 0, "new_project": False, "create_new_project": False, "new_project_width": NEW_PROJECT_INIT_SIZE_X, "new_project_height": NEW_PROJECT_INIT_SIZE_Y, "anim_index": 0, "export": False, "import_as_image": False, "import_as_layer": False, "save_project": False, "exit": False, "new_project_name": "New Project", "copy_from_image_id": None, "what_is_copied": None, "copy_from_part_id": None, "open_project": False, "show_help": False } self.menu_bar = am.AppMenu(master.master, self.messages) self.anim = an.Anim(master, self.messages, **ANIM_INIT) self.panel = pn.Panel(master, self.messages, **PANEL_INIT) self.grid = gd.Grid(master, self.panel, self.messages, **GRID_INIT) self.color_panel = cp.ColorPanel(master, self.messages) self.tools = ts.Tools(master, self.messages) self.width_var = StringVar(value=32) self.height_var = StringVar(value=30) self.name_var = StringVar(value="New Project")