def __init__(self, client, *a, **kw):
        Frame.__init__(self, *a, **kw)

        self._client = client

        self.rowconfigure(0, weight=1)
        self.columnconfigure(0, weight=1)

        self._addresses_w = a_w = Frame(self, width=100)
        a_w.grid(row=0, column=0, sticky="NESW")

        a_w.rowconfigure(0, weight=1)
        a_w.columnconfigure(0, weight=1)

        self._addresses_tv = a_tv = Treeview(a_w, columns=("address", ))
        a_tv.heading("#0", text="#")
        a_tv.heading("address", text="Sender")
        a_tv.column("#0", minwidth=50, width=50)
        a_tv.column("address", minwidth=100, width=100)

        a_tv.grid(row=0, column=0, sticky="NESW")
        add_scrollbars(a_w, a_tv)

        a_tv.bind("<<TreeviewSelect>>", self._on_address_tv_select)

        self.columnconfigure(1, weight=10)

        # ConversationView(DoubleScrollbarFrame) uses `pack` layout manager.
        # This frame handles this.
        self._conversation_w_holder = conv_w = Frame(self)
        conv_w.grid(row=0, column=1, sticky="NESW")

        self._invalidate()
        client.watch_sms_added(self._on_sms_added)
    def __init__(self, master):
        '''Create a new panel with the given parent.'''

        Frame.__init__(self, master)
        self._ship_name = StringVar()
        self._create_ui()
        self.reset()
Exemplo n.º 3
0
 def __init__(self, *args, **kwargs):
     Frame.__init__(self, *args, **kwargs)
     self.__label = Label(self)
     self.__label.pack(side=LEFT)
     self.__entry = Entry(self)
     self.__entry.pack(fill=X, expand=YES)
     self.__checker_function = None
     self.__image = None
Exemplo n.º 4
0
    def __init__(self, conv, *a, **kw):
        Frame.__init__(self, *a, **kw)

        self._conv = conv
        self._s_conv = s_conv = sorted(conv, key = lambda i : i["date"])

        self.columnconfigure(0, weight = 1)
        self.rowconfigure(0, weight = 1)

        self._text = text = Text(self, wrap = WORD)
        text.grid(row = 0, column = 0, sticky = "NESW")

        add_scrollbars(self, text)

        # incoming
        text.tag_config("itime",
            foreground = "grey",
            background = "#eeeeee",
            selectbackground = "SystemHighlight",
            selectforeground = "SystemHighlightText"
        )
        text.tag_config("imessage",
            rmargin = 100
        )

        text.tag_config("otime",
            justify = RIGHT,
            foreground = "grey",
            background = "#eeeeee",
            selectbackground = "SystemHighlight",
            selectforeground = "SystemHighlightText"
        )
        text.tag_config("omessage",
            lmargin1 = 100,
            lmargin2 = 100,
            background = "#f8f8f8",
            selectbackground = "SystemHighlight",
        )

        # separator
        text.tag_config("sep",
            font = ("Arial", 1),
            background = "#dddddd",
            selectbackground = "SystemHighlight",
        )

        for item in s_conv:
            prefix = "i" if item.incoming else "o"

            text.insert(END,
                item.datetime.strftime("%Y.%m.%d %H:%M:%S") + "\n",
                prefix + "time"
            )
            text.insert(END, item.message + "\n", prefix + "message")
            text.insert(END, "\n", "sep")

        text.config(state = DISABLED)
        text.see("end-1c")
