PEATDB/Tables.py
def popupMenu(self, event, rows=None, cols=None, outside=None):
        """Add left and right click behaviour for canvas, should not have to override
            this function, it will take its values from defined dicts in constructor"""
        if outside == None:
            row = self.get_row_clicked(event)
            col = self.get_col_clicked(event)
            coltype = self.model.getColumnType(col)
        popupmenu = Menu(self, tearoff = 0)
        def popupFocusOut(event):
            popupmenu.unpost()

        if outside == 1:
            #if outside table, just show general items            
            popupmenu.add_command(label="Show Prefs", command= self.showtablePrefs)
            popupmenu.add_command(label="Export Table", command= self.exportTable)
            popupmenu.add_command(label="Filter Recs", command= self.showFilteringBar)
        else:
            def add_commands(fieldtype):
                """Add commands to popup menu for col type"""
                #add column actions for this table type defined in self.columnactions
                functions = self.columnactions[fieldtype]
                for f in functions.keys():
                    func = getattr(self, functions[f])
                    popupmenu.add_command(label=f, command= lambda : func(row,col))
                return

            def add_defaultcommands():
                """now add general actions for all cells"""
                main = ["Set Fill Color","Set Text Color","Copy", "Paste", "Fill Down","Fill Right", "Clear Data",
                         "Delete Row", "Select All", "Plot Selected","Plot Options",
                         "Show Prefs"]
                utils = ["View Record", "Formulae->Value", "Export Table"]
                defaultactions={"Set Fill Color" : lambda : self.setcellColor(rows,cols,key='bg'),
                                "Set Text Color" : lambda : self.setcellColor(rows,cols,key='fg'),
                                "Copy" : lambda : self.copyCell(rows, cols),
                                "Paste" : lambda : self.pasteCell(rows, cols),
                                "Fill Down" : lambda : self.fill_down(rows, cols),
                                "Fill Right" : lambda : self.fill_across(cols, rows),
                                "Delete Row" : lambda : self.delete_Row(),
                                "View Record" : lambda : self.getRecordInfo(row),
                                "Clear Data" : lambda : self.delete_Cells(rows, cols),
                                "Select All" : self.select_All,
                                "Plot Selected" : self.plot_Selected,
                                "Plot Options" : self.plotSetup,
                                "Export Table" : self.exportTable,
                                "Show Prefs" : self.showtablePrefs,
                                "Formulae->Value" : lambda : self.convertFormulae(rows, cols)}

                for action in main:
                    if action == 'Fill Down' and (rows == None or len(rows) <= 1):
                        continue
                    if action == 'Fill Right' and (cols == None or len(cols) <= 1):
                        continue
                    else:
                        popupmenu.add_command(label=action, command=defaultactions[action])
                popupmenu.add_separator()
                utilsmenu = Menu(popupmenu, tearoff = 0)
                popupmenu.add_cascade(label="Utils",menu=utilsmenu)
                for action in utils:
                    utilsmenu.add_command(label=action, command=defaultactions[action])
                return

            if self.columnactions.has_key(coltype):
                add_commands(coltype)
            add_defaultcommands()

        popupmenu.bind("<FocusOut>", popupFocusOut)
        popupmenu.focus_set()
        popupmenu.post(event.x_root, event.y_root)
        return popupmenu
Add left and right click behaviour for canvas, should not have to override
            this function, it will take its values from defined dicts in constructor
Add left and right click behaviour for canvas, should not have to override
this function, it will take its values from defined dicts in constructor
Add left and right click behaviour for canvas should not have to override this function it will take its values from defined dicts in constructor
def popupMenu(self, event, rows=None, cols=None, outside=None):
        if outside == None:
            row = self.get_row_clicked(event)
            col = self.get_col_clicked(event)
            coltype = self.model.getColumnType(col)
        popupmenu = Menu(self, tearoff = 0)
        def popupFocusOut(event):
            popupmenu.unpost()
        if outside == 1:
            popupmenu.add_command(label="Show Prefs", command= self.showtablePrefs)
            popupmenu.add_command(label="Export Table", command= self.exportTable)
            popupmenu.add_command(label="Filter Recs", command= self.showFilteringBar)
        else:
            def add_commands(fieldtype):
                functions = self.columnactions[fieldtype]
                for f in functions.keys():
                    func = getattr(self, functions[f])
                    popupmenu.add_command(label=f, command= lambda : func(row,col))
                return
            def add_defaultcommands():
                main = ["Set Fill Color","Set Text Color","Copy", "Paste", "Fill Down","Fill Right", "Clear Data",
                         "Delete Row", "Select All", "Plot Selected","Plot Options",
                         "Show Prefs"]
                utils = ["View Record", "Formulae->Value", "Export Table"]
                defaultactions={"Set Fill Color" : lambda : self.setcellColor(rows,cols,key='bg'),
                                "Set Text Color" : lambda : self.setcellColor(rows,cols,key='fg'),
                                "Copy" : lambda : self.copyCell(rows, cols),
                                "Paste" : lambda : self.pasteCell(rows, cols),
                                "Fill Down" : lambda : self.fill_down(rows, cols),
                                "Fill Right" : lambda : self.fill_across(cols, rows),
                                "Delete Row" : lambda : self.delete_Row(),
                                "View Record" : lambda : self.getRecordInfo(row),
                                "Clear Data" : lambda : self.delete_Cells(rows, cols),
                                "Select All" : self.select_All,
                                "Plot Selected" : self.plot_Selected,
                                "Plot Options" : self.plotSetup,
                                "Export Table" : self.exportTable,
                                "Show Prefs" : self.showtablePrefs,
                                "Formulae->Value" : lambda : self.convertFormulae(rows, cols)}
                for action in main:
                    if action == 'Fill Down' and (rows == None or len(rows) <= 1):
                        continue
                    if action == 'Fill Right' and (cols == None or len(cols) <= 1):
                        continue
                    else:
                        popupmenu.add_command(label=action, command=defaultactions[action])
                popupmenu.add_separator()
                utilsmenu = Menu(popupmenu, tearoff = 0)
                popupmenu.add_cascade(label="Utils",menu=utilsmenu)
                for action in utils:
                    utilsmenu.add_command(label=action, command=defaultactions[action])
                return
            if self.columnactions.has_key(coltype):
                add_commands(coltype)
            add_defaultcommands()
        popupmenu.bind("<FocusOut>", popupFocusOut)
        popupmenu.focus_set()
        popupmenu.post(event.x_root, event.y_root)
        return popupmenu
