Esempio n. 1
0
    def __init__(self, master, max_lines, *args, **kwargs):
        '''Override of ttk.Frame's initialization function'''
        # Initialize root frame
        ttk.Frame.__init__(self, master, *args, **kwargs)

        self.columnconfigure(0, weight=1)  # Entry widget
        self.columnconfigure(1, weight=0)  # AutoScrollbar
        self.rowconfigure(0, weight=1)

        self.MAX_LINES = max_lines  # Max number of lines entry will resize to

        # Initialize multiline entry widget
        self.entry = me.MultilineEntry(self,
                                       self.MAX_LINES,
                                       font=Fonts.get('EntryText'),
                                       relief=tk.FLAT,
                                       wrap='word',
                                       highlightbackground="light grey",
                                       highlightthickness=2,
                                       height=1)
        self.entry.grid(column=0, row=0, sticky=tk.EW)

        # Initialize scrollbar
        self.vsb = asb.AutoScrollbar(self, 1, 0, orient=tk.VERTICAL)
        self.entry.configure(yscrollcommand=self.vsb.set)

        self.bind('<Configure>', self.entry.on_configure)
        self.entry.bind('<Return>', self.__on_enter)
        self.entry.bind('<Shift-Return>', self.__on_newline)
Esempio n. 2
0
    def __init__(self, master, *args, **kwargs):
        '''
        Override of ttk.Frame's initialization function

        :param master: Widget's master
        '''
        # Initialize root frame
        ttk.Frame.__init__(self, master, *args, **kwargs)

        self.columnconfigure(0, weight=1)  # Canvas/Scrollable Frame
        self.columnconfigure(1, weight=0)  # AutoScrollbar
        self.rowconfigure(0, weight=1)

        self.widgets = []
        self.configuring = False

        # Initialize Canvas to hold 'scrollable' frame
        # NOTE  Specify initial width so canvas is not wider than it should be
        self.canvas = tk.Canvas(self,
                                highlightthickness=0,
                                background='red',
                                width=100)
        self.canvas.grid(column=0, row=0, sticky=tk.NSEW)

        # Initialize vertical AutoScrollbar and link to the Canvas
        self.vsb = asb.AutoScrollbar(self,
                                     column=1,
                                     row=0,
                                     orient=tk.VERTICAL,
                                     command=self.canvas.yview)

        self.canvas.configure(yscrollcommand=self.vsb.set)

        # Initialize 'scrollable' frame for actual message content
        self.widget_frame = ttk.Frame(self.canvas, style=self['style'])
        self.widget_frame.columnconfigure(0, weight=1)
        self.widget_frame.rowconfigure(0, weight=0)

        canvas_win_location = (0, 0)
        self.cframe_id = self.canvas.create_window(canvas_win_location,
                                                   window=self.widget_frame,
                                                   anchor='nw')

        # Bind callbacks for when the Message Frame/Canvas is resized
        self.widget_frame.bind('<Configure>', self.__update_scrollregion)
        self.canvas.bind('<Configure>', self.__on_canvas_configure)

        # Bind callbacks for the mouse wheel
        self.widget_frame.bind('<Enter>', self.__bind_mousewheel)
        self.widget_frame.bind('<Leave>', self.__unbind_mousewheel)
Esempio n. 3
0
    def __init__(self,
                 master,
                 tpad,
                 lpad,
                 sfunc=None,
                 hfunc=None,
                 *args,
                 **kwargs):
        '''
        Override of ttk.Frame's initialization function

        :param master: Widget's master
        :param tpad: Padding applied around top of widgets in scroll frame
        :param lpad: Padding applied around left of widgets in scroll frame
        :param sfunc: Pointer to function to call on widgets set to visible
        :param hfunc: Pointer to function to call on widgets set to hidden
        '''
        # Initialize root frame
        ttk.Frame.__init__(self, master, *args, **kwargs)

        self.columnconfigure(0, weight=1)  # Canvas/Scrollable Frame
        self.columnconfigure(1, weight=0)  # AutoScrollbar
        self.rowconfigure(0, weight=1)

        self.widgets = []  # List of widgets in order of top to bottom
        self.num_widgets = 0
        self.configuring = False
        self.wtype = WidgetType.WTYPE_ROOT_CONTAINER
        self.depth = 0  # Attibute indicating 'distance' from root widget
        self.initial_check = False
        self.visible_start_index = -1
        self.VISIBLE_START_INDEX_BUFFER = 2
        self.visible_end_index = -1
        self.VISIBLE_END_INDEX_BUFFER = 2
        self.top_pad = tpad
        self.left_pad = lpad
        self.show_function = sfunc
        self.hide_function = hfunc

        # Initialize Canvas to hold 'scrollable' frame
        self.canvas = tk.Canvas(self, highlightthickness=0)
        self.canvas.wtype = WidgetType.WTYPE_NONROOT_CONTAINER
        self.canvas.depth = self.canvas.master.depth + 1
        self.canvas.grid(column=0, row=0, sticky=tk.NSEW)

        # Initialize vertical AutoScrollbar and link to the Canvas
        self.vsb = asb.AutoScrollbar(self,
                                     column=1,
                                     row=0,
                                     orient=tk.VERTICAL,
                                     command=self.canvas.yview)

        self.canvas.configure(yscrollcommand=self.vsb.set)

        # Initialize 'scrollable' frame for actual message content
        self.widget_frame = ttk.Frame(self.canvas, style=self['style'])
        self.widget_frame.wtype = WidgetType.WTYPE_NONROOT_CONTAINER
        self.widget_frame.depth = self.widget_frame.master.depth + 1
        self.widget_frame.columnconfigure(0, weight=1)

        canvas_win_location = (0, 0)
        self.cframe_id = self.canvas.create_window(canvas_win_location,
                                                   window=self.widget_frame,
                                                   anchor='nw')

        # Bind callbacks for when the Message Frame/Canvas is resized
        self.widget_frame.bind('<Configure>', self.__update_scrollregion)
        self.canvas.bind('<Configure>', self.__on_canvas_configure)

        # Bind callbacks for the mouse wheel
        self.widget_frame.bind('<Enter>', self.__bind_mousewheel)
        self.widget_frame.bind('<Leave>', self.__unbind_mousewheel)