Exemplo n.º 5
0
    def __init__(self, *args, **kwargs):
        Frame.__init__(self, *args, **kwargs)
        Observable.__init__(self)
        self._text = text = Text(self, wrap=NONE, height=1.2, relief=SOLID)
        text.bind('<Configure>', self._on_resize)
        text.bind('<KeyPress>', self._on_key_press)
        text.pack(fill=X, expand=YES, side=LEFT)
        self._default_cursor = text['cursor']
        self._default_background_color = text['background']

        # History
        self._history = []
        text.tag_config('back_button', foreground='grey')
        text.tag_bind('back_button', '<Button-1>', self._on_back_click)
        text.tag_bind('back_button', '<Button-3>', self._on_back_right_click)
        text.tag_bind('back_button', '<Enter>',
                      lambda *args: self._change_cursor_to_hand(True))
        text.tag_bind('back_button', '<Leave>',
                      lambda *args: self._change_cursor_to_hand(False))
                      
        text.insert('1.0', u'\u2190 ', 'back_button')
        # End History

        # Browse Button
        text.tag_config('browse_button', foreground='orange')
        text.tag_bind('browse_button', '<Button-1>', self._on_button_click)
        text.tag_bind('browse_button', '<Enter>',
                      lambda *args: self._change_cursor_to_hand(True))
        text.tag_bind('browse_button', '<Leave>',
                      lambda *args: self._change_cursor_to_hand(False))
        # End Browse Button
                      
        # WinOpen Button
        sys_name = platform.system().lower()
        try:
            __mod = __import__(eval_format('wavesynlib.interfaces.os.{sys_name}.shell.winopen'), globals(), locals(), ['winopen'], -1)
            winopen_func = getattr(__mod, 'winopen')
            def on_winopen_click(*args):
                winopen_func(self._directory)
        except (ImportError, AttributeError):
            def on_winopen_click(*args):
                pass                      
                      
        text.tag_config('winopen_button', foreground='orange')
        text.tag_bind('winopen_button', '<Button-1>', on_winopen_click)
        text.tag_bind('winopen_button', '<Enter>',
                      lambda *args: self._change_cursor_to_hand(True))
        text.tag_bind('winopen_button', '<Leave>',
                      lambda *args: self._change_cursor_to_hand(False))    
        # End WinOpen Button
                
        self._blank_len = 2
        self._browse_text = u'\u25a1'
        self._winopen_text = u'\u25a0'
        self._coding = sys.getfilesystemencoding()
        self._directory = None
Exemplo n.º 6
0
 def __init__(self, *args, **kwargs):
     Frame.__init__(self, *args, **kwargs)
     self.pack(expand=YES, fill=BOTH)
     self._make_widgets()
     self.__on_item_double_click = FunctionChain()
     def dbclick_callback(event):
         item_id = self.tree.identify('item', event.x, event.y)
         item_properties = self.tree.item(item_id)
         self.__on_item_double_click(item_id, item_properties)
     self.tree.bind('<Double-1>', dbclick_callback)
Exemplo n.º 7
0
 def __init__(self, master):
     '''Create the UI for a game of battleship.'''
 
     Frame.__init__(self, master)
     
     self._create_ui()
     
     # these are 'controller' elements that should really be in another class
     self.ai = ShipAI(self.their_grid._model, self.my_grid._model)
     self.reset()
Exemplo n.º 8
0
    def __init__(self, master):
        '''Create the UI for a game of battleship.'''

        Frame.__init__(self, master)

        self._create_ui()

        # these are 'controller' elements that should really be in another class
        self.ai = ShipAI(self.their_grid._model, self.my_grid._model)
        self.reset()
Exemplo n.º 9
0
    def __init__(self, *args, **kwargs):
        self.__i_range   =   i_range  = kwargs.pop('i_range')
        self.__q_range   =   q_range  = kwargs.pop('q_range')
        Frame.__init__(self, *args, **kwargs)
        Observable.__init__(self)
                       
        self.__canvas   = canvas    = ComplexCanvas(self)

        canvas.grid(row=0, column=0, sticky='wens')
        canvas['bg']    = 'black'

        self.__q_slider  = q_slider   = Scale(self, from_=q_range, to=-q_range, orient='vertical')

        q_slider.grid(row=0, column=1, sticky='e')
        self.__i_slider  = i_slider   = Scale(self, from_=-i_range, to=i_range, orient='horizontal')        

        i_slider.grid(row=1, column=0, sticky='s')
        
        self.grid_rowconfigure(0, weight=1)
        self.grid_columnconfigure(0, weight=1)
        
        self.__pad  = 10        
        self.__width    = 0
        self.__height   = 0
        self.__center   = None
        self.__radius   = 0
        self.__bbox     = None
        
        self.__complex_magnitude  = 0 + 0j
        
        canvas.bind('<Configure>', self._on_resize)
        self.__borderBox    = canvas.create_rectangle(0, 0, 10, 10, outline='green')        
        self.__borderCircle = canvas.create_oval(0, 0, 10, 10, outline='green', dash=[1, 2])
        self.__middleCircle = canvas.create_oval(0, 0, 10, 10, outline='green', dash=[1, 2])
        self.__vLine        = canvas.create_line(0, 0, 10, 10, fill='green', dash=[1, 2])
        self.__hLine        = canvas.create_line(0, 0, 10, 10, fill='green', dash=[1, 2])
        self.__dLine        = canvas.create_line(0, 0, 10, 10, fill='green', dash=[1, 2])
        self.__cdLine       = canvas.create_line(0, 0, 10, 10, fill='green', dash=[1, 2])
        self.__scale_circles = []
        for k in range(60):
            if k % 5 == 0:
                color   = 'gold'
            else:
                color   = 'green'
            self.__scale_circles.append(canvas.create_oval(0, 0, 10, 10, fill=color))
            
        self.__indicator1   = self.Indicator(self, solid=False)
        self.__indicator2   = self.Indicator(self)
        
        canvas.bind('<Motion>', self._on_mouse_move)
        canvas.bind('<Button-1>', self._on_click)
        i_slider['command']  = self._on_iq_scale
        q_slider['command']  = self._on_iq_scale
