Triggering OK from the call back on GetParm - lua

I am using the IUP.GetParm dialog to do a search and replace prompt.
The dialog supports 3 buttons, the first two OK and Cancel close the prompt and return to the main program flow.
The third button can be tracked in the parm_action function, what I want to do is use the third button to skip the item and close the dialog, but I can't work out if this is possible.
I have asked this on the IUP mailing list but have not yet had a response.
function param_action(dialog,index)
if index == -4 then
bSkip = true
return 1
end
end
bSkip = false
bConfirm,strFromString,strToString,bSkip =
iup.GetParam("Search and Replace",
param_action,
fhGetTag(ptrRecord)..'-'..fhGetTag(ptr)..
' '..fhGetDisplayText(ptrRecord).." %t\n"..
"Replace: "..strBoxType.."\n"..
"With: "..strBoxType.."\n"..
"btn: %u[Ok,Cancel,Skip] \n"
, strFromString,strToString)
if bConfirm and not(bSkip) then
-- replace string
end
To make this function currently you have to press the Skip button and then the Ok button.

Just re-posting the answer from the IUP mailing list here:
Inside the call-back, when the 3rd button is pressed, set the dialog
attribute "status" to "1" and call the function iup.ExitLoop().

Related

AwesomeWM: Closing the prompt box in code without pressing Enter/Escape

I'm trying to add a keybinding to my rc.lua for shutting down my computer, which will display a prompt like "Shutdown (y/n)? ", and will call a shutdown if "y" is pressed, but will close if anything else is pressed. Here's my attempt so far:
...
awful.key({ modkey, "Control", "Shift" }, "q",
function ()
awful.prompt.run {
prompt = "Shutdown? (y/n) ",
textbox = awful.screen.focused().mypromptbox.widget,
keypressed_callback = function (_, key, _)
if key == "y" then
naughty.notify {
text = "Shutting down!"
}
else
naughty.notify {
text = "Not shutting down!"
}
end
return
end,
}
end,
{description = "shutdown", group = "awesome"}),
...
However, the prompt remains active after keys are pressed - the keypressed_callback will continue to trigger every another key is pressed, until I press either Return or Escape.
This is sensible default behaviour, but in my case I want the prompt to close after the first keypressed_callback event. My first thought was to use a return within the keypressed_callback to try to escape/cancel/destroy the prompt, but that isn't doing anything.
Is there anyway to achieve this?
You can call awful.keygrabber.stop().
I must admit this isn't ideal and that function is actually deprecated. I think this is indeed a feature gap in the prompt module itself.
What I would propose for single character prompts is to use https://awesomewm.org/apidoc/core_components/awful.keygrabber.html directly and implement a non-interactive widget using the textbox.
(another alternative is to use root.fake_input or awful.keyboard to emulate Escape/Enter, but that's a very bad hack)

PICO-8 making a button press show an output of text only once?

I'm a complete newbie to both Lua, PICO-8, and coding in general. I'm having trouble with a function I want to put in my first program. The text is all placeholder, I will change it once I get the code right and comprehend it.
Basically, before the _init() I have a function ow() defined where I press a button and the program displays the text "ow." I put the function name in _update() so that it will update 30x/second to see if the button is pressed; however, this is making the "ow" appear 30 times a second (or however long the button is pressed) instead of appearing once when I initially press the button. How do I fix this? Thank you for your tolerance of a new coder's question in advance. Here's my code:
function ow()
if btn((X))
then print "ow"
--how do i make it do this
--only once?
end
end
function _init()
print "hello."
print "i have been waiting for you."
end
function _update()
ow()
end
function _draw()
end
You need a global variable to save previous status of the button.
function ow()
if btn((X)) then
if not button_was_pressed then
button_was_pressed = true
print "ow"
end
else
button_was_pressed = false
end
end

bacon.js how to combine stream with another based on first ?

I have a stream daysFromApi$ with data (days with meals) from API. When a 'delete' button is clicked, I push mealId to this.deleteBus$. I want to have a new value in the stream: daysAfterDelete$. My problem is that 'first' event is always triggered, but 'done' never triggers, flatMapLatest does not work, map neither.
const daysAfterDelete$ = this.deleteBus$
.log('first') // triggers when new mealId is pushed to deleteBus(a button is clicked)
.flatMapLatest(mealId => Bacon.combineAsArray(daysFromApi$, mealId))
.log('done'); // never triggers
I want to get following flow:
daysFromApi$ : A B C
deleteBus$ : 1 2 3
daysAfterDelete$: (1,A) (2,B) (3,B)
Not quite sure what you want to achieve, but if you want to get the latest value of "days" when the delete is clicked, you can use sampledBy. https://www.webpackbin.com/bins/-Ki3lTzM8PM4zeJKK9C0

Disable/Enable button based on which control has focus

What I'm trying to do here is loop through the different controls and if any of the controls got focus to disable a button. This is a loop that I used for another task, so I'm kinda basing it off of this...
Dim cControl As Control
For Each cControl In Me.controls
If Not cControl.Container Is framClient Then
If Mid(cControl.Name, 1, 3) = "txt" Or Mid(cControl.Name, 1, 3) = "msk" Or Mid(cControl.Name, 1, 3) = "cbo" Then
'WHAT I'm trying to do here is
'if cControl.gotfocus then
'cmdExit.enabled=false
'end if ' but it barks at me
'cControl.Enabled = False
End If
End If
Next
I didn't make these text boxes in an array and I do not want to go through each text box to see if got focus and do whatever. Please take a look.
In vb6 only one control can have focus: the ActiveControl, so there's no point in looping and asking if the control has focus.
If you need to do something based on whether a certain control with a particular name has focus you could do this:
cmdExit.Enabled = (Me.ActiveControl.Name = "MyTextBox")
If you need to do it based on whether any TextBox has focus:
If TypeOf Me.ActiveControl Is TextBox Then
cmdExit.Enabled = false
Else
cmdExit.Enabled = true
End If
You can go ahead with Subclassing of text boxes as suggested in this SO Post.
As the post suggests, you have to do this exercise for every form where you have this requirement. I think, from your post that you have to do it only for one form.

Setting returned text to open an app in applescript

I have a apple script program that I am programming and I want the text the user sends to open an application, But I keep getting error messages saying "Can't get application {"name_of_app"} of <>. The code I very simple and I cant figure out the problem
set deReturnedItems to (display dialog "How many spam messages?" with icon stop default answer "" buttons {"Quit", "OK"} default button 2)
set xpp to text returned of deReturnedItems
set theReturnedItems to (display dialog "How many spam messages?" with icon stop default answer "" buttons {"Quit", "OK"} default button 2)
set amt to the text returned of theReturnedItems
set daReturnedItems to (display dialog "Last thing, what should the spam message say?" default answer "" buttons {"Quit", "OK"} default button 2)
set msg to the text returned of daReturnedItems
repeat [amt] times
tell application [xpp]
activate
tell application "System Events"
keystroke [msg]
keystroke return
end tell
end tell
end repeat
Get rid of those square brackets. Don't use them for variables. Use underscores before and after if you must, like:
repeat _amt_ times
…
end
Also, you need to check to make sure your variable is an integer before you use it in the repeat block.
Incidentally, when you set a variable and then include it in brackets, that's applescript syntax for set the string to a list. For example:
set [x, y, z] to "123"
return x
-- returns "1", and y is set to "2", and z is set to "3"

Resources