<s> '''<STR_LIT>''' <EOL> import os <EOL> import Tkinter as tk <EOL> import ttk <EOL> from rwb . widgets import AutoScrollbar <EOL> from editor_page import EditorPage <EOL> from tablist import TabList <EOL> class CustomNotebook ( tk . Frame ) : <EOL> def __init__ ( self , parent , app = None ) : <EOL> tk . Frame . __init__ ( self , parent ) <EOL> background = self . cget ( "<STR_LIT>" ) <EOL> self . app = app <EOL> self . pages = [ ] <EOL> self . nodelist = [ ] <EOL> self . current_page = None <EOL> self . pw = tk . PanedWindow ( self , orient = "<STR_LIT>" , background = "<STR_LIT>" , <EOL> borderwidth = <NUM_LIT:1> , relief = '<STR_LIT>' , <EOL> sashwidth = <NUM_LIT:3> ) <EOL> self . pw . pack ( side = "<STR_LIT>" , fill = "<STR_LIT>" , expand = True , pady = ( <NUM_LIT:4> , <NUM_LIT:1> ) , padx = <NUM_LIT:4> ) <EOL> self . left = tk . Frame ( self . pw , background = background , borderwidth = <NUM_LIT:0> , highlightthickness = <NUM_LIT:0> ) <EOL> self . right = tk . Frame ( self . pw , background = "<STR_LIT>" , width = <NUM_LIT> , height = <NUM_LIT> , borderwidth = <NUM_LIT:0> , <EOL> highlightthickness = <NUM_LIT:0> ) <EOL> self . pw . add ( self . left ) <EOL> self . pw . add ( self . right ) <EOL> self . list = TabList ( self . left ) <EOL> vsb = AutoScrollbar ( self . left , command = self . list . yview , orient = "<STR_LIT>" ) <EOL> hsb = AutoScrollbar ( self . left , command = self . list . xview , orient = "<STR_LIT>" ) <EOL> self . list . configure ( xscrollcommand = hsb . set , yscrollcommand = vsb . set ) <EOL> self . list . grid ( row = <NUM_LIT:0> , column = <NUM_LIT:1> , sticky = "<STR_LIT>" , padx = <NUM_LIT:0> , pady = <NUM_LIT:0> ) <EOL> vsb . grid ( row = <NUM_LIT:0> , column = <NUM_LIT:0> , sticky = "<STR_LIT>" ) <EOL> hsb . grid ( row = <NUM_LIT:1> , column = <NUM_LIT:1> , sticky = "<STR_LIT>" ) <EOL> self . left . grid_rowconfigure ( <NUM_LIT:0> , weight = <NUM_LIT:1> ) <EOL> self . left . grid_columnconfigure ( <NUM_LIT:1> , weight = <NUM_LIT:1> ) <EOL> self . list . bind ( "<STR_LIT>" , self . on_list_selection ) <EOL> vsb . grid_remove ( ) <EOL> hsb . grid_remove ( ) <EOL> def get_current_page ( self ) : <EOL> return self . current_page <EOL> def on_list_selection ( self , event ) : <EOL> page = self . list . get ( ) [ <NUM_LIT:1> ] <EOL> self . _select_page ( page ) <EOL> def delete_page ( self , page ) : <EOL> print __file__ , "<STR_LIT>" <EOL> if page in self . pages : <EOL> self . pages . remove ( page ) <EOL> self . list . remove ( page ) <EOL> selection = self . list . get ( ) <EOL> page . pack_forget ( ) <EOL> page . destroy ( ) <EOL> def _page_name_changed ( self , page ) : <EOL> self . list . rename ( page ) <EOL> def get_page_by_name ( self , name ) : <EOL> for page in self . pages : <EOL> if page . name == name : <EOL> return page <EOL> return None <EOL> def get_page_for_path ( self , path ) : <EOL> target_path = os . path . abspath ( path ) <EOL> for page in self . pages : <EOL> if page . path == target_path : <EOL> return page <EOL> return None <EOL> def add_custom_page ( self , page_class ) : <EOL> new_page = page_class ( self . right ) <EOL> self . pages . append ( new_page ) <EOL> self . list . add ( new_page . name , new_page ) <EOL> self . _select_page ( new_page ) <EOL> return new_page <EOL> def add_page ( self , path = None , name = None ) : <EOL> if path is None and name is None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if path is not None and name is not None : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> new_page = EditorPage ( self . right , path , name = name , app = self . app ) <EOL> new_page . bind ( "<STR_LIT>" , lambda event , page = new_page : self . _page_name_changed ( page ) ) <EOL> self . pages . append ( new_page ) <EOL> self . list . add ( new_page . name , new_page ) <EOL> self . _select_page ( new_page ) <EOL> return new_page <EOL> def select_page ( self , page ) : <EOL> self . list . select ( page ) <EOL> def _select_page ( self , page ) : <EOL> for p in self . pages : <EOL> p . pack_forget ( ) <EOL> if page is not None : <EOL> page . pack ( fill = "<STR_LIT>" , expand = True , padx = <NUM_LIT:4> , pady = <NUM_LIT:0> ) <EOL> self . after_idle ( page . focus ) <EOL> self . current_page = page <EOL> return page </s>