Exemplo n.º 10
0
 def __init__(self, *args, **kwargs):
     Frame.__init__(self, *args, **kwargs)
     sbar = Scrollbar(self)
     list = Listbox(self)
     sbar.config(command=list.yview)
     list.config(yscrollcommand=sbar.set)
     sbar.pack(side=RIGHT, fill=Y)
     list.pack(side=LEFT, expand=YES, fill=BOTH)
     list.bind('<<ListboxSelect>>', self._on_listbox_click)
     
     self.__list_click_callback = None
     self.__list = list
     self.__sbar = sbar
Exemplo n.º 11
0
    def __init__(self, server, *a, **kw):
        Frame.__init__(self, *a, **kw)

        self._srv = server

        self.rowconfigure(0, weight=1)
        self.columnconfigure(0, weight=1)

        self._nb = nb = Notebook(self)
        nb.grid(row=0, column=0, sticky="NESW")

        self._clients2tabs = {}

        self._update_tabs()

        server.watch_new_client(self._on_new_client)
Exemplo n.º 12
0
 def __init__(self, *args, **kwargs):
     from_ = kwargs.pop('from_')
     to = kwargs.pop('to')
     name = kwargs.pop('name')
     formatter = kwargs.pop('formatter', str)
     self.__formatter = formatter
     Frame.__init__(self, *args, **kwargs)
     
     if name is not None:
         Label(self, text=name).pack(side=LEFT)
     
     self.__scale = Scale(self, from_=from_, to=to, 
                             command=self._on_change)
     self.__scale.pack(side=LEFT, fill=X, expand=YES)
     
     self.__value_label = value_label = Label(self)
     value_label.pack(side=LEFT)
Exemplo n.º 13
0
 def __init__(self, *args, **kwargs):
     Frame.__init__(self, *args, **kwargs)
     canvas = Canvas(self)        
     
     xbar = Scrollbar(self, orient=HORIZONTAL)
     xbar.config(command=canvas.xview)
     canvas.config(xscrollcommand=xbar.set)
     xbar.pack(side=BOTTOM, fill=X)
     
     ybar = Scrollbar(self)
     ybar.config(command=canvas.yview)
     canvas.config(yscrollcommand=ybar.set)
     ybar.pack(side=RIGHT, fill=Y)
     
     canvas.pack(expand=YES, fill=BOTH)
     
     self.__canvas = canvas
