PEATDB/PEATTables.py
def popupMenu(self, event, rows=None, cols=None, outside=None):
        """Add right click behaviour for canvas"""
        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:
            pass
        else:
            def add_peatcommand(fieldtype):
                """Adds all commands per column type based on self.peatactions"""
                model = self.getModel()
                colname = model.getColumnName(col)
                protein = model.getRecName(row)
                functions = self.peatactions[fieldtype]

                for f in functions.keys():
                    func = getattr(self.parentapp, functions[f])
                    if f == 'Open Ekin':
                        ekinmode = self.ekin_actions[coltype]
                        def thisfunc(self=self,function=func,protein=protein,field_name=colname):
                            return function(protein=protein,field_name=field_name,mode=ekinmode)
                    else:
                        def thisfunc(self=self,function=func,protein=protein,field_name=colname):
                            return function(protein=protein,field_name=field_name)
                    popupmenu.add_command(label=f, command=thisfunc)
                return

            def add_commands(fieldtype):
                """Add from columnactions if present"""
                functions = self.columnactions[fieldtype]
                for f in functions.keys():
                    func = getattr(self, functions[f])
                    def thisfunc(self=self,function=func,row=row,col=col):
                        return function(row=row,col=col)
                return

            def add_defaultcommands():
                """now add general actions for all cells"""
                order = [ "Set Fill Color","Set Text Color","Edit","Copy","Paste","Fill Down","Fill Right", "Clear Data",
                         "View Record", "Select All",
                         "Plot Selected","Plot Options"]
                defaultactions={"Edit" : lambda: self.draw_cellentry(row,col),
                                "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),
                                "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 }
                for action in order:
                    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])
                return

            if self.columnactions.has_key(coltype):
                add_commands(coltype)
            if self.peatactions.has_key(coltype):
                add_peatcommand(coltype)
            elif coltype in self.model.ekintypes:
                add_peatcommand('Ekintype')
            add_peatcommand('Sequence')
            add_defaultcommands()

        popupmenu.add_command(label="Show Prefs", command=lambda : self.showtablePrefs())
        popupmenu.add_command(label="Export Table", command= self.exportTable)
        popupmenu.add_command(label="Filter Recs", command= self.showFilteringBar)
        popupmenu.bind("<FocusOut>", popupFocusOut)
        popupmenu.focus_set()
        popupmenu.post(event.x_root, event.y_root)
        return popupmenu
Add right click behaviour for canvas
Add right click behaviour for canvas
Add right click behaviour for canvas
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:
            pass
        else:
            def add_peatcommand(fieldtype):
                model = self.getModel()
                colname = model.getColumnName(col)
                protein = model.getRecName(row)
                functions = self.peatactions[fieldtype]
                for f in functions.keys():
                    func = getattr(self.parentapp, functions[f])
                    if f == 'Open Ekin':
                        ekinmode = self.ekin_actions[coltype]
                        def thisfunc(self=self,function=func,protein=protein,field_name=colname):
                            return function(protein=protein,field_name=field_name,mode=ekinmode)
                    else:
                        def thisfunc(self=self,function=func,protein=protein,field_name=colname):
                            return function(protein=protein,field_name=field_name)
                    popupmenu.add_command(label=f, command=thisfunc)
                return
            def add_commands(fieldtype):
                functions = self.columnactions[fieldtype]
                for f in functions.keys():
                    func = getattr(self, functions[f])
                    def thisfunc(self=self,function=func,row=row,col=col):
                        return function(row=row,col=col)
                return
            def add_defaultcommands():
                order = [ "Set Fill Color","Set Text Color","Edit","Copy","Paste","Fill Down","Fill Right", "Clear Data",
                         "View Record", "Select All",
                         "Plot Selected","Plot Options"]
                defaultactions={"Edit" : lambda: self.draw_cellentry(row,col),
                                "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),
                                "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 }
                for action in order:
                    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])
                return
            if self.columnactions.has_key(coltype):
                add_commands(coltype)
            if self.peatactions.has_key(coltype):
                add_peatcommand(coltype)
            elif coltype in self.model.ekintypes:
                add_peatcommand('Ekintype')
            add_peatcommand('Sequence')
            add_defaultcommands()
        popupmenu.add_command(label="Show Prefs", command=lambda : self.showtablePrefs())
        popupmenu.add_command(label="Export Table", command= self.exportTable)
        popupmenu.add_command(label="Filter Recs", command= self.showFilteringBar)
        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 : pass else : def add_peatcommand ( fieldtype ) : """Adds all commands per column type based on self.peatactions""" model = self . getModel ( ) colname = model . getColumnName ( col ) protein = model . getRecName ( row ) functions = self . peatactions [ fieldtype ] for f in functions . keys ( ) : func = getattr ( self . parentapp , functions [ f ] ) if f == 'Open Ekin' : ekinmode = self . ekin_actions [ coltype ] def thisfunc ( self = self , function = func , protein = protein , field_name = colname ) : return function ( protein = protein , field_name = field_name , mode = ekinmode ) else : def thisfunc ( self = self , function = func , protein = protein , field_name = colname ) : return function ( protein = protein , field_name = field_name ) popupmenu . add_command ( label = f , command = thisfunc ) return def add_commands ( fieldtype ) : """Add from columnactions if present""" functions = self . columnactions [ fieldtype ] for f in functions . keys ( ) : func = getattr ( self , functions [ f ] ) def thisfunc ( self = self , function = func , row = row , col = col ) : return function ( row = row , col = col ) return def add_defaultcommands ( ) : """now add general actions for all cells""" order = [ "Set Fill Color" , "Set Text Color" , "Edit" , "Copy" , "Paste" , "Fill Down" , "Fill Right" , "Clear Data" , "View Record" , "Select All" , "Plot Selected" , "Plot Options" ] defaultactions = { "Edit" : lambda : self . draw_cellentry ( row , col ) , "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 ) , "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 } for action in order : 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 ] ) return if self . columnactions . has_key ( coltype ) : add_commands ( coltype ) if self . peatactions . has_key ( coltype ) : add_peatcommand ( coltype ) elif coltype in self . model . ekintypes : add_peatcommand ( 'Ekintype' ) add_peatcommand ( 'Sequence' ) add_defaultcommands ( ) popupmenu . add_command ( label = "Show Prefs" , command = lambda : self . showtablePrefs ( ) ) popupmenu . add_command ( label = "Export Table" , command = self . exportTable ) popupmenu . add_command ( label = "Filter Recs" , command = self . showFilteringBar ) popupmenu . bind ( "<FocusOut>" , popupFocusOut ) popupmenu . focus_set ( ) popupmenu . post ( event . x_root , event . y_root ) return popupmenu
Add right click behaviour for canvas
Add right click behaviour for canvas
"""Add right click behaviour for canvas""" """Adds all commands per column type based on self.peatactions""" """Add from columnactions if present""" """now add general actions for all cells"""
self
event
rows
cols
outside