wx,html 모듈을 이용하는 첫째 소스는 http 프로토콜만 지원하고 https 프로토콜은 지원하지 않습니다.

그러나,  wx,html2 모듈을 이용하는 둘째 소스는 http 프로토콜과 https 프로토콜 모두를 지원합니다.

셋째 소스는 둘째 소스에 네비게이터(뒤로 가기, 앞으로 가기) 가능을 추가한 소스입니다.

[1] wx.html 모듈을 이용한 소스: simple_html_browser.py

# -*- coding: utf-8 -*-
#!/usr/bin/env python

# Filename: simple_html_browser.py
# Execute: python simple_html_browser.py
#    or
# Execute: ./simple_html.browser.py

import wx
import wx.html

class MyHtmlDialog(wx.Dialog):
    def __init__(self, parent, title):
        wx.Dialog.__init__(self, parent, -1, title, size=(600,400))
        html = wx.html.HtmlWindow(self)
        if "gtk2" in wx.PlatformInfo:
            html.SetStandardFonts()

        wx.CallAfter(html.LoadPage, "http://www.google.com")

if __name__ == "__main__":
    app = wx.App()
    dlg = MyHtmlDialog(None, "Simple HTML Browser")
    dlg.ShowModal()
    dlg.Destroy()
    app.MainLoop()

 

[2] wx.html2 모듈을 이용한 소스: simple_html2_browser.py

# -*- coding: utf-8 -*-
#!/usr/bin/env python

# Filename: simple_html2_browser.py
# Execute: python simple_html2_browser.py
#    or
# Execute: ./simple_html2_browser.py

import wx
import wx.html2

class MyHtml2Dialog(wx.Dialog):
    def __init__(self, parent, title):
        wx.Dialog.__init__(self, parent, -1, title, size=(600,400))
        html = wx.html2.WebView.New(self)
        if "gtk2" in wx.PlatformInfo:
            html.SetStandardFonts()

        wx.CallAfter(html.LoadURL, "https://www.google.com")

if __name__ == "__main__":
    app = wx.App()
    dlg = MyHtml2Dialog(None, "Simple HTML2 Browser")
    dlg.ShowModal()
    dlg.Destroy()
    app.MainLoop()

 

 

[3] 위의 둘째 것을 쓸 만 한하게 수정한 웹 브라우저 소스: simple_browser_wk.py

# -*- coding: utf-8 -*-
#!/usr/bin/env python

# Filename: simple_browser_wk.py
#
# Execute: python3 simple_browser_wk.py
#    or
# Execute: pythonw simple_browser_wk.py
#    or
# Execute: ./simple_browser_wk.py
#
# Date: 2020.11.29   Version 0.0.4

import wx 
import wx.html2 

class MyBrowser(wx.Frame): 
    def __init__(self, parent, title): 
        super(MyBrowser, self).__init__(parent, title = title,size = (800,400))  
        sizer = wx.BoxSizer(wx.VERTICAL) 

        hsizer = wx.BoxSizer(wx.HORIZONTAL) 
        emptyText = wx.StaticText(self, -1 , "     ", (10, 10), (10, -1))
        emptyText.SetBackgroundColour('#DDDDDD')
        self.addrText = wx.TextCtrl(self, wx.ID_ANY, value="", size=(300, 30))
        self.addrText.SetFont( wx.Font(12, wx.ROMAN, wx.NORMAL, wx.NORMAL)  )
        self.addrText.SetBackgroundColour('white')
        self.addrText.Bind(wx.EVT_CHAR, self.OnCharEvent)
        self.prevButton = wx.Button(self, 1, '<', (10, 10), (20, -1))
        self.prevButton.Bind(wx.EVT_BUTTON, self.OnPrevButton, id=1)
        self.nextButton = wx.Button(self, 1, '>', (10, 10), (20, -1))
        self.nextButton.Bind(wx.EVT_BUTTON, self.OnNextButton, id=1)
        self.homeButton = wx.Button(self, 1, 'Home', (10, 10), (80, -1))
        self.homeButton.Bind(wx.EVT_BUTTON, self.OnHomeButton, id=1)
        self.exitButton = wx.Button(self, 1, 'Exit', (10, 10), (80, -1))
        self.exitButton.Bind(wx.EVT_BUTTON, self.OnCloseButton, id=1)

        hsizer.Add(self.exitButton, 3, wx.EXPAND, 10) 
        hsizer.Add(self.homeButton, 3, wx.EXPAND, 10) 
        hsizer.Add(self.prevButton, 1, wx.EXPAND, 10) 
        hsizer.Add(self.nextButton, 1, wx.EXPAND, 10) 
        hsizer.Add(self.addrText, 30, wx.EXPAND, 10) 
        hsizer.Add(emptyText, 1, wx.EXPAND, 10) 
        sizer.Add(hsizer, 1, wx.EXPAND, 10) 
        self.browser = wx.html2.WebView.New(self) 
        sizer.Add(self.browser, 20, wx.EXPAND, 10) 
        self.SetSizer(sizer) 
        self.SetSize((800, 700)) 
        self.Bind(wx.html2.EVT_WEBVIEW_NAVIGATED, self.OnNavigated)
        self.OpenWebPage("https://www.google.com")

    def OnCharEvent(self, event):
        keycode = event.GetKeyCode()
        controlDown = event.CmdDown()
        altDown = event.AltDown()
        shiftDown = event.ShiftDown()

        if (not shiftDown) and (not altDown) and (not controlDown) and keycode == 13 :      # [Enter] key
            self.OpenWebPage(self.addrText.GetValue())

    def OnCloseButton(self, event):
        self.Destroy()
        quit()

    def OnHomeButton(self, event):
        self.OpenWebPage("https://scripting.tistory.com")
        event.Skip()

    def OnPrevButton(self, event):
         if self.browser.CanGoBack():
             self.browser.GoBack()
         event.Skip()

    def OnNextButton(self, event):
         if self.browser.CanGoForward():
             self.browser.GoForward()
         event.Skip()

    def OnNavigated(self, event): 
        self.addrText.SetLabel(self.browser.CurrentURL)
        # print(self.browser.CurrentTitle)
        self.SetTitle("SimpleBrowser - {0}".format(self.browser.CurrentTitle))
        event.Skip()

    def OpenWebPage(self, addr): 
        self.browser.LoadURL(addr)
        self.SetTitle("Simpl Browser")
        self.addrText.SetLabel(addr)
        self.Show() 