Exemplo n.º 14
0
    def __init__(self, *args, **kwargs):
        pil_image = kwargs.pop('pil_image')
        photo = ImageTk.PhotoImage(pil_image)
        self.__photo = photo
        self.__origin_image = pil_image
        self.__zoomed_image = pil_image
        Frame.__init__(self, *args, **kwargs)

        frame = Frame(self)
        frame.pack(fill='x')
        
        save_dlg = lambda: asksaveasfilename(filetypes=[('JPEG', '.jpg'), ('PNG', '.png')], defaultextension='.jpg')        
                        
        def on_save(image):
            filename = save_dlg()
            if filename:
                image.save(filename)
        
        Label(frame, text=eval_format('id={id(self)}')).pack(side='left')
        Button(frame, text='Save Origin', command=lambda:on_save(self.__origin_image)).pack(side='left')
        Button(frame, text='Save Zoomed', command=lambda:on_save(self.__zoomed_image)).pack(side='left')

        scale = Scale(frame, from_=0, to=100, orient='horizontal', value=100)
        scale.pack(side='left')
        zoomed_label = Label(frame, text='100%')
        zoomed_label.pack(side='left')
        
        self.__label = label = Label(self, image=photo)
        label.pack(expand=YES, fill=BOTH)
        
        def on_scale(val):
            val = float(val)
            width, height = self.__origin_image.size
            width = int(width * val / 100)
            height = int(height * val / 100)
            zoomed_image = self.__origin_image.resize((width, height), 
                                                      Image.ANTIALIAS)
            self.__zoomed_image = zoomed_image
            self.__photo = ImageTk.PhotoImage(zoomed_image)
            self.__label['image'] = self.__photo
            zoomed_label['text'] = '{}%'.format(int(val))
            
        scale['command'] = on_scale
Exemplo n.º 15
0
 def __init__(self, master=None, **kw):
     Frame.__init__(self, master, **kw)
     
     # Font selector
     selector_frame = LabelFrame(self, text='Font Selector')
     selector_frame.pack(side=LEFT)
     # Font face
     face_frame = LabelFrame(selector_frame, text='Font Face')
     face_frame.pack()
     face_list = ScrolledList(face_frame)
     face_list.pack()
     fonts = list(tkFont.families(self))
     fonts.sort()
     for font in fonts:
         face_list.insert(END, font)
     face_list.list_click_callback = self._on_face_select
     self.face_list = face_list
         
     # Font size
     size_frame = LabelFrame(selector_frame, text='Font Size')
     size_frame.pack()
     size_combo = Combobox(size_frame, takefocus=1, stat='readonly')
     size_combo.pack()
     size_combo['value'] = range(7, 23)
     size_combo.current(0)
     size_combo.bind('<<ComboboxSelected>>', self._on_size_select)
     self.size_combo = size_combo
     
     # Font Sample
     default_font = ('Courier', 10, tkFont.NORMAL)
     sample_frame = LabelFrame(self, text='Samples')
     sample_frame.pack(side=RIGHT, expand=YES, fill=Y)
     sample_label = Label(sample_frame, 
                          text='\tabcdefghij\t\n\tABCDEFGHIJ\t\n\t0123456789\t', 
                          font=default_font)
     sample_label.pack(expand=YES)
     self.sample_label = sample_label
     
     self.face = default_font[0]
     self.size = default_font[1]
     size_combo.current(self.size - 7)
Exemplo n.º 16
0
    def __init__(self, master, **kwargs):
        '''
          Initialisation. The DoubleScrollbarFrame consist of :
            - an horizontal scrollbar
            - a  vertical   scrollbar
            - a canvas in which the user can place sub-elements
        '''

        Frame.__init__(self, master, **kwargs)

        # Canvas creation with double scrollbar
        self.hscrollbar = Scrollbar(self, orient=HORIZONTAL)
        self.vscrollbar = Scrollbar(self, orient=VERTICAL)
        self.sizegrip = Sizegrip(self)
        self.canvas = Canvas(self,
                             bd=0,
                             highlightthickness=0,
                             yscrollcommand=self.vscrollbar.set,
                             xscrollcommand=self.hscrollbar.set)
        self.vscrollbar.config(command=self.canvas.yview)
        self.hscrollbar.config(command=self.canvas.xview)
