# Version 0.8
# Author: Miguel Martinez Lopez
# Uncomment the next line to see my email
# print "Email: ", "61706c69636163696f6e616d656469646140676d61696c2e636f6d".decode("hex")
from __future__ import print_function
try:
from tkinter import *
except ImportError:
from Tkinter import *
class SimultaneousPanels(PanedWindow):
def __init__(self):
self.collectionOfPanedWindows = {}
def create_widget(self,master, tag= '_default', **kargs):
widget = PanedWindow(master, **kargs)
self.add_widget(widget,tag)
return widget
def add_widget(self, widget, tag):
widget.other_paned_windows = []
if tag in self.collectionOfPanedWindows:
for pwindow in self.collectionOfPanedWindows[tag]:
widget.other_paned_windows.append(pwindow)
pwindow.other_paned_windows.append(widget)
self.collectionOfPanedWindows[tag].append(widget)
else:
self.collectionOfPanedWindows[tag] = [widget]
widget.bindtags( ('SimultaneousPanels',)+ widget.bindtags() )
widget.bind_class('SimultaneousPanels', '<Button-1>', self.sash_mark)
widget.bind_class('SimultaneousPanels', '<B1-Motion>', self.sash_dragto)
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 __debug_all_panes(self, panedwindow):
list_of_widgets = [panedwindow]
list_of_widgets.extend(panedwindow.other_paned_windows)
for widget in list_of_widgets:
self.__debug_panes_in_panedwindow(widget)
print()
def __debug_panes_in_panedwindow(self, panedwindow):
for tcl_object in panedwindow.panes():
pane = panedwindow.nametowidget( str( tcl_object ) )
if panedwindow["orient"] == HORIZONTAL:
print( pane.winfo_width(), end=" ")
else:
print( pane.winfo_height(), end=" ")
print()
def sash_dragto(self,event):
this_widget = event.widget
activedSash = this_widget.activedSash
coord_x = event.x
coord_y = event.y
if activedSash != None:
for pwindow in this_widget.other_paned_windows:
pwindow.sash_place(activedSash, coord_x, coord_y)
this_widget.sash_place(activedSash, coord_x, coord_y)
return "break"
def clear(self):
for list_of_panels in self.collectionOfPanedWindows.values():
for panel in list_of_panels:
del panel.other_paned_windows
self.delete_bindtag(panel)
self.collectionOfPanedWindows = {}
def delete_tag(self, tag):
for widget in self.collectionOfPanedWindows[tag]:
del widget.other_paned_windows
self.delete_bindtag(widget)
del self.collectionOfPanedWindows[tag]
def delete_widget(self, widget, tag):
for panel in self.collectionOfPanedWindows[tag]:
panel.other_paned_windows.remove(widget)
self.delete_bindtag(widget)
del widget.other_paned_windows
def delete_bindtag(self, widget):
new_bindtags = list(widget.bindtags())
new_bindtags.remove('SimultaneousPanels')
widget.bindtags(tuple(new_bindtags))
def test():
root = Tk()
connectedPanels = SimultaneousPanels()
Button(root, text="Click here to destroy conexion between panels", command = connectedPanels.clear).pack()
for i in range(3):
emptySpace = Frame(root, height=10)
emptySpace.pack()
m = connectedPanels.create_widget(root, bd=1, orient=VERTICAL,sashwidth=2,sashrelief=RIDGE)
m.pack()
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 9 2014-06-24 15:37:53
+++ revision 10 2014-09-17 15:43:33
@@ -1,14 +1,19 @@
-# Version 0.7
+# Version 0.8
# Author: Miguel Martinez Lopez
# Uncomment the next line to see my email
# print "Email: ", "61706c69636163696f6e616d656469646140676d61696c2e636f6d".decode("hex")
+from __future__ import print_function
-from Tkinter import *
+try:
+ from tkinter import *
+except ImportError:
+ from Tkinter import *
+
class SimultaneousPanels(PanedWindow):
- def __init__(self):
+ def __init__(self):
self.collectionOfPanedWindows = {}
def create_widget(self,master, tag= '_default', **kargs):
@@ -44,14 +49,23 @@
else:
this_widget.activedSash = None
- def __debug_panes(self, panedwindow):
+ def __debug_all_panes(self, panedwindow):
+ list_of_widgets = [panedwindow]
+ list_of_widgets.extend(panedwindow.other_paned_windows)
+
+ for widget in list_of_widgets:
+ self.__debug_panes_in_panedwindow(widget)
+
+ print()
+
+ def __debug_panes_in_panedwindow(self, panedwindow):
for tcl_object in panedwindow.panes():
pane = panedwindow.nametowidget( str( tcl_object ) )
- if panedwindow.orient == HORIZONTAL:
- print pane.winfo_width(),
+ if panedwindow["orient"] == HORIZONTAL:
+ print( pane.winfo_width(), end=" ")
else:
- print pane.winfo_height(),
- print
+ print( pane.winfo_height(), end=" ")
+ print()
def sash_dragto(self,event):
this_widget = event.widget
@@ -65,7 +79,7 @@
pwindow.sash_place(activedSash, coord_x, coord_y)
this_widget.sash_place(activedSash, coord_x, coord_y)
-
+
return "break"
def clear(self):