Esempio n. 1
0
class FileBrowseDialog(Dialog):
    """Dialog to select files from the filesystem."""
    def __init__(self, parent, title, provider, message=None, **args):
        """ From args:
                message: message tooltip to show when browsing.
                selected: the item that should be selected.
        """
        self.value = None
        self.provider = provider
        self.message = args.get('message', None)
        Dialog.__init__(self, parent, title,
                        buttons=[('Select', RESULT_YES), ('Cancel', RESULT_CANCEL)])
        
    def body(self, bodyFrame):
        bodyFrame.config(bg='white')
        gui.configureWeigths(bodyFrame)
        self._createTree(bodyFrame)
        if self.message:
            label = tk.Label(bodyFrame, text=self.message, bg='white',
                     image=self.getImage('fa-lightbulb-o.png'), compound=tk.LEFT)
            label.grid(row=1, column=0, sticky='nw', padx=5, pady=5)
        self.initial_focus = self.tree
        
    def _createTree(self, parent):
        self.tree = BoundTree(parent, self.provider)
        
    def apply(self):
        index = self.tree.index(self.tree.getFirst())
        self.value = self.tree._objects[index]
    
    def validate(self):
        if self.tree.getFirst() is None:
            showError("Validation error", "Please select an element", self)
            return False
        return True                
Esempio n. 2
0
class FileBrowseDialog(Dialog):
    """Dialog to select files from the filesystem."""
    def __init__(self, parent, title, provider, message=None, **args):
        """ From args:
                message: message tooltip to show when browsing.
                selected: the item that should be selected.
        """
        self.value = None
        self.provider = provider
        self.message = args.get('message', None)
        Dialog.__init__(self, parent, title,
                        buttons=[('Select', RESULT_YES), ('Cancel', RESULT_CANCEL)])
        
    def body(self, bodyFrame):
        bodyFrame.config(bg='white')
        gui.configureWeigths(bodyFrame)
        self._createTree(bodyFrame)
        if self.message:
            label = tk.Label(bodyFrame, text=self.message, bg='white',
                     image=self.getImage('fa-lightbulb-o.png'), compound=tk.LEFT)
            label.grid(row=1, column=0, sticky='nw', padx=5, pady=5)
        self.initial_focus = self.tree
        
    def _createTree(self, parent):
        self.tree = BoundTree(parent, self.provider)
        
    def apply(self):
        index = self.tree.index(self.tree.getFirst())
        self.value = self.tree._objects[index]
    
    def validate(self):
        if self.tree.getFirst() is None:
            showError("Validation error", "Please select an element", self)
            return False
        return True                
Esempio n. 3
0
 def _createTree(self, parent):
     self.tree = BoundTree(parent,
                           self.provider,
                           selectmode=self._selectmode)
     if self._selectOnDoubleClick:
         self.tree.itemDoubleClick = lambda obj: self._handleResult(
             RESULT_YES)
     self.tree.grid(row=1, column=0)
Esempio n. 4
0
    def _createTree(self, parent):
        treeFrame = tk.Frame(parent)
        treeFrame.grid(row=0, column=0, sticky='news')
        treeFrame.rowconfigure(0, weight=1)
        self.trees = []
        self.tree = None

        for i, p in enumerate(self.provider):
            t = BoundTree(treeFrame, p,
                          selectmode=self._selectmode)
            t.grid(row=0, column=i, padx=5, pady=5, sticky='news')
            treeFrame.columnconfigure(i, weight=1)
            self.trees.append(t)