Exemplo n.º 17
0
    def __init__(self, client, *a, **kw):
        Frame.__init__(self, *a, **kw)

        self._client = client

        self.rowconfigure(0, weight = 1)
        self.columnconfigure(0, weight = 1)

        self._nb = nb = Notebook(self)
        nb.grid(row = 0, column = 0, sticky = "NESW")

        self._convs_w = convs_w = ClientConversationsView(client, nb)
        nb.add(convs_w, text = "Conversations")

        self._sms_w = sms_w = Frame(nb)
        nb.add(sms_w, text = "SMS")

        sms_w.rowconfigure(0, weight = 1)
        sms_w.columnconfigure(0, weight = 1)

        self._sms_tv = sms_tv = Treeview(sms_w, columns = ("address", "body"))
        sms_tv.heading("#0", text = "#")
        sms_tv.heading("address", text = "Sender")
        sms_tv.heading("body", text = "Message")
        sms_tv.column("#0", minwidth = 50)
        sms_tv.column("address", minwidth = 100)
        sms_tv.column("body", minwidth = 500)

        sms_tv.grid(row = 0, column = 0, sticky = "NESW")

        add_scrollbars(sms_w, sms_tv)

        sms_tv.bind("<Double-1>", self._on_double_1)

        self._calls_w = calls_w = Frame(nb)
        nb.add(calls_w, text = "Calls")

        self._invalidate()

        client.watch_sms_added(self._on_sms_added)
Exemplo n.º 18
0
    def __init__(self, *args, **kwargs):
        Frame.__init__(self, *args, **kwargs)
        Observable.__init__(self)
        self._text = text = Text(self, wrap=NONE, height=1.2, relief=SOLID)
        text.bind('<Configure>', self._on_resize)
        text.bind('<KeyPress>', self._on_key_press)
        text.pack(fill=X, expand=YES, side=LEFT)
        self._default_cursor = text['cursor']
        self._default_background_color = text['background']


        # Browse Button
        text.tag_config('browse_button', foreground='orange')
        text.tag_bind('browse_button', '<Button-1>', self._on_button_click)
        text.tag_bind('browse_button', '<Enter>',
                      lambda *args: self._change_cursor_to_hand(True))
        text.tag_bind('browse_button', '<Leave>',
                      lambda *args: self._change_cursor_to_hand(False))
        # End Browse Button
                
        self._blank_len = 2
        self._browse_text = 'BROWSE'
        self._coding = sys.getfilesystemencoding()
        self._directory          = None
Exemplo n.º 19
0
    def __init__(self, master, columns, column_weights=None, cnf={}, **kw):
        """
        Construct a new multi-column listbox widget.

        :param master: The widget that should contain the new
            multi-column listbox.

        :param columns: Specifies what columns should be included in
            the new multi-column listbox.  If ``columns`` is an integer,
            the it is the number of columns to include.  If it is
            a list, then its length indicates the number of columns
            to include; and each element of the list will be used as
            a label for the corresponding column.

        :param cnf, kw: Configuration parameters for this widget.
            Use ``label_*`` to configure all labels; and ``listbox_*``
            to configure all listboxes.  E.g.:

                >>> mlb = MultiListbox(master, 5, label_foreground='red')
        """
        # If columns was specified as an int, convert it to a list.
        if isinstance(columns, int):
            columns = list(range(columns))
            include_labels = False
        else:
            include_labels = True

        if len(columns) == 0:
            raise ValueError("Expected at least one column")

        # Instance variables
        self._column_names = tuple(columns)
        self._listboxes = []
        self._labels = []

        # Pick a default value for column_weights, if none was specified.
        if column_weights is None:
            column_weights = [1] * len(columns)
        elif len(column_weights) != len(columns):
            raise ValueError('Expected one column_weight for each column')
        self._column_weights = column_weights

        # Configure our widgets.
        Frame.__init__(self, master, **self.FRAME_CONFIG)
        self.grid_rowconfigure(1, weight=1)
        for i, label in enumerate(self._column_names):
            self.grid_columnconfigure(i, weight=column_weights[i])

            # Create a label for the column
            if include_labels:
                l = Label(self, text=label, **self.LABEL_CONFIG)
                self._labels.append(l)
                l.grid(column=i, row=0, sticky='news', padx=0, pady=0)
                l.column_index = i

            # Create a listbox for the column
            lb = Listbox(self, **self.LISTBOX_CONFIG)
            self._listboxes.append(lb)
            lb.grid(column=i, row=1, sticky='news', padx=0, pady=0)
            lb.column_index = i

            # Clicking or dragging selects:
            lb.bind('<Button-1>', self._select)
            lb.bind('<B1-Motion>', self._select)
            # Scroll whell scrolls:
            lb.bind('<Button-4>', lambda e: self._scroll(-1))
            lb.bind('<Button-5>', lambda e: self._scroll(+1))
            lb.bind('<MouseWheel>', lambda e: self._scroll(e.delta))
            # Button 2 can be used to scan:
            lb.bind('<Button-2>', lambda e: self.scan_mark(e.x, e.y))
            lb.bind('<B2-Motion>', lambda e: self.scan_dragto(e.x, e.y))
            # Dragging outside the window has no effect (diable
            # the default listbox behavior, which scrolls):
            lb.bind('<B1-Leave>', lambda e: 'break')
            # Columns can be resized by dragging them:
            l.bind('<Button-1>', self._resize_column)

        # Columns can be resized by dragging them.  (This binding is
        # used if they click on the grid between columns:)
        self.bind('<Button-1>', self._resize_column)

        # Set up key bindings for the widget:
        self.bind('<Up>', lambda e: self.select(delta=-1))
        self.bind('<Down>', lambda e: self.select(delta=1))
        self.bind('<Prior>', lambda e: self.select(delta=-self._pagesize()))
        self.bind('<Next>', lambda e: self.select(delta=self._pagesize()))

        # Configuration customizations
        self.configure(cnf, **kw)
