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 sash_dragto(self,event):
this_widget = event.widget
activedSash = this_widget.activedSash
if activedSash != None:
for pwindow in this_widget.other_paned_windows:
pwindow.sash_place(activedSash, event.x, event.y)
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))
Diff to Previous Revision
--- revision 5 2014-06-04 01:00:14
+++ revision 6 2014-06-14 01:41:18
@@ -1,32 +1,29 @@
-from Tkinter import *
-
class SimultaneousPanels(PanedWindow):
def __init__(self):
- self.collectionOfPanedsWindows = {}
+ self.collectionOfPanedWindows = {}
def create_widget(self,master, tag= '_default', **kargs):
widget = PanedWindow(master, **kargs)
- self.add_conexion(widget,tag)
+ self.add_widget(widget,tag)
return widget
- def add_conexion(self, widget, tag):
- widget.other_paneds_windows = []
+ def add_widget(self, widget, tag):
+ widget.other_paned_windows = []
- if tag in self.collectionOfPanedsWindows:
- for pwindow in self.collectionOfPanedsWindows[tag]:
- widget.other_paneds_windows.append(pwindow)
- pwindow.other_paneds_windows.append(widget)
+ if tag in self.collectionOfPanedWindows:
+ for pwindow in self.collectionOfPanedWindows[tag]:
+ widget.other_paned_windows.append(pwindow)
+ pwindow.other_paned_windows.append(widget)
- self.collectionOfPanedsWindows[tag].append(widget)
+ self.collectionOfPanedWindows[tag].append(widget)
else:
- self.collectionOfPanedsWindows[tag] = [widget]
+ self.collectionOfPanedWindows[tag] = [widget]
-
- widget.bind('<Button-1>', self.sash_mark)
- widget.bind('<B1-Motion>', self.sash_dragto)
-
+ 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
@@ -44,26 +41,32 @@
activedSash = this_widget.activedSash
if activedSash != None:
- for pwindow in this_widget.other_paneds_windows:
+ for pwindow in this_widget.other_paned_windows:
pwindow.sash_place(activedSash, event.x, event.y)
+ 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 test():
+ def delete_tag(self, tag):
+ for widget in self.collectionOfPanedWindows[tag]:
+ del widget.other_paned_windows
+ self.delete_bindtag(widget)
- root = Tk()
- root.geometry("190x350")
+ del self.collectionOfPanedWindows[tag]
- connectedPanels = SimultaneousPanels()
+ 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
- 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)
+ def delete_bindtag(self, widget):
+ new_bindtags = list(widget.bindtags())
+ new_bindtags.remove('SimultaneousPanels')
+ widget.bindtags(tuple(new_bindtags))
- for j in range(3):
- panel= Label(m, text="panel number %s" %j)
- m.add(panel)
-
- root.mainloop()
-
-if __name__ == '__main__':
- test()
+