【发布时间】:2013-08-16 01:51:54
【问题描述】:
我正在编写一个基于状态机的 python 程序,该程序当前将机器的状态打印到控制台。这作为日志很有用,但不是最用户友好的界面。
我很想知道是否有在 Python 中使用 ncurses 的好例子,最好是在 OOP 中在表格中呈现变化信息(例如:状态信息)的东西。
已经尝试过python中的curses包,但是它不像我想要的那样OO。
这是流当前的样子:
manager: st_machine_01 state INITIALISE
manager: st_machine_01 state GET_LIST_PAGES
manager: st_machine_02 state EXIT
manager: st_machine_03 state INITIALISE
manager: st_machine_03 state GET_LIST_PAGES
manager: st_machine_04 state EXIT
manager: st_machine_05 state INITIALISE
manager: st_machine_05 state GET_LIST_PAGES
manager: st_machine_01 state GET_LIST_PAGES
manager: st_machine_05 state GET_LIST_PAGES
manager: st_machine_05 state EXIT
manager: st_machine_01 state GET_LIST_PAGES
manager: st_machine_06 state INITIALISE
manager: st_machine_06 state GET_LIST_PAGES
manager: st_machine_01 state GET_LIST_PAGES
manager: st_machine_06 state GET_LIST_PAGES
manager: st_machine_01 state EXIT
manager: st_machine_06 state GET_LIST_PAGES
manager: st_machine_07 state INITIALISE
manager: st_machine_07 state GET_LIST_PAGES
manager: st_machine_06 state GET_LIST_PAGES
manager: st_machine_06 state EXIT
而在上述流的最后一点呈现的 ncurses “表格”看起来像:
manager: st_machine_01 state EXIT
manager: st_machine_02 state EXIT
manager: st_machine_03 state GET_LIST_PAGES
manager: st_machine_04 state EXIT
manager: st_machine_05 state EXIT
manager: st_machine_06 state EXIT
manager: st_machine_07 state GET_LIST_PAGES
我正在寻求在 Python 2.7 64 位、Windows 7 64 位上执行此操作。
【问题讨论】:
-
机器正常运行时看起来还不错。如果您将显示限制为仅 7 行和一个状态或 cmd 行,您可以在状态更改时短暂闪烁屏幕。如果您快速重新打印新状态,它看起来会很酷。你可以在最后一行添加一个日志条目,
st_machine_05 changed to Get_List_Pages from state Exit...
标签: python ncurses state-machine