Exemplo n.º 20
0
    def __init__(self, *args, **kwargs):
        Frame.__init__(self, *args, **kwargs)
        timer = TkTimer(widget=self, interval=200, active=False)
        
        balloon = Scripting.root_node.balloon
                
        self.__busy_lamp = six.moves.tkinter.Label(self, bg='forestgreen', width=1)
        self.__busy_lamp.pack(side=RIGHT, fill='y')
        
        self.__membar = IntVar(0)
        self._make_mem_status()

        # Transparent Scale {
        def on_scale(val):
            Scripting.root_node.console.set_transparency(val)
        trans_scale = Scale(self, from_=0.2, to=1.0, orient='horizontal', value=1, command=on_scale)
        trans_scale.pack(side='right')
        balloon.bind_widget(trans_scale, balloonmsg='Set the transparency of the console.')
        # } End Transparent Scale

        # Topmost Button {
        import six.moves.tkinter as tkinter
        topmost_button = tkinter.Button(self, text='TOP', relief='groove') 
        topmost_button.pack(side='right')
        
        def on_click():
            tk_root = Scripting.root_node.tk_root
            b = bool(tk_root.wm_attributes('-topmost'))
            fg = 'black' if b else 'lime green'
            topmost_button['fg'] = fg
            tk_root.wm_attributes('-topmost', not b)
            
        topmost_button['command'] = on_click
        balloon.bind_widget(topmost_button, balloonmsg='Set the console as a topmost window.')
        # } End Topmost Button 
        
        #{ Window Combo
        window_combo = Combobox(self, value=[], takefocus=1, stat='readonly')
        def on_selected(event):
            text = event.widget.get()
            wid = int(text.split(':')[1].strip())
            Scripting.root_node.windows[wid].tk_object.deiconify()
        window_combo.bind('<<ComboboxSelected>>', on_selected)
        window_combo.pack(side='right', fill='y') # deiconify a window
        
        @SimpleObserver
        def on_windows_change(node, command):
            values = window_combo['values']
            if values == '':
                values = []
            if isinstance(values, tuple):
                values = list(values)
            node_id = id(node)
            if command == 'new':
                type_name = node.__class__.__name__
                values.append(eval_format('{type_name}: {node_id}'))
            elif command == 'del':
                for index, value in enumerate(values):
                    wid = int(value.split(':')[1].strip())
                    if node_id == wid:
                        del values[index]
            window_combo['values'] = values
            if len(values) > 0:
                window_combo.current(len(values)-1)
            else:
                window_combo.set('')
            
        Scripting.root_node.windows.add_observer(on_windows_change)
        #} End Window Combo
                
        self.__lock = thread.allocate_lock()
        self.__busy = False
             
        get_memory_usage = Scripting.root_node.os.get_memory_usage
        
        @SimpleObserver
        def check_busy():
            self._set_busy_light()
            
        @SimpleObserver
        def check_mem():
            self.__membar.set(get_memory_usage())
            
        timer.add_observer(check_busy)
        timer.divider(divide_by=10).add_observer(check_mem)
        timer.active = True
Exemplo n.º 21
0
 def __init__(self, master):
     Frame.__init__(self, master)
     self._create_ui()
