View
120
Download
5
Category
Preview:
DESCRIPTION
Python Essential 세미나. 2001. 5. 22( 화 ). GUI Programming - Part 2 ( GUI for Python - wxPython ). 발표자 : 최용준. Python’s GUI Binding (1). Tkinter “TK interface” TK GUI toolkit / Python standard module Unix, Windows, Mac 등에서 사용 PyGTK Gtk+(Gimp Tool Kit) widget 을 위한 Python binding. - PowerPoint PPT Presentation
Citation preview
Python Essential 세미나 1
Python Essential Python Essential 세미나세미나
GUI Programming - Part 2
( GUI for Python - wxPython )
발표자 : 최용준
2001. 5. 22(2001. 5. 22( 화화 ))
Python Essential 세미나 2
Python’s GUI Binding (1)
• Tkinter– “TK interface”– TK GUI toolkit / Python standard module– Unix, Windows, Mac 등에서 사용
• PyGTK– Gtk+(Gimp Tool Kit) widget 을 위한 Py
thon binding
Python Essential 세미나 3
Python’s GUI Binding (2)
• Gnome-python– GNOME 의 Python binding
• PyQt– Python 의 Qt 확장모듈
• PyKDE– Python 의 KDE 확장모듈
• Etc…– WPY(MFC, Tk), Pmw(Tkinter), FXPY(F
OX GUI lib. Interface)
Python Essential 세미나 4
wxPython Module
• wxWindows GUI lib. 를 Python 에서 사용하기 위한 Python 확장 모듈
• C 와 C++, SWIG(Simplified Wrapper and Interface Generator), Python 으로 작성
Python Essential 세미나 5
wxWindows, native API
wxWindows
GTK+ MotifWindows API
Mac
Windows System
OS
Native API
Python Essential 세미나 6
wxPython, wxWindows
Python Application Program
wxPython Module
wxWindows
GTK+ Windows API
Windows System
OS
Python Essential 세미나 7
wxWindows
• C++ 로 작성된 Cross-platform GUI library
• MS-Windows(w) 와 X-Window(x)에서 사용 가능하다는 뜻의 wx
• 현재 Windows, X-Window, Mac에서 사용가능
Python Essential 세미나 8
wxWindows 특징 (1)
• 최소한의 코드 수정으로 cross platform C++ 응용프로그램 작성
• Native API 에 대해 각각의 wxWindows 버전이 존재 , native GUI 의 ‘ look and feel’ 을 갖음
• 파일복사 , 삭제 , 소켓 , 쓰레드등 운영체제간 공통적인 기능을 제공
• 스트링 , 배열 , 링크드리스트 , 해시테이블등의 데이터 구조
Python Essential 세미나 9
wxWindows 특징 (2)
• Qt, BeOS, OS/2, Windows CE, QNX/Photon, FLT 로의 포팅도 고려하고 있고 일부 개발중
Python Essential 세미나 10
wxPython 특징• Python 과 wxWindows 의 특징을
모두 가짐• 현재는 Gtk+, Windows 버전만 지원• 대부분의 wxWindows 클래스를 구현• Python 과 C++ 언어상의 특징 때문에
차이점 존재– Argument pointer 로 결과값을 반환하는
경우– 오버로딩된 함수를 사용하는 경우
Python Essential 세미나 11
wxPython 예제 1 (1)from wxPython.wx import *
class MyApp(wxApp): def OnInit(self): frame = wxFrame(NULL, -1, "Hello from wxPython") frame.Show(true) self.SetTopWindow(frame) return true
app = MyApp(0)app.MainLoop()
Python Essential 세미나 13
wxPython 클래스 구조
• Application Class– 화면에 보이지 않는 부분– OS 로부터 이벤트를 받아 처리– 무한루프 ( 이벤트 드리븐 방식 )
• Main Frame Class– 화면에 보이는 부분– 버튼 , 컨크롤등의 배치
Python Essential 세미나 14
wxPython 예제 2 (1)from wxPython.wx import *
ID_ABOUT = 101ID_EXIT = 102
class MyFrame(wxFrame): def __init__(self, parent, ID, title): wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, wxSize(200, 150)) self.CreateStatusBar() self.SetStatusText("This is the statusbar")
menu = wxMenu() menu.Append(ID_ABOUT, "&About", "More information about this program") menu.AppendSeparator() menu.Append(ID_EXIT, "E&xit", "Terminate the program")
menuBar = wxMenuBar() menuBar.Append(menu, "&File");
self.SetMenuBar(menuBar)
class MyApp(wxApp): def OnInit(self): frame = MyFrame(NULL, -1, "Hello from wxPython") frame.Show(true) self.SetTopWindow(frame) return true
app = MyApp(0)app.MainLoop()
Python Essential 세미나 16
wxPython EVENTEVT_SIZE 프로그램 창의 크기가 변했을 때 발생
EVT_MOVE 프로그램 창의 위치가 이동되었을 때 발생
EVT_CLOSE 메인 프레임이 닫혔을 때 발생
EVT_PAINT 프로그램의 일부분이 가려져 , 다시 그려져야 할 필요가 있을 때
EVT_CHAR 키보드가 눌렸을 때 발생
EVT_IDLE 시스템이 어떠한 이벤트를 처리하고 않는 유휴기간일때 발생
EVT_LEFT_DOWN 마우스 왼쪽 버튼이 눌려졌을 때 발생
EVT_LEFT_UP 마우스 왼쪽 버튼을 눌렀다가 뗄 때 발생
EVT_LEFT_DCLICK 마우스 왼쪽 버튼을 더블 클릭 할 때 발생
EVT_MOTION 마우스를 움직일 때 발생
EVT_SCROLL 스크롤 바에서 스크롤을 하게 될 때 발생
EVT_BUTTON 버튼을 클릭했을 때 발생
EVT_MENU 메뉴 항목을 눌렀을 때 발생
Python Essential 세미나 17
wxPython 예제 3 (1)from wxPython.wx import *
ID_ABOUT = 101ID_EXIT = 102
class MyFrame(wxFrame): def __init__(self, parent, ID, title): wxFrame.__init__(self, parent, ID, title, wxDefaultPosition, wxSize(200, 150))
self.CreateStatusBar() self.SetStatusText("This is the statusbar") menu = wxMenu() menu.Append(ID_ABOUT, "&About", "More information about this program") menu.AppendSeparator() menu.Append(ID_EXIT, "E&xit", "Terminate the progra
m") menuBar = wxMenuBar() menuBar.Append(menu, "&File"); self.SetMenuBar(menuBar)
EVT_MENU(self, ID_ABOUT, self.OnAbout) EVT_MENU(self, ID_EXIT, self.TimeToQuit)
def OnAbout(self, event): dlg = wxMessageDialog(self, "This sample program sh
ows off\n" "frames, menus, statusbars, and this\n" "message dialog.", "About Me", wxOK | wxICON_INFOR
MATION) dlg.ShowModal() dlg.Destroy()
def TimeToQuit(self, event): self.Close(true)
class MyApp(wxApp): def OnInit(self): frame = MyFrame(NULL, -1, "Hello from wxPython") frame.Show(true) self.SetTopWindow(frame) return true
app = MyApp(0)app.MainLoop()
Python Essential 세미나 19
wxPython Programming Style
• 객체 ( 컨트롤 ) 를 생성• 객체에 해당하는 속성을 세팅• 적절한 이벤트를 객체와 연결시킴• 만들어진 객체가 화면에 보이도록
함• 사용자의 입력 ( 반응 ) 을 기다림
Recommended