pronterface.py에서 graph.py를 분석하면 알기 쉽습니다.
이 클래스 선언을 살펴보면
class Graph(BufferedCanvas):
'''A class to show a Graph with Pronterface.'''
클래스 생성자에
def __init__(self, parent, id, root, pos = wx.DefaultPosition,
size = wx.Size(150, 80), style = 0, parent_graph = None):
# Forcing a no full repaint to stop flickering
style = style | wx.NO_FULL_REPAINT_ON_RESIZE
super(Graph, self).__init__(parent, id, pos, size, style)
self.root = root
이렇게 Timer를 생성하고,
self.timer = wx.Timer(self)
그 타이머 처리기에 self.updateTemperatures를 지정해줍니다.
self.Bind(wx.EVT_TIMER, self.updateTemperatures, self.timer)
그러면 해당 타이머가 실행될 때 self.updateTemperatures함수가 불리게 됩니다.
def updateTemperatures(self, event):
self.AddBedTemperature(self.bedtemps[-1])
self.AddBedTargetTemperature(self.bedtargettemps[-1])
self.AddExtruder0Temperature(self.extruder0temps[-1])
self.AddExtruder0TargetTemperature(self.extruder0targettemps[-1])
self.AddExtruder1Temperature(self.extruder1temps[-1])
self.AddExtruder1TargetTemperature(self.extruder1targettemps[-1])
self.AddFanPower(self.fanpowers[-1])
if self.rescaley:
self._ybounds.update()
self.Refresh() # 이 호출로 draw() 라는 함수가 불리게 된다.
def draw(self, dc, w, h):
dc.SetBackground(wx.Brush(self.root.settings.graph_color_background))
dc.Clear()
gc = wx.GraphicsContext.Create(dc) # dc로부터 gc를 생성한다.
self.width = w
self.height = h
self.drawgrid(dc, gc)
self.drawbedtargettemp(dc, gc)
self.drawbedtemp(dc, gc)
self.drawfanpower(dc, gc)
self.drawextruder0targettemp(dc, gc)
self.drawextruder0temp(dc, gc)
if self.extruder1targettemps[-1]>0 or self.extruder1temps[-1]>5:
self.drawextruder1targettemp(dc, gc)
self.drawextruder1temp(dc, gc)
이제 남은 문제는 그래프 영역의 크기를 무엇이 결정하는가이다.
그래프 영역을 화면에 추가하는 코드는 gui/controls.py에 있다.
if root.display_graph:
root.graph = Graph(parentpanel, wx.ID_ANY, root)
add("tempgraph", root.graph, flag = wx.EXPAND | wx.ALL, border = 5)
root.graph.Bind(wx.EVT_LEFT_DOWN, root.graph.show_graph_window)
로그 영역은 gui/_init_.py에 다음과 같이 추가하는 코드가 있는데,
크기랑 위치는 어떻게 지정하는지 아직 잘 모르겠다.
log_pane = LogPaneToggleable(self, logpanel, [self.lowersizer])
left_pane.parentsizers.append(self.splitterwindow)
logpanel.SetSizer(log_pane)
wxPython 예제를 찾아서 보는 게 더 빠를지도 모르겠다.
하여튼 주말까지는 계속 노력할 예정.
생각이 바뀌었습니당.
wxPython 튜터리얼 보기로 했습니다. ㅋㅋㅋ
'실전 임베디드' 카테고리의 다른 글
| pronterface Graph 박스 부분 (0) | 2019.10.05 |
|---|---|
| wxPython GUI 만들기 설명 (0) | 2019.10.05 |
| STM32F407 Flash Memory Map (0) | 2019.10.05 |
| 웹에서 큰 파일 이어올리기 (0) | 2019.10.04 |
| Python Pycharm BesutifulSoup 4 설치 (0) | 2019.10.04 |