forked from szullino/XNAT-PIC
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ScrollableNotebook.py
116 lines (96 loc) · 4.24 KB
/
ScrollableNotebook.py
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
# -*- coding: utf-8 -*-
"""
Created on May 30, 2022
@author: Francesco Gammaraccio
"""
# Copyright (c) Muhammet Emin TURGUT 2020
# For license see LICENSE
from tkinter import *
import ttkbootstrap as ttk
class ScrollableNotebook(ttk.Frame):
def __init__(self,parent,wheelscroll=False,tabmenu=False,*args,**kwargs):
ttk.Frame.__init__(self, parent, *args)
self.xLocation = 0
self.notebookContent = ttk.Notebook(self,**kwargs)
self.notebookContent.pack(fill="both", expand=True)
self.notebookTab = ttk.Notebook(self,**kwargs)
self.notebookTab.bind("<<NotebookTabChanged>>",self._tabChanger)
if wheelscroll==True: self.notebookTab.bind("<MouseWheel>", self._wheelscroll)
slideFrame = ttk.Frame(self)
slideFrame.place(relx=1.0, x=0, y=1, anchor=NE)
self.menuSpace=30
if tabmenu==True:
self.menuSpace=50
bottomTab = ttk.Label(slideFrame, text=" \u2630 ")
bottomTab.bind("<1>",self._bottomMenu)
bottomTab.pack(side=RIGHT)
leftArrow = ttk.Label(slideFrame, text=" \u276E")
leftArrow.bind("<1>",self._leftSlide)
leftArrow.pack(side=LEFT)
rightArrow = ttk.Label(slideFrame, text=" \u276F")
rightArrow.bind("<1>",self._rightSlide)
rightArrow.pack(side=RIGHT)
self.notebookContent.bind("<Configure>", self._resetSlide)
def _wheelscroll(self, event):
if event.delta > 0:
self._leftSlide(event)
else:
self._rightSlide(event)
def _bottomMenu(self,event):
tabListMenu = Menu(self, tearoff = 0)
for tab in self.notebookTab.tabs():
tabListMenu.add_command(label=self.notebookTab.tab(tab, option="text"),command= lambda temp=tab: self.select(temp))
try:
tabListMenu.tk_popup(event.x_root, event.y_root)
finally:
tabListMenu.grab_release()
def _tabChanger(self,event):
try: self.notebookContent.select(self.notebookTab.index("current"))
except: pass
def _rightSlide(self,event):
if self.notebookTab.winfo_width()>self.notebookContent.winfo_width()-self.menuSpace:
if (self.notebookContent.winfo_width()-(self.notebookTab.winfo_width()+self.notebookTab.winfo_x()))<=self.menuSpace+5:
self.xLocation-=20
self.notebookTab.place(x=self.xLocation,y=0)
def _leftSlide(self,event):
if not self.notebookTab.winfo_x()== 0:
self.xLocation+=20
self.notebookTab.place(x=self.xLocation,y=0)
def _resetSlide(self,event=None):
self.notebookTab.place(x=0,y=0)
self.xLocation = 0
def add(self,frame,**kwargs):
if len(self.notebookTab.winfo_children())!=0:
self.notebookContent.add(frame, text="",state="hidden")
else:
self.notebookContent.add(frame, text="")
self.notebookTab.add(ttk.Frame(self.notebookTab),**kwargs)
def forget(self,tab_id):
self.notebookContent.forget(self.__ContentTabID(tab_id))
self.notebookTab.forget(tab_id)
def hide(self,tab_id):
self.notebookContent.hide(self.__ContentTabID(tab_id))
self.notebookTab.hide(tab_id)
def identify(self,x, y):
return self.notebookTab.identify(x,y)
def index(self,tab_id):
return self.notebookTab.index(tab_id)
def __ContentTabID(self,tab_id):
return self.notebookContent.tabs()[self.notebookTab.tabs().index(tab_id)]
def insert(self,pos,frame, **kwargs):
self.notebookContent.insert(pos,frame, **kwargs)
self.notebookTab.insert(pos,frame,**kwargs)
def select(self,tab_id):
## self.notebookContent.select(self.__ContentTabID(tab_id))
self.notebookTab.select(tab_id)
def tab(self,tab_id, option=None, **kwargs):
kwargs_Content = kwargs.copy()
kwargs_Content["text"] = "" # important
self.notebookContent.tab(self.__ContentTabID(tab_id), option=None, **kwargs_Content)
return self.notebookTab.tab(tab_id, option=None, **kwargs)
def tabs(self):
## return self.notebookContent.tabs()
return self.notebookTab.tabs()
def enable_traversal(self):
self.notebookContent.enable_traversal()
self.notebookTab.enable_traversal()