Esempio n. 5
0
class ListDialog(Dialog):
    """
    Dialog to select an element from a list.
    It is implemented using a Tree widget.
    """
    def __init__(self, parent, title, provider, message=None, **kwargs):
        """ From kwargs:
                message: message tooltip to show when browsing.
                selected: the item that should be selected.
                validateSelectionCallback: a callback function to validate selected items.
        """
        self.values = []
        self.provider = provider
        self.message = message
        self.validateSelectionCallback = kwargs.get(
            'validateSelectionCallback', None)
        self._selectmode = kwargs.get('selectmode', 'extended')

        Dialog.__init__(self,
                        parent,
                        title,
                        buttons=[('Select', RESULT_YES),
                                 ('Cancel', RESULT_CANCEL)])

    def body(self, bodyFrame):
        bodyFrame.config(bg='white')
        gui.configureWeigths(bodyFrame)
        self._createTree(bodyFrame)
        if self.message:
            label = tk.Label(bodyFrame,
                             text=self.message,
                             bg='white',
                             image=self.getImage(Icon.LIGHTBULB),
                             compound=tk.LEFT)
            label.grid(row=1, column=0, sticky='nw', padx=5, pady=5)
        self.initial_focus = self.tree

    def _createTree(self, parent):
        self.tree = BoundTree(parent,
                              self.provider,
                              selectmode=self._selectmode)

    def apply(self):
        self.values = self.tree.getSelectedObjects()

    def validate(self):
        self.apply()  # load self.values with selected items
        err = ''

        if self.values:
            if self.validateSelectionCallback:
                err = self.validateSelectionCallback(self.values)
        else:
            err = "Please select an element"

        if err:
            showError("Validation error", err, self)
            return False

        return True
Esempio n. 6
0
class ListDialog(Dialog):
    """
    Dialog to select an element from a list.
    It is implemented using a Tree widget.
    """
    def __init__(self, parent, title, provider, 
                 message=None, **kwargs):
        """ From kwargs:
                message: message tooltip to show when browsing.
                selected: the item that should be selected.
                validateSelectionCallback: a callback function to validate selected items.
        """
        self.values = []
        self.provider = provider
        self.message = message
        self.validateSelectionCallback = kwargs.get('validateSelectionCallback', None)
        self._selectmode = kwargs.get('selectmode', 'extended')
        
        Dialog.__init__(self, parent, title,
                        buttons=[('Select', RESULT_YES), ('Cancel', RESULT_CANCEL)])
        
    def body(self, bodyFrame):
        bodyFrame.config(bg='white')
        gui.configureWeigths(bodyFrame)
        self._createTree(bodyFrame)
        if self.message:
            label = tk.Label(bodyFrame, text=self.message, bg='white',
                     image=self.getImage(Icon.LIGHTBULB), compound=tk.LEFT)
            label.grid(row=1, column=0, sticky='nw', padx=5, pady=5)
        if self.tree:
            self.initial_focus = self.tree
        
    def _createTree(self, parent):
        self.tree = BoundTree(parent, self.provider, selectmode=self._selectmode)
        
    def apply(self):
        self.values = self.tree.getSelectedObjects()
    
    def validate(self):
        self.apply() # load self.values with selected items
        err = ''
        
        if self.values:
            if self.validateSelectionCallback:
                err = self.validateSelectionCallback(self.values)
        else:
            err = "Please select an element"
            
        if err:
            showError("Validation error", err, self)
            return False
        
        return True
Esempio n. 7
0
 def _createTree(self, parent):
     self.tree = BoundTree(parent, self.provider)
Esempio n. 8
0
 def _createTree(self, parent):
     self.tree = BoundTree(parent, self.provider, selectmode=self._selectmode)
Esempio n. 9
0
 def _createTree(self, parent):
     self.tree = BoundTree(parent, self.provider)
Esempio n. 10
0
 def _createTree(self, parent):
     self.tree = BoundTree(parent,
                           self.provider,
                           selectmode=self._selectmode)
Esempio n. 11
0
class ListDialog(Dialog):
    """
    Dialog to select an element from a list.
    It is implemented using the Tree widget.
    """
    def __init__(self, parent, title, provider, message=None, **kwargs):
        """ From kwargs:
                message: message tooltip to show when browsing.
                selected: the item that should be selected.
                validateSelectionCallback:
                    a callback function to validate selected items.
                allowSelect: if set to False, the 'Select' button will not
                    be shown.
                allowsEmptySelection: if set to True, it will not validate
                    that at least one element was selected.
        """
        self.values = []
        self.provider = provider
        self.message = message
        self.validateSelectionCallback = kwargs.get('validateSelectionCallback',
                                                    None)
        self._selectmode = kwargs.get('selectmode', 'extended')
        self._selectOnDoubleClick = kwargs.get('selectOnDoubleClick', False)
        self._allowsEmptySelection = kwargs.get('allowsEmptySelection', False)

        buttons = []
        if kwargs.get('allowSelect', True):
            buttons.append(('Select', RESULT_YES))
        buttons.append(('Cancel', RESULT_CANCEL))

        Dialog.__init__(self, parent, title, buttons=buttons, **kwargs)
        
    def body(self, bodyFrame):
        bodyFrame.config()
        gui.configureWeigths(bodyFrame)
        self._createTree(bodyFrame)
        if self.message:
            label = tk.Label(bodyFrame, text=self.message, compound=tk.LEFT,
                             image=self.getImage(Icon.LIGHTBULB))
            label.grid(row=1, column=0, sticky='nw', padx=5, pady=5)
        self.initial_focus = self.tree
        
    def _createTree(self, parent):
        self.tree = BoundTree(parent, self.provider, selectmode=self._selectmode)
        if self._selectOnDoubleClick:
            self.tree.itemDoubleClick = lambda obj: self._handleResult(RESULT_YES)

    def apply(self):
        self.values = self.tree.getSelectedObjects()
    
    def validate(self):
        self.apply() # load self.values with selected items
        err = ''
        
        if self.values:
            if self.validateSelectionCallback:
                err = self.validateSelectionCallback(self.values)
        else:
            if not self._allowsEmptySelection:
                err = "Please select an element"
            
        if err:
            showError("Validation error", err, self)
            return False
        
        return True