Exemplo n.º 22
0
 def __init__(self, *args, **kwargs):
     Frame.__init__(self, *args, **kwargs)
Exemplo n.º 23
0
    def __init__(self, master):
        '''Create a new ship panel.
        <master> is the parent TKinter element.'''

        Frame.__init__(self, master)
        self._create_ui()
Exemplo n.º 24
0
 def __init__(self, parent=None, text='', file=None):
     Frame.__init__(self, parent)
     self.pack(expand=YES, fill=BOTH)
     self.make_widgets()
     self.set_text(text, file)
Exemplo n.º 25
0
    def __init__(self, master, columns, column_weights=None, cnf={}, **kw):
        """
        Construct a new multi-column listbox widget.

        :param master: The widget that should contain the new
            multi-column listbox.

        :param columns: Specifies what columns should be included in
            the new multi-column listbox.  If ``columns`` is an integer,
            the it is the number of columns to include.  If it is
            a list, then its length indicates the number of columns
            to include; and each element of the list will be used as
            a label for the corresponding column.

        :param cnf, kw: Configuration parameters for this widget.
            Use ``label_*`` to configure all labels; and ``listbox_*``
            to configure all listboxes.  E.g.:

                >>> mlb = MultiListbox(master, 5, label_foreground='red')
        """
        # If columns was specified as an int, convert it to a list.
        if isinstance(columns, int):
            columns = list(range(columns))
            include_labels = False
        else:
            include_labels = True

        if len(columns) == 0:
            raise ValueError("Expected at least one column")

        # Instance variables
        self._column_names = tuple(columns)
        self._listboxes = []
        self._labels = []

        # Pick a default value for column_weights, if none was specified.
        if column_weights is None:
            column_weights = [1] * len(columns)
        elif len(column_weights) != len(columns):
            raise ValueError('Expected one column_weight for each column')
        self._column_weights = column_weights

        # Configure our widgets.
        Frame.__init__(self, master, **self.FRAME_CONFIG)
        self.grid_rowconfigure(1, weight=1)
        for i, label in enumerate(self._column_names):
            self.grid_columnconfigure(i, weight=column_weights[i])

            # Create a label for the column
            if include_labels:
                l = Label(self, text=label, **self.LABEL_CONFIG)
                self._labels.append(l)
                l.grid(column=i, row=0, sticky='news', padx=0, pady=0)
                l.column_index = i

            # Create a listbox for the column
            lb = Listbox(self, **self.LISTBOX_CONFIG)
            self._listboxes.append(lb)
            lb.grid(column=i, row=1, sticky='news', padx=0, pady=0)
            lb.column_index = i

            # Clicking or dragging selects:
            lb.bind('<Button-1>', self._select)
            lb.bind('<B1-Motion>', self._select)
            # Scroll whell scrolls:
            lb.bind('<Button-4>', lambda e: self._scroll(-1))
            lb.bind('<Button-5>', lambda e: self._scroll(+1))
            lb.bind('<MouseWheel>', lambda e: self._scroll(e.delta))
            # Button 2 can be used to scan:
            lb.bind('<Button-2>', lambda e: self.scan_mark(e.x, e.y))
            lb.bind('<B2-Motion>', lambda e: self.scan_dragto(e.x, e.y))
            # Dragging outside the window has no effect (diable
            # the default listbox behavior, which scrolls):
            lb.bind('<B1-Leave>', lambda e: 'break')
            # Columns can be resized by dragging them:
            l.bind('<Button-1>', self._resize_column)

        # Columns can be resized by dragging them.  (This binding is
        # used if they click on the grid between columns:)
        self.bind('<Button-1>', self._resize_column)

        # Set up key bindings for the widget:
        self.bind('<Up>', lambda e: self.select(delta=-1))
        self.bind('<Down>', lambda e: self.select(delta=1))
        self.bind('<Prior>', lambda e: self.select(delta=-self._pagesize()))
        self.bind('<Next>', lambda e: self.select(delta=self._pagesize()))

        # Configuration customizations
        self.configure(cnf, **kw)
Exemplo n.º 26
0
 def __init__(self, master):
     Frame.__init__(self, master)
