mikshaw
Group: Members
Posts: 4856
Joined: July 2004 |
|
Posted: Oct. 17 2007,02:28 |
|
I see.
Well, anyway, I messed with it=o)
Regardless of whether or not you want to encourage the backup, there were two things about the script that I didn't think are necessary. The first (w:callback) I'm not sure about, but the second (backupBtn:callback) I'm pretty sure is a kluge for a bug created by the use of backupBtn:type(). "type" when applied to buttons implies button type, but the type you supplied was a box type. I can't see why this would cause the check button to consistently be "on", but removing the type line stopped it.
Code Sample |
[code]w = fltk:Fl_Double_Window(205, 175, "DSL Exit Options") --[[ -- I don't think this is needed? w:callback( function(w) os.exit(0) end) ]]
shutdownGroup = fltk:Fl_Group(40, 15, 135, 75)
shutdownBtn = fltk:Fl_Round_Button(55, 15, 95, 25, "Shutdown") shutdownBtn:type(fltk.FL_RADIO_BUTTON) shutdownBtn:value(1) shutdownBtn:callback( function(shutdownBtn) -- backupBtn:value(1) backupBtn:show() end)
rebootBtn = fltk:Fl_Round_Button(55, 35, 100, 25, "Reboot") rebootBtn:type(fltk.FL_RADIO_BUTTON) rebootBtn:value(0) rebootBtn:callback( function(rebootBtn) -- backupBtn:value(1) backupBtn:show() end)
promptBtn = fltk:Fl_Round_Button(55, 55, 115, 25, "Exit to Prompt"); promptBtn:type(fltk.FL_RADIO_BUTTON) promptBtn:value(0) promptBtn:callback( function(promptBtn) -- backupBtn:value(0) backupBtn:hide() end)
fltk:Fl_End() -- End of shutdown group
backupBtn = fltk:Fl_Check_Button(70, 85, 80, 30, "Backup") backupBtn:tooltip("Uncheck to skip backup") backupBtn:value(1) --[[ -- I know this isn't needed. The value of backupBtn will normally -- change itself automatically. Setting the button type to a -- boxtype causes the problem that this callback fixes. backupBtn:type(fltk.FL_DOWN_BOX) backupBtn:callback( function(backupBtn) if backupBtn:value() == 0 then backupBtn:value(1) else backupBtn:value(0) end end) ]]
--[[ the backup and reboot checks are now nested inside the prompt check. If the prompt is true, the others are not checked, and there is no need to check backup ]] okBtn = fltk:Fl_Return_Button(25, 130, 60, 25, "OK") okBtn:callback( function(okBtn) if promptBtn:value() == 1 then os.execute("pidof jwm >/dev/null && pkill jwm") os.execute("pidof fluxbox && pkill fluxbox") os.execute("pidof swm && pkill swm") os.exit(0) else if backupBtn:value() == 0 then os.execute("> /opt/.backup_device") backupReq = "" else backupReq = "yes" end if rebootBtn:value() == 1 then os.execute("/usr/local/bin/exitcheck.sh reboot " .. backupReq) else os.execute("/usr/local/bin/exitcheck.sh shutdown " .. backupReq) end end os.exit(0) end)
cancelBtn = fltk:Fl_Button(115, 130, 60, 25, "Cancel") cancelBtn:callback( function(cancelBtn) os.exit(1) end)
w:show() Fl:run() |
-------------- http://www.tldp.org/LDP/intro-linux/html/index.html
|