def popupMenu ( self , event , rows = None , cols = None , outside = None ) : if outside == None : row = self . get_row_clicked ( event ) col = self . get_col_clicked ( event ) coltype = self . model . getColumnType ( col ) popupmenu = Menu ( self , tearoff = 0 ) def popupFocusOut ( event ) : popupmenu . unpost ( ) if outside == 1 : popupmenu . add_command ( label = "Show Prefs" , command = self . showtablePrefs ) popupmenu . add_command ( label = "Export Table" , command = self . exportTable ) popupmenu . add_command ( label = "Filter Recs" , command = self . showFilteringBar ) else : def add_commands ( fieldtype ) : """Add commands to popup menu for col type""" functions = self . columnactions [ fieldtype ] for f in functions . keys ( ) : func = getattr ( self , functions [ f ] ) popupmenu . add_command ( label = f , command = lambda : func ( row , col ) ) return def add_defaultcommands ( ) : """now add general actions for all cells""" main = [ "Set Fill Color" , "Set Text Color" , "Copy" , "Paste" , "Fill Down" , "Fill Right" , "Clear Data" , "Delete Row" , "Select All" , "Plot Selected" , "Plot Options" , "Show Prefs" ] utils = [ "View Record" , "Formulae->Value" , "Export Table" ] defaultactions = { "Set Fill Color" : lambda : self . setcellColor ( rows , cols , key = 'bg' ) , "Set Text Color" : lambda : self . setcellColor ( rows , cols , key = 'fg' ) , "Copy" : lambda : self . copyCell ( rows , cols ) , "Paste" : lambda : self . pasteCell ( rows , cols ) , "Fill Down" : lambda : self . fill_down ( rows , cols ) , "Fill Right" : lambda : self . fill_across ( cols , rows ) , "Delete Row" : lambda : self . delete_Row ( ) , "View Record" : lambda : self . getRecordInfo ( row ) , "Clear Data" : lambda : self . delete_Cells ( rows , cols ) , "Select All" : self . select_All , "Plot Selected" : self . plot_Selected , "Plot Options" : self . plotSetup , "Export Table" : self . exportTable , "Show Prefs" : self . showtablePrefs , "Formulae->Value" : lambda : self . convertFormulae ( rows , cols ) } for action in main : if action == 'Fill Down' and ( rows == None or len ( rows ) <= 1 ) : continue if action == 'Fill Right' and ( cols == None or len ( cols ) <= 1 ) : continue else : popupmenu . add_command ( label = action , command = defaultactions [ action ] ) popupmenu . add_separator ( ) utilsmenu = Menu ( popupmenu , tearoff = 0 ) popupmenu . add_cascade ( label = "Utils" , menu = utilsmenu ) for action in utils : utilsmenu . add_command ( label = action , command = defaultactions [ action ] ) return if self . columnactions . has_key ( coltype ) : add_commands ( coltype ) add_defaultcommands ( ) popupmenu . bind ( "<FocusOut>" , popupFocusOut ) popupmenu . focus_set ( ) popupmenu . post ( event . x_root , event . y_root ) return popupmenu
Add left and right click behaviour for canvas, should not have to override
this function, it will take its values from defined dicts in constructor
Add left and right click behaviour for canvas should not have to override this function it will take its values from defined dicts in constructor
"""Add left and right click behaviour for canvas, should not have to override
            this function, it will take its values from defined dicts in constructor""" #if outside table, just show general items             """Add commands to popup menu for col type""" #add column actions for this table type defined in self.columnactions """now add general actions for all cells"""
self
event
rows
cols
outside