2013-08-16 2 views
1

현재 기계의 상태를 콘솔에 출력하는 상태 기반의 Python 프로그램을 작성하고 있습니다. 이것은 로그로서 유용하지만 사용자 친화적 인 인터페이스는 아닙니다.Python ncurses 템플릿, 테이블

파이썬에서 ncurses를 사용하는 좋은 예가 있는지 알고 싶습니다. 테이블에 변화하는 정보 (예 : 상태 정보)를 제공하는 OOP의 것이 좋을 것 같습니다.

이미 파이썬에서 curses 패키지를 시도했지만, 원하는대로 OO가 아닙니다.

스트림이 현재 모습입니다 같은 :

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 

난 :

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를 "테이블"과 같이 보일 것입니다 반면 Python 2.7 64 비트, Windows 7 64 비트에서이 작업을 수행하려고합니다.

+0

기계가 제대로 작동하면 꽤 잘 보입니다. 디스플레이를 7 행과 상태 또는 cmd 행으로 제한하면 상태가 변경 될 때마다 화면을 brifly 플래싱 할 수 있습니다. 새로운 상태를 빨리 재 인쇄하면 매우 멋지게 보일 것입니다. 마지막 행에 로그 항목을 추가 할 수 있습니다.'st_machine_05가 상태 종료에서 Get_List_Pages로 변경되었습니다 .' ... – Dru

답변

0

표준 curses 모듈을 사용할 수 있습니다. 설명서 here을 찾을 수 있습니다.

+0

curses 패키지가 원하는만큼 완벽하지 않습니다. – dilbert

+0

질문에 추가 조건을 추가 할 수 있습니까? 감사. –

0

curses이 충분하지 않은 경우 (일부 명시되지 않은 이유로) pycdk 또는 urwid이 사용자의 요구에 더 적합 할 수 있습니다.

0

.

ncurses 패키지는 매우 OO가 아니지만 OO 방식을 사용하면 이점을 얻을 수 있습니다. 이러한 몇 가지 클래스에서의 ncurses 패키지에 대한 모든 액세스를 유지하는 경우

class screen { 
    class rectangle { 
    class line { 
     string default_text="please enter a command (press 'e' to list available events) >> "; 
    } 
    } 
} 

sm_window = new screen("sc1").new rectangle("log_rect", lines=7); 
log_rect.line[7] = "st_machine_05 changed to Get_List_Pages from state Exit"; 

당신은 멀리 당신을 따라 고추의 ncurses는 기존의 응용 프로그램을 통해 모든 호출하는 경우에 비해 수 있습니다.

어떤 이유로 든 비공개 필드를 비공개로 설정하지 않은 경우 스크린 클래스에서 필요한 모든 프로그램 데이터에 액세스 할 수 있습니다.

+0

필자는 이전에 파이썬에서 ncurses를 사용했으며, 말하듯이 ncurses가 모든 곳에서 호출되어 "후춧가루를 뿌린"것이므로 OO로 이동하고 GUI 기반 프레임 워크와 같은 이벤트 구동 형을 얻고 싶습니다. – dilbert

+1

저는 파이썬을 배우려고 생각하고 있었고 도움을 줄 것이라고 생각했습니다. – Dru