WPF Web View
import clr
clr.AddReference("PresentationFramework")
clr.AddReference("PresentationCore");
clr.AddReference('System.Data')
clr.AddReference('System.Windows.Forms')
import System
from System import *
from System.Data import *
from System.Type import GetType
from System.Threading.Tasks import Task
from System.Windows import *
from System.Windows.Controls import *
from System.Windows.Controls.Primitives import *
from System.Windows.Media import *
from System.Windows.Media.Imaging import *
from System.Windows.Media.Effects import *
from System.Windows.Shapes import Rectangle
from System.Windows.Data import Binding
from System.Windows.Ink import Stroke
from System.Windows.Forms import ( FolderBrowserDialog, DialogResult )
from Microsoft.Win32 import ( OpenFileDialog, SaveFileDialog )
import ctrl
import vbox
import hbox
class WpfWeb():
def __init__(self,url=None,tool=False):
self.web = WebBrowser()
self.ctrl = self.web
self.web.Navigated += self.loaded_hndler
if tool:
self.vbox = vbox.WpfVBox()
self.hbox = hbox.WpfHBox()
self.text = TextBox()
self.hbox.add_item(self.button("<-", self.back_handler))
self.hbox.add_item(self.button("->", self.forward_handler))
self.hbox.add_item(self.button("<>", self.refresh_handler))
self.hbox.add_item(self.text, {'expand':True})
self.hbox.add_item(self.button("Go", self.go_Handler))
self.vbox.add_item(self.hbox.ctrl)
self.vbox.add_item(self.web,expand=True)
self.ctrl = self.vbox.ctrl
if url: self.go(url)
def button(self,label,handler): b = Button(); b.Content = label; b.Click += handler; return b
def loaded_hndler(self,sender,args): self.text.Text = self.web.Source.ToString()
def go_Handler(self,sender,args):
uri = self.text.Text
if not uri.startswith('http'): uri = "http://" + uri; self.text.Text = uri
self.Go(uri)
def back_handler(self,sender,args): self.back()
def forward_handler(self,sender,args): self.forward()
def refresh_handler(self,sender,args): self.refresh()
def go(self,uri): self.web.Navigate(System.Uri(uri, System.UriKind.RelativeOrAbsolute));
def back(self):
if self.web.CanGoBack: self.web.GoBack()
def forward(self):
if self.web.CanGoForward: self.web.GoForward()
def refresh(self): self.web.Refresh()
def html(self): return self.web.Document.documentElement.InnerHtml
if __name__ == "__main__":
import win
app = win.Win("Web Demo",320,240)
b = WpfWeb("http://google.co.kr", tool=True)
app.set_content(b.ctrl)
app.run()
댓글 없음:
댓글 쓰기