I'm trying to add some buttons at the end of a small program that will end uo being pretty extensive when all is said and done. once the program is run I'm want 3 buttons {"Show formula", "return to list", "exit"}
I have no idea what I'm doing lol, I'm basically constantly googling while I'm writing this and I think I need help
I had some code after the buttons option but it kept giving me "end" errors. I deleted the code and I forget that I had to show yall
here's my code
set x to item 1 of (choose from list {"Divers consumption at depth", "Free gas volume", "Price list"})
if x is "Divers consumption at depth" then
display dialog "what is divers breathing volume (default 1.4 l/min?" default answer "1.4"
set varDvol to text returned of result
display dialog "What is divers absolute depth pressure" default answer ""
set varPbar to text returned of result
set answer to varDvol * varPbar
display dialog "Diver consumption is " & answer as text buttons {"See formula", "Return to list", "Exit"}
I would like the buttons to just what they say. the show formula button would show "Consumption = volume * pressure", return to list would return to the original list if another function needs to be preformed, and exit would exit the application
You are looking for a structure like this:
display dialog "Diver consumption is " & answer as text buttons {"See formula", "Return to list", "Exit"}
set response to button returned of result
if response = "See formula" then
#do one thing
else if response = "Return to list" then
#do a different thing
else if response = "Exit" then
#do a third thing
end if
Related
How to configure a shortcut key in awesome to toggle a client window vertical maximization to the left half of the screen (snap to left)?
Module awful.placement has an example that may help, but there is no mention on how to implement a toggle that would be able to maximize the client or restore it to its prior size and location.
Currently I have the following in rc.lua:
clientkeys = gears.table.join(
-- ...
awful.key({ modkey, "Mod1" }, "Left",
function (c)
-- Simulate Windows 7 'edge snap' (also called aero snap) feature
local f = awful.placement.scale + awful.placement.left + awful.placement.maximize_vertically
f(c.focus, {honor_workarea=true, to_percent = 0.5})
end ,
{description = "maximize vertically to the left half of screen", group = "client"})
)
Are you looking for awful.placement.restore? It seems to do be what you are looking for. However, the documentation says one has to "set[...] the right context argument" for this, but does not mention which one that is.
I think it should be scale since it is the first one in your chain, but I fail to see the logic in calling this chain "scale".
To turn that into a toggle, you can "invent" a new client property. Something like this: if c.my_toggle then print("a") else print("b") end c.my_toggle = not c.my_toggle. This way, the my_toggle property tracks which function you have to call.
I have a script that I'd like to use to automate processes in Audacity. I have it set up so that all the functions I want to do in Audacity are keyboard shortcuts (since I don't think Audacity uses standard window menus like is required for WinMenuSelectItem()) In other words, my whole code consists of multiple instances of the Send() command. The problem is, AutoIT executes the code too fast. I've tried using WinWait(), but the processes take variable amounts of time. I've also tried ShellExecuteWait() and RunWait()Is there a way to get it to wait until the program isn't doing something, and then execute my send commands? Here's some of my code
Run("C:\Program Files (x86)\Audacity\audacity.exe")
; wait until it's active
WinWaitActive("Audacity")
; get the dialogue box to go away
Send("{ENTER}")
RunWait("Audacity")
; open files
Send("^o")
RunWait("Audacity")
; open the certain file & press enter
Send("test.wav")
RunWait("Audacity")
Send("{ENTER}")
RunWait("Audacity")
; select left boundary of silence period
Send("[")
RunWait("Audacity")
Send("000000100{ENTER}")
RunWait("Audacity")
; select right boundary of silence period
Send("]")
RunWait("Audacity")
Send("200000000{ENTER}")
RunWait("Audacity")
; Use for debugging issues. Systray icon show current line.
Opt('TrayIconDebug', 1)
; Delay default: 250s
Opt('WinWaitDelay', 400)
; Delay default: 5s
Opt('SendKeyDelay', 100)
; Path of the wav file.
$sInFile = #WorkingDir & '\test.wav'
; Optional permanent change of splash screen setting.
_SplashScreen(True)
; Run Audacity and argument of the wav file.
$iPid = Run('"C:\Program Files (x86)\Audacity\audacity.exe" "' & $sInFile & '"')
; Check if Run Audacity failed.
If #error Then
MsgBox(0x40030, #ScriptName, 'Failed to run Audacity')
Exit 1
EndIf
; Wait for main window to get handle. Title is the filename with no extension.
$hMainWindow = WinWait('[TITLE:test; CLASS:wxWindowNR]', '', 10)
; Check allowed timeout of window.
If Not $hMainWindow Then
MsgBox(0x40030, #ScriptName, 'Audacity window not detected.')
Exit 1
EndIf
; If splash screen setting not 0 then handle the window.
If _SplashScreen() Then
AdlibRegister('_WelcomeWindow')
WinWait('Welcome to Audacity', '', 3)
AdlibUnRegister('_WelcomeWindow')
EndIf
; Send '[' to main window to trigger Left Boundary window.
ControlSend($hMainWindow, '', '', '[')
; Get handle of Left Boundary window.
$hMsgWindow = WinWait('Set Left Selection Boundary', '', 5)
; Check allowed timeout of window.
If Not $hMsgWindow Then
MsgBox(0x40030, #ScriptName, 'Selection Boundary window not detected.')
Exit 1
EndIf
; Activate window, set time and click OK.
If WinActivate($hMsgWindow) Then
ControlSend($hMsgWindow, '', 'wxWindowNR1', '{LEFT 3}1'); 1000
ControlClick($hMsgWindow, '', 'Button2'); OK
EndIf
; Send ']' to main window to trigger Right Boundary window.
ControlSend($hMainWindow, '', '', ']')
; Get handle of Right Boundary window.
$hMsgWindow = WinWait('Set Right Selection Boundary', '', 5)
; Check allowed timeout of window.
If Not $hMsgWindow Then
MsgBox(0x40030, #ScriptName, 'Selection Boundary window not detected.')
Exit 1
EndIf
; Activate window, set time and click OK.
If WinActivate($hMsgWindow) Then
; Audacity shows 1000 and focus is on the 1st non zero digit which is 1.
ControlSend($hMsgWindow, '', 'wxWindowNR1', '2'); 2000
ControlClick($hMsgWindow, '', 'Button2'); OK
EndIf
; More code to do.
Sleep(1000)
MsgBox(0x40040, #ScriptName, 'End of automation.' & #CRLF & #CRLF & _
'You can close Audacity to finish.')
; Wait for Audacity process to close.
ProcessWaitClose($iPid)
Exit
Func _WelcomeWindow()
; Used by AdlibRegister to handle the Welcome window.
; Welcome window hides if closed so need to check if exist and is visible (2).
If WinExists('Welcome to Audacity') Then
If BitAND(WinGetState('Welcome to Audacity'), 2) Then
WinClose('Welcome to Audacity')
Else
AdlibUnRegister('_WelcomeWindow')
EndIf
EndIf
EndFunc
Func _SplashScreen($bDisable = False)
; Write to audacity.cfg to disable splash screen.
Local $sIniFile = #AppDataDir & '\Audacity\audacity.cfg'
If IniRead($sIniFile, 'GUI', 'ShowSplashScreen', '1') = '1' Then
If $bDisable Then
; Return 1 if ini file change is success.
If IniWrite($sIniFile, 'GUI', 'ShowSplashScreen', '0') Then
Return 1
EndIf
Else
; Return 1 if check for splash screen is enabled.
Return 1
EndIf
EndIf
EndFunc
Opt() is used to slow down the wait of windows and the sends.
Also added Opt('TrayIconDebug', 1) for debugging though if
the script is considered good then you can remove that Opt().
ControlSend() is used instead of Send() as ControlSend()
targets windows and controls based of title, text, etc.
The Opt() delays are not required though was added to
demonstrate the usage, though perhaps Audacity may struggle
to keep with the speed that AutoIt can automate.
If possible, suggest use of Control*() functions for automation.
Storing window handles in a variable can help save retyping titles
in the code. WinWait() returns a window handle which is ideal and
if the timeout parameter is used, then 0 indicates the window not
found so automation can be aborted.
The Classname of the main window is not enough on its own as
Audacity creates many invisible windows with the same Classname.
So, the title may need to be used as well. The title could be
used alone though titled by filename may not be unique at times.
See Window Titles and Text Advanced for usage.
WinActivate() is used on the Boundary windows although it
may not be needed as control*() usually do not need active
windows. Standard Msgboxes in comparison may require to be
active to accept messages sent to them.
ShellExecuteWait() and RunWait() are no good for automation
as they block the script from continuing until the executed
process has finished.
So use ShellExecute() or Run() instead.
The repetitive use of RunWait("Audacity") seems like
desperation to correct the behavior perhaps, though flawed.
Waiting for windows to appear is how to control flow and then
functions such as ControlCommand() can detect state of controls.
ControlClick() is used on the buttons.
CtrlID of Classname Button2 is used though if the script
is always for English users then you can use the text which
would be OK for the OK button.
The ProcessWaitClose($iPid) is optional.
It is sometimes useful to wait for the program
being automated to exit before the script exits.
You comment "get the dialogue box to go away" in you code
after starting Audacity. You can change the setting on the
dialogue box or Preferences -> Interface options. Advice
disabling as it is a future problem to keep handling.
I added some code to disable the setting in the
audacity.cfg file. If not preferred to disable with
_SplashScreen(True) or done manually then
the AdLibRegister('_WelcomeWindow') call will handle
closing the window. Note that the Welcome window does
not close but rather hides.
_SplashScreen(True) changes splash setting to 0 to disable the splash.
_SplashScreen(False) or _SplashScreen() does no change of settings.
The call returns 1 if splash is enabled else 0.
I'm using capybara to go throught a table that has the name of a country in a column and a dropdown with names in another.
The code is like this:
within('tbody') do
all('tr').each do |line|
unless line.has_css?('United Kingdom')
if line.has_css?('span', text: 'Austria')
find('input[id*="_name-selectized"]').click
find('div[data-selectable]', text: austria_person.name).click
end
end
end
end
But this is too slow, I want to know if there is a fastest way to see each line and select a dropdown option according to the country.
Capybara provides automatic waiting/retrying behavior on most of its methods (all and first don't by default) due to the asynchronous nature of most web apps. This is great for most cases where you're looking for exactly what you need to be on the page, however in a case like yours where you're making decisions on what to do based on what is or isn't on the page it can lead to delays.
For example, in your code when you call line.has_css?('United Kingdom') Capybara is waiting up to Capybara.default_max_wait_time for the text to appear. If you know the row is loaded and isn't going to be dynamically changing then that waiting is just wasted time. Luckily you can disable the waiting time by passing wait: false (or 0).
Therefore
within('tbody') do
all('tr').each do |line|
unless line.has_css?('United Kingdom', wait: false)
if line.has_css?('span', text: 'Austria', wait: false)
find('input[id*="_name-selectized"]').click
find('div[data-selectable]', text: austria_person.name).click
end
end
end
end
will probably be significantly faster for you. A second optimization could be if the items you need to click on are actually in the row then scope those to reduce the amount of elements that have to be searched.
within('tbody') do
all('tr').each do |line|
within(line) do
unless page.has_css?('United Kingdom', wait: false)
if page.has_css?('span', text: 'Austria', wait: false)
find('input[id*="_name-selectized"]').click
find('div[data-selectable]', text: austria_person.name).click
end
end
end
end
end
If there are a lot of spans per line you could also speed up the line.has_css?('span', text: 'Austria', wait: false) by switching to an XPath that checks the text in the XPath expression (rather than using the text option) since it would mean the browser would find the correct span rather than returning every span to Capybara which then has to check the text.
I'm completely new to Shiny and I can't get a textOutput to render when I want it to.
observeEvent(input$btnPersistencia, {
output$txtProtActual <- renderText("PROCESSING...")
print("This does print in console")
#SomeCodeHere that takes about 10 seconds to finish
output$txtProtActual <- renderText(paste("Archivo Persistencia Actual: ", basename(values$file), "\n Dim: ", isolate(input$sliderDimension), "\n Filtr: ", isolate(input$txtMaxFil)))
})
The text isn't showing "Processing..." while #SomeCodeHere is running. I really don't understand why. Shouldn't it work?
The text is only rendered AFTER the observeEvent is finished. I know this because if I remove the SECOND renderText(), the text takes the value "Processing..." when the processing is over.
If this is the normal behaviour, is there a way to force the render before the observeEvent is over?
EDIT:
Is there another (any) way to achieve what I want?
Posting my comment as an answer (thanks!)
The article about Progress Bars is here and the reference here.
Here's your code with the progress bar:
observeEvent(input$btnPersistencia, {
withProgress(message = 'PROCESSING...', value = 0, {
incProgress(1/2)
#SomeCodeHere that takes about 10 seconds to finish
Sys.sleep(10)
})
output$txtProtActual <- renderText({
paste("Archivo Persistencia Actual: ", basename(values$file),
"\n Dim: ", isolate(input$sliderDimension),
"\n Filtr: ", isolate(input$txtMaxFil)
)
})
})
Although it's not related to your question, I've noticed you've placed an output inside an observeEvent with some isolate wrapping inputs.
One of the shiny developers talks about observers in the first two videos of shiny's 2016 conference. It helped me understand a lot better how to use observers and I thought you might find it useful. :]
I have a portion of code where I pick the value in a button and use it for other purposes. Or, at least, this is what I'd like to do.
The button changes value at every refresh of the page (it's a webpage).
For example: at the first access the button's value (or label) is "Results List (51)" but, if I refresh the page, the value becomes "Results List (11)".
What changes is the number inside the brackets (that identifies the number of results inside the list).
This is the code interested:
ok = Browser("Bwr").Page("Page").Frame("Frame").WebButton("name:=Results List OK").GetToProperty("name")
ko = Browser("Bwr").Page("Page").Frame("Frame").WebButton("name:=Results List KO").GetToProperty("name")
If InStr(ko, "0") > 0 and Instr(ok, "0")=0 Then
reporter.ReportEvent 0, "Riabbinamento effettuato", "Operazione effettuata con esito positivo: tutte le misure sono state riabbinate"
else reporter.ReportEvent 1, "Riabbinamento fallito", "Operazione effettuata con esito negativo: ci sono misure su cui l'operazione รจ fallita"
End If
Don't pay attention to the reporter (I'm Italian, it's written in my language).
If I execute the above code QTP puts in ok the string "Results List OK" but I want to put in ok the string "Results List OK (n)" (with n being the number that changes at every refresh of the page).
Basically I only need the number inside the brackets in order to make the IF truly works...
Any idea?!
You want to use a regular expression to map the property.
Result List (\d+)
or just Result List.*
Ok problem solved.
I've used GetRoProperty instead of GetToProperty and modified the value in the brackets after WebElement from "name:=Results List OK" to "name:=Results List OK.*"
Thanks to gigatropolis for the useful tips (I upvoted your answer) but it was only half the solution :)