File: htmhtm.py

package info (click to toggle)
frogatto-data 1.2%2Bdfsg-1
  • links: PTS, VCS
  • area: non-free
  • in suites: wheezy
  • size: 201,844 kB
  • sloc: python: 302; xml: 223; perl: 139; sh: 48; makefile: 13; ruby: 4
file content (130 lines) | stat: -rwxr-xr-x 3,761 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -> htmhtm - the synched .htm file viewing utility
# -> To run this you will require wxPython.
# -> Put the name of the htm or html files you want to compare in the LeftView and RightView variables.
# -> The right scrollbars effect only their window, the left scrollbars effect both windows.

LeftView = "/home/david/Documents/pots/it.po.html"
RightView = "/home/david/Documents/pots/pt_BR.po.html"



import wx
import  wx.html as  html

class MySplitter(wx.SplitterWindow):
	def __init__(self, parent, ID):
		wx.SplitterWindow.__init__(self, parent, ID,
								   style = wx.SP_LIVE_UPDATE
								   )
		
		self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self.OnSashChanged)
		self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGING, self.OnSashChanging)

	def OnSashChanged(self, evt):
		#print "sash changed to %s" % str(evt.GetSashPosition())
		pass

	def OnSashChanging(self, evt):
		#print "sash changing to %s" % str(evt.GetSashPosition())
		# uncomment this to not allow the change
		#evt.SetSashPosition(-1)
		pass
	
		
		
# This shows how to catch the OnLinkClicked non-event.  (It's a virtual
# method in the C++ code...)
class MyHtmlWindow(html.HtmlWindow):
	def __init__(self, parent, id):
		html.HtmlWindow.__init__(self, parent, id, style=wx.NO_FULL_REPAINT_ON_RESIZE)
		if "gtk2" in wx.PlatformInfo:
			self.SetStandardFonts()
		
		self.Bind(wx.EVT_SCROLLWIN, self.OnScroll)
		
	def OnScroll(self, evt):
		#print "scroll " + str(evt.GetPosition())
		if(evt.GetOrientation() == 8):
			self.Scroll(self.GetViewStart()[0], evt.GetPosition())
		else:
			self.Scroll(evt.GetPosition(), self.GetViewStart()[1])
			
	def SetSynch(self, target):
		print "set target " + str(target)
		self.synch = target
		
class MyHtmlSynchWindow(html.HtmlWindow):
	def __init__(self, parent, id):
		html.HtmlWindow.__init__(self, parent, id, style=wx.NO_FULL_REPAINT_ON_RESIZE)
		if "gtk2" in wx.PlatformInfo:
			self.SetStandardFonts()
		
		self.Bind(wx.EVT_SCROLLWIN, self.OnScroll)
		
	def OnScroll(self, evt):
		#print "scroll " + str(evt.GetPosition())
		if(evt.GetOrientation() == 8):
			delta = self.GetViewStart()[1] - evt.GetPosition()
			self.Scroll(self.GetViewStart()[0], self.GetViewStart()[1]-delta)
			self.synch.Scroll(self.synch.GetViewStart()[0], self.synch.GetViewStart()[1]-delta)
		else:
			delta = self.GetViewStart()[0] - evt.GetPosition()
			self.Scroll(self.GetViewStart()[0]-delta, self.GetViewStart()[1])
			self.synch.Scroll(self.synch.GetViewStart()[0]-delta, self.synch.GetViewStart()[1])
			
	def SetSynch(self, target):
		print "set target " + str(target)
		self.synch = target


class Example(wx.Frame):
	def __init__(self, parent, title):
		super(Example, self).__init__(parent, title=title, 
			size=(1200, 800))
			
		self.InitUI()
		self.Show()	 
		
	def InitUI(self):
		splitter = MySplitter(self, -1)
		sty = wx.BORDER_SUNKEN
		

		p1 = wx.Panel(splitter, style=sty)
		p1.SetBackgroundColour("pink")
		#wx.StaticText(p1, -1, "Panel One", (5,5))

		p2 = wx.Panel(splitter, style=sty)
		p2.SetBackgroundColour("sky blue")
		wx.StaticText(p2, -1, "Panel Two", (5,5))
		
		self.html = MyHtmlSynchWindow(p1, 10)
		self.html.LoadPage(LeftView)

		self.box1 = wx.BoxSizer(wx.VERTICAL)
		self.box1.Add(self.html, 1, wx.EXPAND | wx.ALL, 2)
		p1.SetSizer(self.box1)
		
		self.html_ = MyHtmlWindow(p2, 11)
		self.html_.LoadPage(RightView)

		self.box2 = wx.BoxSizer(wx.VERTICAL)
		self.box2.Add(self.html_, 1, wx.EXPAND | wx.ALL, 2)
		p2.SetSizer(self.box2)
		
		self.html.SetSynch(self.html_)
		self.html_.SetSynch(self.html)
		
		splitter.SetMinimumPaneSize(500)
		splitter.SplitVertically(p1, p2, -100)
		
		


if __name__ == '__main__':
  
	app = wx.App()
	Example(None, title='HtmHtm')
	app.MainLoop()