Esempio n. 12
0
 def _fillLeftPanel(self, frame):
     gui.configureWeigths(frame)
     self.tree = BoundTree(frame, self.treeProvider)
     self.tree.grid(row=0, column=0, sticky='news')
     self.itemConfig = self.tree.itemConfig
     self.getImage = self.tree.getImage
Esempio n. 13
0
class ObjectBrowser(tk.Frame):
    """ This class will implement a simple object browser.
    Basically, it will display a list of elements at the left
    panel and can display a preview and description on the
    right panel for the selected element.
    An ObjectView will be used to grab information for
    each element such as: icon, preview and description.
    A TreeProvider will be used to populate the list (Tree).
    """
    def __init__(self, parent, treeProvider, 
                 showPreview=True, showPreviewTop=True,
                 **args):
        tk.Frame.__init__(self, parent, **args)
        self.treeProvider = treeProvider
        self._lastSelected = None
        gui.configureWeigths(self)
        self.showPreviewTop = showPreviewTop
        # The main layout will be two panes, 
        # At the left containing the elements list
        # and the right containing the preview and description
        p = tk.PanedWindow(self, orient=tk.HORIZONTAL)
        p.grid(row=0, column=0, sticky='news')
        
        leftPanel = tk.Frame(p)
        self._fillLeftPanel(leftPanel)
        p.add(leftPanel, padx=5, pady=5)
        p.paneconfig(leftPanel, minsize=300)
        
        if showPreview:
            rightPanel = tk.Frame(p)            
            self._fillRightPanel(rightPanel)
            p.add(rightPanel, padx=5, pady=5)    
            p.paneconfig(rightPanel, minsize=200)    
        
            # Register a callback when the item is clicked
            self.tree.itemClick = self._itemClicked
        
    def _fillLeftPanel(self, frame):
        gui.configureWeigths(frame)
        self.tree = BoundTree(frame, self.treeProvider)
        self.tree.grid(row=0, column=0, sticky='news')
        self.itemConfig = self.tree.itemConfig
        self.getImage = self.tree.getImage
    
    def _fillRightPanel(self, frame):
        frame.columnconfigure(0, weight=1)
        
        if self.showPreviewTop:
            top = tk.Frame(frame)
            top.grid(row=0, column=0, sticky='news')
            frame.rowconfigure(0, weight=3)
            gui.configureWeigths(top)
            top.rowconfigure(0, minsize=200)
            self._fillRightTop(top)
        
        bottom = tk.Frame(frame)
        bottom.grid(row=1, column=0, sticky='news')
        frame.rowconfigure(1, weight=1)
        gui.configureWeigths(bottom)
        bottom.rowconfigure(1, weight=1)
        self._fillRightBottom(bottom)
        
    def _fillRightTop(self, top):
        self.noImage = self.getImage('no-image128.png')
        self.label = tk.Label(top, image=self.noImage)
        self.label.grid(row=0, column=0, sticky='news')
        
    def _fillRightBottom(self, bottom):
        self.text = TaggedText(bottom, width=40, height=15, bg='white')
        self.text.grid(row=0, column=0, sticky='news')
        
    def _itemClicked(self, obj):
        self._lastSelected = obj
        img, desc = self.treeProvider.getObjectPreview(obj)
        # Update image preview
        if self.showPreviewTop:
            if isinstance(img, str):
                img = self.getImage(img)
            if img is None:
                img = self.noImage
            self.label.config(image=img)
        # Update text preview
        self.text.setReadOnly(False)
        self.text.clear()
        if desc is not None:
            self.text.addText(desc)
        self.text.setReadOnly(True)
            
    def getSelected(self):
        """ Return the selected object. """
        return self._lastSelected
