old_contents: from telescope import LST
  from windows import TelescopeEventView
  import Tkinter as tk
  from itertools import cycle
  import numpy as np
  from read import ReadProtoBuf
  from threading import Event
  
  from collections import deque
  
  queue = deque(maxlen=100)
  stop_event = Event()
  
  
  def check_queue():
      if len(queue) > 0:
          root.event_generate('<<new_event>>')
      root.after(10, check_queue)
  
  
  def handle_new_event(event):
      viewer = next(viewers)
      event = queue.popleft()
      viewer.data = np.array(event.data)
  
  
  lst = LST(position_x=0, position_y=0, telescope_id=0)
  
  root = tk.Tk()
  
  reader = ReadProtoBuf(
      '127.0.0.1',
      5000,
      queue,
      stop_event,
  )
  
  
  top = tk.Frame(root)
  bottom = tk.Frame(root)
  
  viewer1 = TelescopeEventView(top, lst)
  viewer2 = TelescopeEventView(top, lst)
  viewer3 = TelescopeEventView(top, lst)
  viewer4 = TelescopeEventView(bottom, lst)
  viewer5 = TelescopeEventView(bottom, lst)
  viewer6 = TelescopeEventView(bottom, lst)
  
  viewers = cycle(
      [viewer1, viewer2, viewer3, viewer4, viewer5, viewer6]
  )
  
  viewer1.pack(side=tk.LEFT, expand=True, fill=tk.BOTH)
  viewer2.pack(side=tk.LEFT, expand=True, fill=tk.BOTH)
  viewer3.pack(side=tk.LEFT, expand=True, fill=tk.BOTH)
  viewer4.pack(side=tk.LEFT, expand=True, fill=tk.BOTH)
  viewer5.pack(side=tk.LEFT, expand=True, fill=tk.BOTH)
  viewer6.pack(side=tk.LEFT, expand=True, fill=tk.BOTH)
  
  root.bind('<<new_event>>', handle_new_event)
  top.pack(side=tk.TOP, expand=True, fill=tk.BOTH)
  bottom.pack(side=tk.BOTTOM, expand=True, fill=tk.BOTH)
  
  
  if __name__ == '__main__':
      try:
          reader.start()
          root.after(1, check_queue)
          root.mainloop()
      except (SystemExit, KeyboardInterrupt):
          pass
      stop_event.set()
  
new_contents: '''
  A viewer for cta events, currently only LSTs are supported
  
  Usage:
      cta_event_viewer.py [options]
  
  Options:
      --ip=<ip>       the ip to listen to [default: 127.0.0.1]
      --port=<port>   the port to listen to [default: 5000]
      --rows=<rows>   number of rows of telescope views [default: 2]
      --cols=<cols>   number of columns of telescope views [default: 2]
  '''
  from telescope import LST
  from windows import TelescopeEventView
  import Tkinter as tk
  from itertools import cycle
  import numpy as np
  from read import ReadProtoBuf
  from threading import Event
  
  from collections import deque
  from docopt import docopt
  
  args = docopt(__doc__)
  
  queue = deque(maxlen=100)
  stop_event = Event()
  
  
  def check_queue():
      if len(queue) > 0:
          root.event_generate('<<new_event>>')
      root.after(10, check_queue)
  
  
  def handle_new_event(event):
      viewer = next(viewers)
      event = queue.popleft()
      print(len(queue))
      viewer.data = np.array(event.data)
  
  
  root = tk.Tk()
  
  reader = ReadProtoBuf(
      args['--ip'],
      args['--port'],
      queue,
      stop_event,
  )
  
  viewers = []
  for i in range(int(args['--rows'])):
      root.rowconfigure(i, weight=1)
      for j in range(int(args['--cols'])):
          root.columnconfigure(j, weight=1)
          viewer = TelescopeEventView(root, LST, cmap='hot')
          viewer.grid(row=i, column=j, sticky='nswe')
          viewers.append(viewer)
  
  viewers = cycle(viewers)
  root.bind('<<new_event>>', handle_new_event)
  
  
  if __name__ == '__main__':
      try:
          reader.start()
          root.after(1, check_queue)
          root.mainloop()
      except (SystemExit, KeyboardInterrupt):
          pass
      stop_event.set()
  
subject: use command line options for port, ip and layout