-- RemoveSpins.lua written by F.Damberger -- 9. June 2006 -- -- purpose: removes all spins with matching label from a project -- -- uses a dialog box and remembers values entered. -- if the label field is left empty ALL spins are erased!!! t = {} --1. Set up dialog window v = gui.createMainWindow() v:setCaption( "RemoveSpins dialog" ) t.frm = gui.createGrid( v, 2, false ) v:setCentralWidget( t.frm ) v:show() t.frm:show() -- Labels for first two columns t.ProjectListLabel = gui.createLabel( t.frm, "Select Project" ) t.ProjectListCB = gui.createComboBox( t.frm ) --2. Read ProjectNames into ProjectList combobox SelectedItemIndex = nil for Id,Project in pairs( cara:getProjects() ) do ItemIndex = t.ProjectListCB:addItem( Project:getName() ) t.ProjectListCB:setCurrentItem( ItemIndex ) if RemoveSpinsProjectName == t.ProjectListCB:getCurrentText() then SelectedItemIndex = ItemIndex end end -- for all projects if SelectedItemIndex then -- set to previous choice if it exists t.ProjectListCB:setCurrentItem( SelectedItemIndex ) end -- Display ProjectList Combobox t.ProjectListLabel:show() t.ProjectListCB:show() -- Create Label and Combobox for Spin Label t.RemoveSpinsLabelLELabel = gui.createLabel( t.frm, "Enter nothing for no label filter (erase all) or the label of spins to remove" ) t.RemoveSpinsLabelLE = gui.createLineEdit( t.frm ) if RemoveSpinsLabel then -- determine if RemoveSpinsLabel already exists t.RemoveSpinsLabelLE:setText( RemoveSpinsLabel ) else t.RemoveSpinsLabelLE:setText( "?" ) -- default value end -- Display Label and LineEdit windows t.RemoveSpinsLabelLELabel:show() t.RemoveSpinsLabelLE:show() --6. OK and Cancel Buttons t.okbutton = gui.createPushButton(t.frm, "OK" ) t.cancelbutton = gui.createPushButton( t.frm, "Cancel" ) t.okbutton:show() t.cancelbutton:show() -- cancel button Callback t.cancelbutton:setCallback( gui.event.Clicked, function (self) v:close() end ) -- OK button Callback t.okbutton:setCallback( gui.event.Clicked, function (self) -- =============== Determine User Preferences =========================== t.P = cara:getProject( t.ProjectListCB:getCurrentText() ) print( "current text"..t.ProjectListCB:getCurrentText() ) RemoveSpinsProjectName = t.P:getName() RemoveSpinsLabel = t.RemoveSpinsLabelLE:getText() print("Name of project"..RemoveSpinsProjectName) print("Spin label") print(RemoveSpinsLabel) t.Spins = t.P:getSpins() for SpinId,Spin in pairs( t.Spins ) do if Spin:getLabel() == RemoveSpinsLabel or RemoveSpinsLabel == "" then --t.P:unassignSpin( Spin ) --t.P:removeSpin( Spin ) print( "removing spin"..SpinId ) end end v:close() end )