Esempio n. 14
0
class ListDialog(Dialog):
    """
    Dialog to select an element from a list.
    It is implemented using the Tree widget.
    """
    def __init__(self, parent, title, provider, message=None, **kwargs):
        """ From kwargs:
                message: message tooltip to show when browsing.
                selected: the item that should be selected.
                validateSelectionCallback:
                    a callback function to validate selected items.
                allowSelect: if set to False, the 'Select' button will not
                    be shown.
                allowsEmptySelection: if set to True, it will not validate
                    that at least one element was selected.
        """
        self.values = []
        self.provider = provider
        self.message = message
        self.validateSelectionCallback = kwargs.get(
            'validateSelectionCallback', None)
        self._selectmode = kwargs.get('selectmode', 'extended')
        self._selectOnDoubleClick = kwargs.get('selectOnDoubleClick', False)
        self._allowsEmptySelection = kwargs.get('allowsEmptySelection', False)

        buttons = []
        if kwargs.get('allowSelect', True):
            buttons.append(('Select', RESULT_YES))
        buttons.append(('Cancel', RESULT_CANCEL))

        Dialog.__init__(self, parent, title, buttons=buttons, **kwargs)

    def body(self, bodyFrame):
        bodyFrame.config()
        gui.configureWeigths(bodyFrame)
        dialogFrame = tk.Frame(bodyFrame)
        dialogFrame.grid(row=0, column=0, sticky='news', padx=5, pady=5)
        dialogFrame.config()
        gui.configureWeigths(dialogFrame, row=1)
        self._createFilterBox(dialogFrame)
        self._createTree(dialogFrame)
        if self.message:
            label = tk.Label(bodyFrame,
                             text=self.message,
                             compound=tk.LEFT,
                             image=self.getImage(Icon.LIGHTBULB))
            label.grid(row=2, column=0, sticky='nw', padx=5, pady=5)
        self.initial_focus = self.tree

    def _createTree(self, parent):
        self.tree = BoundTree(parent,
                              self.provider,
                              selectmode=self._selectmode)
        if self._selectOnDoubleClick:
            self.tree.itemDoubleClick = lambda obj: self._handleResult(
                RESULT_YES)
        self.tree.grid(row=1, column=0)

    def _createFilterBox(self, content):
        """ Create the Frame with Filter widgets """
        def _onSearch(e=None):
            def comparison():
                pattern = self._searchVar.get().lower()
                return [
                    w[0] for w in self.lista.items()
                    if pattern in self.lista.get(w[0]).lower()
                ]

            self.tree.update()
            self.lista = {}

            for item in self.tree.get_children():

                itemStr = self.tree.item(item)['text']
                for value in self.tree.item(item)['values']:
                    itemStr = itemStr + " " + str(value)

                self.lista[item] = itemStr

            if self._searchVar.get() != '':
                matchs = comparison()
                if matchs:
                    for item in self.tree.get_children():
                        if item not in matchs:
                            self.tree.delete(item)
                else:
                    self.tree.delete(*self.tree.get_children())

        self.searchBoxframe = tk.Frame(content)
        label = tk.Label(self.searchBoxframe, text="Filter")
        label.grid(row=0, column=0, sticky='nw')
        self._searchVar = tk.StringVar(value='')
        self.entry = tk.Entry(self.searchBoxframe,
                              bg='white',
                              textvariable=self._searchVar,
                              width=40)

        self.entry.bind('<KeyRelease>', _onSearch)
        self.entry.focus_set()
        self.entry.grid(row=0, column=1, sticky='news')
        self.searchBoxframe.grid(row=0,
                                 column=0,
                                 sticky='news',
                                 padx=5,
                                 pady=(10, 5))

    def apply(self):
        self.values = self.tree.getSelectedObjects()

    def validate(self):
        self.apply()  # load self.values with selected items
        err = ''

        if self.values:
            if self.validateSelectionCallback:
                err = self.validateSelectionCallback(self.values)
        else:
            if not self._allowsEmptySelection:
                err = "Please select an element"

        if err:
            showError("Validation error", err, self)
            return False

        return True