Exemplo n.º 27
0
    def __init__(self,
                 master=None,
                 work=WORK_TM,
                 rest=REST_TM,
                 server=HOST,
                 port=PORT,
                 mode='fascist'):
        """create the task widget and get things started"""

        self.lid_state = "open"
        self.lid_time = time.time()
        self.interrupt_count = 0
        self.then = 0.0
        self.old_work = 0.0
        self.state = "working"
        self.cancel_rest = 0

        self.log = logging.getLogger(__name__)

        Frame.__init__(*(self, master))

        self.mode = StringVar()
        self.mode.set(mode)  # "fascist" or "friendly"

        # create main interactor window
        self.workmeter = Meter(self, background="grey50")
        self.workmeter.pack()

        self.work_frame = Frame(self)
        self.work_frame.pack()
        self.work_label = Label(self.work_frame, text="Work time:")
        self.work_label.pack(side=LEFT)
        self.work_scl = Scale(self.work_frame,
                              orient=HORIZONTAL,
                              from_=1,
                              to=max(45, work),
                              command=self.reset_duration)
        self.work_scl.set(work)
        self.work_scl.pack(side=LEFT)

        self.rest_frame = Frame(self)
        self.rest_frame.pack()
        self.rest_label = Label(self.rest_frame, text="Rest time:")
        self.rest_label.pack(side=LEFT)
        self.rest_scl = Scale(self.rest_frame,
                              orient=HORIZONTAL,
                              from_=1,
                              to=max(15, rest),
                              command=self.reset_duration)
        self.rest_scl.set(rest)
        self.rest_scl.pack(side=LEFT)

        self.radio_frame = Frame(self)
        self.radio_frame.pack()
        self.dictator = Radiobutton(self.radio_frame,
                                    text="Fascist",
                                    variable=self.mode,
                                    value="fascist")
        self.friend = Radiobutton(self.radio_frame,
                                  text="Friendly",
                                  variable=self.mode,
                                  value="friendly")
        self.dictator.pack(side=LEFT)
        self.friend.pack(side=LEFT)

        self.button_frame = Frame(self)
        self.button_frame.pack()
        self.restb = Button(self.button_frame, text="Rest", command=self.rest)
        self.restb.pack(side=LEFT)
        self.stopb = Button(self.button_frame, text="Quit", command=self.quit)
        self.stopb.pack(side=LEFT)
        self.helpb = Button(self.button_frame, text="Help", command=self.help)
        self.helpb.pack(side=LEFT)

        # create the cover window
        self.cover = Toplevel(background="black")
        self.cover.withdraw()
        # user can't resize it
        self.cover.resizable(0, 0)
        # when displayed, it should cover all displays
        (w, h) = (self.winfo_vrootwidth(), self.winfo_vrootheight())
        if self.log.getEffectiveLevel() <= logging.DEBUG:
            # but we reduce it while debugging
            w, h = (w / 5, h / 5)
        self.cover.geometry("%dx%d+0+0" % (w, h))

        # and it's undecorated
        self.cover.overrideredirect(1)

        # cover contains a frame with rest message and meter
        f = Frame(self.cover, background="black")
        self.restnote = Label(f, background="black", foreground="white")
        self.restmeter = Meter(f, background="grey50", height=10, width=200)
        self.restnote.pack(pady=2)
        self.restmeter.pack(fill="x", expand=1, pady=2)
        self.cancel_button = Button(f, text="Cancel Rest", command=self.cancel)
        f.pack()

        # initialize interrupt information
        self.linux_interrupts = 0
        # used by the default activity checker
        self.mouse = None

        self.setup_server(server, port)

        # self.last_int is the last time the server was alerted to activity
        # self.now is the server's notion of the current time
        # idle time is therefore max(0, self.now-self.last_int)
        (self.last_int, _w_time, _r_time, self.now) = self.server.get()
        self.idle = max(0, self.now - self.last_int)

        self.bgcolor = self["background"]

        # start the ball rolling
        self.after(CHK_INT, self.tick)
        self.work()
Exemplo n.º 28
0
 def __init__(self, master):
     Frame.__init__(self, master)
Exemplo n.º 29
0
 def __init__(self, *args, **kwargs):
     Frame.__init__(self, *args, **kwargs)
     self.pack(expand=YES, fill=BOTH)
     self.make_widgets()