Ignore:
Timestamp:
Mar 1, 2021 8:32:50 AM (2 years ago)
Author:
toby
Message:

popup menu for GSGrids; split off sequential display; rename File menu in background, reload atoms to update; select atoms from listbox; copy selected to drawatoms; right-click draw & atoms popups; fix atom highlighting in Atoms tab; help button on plots & help updates; spyder cleanup & reformat

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/GSASIIctrlGUI.py

    r4822 r4833  
    45474547            if rowLblCallback: wx.EVT_MOTION(self.GetGridRowLabelWindow(), OnMouseMotion)
    45484548
     4549    def setupPopup(self,lblList,callList):
     4550        '''define a callback that creates a popup menu. The rows associated
     4551        with the items selected items are selected in the table and if
     4552        an item is called from the menu, the corresponding function
     4553        is called to perform an action on the
     4554
     4555        :param list lblList: list of str items that will be placed in the
     4556          popup menu
     4557        :param list callList: list of functions to be called when a
     4558        :returns: a callback that can be used to create the menu
     4559
     4560        Sample usage::
     4561
     4562            lblList = ('Delete','Set atom style','Set atom label',
     4563                           'Set atom color','Set view point','Generate copy',
     4564                           'Generate surrounding sphere','Transform atoms',
     4565                           'Generate bonded')
     4566            callList = (DrawAtomsDelete,DrawAtomStyle, DrawAtomLabel,
     4567                            DrawAtomColor,SetViewPoint,AddSymEquiv,
     4568                            AddSphere,TransformSymEquiv,
     4569                            FillCoordSphere)
     4570            onRightClick = drawAtoms.setupPopup(lblList,callList)
     4571            drawAtoms.Bind(wg.EVT_GRID_CELL_RIGHT_CLICK, onRightClick)
     4572            drawAtoms.Bind(wg.EVT_GRID_LABEL_RIGHT_CLICK, onRightClick)
     4573
     4574        '''
     4575        def createPopup(event):
     4576            def OnPopup(event):
     4577                callback = callList[menuIndx.index(event.GetId())]
     4578                self.ClearSelection()
     4579                for r in indx:
     4580                    self.SelectRow(r,True)
     4581                callback(event)
     4582            # get selections
     4583            indx = self.GetSelectedRows()
     4584            indx += [row for row,col in self.GetSelectedCells()]
     4585            for top,bottom in zip([r for r,c in self.GetSelectionBlockTopLeft()],
     4586                          [r for r,c in self.GetSelectionBlockBottomRight()]):
     4587                indx += list(range(top,bottom+1))
     4588            indx = list(set(indx))
     4589            if len(indx) == 0: # nothing selected, get current row
     4590                r,_ =  event.GetRow(),event.GetCol()
     4591                if r < 0:
     4592                    return
     4593                indx = [r]
     4594            # make a pop-up menu
     4595            menu = wx.Menu()
     4596            menuIndx = []
     4597            for l in lblList:
     4598                menuIndx.append(wx.NewIdRef())
     4599                menu.Append(menuIndx[-1], l)
     4600                self.Bind(wx.EVT_MENU, OnPopup, id=menuIndx[-1])
     4601            self.PopupMenu(menu)
     4602            menu.Destroy()
     4603        return createPopup
     4604       
    45494605    def completeEdits(self):
    45504606        'complete any outstanding edits'
Note: See TracChangeset for help on using the changeset viewer.