Esempio n. 15
0
class ObjectBrowser(tk.Frame):
    """ This class will implement a simple object browser.
    Basically, it will display a list of elements at the left
    panel and can display a preview and description on the
    right panel for the selected element.
    An ObjectView will be used to grab information for
    each element such as: icon, preview and description.
    A TreeProvider will be used to populate the list (Tree).
    """
    def __init__(self,
                 parent,
                 treeProvider,
                 showPreview=True,
                 showPreviewTop=True,
                 **args):
        tk.Frame.__init__(self, parent, **args)
        self.treeProvider = treeProvider
        self._lastSelected = None
        gui.configureWeigths(self)
        self.showPreviewTop = showPreviewTop
        # The main layout will be two panes,
        # At the left containing the elements list
        # and the right containing the preview and description
        p = tk.PanedWindow(self, orient=tk.HORIZONTAL)
        p.grid(row=0, column=0, sticky='news')

        leftPanel = tk.Frame(p)
        self._fillLeftPanel(leftPanel)
        p.add(leftPanel, padx=5, pady=5)
        p.paneconfig(leftPanel, minsize=300)

        if showPreview:
            rightPanel = tk.Frame(p)
            self._fillRightPanel(rightPanel)
            p.add(rightPanel, padx=5, pady=5)
            p.paneconfig(rightPanel, minsize=200)

            # Register a callback when the item is clicked
            self.tree.itemClick = self._itemClicked

    def _fillLeftPanel(self, frame):
        gui.configureWeigths(frame)
        self.tree = BoundTree(frame, self.treeProvider)
        self.tree.grid(row=0, column=0, sticky='news')
        self.itemConfig = self.tree.itemConfig
        self.getImage = self.tree.getImage

    def _fillRightPanel(self, frame):
        frame.columnconfigure(0, weight=1)

        if self.showPreviewTop:
            top = tk.Frame(frame)
            top.grid(row=0, column=0, sticky='news')
            frame.rowconfigure(0, weight=3)
            gui.configureWeigths(top)
            top.rowconfigure(0, minsize=200)
            self._fillRightTop(top)

        bottom = tk.Frame(frame)
        bottom.grid(row=1, column=0, sticky='news')
        frame.rowconfigure(1, weight=1)
        gui.configureWeigths(bottom)
        bottom.rowconfigure(1, weight=1)
        self._fillRightBottom(bottom)

    def _fillRightTop(self, top):
        self.noImage = self.getImage('no-image128.png')
        self.label = tk.Label(top, image=self.noImage)
        self.label.grid(row=0, column=0, sticky='news')

    def _fillRightBottom(self, bottom):
        self.text = TaggedText(bottom,
                               width=40,
                               height=15,
                               bg='white',
                               takefocus=0)
        self.text.grid(row=0, column=0, sticky='news')

    def _itemClicked(self, obj):
        self._lastSelected = obj
        img, desc = self.treeProvider.getObjectPreview(obj)
        # Update image preview
        if self.showPreviewTop:
            if isinstance(img, str):
                img = self.getImage(img)
            if img is None:
                img = self.noImage
            self.label.config(image=img)
        # Update text preview
        self.text.setReadOnly(False)
        self.text.clear()
        if desc is not None:
            self.text.addText(desc)
        self.text.setReadOnly(True)
        if hasattr(self, 'entryLabel') and not self._lastSelected.isDir():
            self.entryVar.set(self._lastSelected.getFileName())

    def getSelected(self):
        """ Return the selected object. """
        return self._lastSelected
Esempio n. 16
0
 def _fillLeftPanel(self, frame):
     gui.configureWeigths(frame)
     self.tree = BoundTree(frame, self.treeProvider)
     self.tree.grid(row=0, column=0, sticky='news')
     self.itemConfig = self.tree.itemConfig
     self.getImage = self.tree.getImage
Esempio n. 17
0
 def _createTree(self, parent):
     self.tree = BoundTree(parent, self.provider, selectmode=self._selectmode)
     if self._selectOnDoubleClick:
         self.tree.itemDoubleClick = lambda obj: self._handleResult(RESULT_YES)