Exemplo n.º 1
0
    def _createDataTree(self, parent, bgColor):
        """Create a tree on the left panel to store how 
        many object are from each type and the hierarchy.
        """
        defaultFont = gui.getDefaultFont()
        self.style.configure("W.Treeview",
                             background=pwutils.Color.LIGHT_GREY_COLOR,
                             borderwidth=0,
                             rowheight=defaultFont.metrics()['linespace'])
        self.dataTree = Tree(parent, show='tree', style='W.Treeview')
        self.dataTree.column('#0', minwidth=300)
        self.dataTree.tag_configure('protocol',
                                    image=self.getImage('python_file.gif'))
        self.dataTree.tag_configure('protocol_base',
                                    image=self.getImage('class_obj.gif'))
        f = tkFont.Font(family='helvetica', size='10', weight='bold')
        self.dataTree.tag_configure('non-empty', font=f)
        self.dataTree.grid(row=0, column=0, sticky='news')

        # bind click events
        self.dataTree.tag_bind(DATA_TAG, '<Double-1>', self._dataItemClick)
        self.dataTree.tag_bind(DATA_TAG, '<Return>', self._dataItemClick)
        self.dataTree.tag_bind(DATA_TAG, '<KP_Enter>', self._dataItemClick)

        # Program automatic refresh
        self.dataTree.after(3000, self._automaticRefreshData)

        self._updateDataTree()
Exemplo n.º 2
0
    def __init__(self,
                 parent,
                 tooltipCallback=None,
                 tooltipDelay=1500,
                 **kwargs):
        defaults = {'bg': 'white'}
        defaults.update(kwargs)
        Scrollable.__init__(self, parent, tk.Canvas, **defaults)

        self.lastItem = None  # Track last item selected
        self.lastPos = (0, 0)  # Track last clicked position
        self.eventPos = (0, 0)
        self.firstPos = None  # Track first clicked position (for a drag action)
        self.items = {}  # Keep a dictionary with high-level items
        self.cleanSelected = True

        self.onClickCallback = None
        self.onDoubleClickCallback = None
        self.onRightClickCallback = None
        self.onControlClickCallback = None
        self.onAreaSelected = None

        # Add bindings
        self.bind("<Button-1>", self.onClick)
        self.bind("<ButtonRelease-1>", self.onButton1Release)
        self.bind("<Button-3>", self.onRightClick)
        self.bind("<Button-2>", self.onRightClick)
        self.bind("<Double-Button-1>", self.onDoubleClick)
        self.bind("<B1-Motion>", self.onDrag)
        # Hide the right-click menu
        self.bind('<FocusOut>', self._unpostMenu)
        self.bind("<Key>", self._unpostMenu)
        self.bind("<Control-1>", self.onControlClick)
        # self.bind("<MouseWheel>", self.onScroll)
        # Scroll bindings in Linux
        self.bind("<Shift-Button-4>", self.zoomerP)
        self.bind("<Shift-Button-5>", self.zoomerM)

        self._tooltipId = None
        self._tooltipOn = False  # True if the tooltip is displayed
        self._tooltipCallback = tooltipCallback
        self._tooltipDelay = tooltipDelay

        self._runsFont = getDefaultFont().copy()
        self._zoomFactor = DEFAULT_ZOOM

        if tooltipCallback:
            self.bind('<Motion>', self.onMotion)
            # self.bind('<Leave>', self.onLeave)
            self._createTooltip()  # This should set

        self._menu = tk.Menu(self, tearoff=0)
Exemplo n.º 3
0
    def __init__(self,
                 headerList,
                 dataList,
                 mesg=None,
                 title=None,
                 height=10,
                 width=400,
                 padding=10,
                 outFileName=None):
        """Get new widget that has as parent the top level window and set title.
        tables can be dump to a csv file. The name of the file is outFileName
        """
        self.title = title
        self.headerList = headerList
        self.dataList = dataList
        self.outFileName = outFileName
        win = tk.Toplevel()
        if title:
            win.wm_title(title)

        # frame to place all other widgets
        frame = tk.Frame(win)

        font = getDefaultFont()
        font.metrics()
        fontheight = font.metrics()['linespace']
        style = ttk.Style()
        style.configure('Calendar.Treeview', font=font, rowheight=fontheight)

        # add a "save data" button
        saveDataButton = ttk.Button(master=win,
                                    text="Save Data",
                                    command=self.saveData)
        # create treeview to store multi list with data
        tree = ttk.Treeview(columns=headerList,
                            show="headings",
                            master=win,
                            style='Calendar.Treeview',
                            height=height)

        # define scrollbars to be added
        if len(dataList) > height:
            ysb = ttk.Scrollbar(orient=tk.VERTICAL,
                                command=tree.yview,
                                master=win)
            # xsb = ttk.Scrollbar(orient=tk.HORIZONTAL,
            # command= tree.xview, master=win)
            # add them to three view
            tree.configure(yscroll=ysb.set)  # , xscroll=xsb.set)

        # create rows and columns
        counterRow = 1
        colWidths = []  # list with maximum width per column
        # create headers
        for col in headerList:
            tree.heading(col, text=col.title())
            # save neede width for this cell
            (w, h) = (font.measure(col.title()), font.metrics("linespace"))
            colWidths.append(w)

        # insert other rows
        # tag rows as odd or even so they may have different background colors
        for item in dataList:
            if counterRow % 2:
                tree.insert('', 'end', values=item, tags=('evenrow', ))
            else:
                tree.insert('', 'end', values=item, tags=('oddrow', ))
            counterRow += 1
            counterCol = 0
            for i in item:
                (w, h) = (font.measure(i), font.metrics("linespace"))
                if colWidths[counterCol] < w:
                    colWidths[counterCol] = w
                counterCol += 1

        # if width less than sum of column widths expand them
        sumColWid = sum(colWidths) + 20
        if sumColWid < width:
            sumColWid = width
            factor = int(width / sumColWid) + 1
            colWidths = [i * factor for i in colWidths]

        for col, colWidth in zip(headerList, colWidths):
            tree.column(col, width=colWidth + padding)

        # color by rows
        tree.tag_configure('evenrow', background='white')
        tree.tag_configure('oddrow', background='light grey')

        # message placed at the window top
        msg = ttk.Label(wraplength=sumColWid,
                        justify="left",
                        anchor="n",
                        padding=(10, 2, 10, 6),
                        text=mesg,
                        master=win,
                        font=font)

        # set mg in grid 0,0
        msg.grid(row=0, column=0)
        # set button in grid 1 0
        saveDataButton.grid(row=1, column=0)
        # set ysg in grid 2 0
        tree.grid(row=2, column=0)
        # set ysg in grid 2 1
        # but only if number of elements is larger than height
        if len(dataList) > height:
            ysb.grid(row=2, column=1, sticky='ns')