项目作者: shenghaoyang

项目描述 :
Python LCDd client (LCDproc server client)
高级语言: Python
项目地址: git://github.com/shenghaoyang/pylcddc.git
创建时间: 2018-04-18T05:57:20Z
项目社区:https://github.com/shenghaoyang/pylcddc

开源协议:MIT License

下载


pylcddc

A python library for interfacing with LCDd, the server
component of the commonly known LCDproc

Features:

  • Object-oriented interface support for all native
    LCDd widgets

    • Full frame support, nest widget objects in frames, treat frames
      like widget containers
    • Support for user-created composite widgets, that can be used just
      like native widgets (no easy API for now, changes to come later)
  • Decoupled thread to service LCDd screen switching responses

  • One I/O method to update screen, no funky exception handling everywhere

Installation

pip install pylcddc

More TODOs

  • See TODO.md for more information and TODOs

Version support

  • Tested on LCDd packaged with LCDproc version 0.5.9
  • Protocol version 0.3

Modules for users

  • pylcddc.client: client for LCDd
  • pylcddc.screen: screens to attach to clients
  • pylcddc.widgets: widgets to place in screens
  • pylcddc.exceptions: exceptions raised by the library

Modules for developers

  • pylcddc.responses: LCDd response decoder and abstractions
  • pylcddc.commands: LCDd request generation

Examples

Don’t really use these for production code…

See more examples in /demo

Simple usage for static display

  1. import pylcddc.client as client
  2. import pylcddc.widgets as widgets
  3. import pylcddc.screen as screen
  4. title = widgets.Title('title_widget',
  5. 'Hello, World!')
  6. main_scr = screen.Screen('main', [title])
  7. c = client.Client('localhost', 13666)
  8. c.add_screen(main_scr)
  9. input('Press any key to exit')
  10. c.close()

Nest widgets in frames

  1. import pylcddc.client as client
  2. import pylcddc.widgets as widgets
  3. import pylcddc.screen as screen
  4. import platform
  5. flavorful_text_widgets = [widgets.String(f'flv_tx{i}', 1, 1 + i, text) for
  6. i, text in enumerate(
  7. 'now you see me\nnow you dont\nso scary\nsuch wow'.splitlines())]
  8. frame_top = widgets.Frame('frame_top', flavorful_text_widgets,
  9. 1, 1, 10, 1, 10, 4,
  10. widgets.Frame.Direction.VERTICAL, 8)
  11. platform_text = widgets.Scroller('platform', 1, 2, 20, 1,
  12. widgets.Scroller.Direction.HORIZONTAL, 1,
  13. 'pylcddc running on '
  14. + ' '.join(platform.uname()))
  15. main_scr = screen.Screen('main', [frame_top, platform_text])
  16. c = client.Client('localhost', 13666)
  17. c.add_screen(main_scr)
  18. input('Press any key to exit')
  19. c.close()

Simple timed display updates and display attributes

  1. import pylcddc.client as client
  2. import pylcddc.widgets as widgets
  3. import pylcddc.screen as screen
  4. import pylcddc.exceptions as lcdexcept
  5. import time
  6. time_string = widgets.Scroller('time', 1, 1, 20, 2,
  7. widgets.Scroller.Direction.HORIZONTAL, 8,
  8. time.ctime())
  9. main_scr = screen.Screen('main', [time_string],
  10. heartbeat=screen.ScreenAttributeValues.Heartbeat.OFF)
  11. c = client.Client('localhost', 13666)
  12. c.add_screen(main_scr)
  13. print('pylcdd time demo\nUse ^C to exit')
  14. try:
  15. while True:
  16. time_string.text = time.ctime()
  17. c.update_screens([main_scr])
  18. print('updated time to: ', time.ctime())
  19. time.sleep(0.1)
  20. except lcdexcept.RequestError as e:
  21. print('LCDd refused our request', e)
  22. except lcdexcept.FatalError as e:
  23. print('pylcddc fatal internal error', e)
  24. except KeyboardInterrupt:
  25. print('exitting')
  26. c.close() # there might be exceptions from OS system call failures here

Licensing

See LICENSE.txt for more details