코드를 사용하여 콘솔 화면을 만들려고 시도하는 동안 'AttributeError'가 레이아웃을 만들고 레이아웃에 일부 텍스트를 표시합니다. 다음으로 레이아웃은 urwid 라이브러리의 원시 디스플레이 모듈을 사용하여 콘솔 화면에 표시됩니다. (내 전체 프로젝트에 대한 더 많은 정보는 widget advice for a console project과 urwid for a console project에서 얻을 수 있습니다. 내 스카이프 도움말 요청은 here입니다.) 그러나 아래에 설명 된 것처럼 AttributeError가 발생하면서 코드를 실행하는 데 실패합니다. /usr/lib64/python2.7/site-packages/urwid에서 urwid에 대한 소스 코드를 살펴보면 main_loop.py와 curses_display.py가 draw_screen 함수에 다른 인수를 가지고있는 것을 볼 수 있습니다 : main_loop.py -> def draw_screen 자기) :아래의 코드는
curses_display.py> 데프 draw_screen (자기 (COLS 행), R) :
내가 specificFile 명령에서 수입 draw_screen처럼 무언가에 의해 사용되는 하나를 지정해야합니까? 아니면 근본적으로 잘못된 캔버스 컨셉을보고 있습니까? 나는 또한 프레임 클래스 (클래스 프레임 (BoxWidget) :) 볼 수있는 파일의 /usr/lib64/python2.7/site-packages/urwid/ container.py는 렌더링 기능을 가지고있다 (데프 렌더링 (자기, 크기, 초점 = 거짓) :)
코드를 실행에오류는 다음과 같습니다
Traceback (most recent call last):
File "./yamlUrwidUIPhase6.py", line 104, in <module>
main() File "./yamlUrwidUIPhase6.py", line 98, in main
form.main()
File "./yamlUrwidUIPhase6.py", line 51, in main
self.loop.run()
File "/usr/lib64/python2.7/site-packages/urwid/main_loop.py", line 274, in run
self.screen.run_wrapper(self._run)
File "/usr/lib64/python2.7/site-packages/urwid/raw_display.py", line 237, in run_wrapper return fn()
File "/usr/lib64/python2.7/site-packages/urwid/main_loop.py", line 285, in _run self.draw_screen()
File "/usr/lib64/python2.7/site-packages/urwid/main_loop.py", line 508, in draw_screen
canvas = self._topmost_widget.render(self.screen_size, focus=True)
AttributeError: 'NoneType' object has no attribute 'render'
코드 :
import sys
sys.path.append('./lib')
import os
from pprint import pprint
import random
import urwid
ui=urwid.raw_display.Screen()
class FormDisplay(object):
def __init__(self):
global ui
self.ui = ui
self.palette = self.ui.register_palette([
('Field', 'dark green, bold', 'black'), # information fields, Search: etc.
('Info', 'dark green', 'black'), # information in fields
('Bg', 'black', 'black'), # screen background
('InfoFooterText', 'white', 'dark blue'), # footer text
('InfoFooterHotkey', 'dark cyan, bold', 'dark blue'), # hotkeys in footer text
('InfoFooter', 'black', 'dark blue'), # footer background
('InfoHeaderText', 'white, bold', 'dark blue'), # header text
('InfoHeader', 'black', 'dark blue'), # header background
('BigText', RandomColor(), 'black'), # main menu banner text
('GeneralInfo', 'brown', 'black'), # main menu text
('LastModifiedField', 'dark cyan, bold', 'black'), # Last modified:
('LastModifiedDate', 'dark cyan', 'black'), # info in Last modified:
('PopupMessageText', 'black', 'dark cyan'), # popup message text
('PopupMessageBg', 'black', 'dark cyan'), # popup message background
('SearchBoxHeaderText', 'light gray, bold', 'dark cyan'), # field names in the search box
('SearchBoxHeaderBg', 'black', 'dark cyan'), # field name background in the search box
('OnFocusBg', 'white', 'dark magenta') # background when a widget is focused
])
urwid.set_encoding('utf8')
def main(self):
global ui
#self.view = ui.run_wrapper(formLayout)
self.ui.start()
self.view = formLayout()
self.loop = urwid.MainLoop(self.view, self.palette, unhandled_input=self.unhandled_input)
self.loop.run()
def unhandled_input(self, key):
if key == 'f8':
quit()
return
def formLayout():
global ui
text1 = urwid.Text("Urwid 3DS Application program - F8 exits.")
text2 = urwid.Text("One mission accomplished")
textH = urwid.Text("topmost Pile text")
cols = urwid.Columns([text1,text2])
pile = urwid.Pile([textH,cols])
fill = urwid.Filler(pile)
textT = urwid.Text("Display")
textSH = urwid.Text("Pile text in Frame")
textF = urwid.Text("Good progress !")
frame = urwid.Frame(fill,header=urwid.Pile([textT,textSH]),footer=textF)
dim = ui.get_cols_rows()
#ui is treated as global handle for all functions, either belonging
#to any class or standalone functions such as formLayout
#need to check if screen has been started
if not ui._started:
print("Screen has not been started, so no use of rendering.Thus return :-(")
return
ui.draw_screen(dim, frame.render(dim, True))
return
def RandomColor():
'''Pick a random color for the main menu text'''
listOfColors = ['dark red', 'dark green', 'brown', 'dark blue',
'dark magenta', 'dark cyan', 'light gray',
'dark gray', 'light red', 'light green', 'yellow',
'light blue', 'light magenta', 'light cyan', 'default']
color = listOfColors[random.randint(0, 14)]
return color
def main():
form = FormDisplay()
form.main()
########################################
##### MAIN ENTRY POINT
########################################
if __name__ == '__main__':
main()
난 몰라 이 기본 코드 프레임 워크에 더 많은 것을 추가하려고하면 formLayout 함수를 변경하려고합니다. 여기서 yml 파일의 값을 읽는 기준으로 화면을 계속 업데이트하기 위해 formLayout을 반복적으로 호출하는 다른 함수가 추가됩니다. 나는 이미 yaml 파일을 읽고 주문 된 사전을 추출하는 것을 다루는 별도의 코드를 가지고있다. 기본 콘솔을 작동시키는 방법을 파악한 후에 두 가지를 통합하여 최종 응용 프로그램을 만들 수 있습니다.
캔버스에'dir'을 실행할 수 있고 얻은 것을 볼 수 있습니까? Python REPL ofc. –
나는 캔버스에 달리는 것이 무엇을 의미하는지 이해하지 못했다. 나는 그 명령이 명령이라는 것을 알고 있는데, 어디에서 명령을 내리고 싶습니까? –
python repl을 엽니 다. 클래스를 가져 와서'frame' 클래스에서'dir'을 실행하십시오. 렌더링이 존재하는지 확인하십시오. 그런 다음'widget'의'dir()'에서'dir'을 실행하여'render'가 실제로 있는지 확인하십시오. –