if __name__ == "__main__":	
    ex = wx.App() 
    f = MyBrowser(None,'Simple Btowser') 
    f.Show()
    ex.MainLoop()
    

 

 

 

 

 

Posted by Scripter

댓글을 달아 주세요

최근(2020년 11월 21일)에 릴리즈 4.1.1이 발표되었습니다.

C++ 언어로 작성된 wxPython은 Python2 와 Python3  모두에 사용가능한

Python의 GUI 래퍼(wrapper)입니다.

 

[1] wxPython 홈페이지

[2] wxPython 4.1.1 설치하기

   처음 설치 명령: pippip install wxPython==4.1.1

   업그레이드 명령: pippip install --upgrade wxPython==4.1.1

 

[3] 설치 후 버전 확인하기

>>> import wx
>>> wx.version()
'4.1.1 msw (phoenix) wxWidgets 3.1.5'
>>> wx.__version__
'4.1.1'

[4] 설치된 wxPython의 버전을 확인하는 GUI 소스

# -*- coding: utf-8 -*-
#!/usr/bin/env python

# Filename: versionGUI.py
#
# Date: 2020.11.28

import wx


class VersionDialog(wx.Dialog):
    def __init__(self, parent, title):
        wx.Dialog.__init__(self, parent, -1, title, size=(475, 240))
        self.sbox = wx.StaticBox(self, -1, 'Version Information', (10, 20), size=(440, 100))        
        self.sbox.SetFont( wx.Font(10, wx.ROMAN, wx.NORMAL, wx.NORMAL)  )
        
        font = wx.Font(11, wx.ROMAN, wx.NORMAL, wx.NORMAL) 
        a = wx.StaticText(self, -1 , "wx.version() = {0}".format(wx.version()), (15, 60))
        a.SetFont( font )
        b = wx.StaticText(self, -1 , "wx.__version__ = %s" % wx.__version__, (15, 85))
        b.SetFont( font )
        
        wx.StaticLine(self, 1,  (15, 145), (430, 2))
        wx.Button(self, 1, 'Okay', (340, 165), (100, -1))
        self.Bind(wx.EVT_BUTTON, self.OnClose, id=1)

    def OnClose(self, event):
        self.Destroy()
        quit()


if __name__ == "__main__":
    app = wx.App()
    dia = VersionDialog(None, "Version of wxPython")
    dia.ShowModal()
    if dia != None:
        dia.Destroy()
    app.MainLoop()

실행 결과:

 

 

 

Posted by Scripter

댓글을 달아 주세요

간단한 정수 계산, 분수 계산, 복소수 계산, 벡터 계산, 다항식 계산, 조립제법 등을

웹 상에서 바로 할 수 있는 Simple Web Calculator 입니다.

 

[ 정수 계산 예시 ]

Posted by Scripter

댓글을 달아 주세요