Example #1
0
def main():
    logging.basicConfig(level=logging.DEBUG, filename="/tmp/squiggly.log")

    # Add movement using h/j/k/l to default command map
    urwid.command_map["k"] = urwid.CURSOR_UP
    urwid.command_map["j"] = urwid.CURSOR_DOWN
    urwid.command_map["h"] = urwid.CURSOR_LEFT
    urwid.command_map["l"] = urwid.CURSOR_RIGHT

    client = Client()

    view = SquigglyView()
    view.load_group_view(client.list_groups())

    def on_select_group(group_item):
        name = group_item.data["name"]
        data = client.list_topics(name)
        view.load_topic_view(data)

    def on_topic_more(topic_listbox):
        group = topic_listbox.data["group"]
        after = topic_listbox.data["last"]
        order = topic_listbox.data["order"]
        period = topic_listbox.data["period"]
        data = client.list_topics(group, after, order, period)
        topic_listbox.load_more(data)

    def on_topic_select(topic_listbox):
        topic_id = topic_listbox.data["id36"]
        data = client.get_topic(topic_id)
        view.load_comment_view(data)

    view.connect_signal("group_select", on_select_group)
    view.connect_signal("topic_more", on_topic_more)
    view.connect_signal("topic_select", on_topic_select)

    event_loop = urwid.SelectEventLoop()
    main_loop = urwid.MainLoop(view, palette, event_loop=event_loop)

    try:
        main_loop.run()
    except KeyboardInterrupt:
        pass
Example #2
0
 def setUp(self):
     self.evl = urwid.SelectEventLoop()
Example #3
0
    config_file = os.path.expanduser('~')
    if config_file != '~':
        config_file = os.path.join(config_file, '.urmpc.conf')
        if not os.path.isfile(config_file):
            config_file = os.path.join(os.environ.get('HOME', ''),
                                       '.urmpc.conf')
            if not os.path.isfile(config_file):
                config_file = os.path.join('urmpclib', 'urmpc.conf.example')
                if not os.path.isfile(config_file):
                    raise IOError('Configuration file not found.')

    config.read(config_file)
    palette = configuration.extract_palette(config, 'palette')
    mpc = urmpd.MPDClient()
    mpc.connect(config.mpd.host, int(config.mpd.port))
    event_loop = urwid.SelectEventLoop()

    # Get urwid set up
    #FIXME: Passing None in here is ugly and will eventually break if urwid decides
    #       to be more strict about it.
    loop = urwid.MainLoop(None, palette, event_loop=event_loop)
    signals._mainloop = loop

    # Main widget uses mpd
    frame = MainFrame(mpc)
    loop.widget = frame

    # Idler runs cloned mpc connection, uses MainLoop to force redraw on MPD events
    idler = urmpd.Idler(mpc, loop)
    event_loop.watch_file(idler, idler)
Example #4
0
    if arg == 'abort':
      pass
    else:
      self.save_on_quit = arg
      raise urwid.ExitMainLoop

def quit(obj):
  pane.set_overlay('save')

manager = TListManager(tlist_io.load_list_data())
pane = OverlayPane(manager)
sig_handler = SignalHandler(pane)

urwid.connect_signal(pane, 'save', sig_handler.save)

event = urwid.SelectEventLoop()
loop = urwid.MainLoop(pane, event_loop=event, pop_ups=True, handle_mouse=True)

while True:
  with loop.start():
    try:
      event.run()
    except KeyboardInterrupt:
      pane.set_overlay('save')
  if sig_handler.background:
    os.kill(sig_handler.PID, signal.SIGTSTP)
    sig_handler.background = False
    signal.signal(signal.SIGTSTP, sig_handler.SIGTSTP)
  elif sig_handler.save_on_quit:
    if sig_handler.save_on_quit == 'yes':
      tlist_io.save_all(manager.pull_list_data())