Welcome, guest | Sign In | My Account | Store | Cart
from Tkinter import *

class SimultaneousPanels(PanedWindow):

 	def __init__(self):
		self.collectionOfPanedsWindows = {}

	def create_widget(self,master, tag= '_default', **kargs):
		widget = PanedWindow(master, **kargs)
		widget.other_paneds_windows = []

		if tag in self.collectionOfPanedsWindows:
			for pwindow in self.collectionOfPanedsWindows[tag]:
				widget.other_paneds_windows.append(pwindow)
				pwindow.other_paneds_windows.append(widget)

			self.collectionOfPanedsWindows[tag].append(widget)
		else:
			self.collectionOfPanedsWindows[tag] = [widget]


		widget.bind('<Button-1>', self.sash_mark)
		widget.bind('<B1-Motion>', self.sash_dragto)

		return widget

	def sash_mark(self,event):
		this_widget = event.widget

		identity = this_widget.identify(event.x, event.y)

		if len(identity) ==2:
			index = identity[0]
			this_widget.activedSash=index
		else:
			this_widget.activedSash = None

	def sash_dragto(self,event):
		this_widget = event.widget
		activedSash = this_widget.activedSash

		if activedSash != None:
			for pwindow in this_widget.other_paneds_windows:
				pwindow.sash_place(activedSash, event.x, event.y)

def test():

	def _print(x,y):
		print "Window: %s; Pane: %s" %(x,y)
	root = Tk()
	root.geometry("190x350")

	connectedPanels = SimultaneousPanels()

	for i in range(3):
		m = connectedPanels.create_widget(root, bd=1, orient=VERTICAL,sashwidth=2,sashrelief=RIDGE)
		m.place(x=30,y=30+100*i)

		for j in range(3):
			panel= Label(m, text="panel number %s" %j)
			m.add(panel)

	root.mainloop()

if __name__ == '__main__':
	test()

Diff to Previous Revision

--- revision 1 2014-05-07 22:13:44
+++ revision 2 2014-06-03 20:31:40
@@ -1,63 +1,64 @@
 from Tkinter import *
 
-class ParallelPanedWindows(PanedWindow):
-	
-	collectionOfPanedsWindows = {}
-	
-	def __init__(self, master, tag= 'default', **kargs):
-		
-		PanedWindow.__init__(self, master, **kargs)
-		
-		self.other_paneds_windows = []
-		
+class SimultaneousPanels(PanedWindow):
+
+ 	def __init__(self):
+		self.collectionOfPanedsWindows = {}
+
+	def create_widget(self,master, tag= '_default', **kargs):
+		widget = PanedWindow(master, **kargs)
+		widget.other_paneds_windows = []
+
 		if tag in self.collectionOfPanedsWindows:
 			for pwindow in self.collectionOfPanedsWindows[tag]:
-				self.other_paneds_windows.append(pwindow)
-				pwindow.other_paneds_windows.append(self)
-				
-			self.collectionOfPanedsWindows[tag].append(self)
+				widget.other_paneds_windows.append(pwindow)
+				pwindow.other_paneds_windows.append(widget)
+
+			self.collectionOfPanedsWindows[tag].append(widget)
 		else:
-			self.collectionOfPanedsWindows[tag] = [self]
-				
-		
-		
-		self.bind('<Button-1>', self.sash_mark)
-		self.bind('<B1-Motion>', self.sash_dragto)
-		
-		
+			self.collectionOfPanedsWindows[tag] = [widget]
+
+
+		widget.bind('<Button-1>', self.sash_mark)
+		widget.bind('<B1-Motion>', self.sash_dragto)
+
+		return widget
+
 	def sash_mark(self,event):
-		identity = self.identify(event.x, event.y)
+		this_widget = event.widget
+
+		identity = this_widget.identify(event.x, event.y)
 
 		if len(identity) ==2:
 			index = identity[0]
-			self.marked=index
+			this_widget.activedSash=index
 		else:
-			self.marked = None
+			this_widget.activedSash = None
 
 	def sash_dragto(self,event):
-		if self.marked != None:
-			for pwindow in self.other_paneds_windows:
-				pwindow.sash_place(self.marked, event.x, event.y)
+		this_widget = event.widget
+		activedSash = this_widget.activedSash
+
+		if activedSash != None:
+			for pwindow in this_widget.other_paneds_windows:
+				pwindow.sash_place(activedSash, event.x, event.y)
 
 def test():
+
+	def _print(x,y):
+		print "Window: %s; Pane: %s" %(x,y)
 	root = Tk()
-	m1 = ParallelPanedWindows(root, bd=1, orient=VERTICAL,sashwidth=2,sashrelief=RIDGE)
-	m1.place(x=30,y=30)
+	root.geometry("190x350")
 
-	top1 = Label(m1, text="top pane1")
-	m1.add(top1)
+	connectedPanels = SimultaneousPanels()
 
-	bottom1 = Label(m1, text="bottom pane1")
-	m1.add(bottom1)
+	for i in range(3):
+		m = connectedPanels.create_widget(root, bd=1, orient=VERTICAL,sashwidth=2,sashrelief=RIDGE)
+		m.place(x=30,y=30+100*i)
 
-	m2 = ParallelPanedWindows(root, bd=1, orient=VERTICAL,sashwidth=2,sashrelief=RIDGE)
-	m2.place( x=30, y =130)
-
-	top2 = Label(m2, text="top pane2")
-	m2.add(top2)
-
-	bottom2 = Label(m2, text="bottom pane2")
-	m2.add(bottom2)
+		for j in range(3):
+			panel= Label(m, text="panel number %s" %j)
+			m.add(panel)
 
 	root.mainloop()
 

History