AppleScript: Don't let the user continue until the value is greater than 0 - compare

I am trying to make the user to input the amount of X things, but these things can't be lower than 0, and in the case the user input more than 32 the code should wanrn the user but still allow to continue if chose to.
This is the code I have so far:
set aerender_clone to 0
set USER_instances to 0
repeat until USER_instances ≥ 1
set USER_instances to the text returned of (display dialog "Render instances" default answer 1 with icon note buttons {"Cancel", "Continue"} default button "Continue")
if USER_instances < 0 then
display dialog "Atleast 1 instance must be selected" with icon note buttons {"sure, ok"} default button "sure, ok"
else if USER_instances > 32 then
display dialog "We recomend a maximum of 32, still want to continue?" with icon note buttons {"No", "Yes"} default button "No"
set USER_instances to 0
else
display dialog "Code is working!"
set aerender_clone to USER_instances
end if
end repeat
The thing is that If I input a number like 4, 8, 6, the code keeps warning me that my number is greater than 32, but if I input 12 the code continues.
I am a bit lost here.

You'll want to set your USER_instances variable to an actual number value with as number:
set USER_instances to the text returned of (display dialog "Render instances" default answer 1 with icon note buttons {"Cancel", "Continue"} default button "Continue") as number
The comparison should work after adding as number to the end of the declaration.

If anyone need it, this is, now, the correct code, thanks to l'L'l answser.
set aerender_clone to 0 as number
set USER_instances to 0 as number
set UserOptions to {yes, no}
set USERcanContinue to no
repeat until USERcanContinue contains yes
repeat until USER_instances is greater than 0
set USER_instances to (the text returned of (display dialog "Render instances" default answer 1 with icon note buttons {"Cancel", "Continue"} default button "Continue")) as number
if USER_instances is less than 1 then
display dialog "Atleast 1 instance must be selected" with icon note buttons {"sure, ok"} default button "sure, ok"
else
-- skip
end if
end repeat
if USER_instances is greater than 32 then
display dialog "We recomend a maximum of 32, still want to continue?" with icon note buttons {"No", "Yes"} default button "No"
if button returned of result = "No" then
set USERcanContinue to no
set USER_instances to 0 as number
else
if button returned of result = "Yes" then
set USERcanContinue to yes
end if
end if
else
set USERcanContinue to yes
end if
end repeat
set aerender_clone to USER_instances

Related

CTabCtrl, enabling and disabling tabs

Using Visual C++ MFC.
I have a dialog page, which contains a tab control object. I've created my own tab control class derived from CTabCtrl, where I created all my tab pages contained in an array, like so:
tabArray[0] = new TabPage;
tabArray[1] = new TabPage;
tabArray[0]->Create(DIALOG, this);
tabArray[1]->Create(DIALOG, this);
In my initial dialog page, I have a bunch of checkboxes. Depending on the state of these checkboxes, I add/remove the tab pages (but not the underlying TabPage classes!).
This is done like so. I keep track of which tabs are enabled/disabled in m_fTabEnabled. The state of the tab is toggled with the checkbox. This is used to determine which tab needs to be inserted.
m_fTabEnabled[iTab] = !m_fTabEnabled[iTab];
DeleteAllItems();
for(int i = 0; i < NUMOFTABS; ++i)
{
if(m_fTabEnabled[i]) InsertItem(i, m_sTabNames[i]);
}
Using this method, I have an issue that if I have three tabs enabled, and I remove the second tab, that the dialog containing the data from the second tab is displayed on the third tab. For example:
tab 1, label 1, contains: 1
tab 2, label 2, contains: 2
tab 3, label 3, contains: 3
remove tab 2, tab 3 is shifted to tab 2
tab 1, label 1, contains: 1
tab 2, label 3, contains: 2
tab 3 hidden.
This causes a problem when I'm retrieving data from the tabs, because what I filled in tab three is lost to the data that used to be in tab two.
Does anybody have any suggestions on ways to manage this?

GCP Data Prep- forward and backward fill

I have the following table which I am trying to wrangle in GCP Data prep:
Timestamp Event
2018-04-01 0
2018-04-02 0
2018-04-03 0
2018-04-04 0
2018-04-05 1
2018-04-06 0
2018-04-07 0
2018-04-08 0
I am trying to transform it in a way such that if Event is 1, then the previous 3 entries in the Event are set to 1 and the next 2 entries in Event are set to 2.
So, essentially the data set will look like the below after transformation
Timestamp Event
2018-04-01 0
2018-04-02 1
2018-04-03 1
2018-04-04 1
2018-04-05 1
2018-04-06 2
2018-04-07 2
2018-04-08 0
I have tried to use window and conditionals to achieve this, but w/o success.
Any ideas on how this transformation can be achieved? I am open to splitting the column or creating a new derived column if that can help achieve this result.
Thanks!
You can use window functions as part of your conditions in your IF statements. Using the PREV and NEXT window functions you can get the values at X rows above or below the current row in your window. Once you got the values, you can compare if they match the expected value and shape your IF statement accordingly.
For your use case, you need to verify if the PREV value at 1 or 2 position prior is equal to one and replace these rows by the number 2. If not true, if the NEXT value at position 1, 2 or 3 is equal to 1, the rows should be replaced with the number 1. Lastly, you need to check if the value at the current row is 1 and replace the remaining rows with 0. Converting this into a formula accepted by Dataprep would look like the following:
IF(PREV(Event, 1) == 1 || PREV(Event, 2) == 1, 2, IF(NEXT(Event, 1) == 1 || NEXT(Event, 2) == 1 || NEXT(Event, 3) == 1, 1, IF(Event == 1, 1, 0)))
To enter this formula on Dataprep, under the Function tab, select “Custom Formula”. Under the custom formula window, set the formula type to “Multiple row formula” as the PREV and NEXT function requires an additional argument specifying which column to sort by.

Is there a way to reassign a grid layout to a label?

I have created a GUI with the aid of Tkinter that has created a 3 [C]olomn by 8 [R]ow, (I have placed the borders of the 'cells' in red) and output is like so:
Just to calrify:
Where the "logo [E]" is (C1,R1) & (C1,R2) are rowspanned and where the "main window" is from (C2,R3) to (C3,R8) are colomnspanned and rowspanned.
All are Label widget except for (C1,R3 to C1,R8), which are button widgets with a command to display a string in "Main Window" (gray area).
My aim is to make the "Main Window"(gray area) display only in different grid layouts based on the selected button on the left. So for example I would like to make the grey have a grid layout of 2col by 4 row when C1,R6 is pressed, or when C1,R3 is pressed the grid layout to be 2Cx6R all in the gray area.
Q: Is there a way of re-gridding a label? If so how? Or an alternative approach?
ADDENDUM:
Ideally I would like to update the GREEN area with different number of row and column configurations. For example: When Micro Audit is touched, the Green area will configure itself to have 4 rows by 2 columns, and when Find Item is selected, it will only 3 rows with 1 column, etc. :

capture 2 texts from the screen and compare them using AutoHotkey

I'm working with AutoHotkey and I need to capture two sentences from my screen and compare them. Anyone knows how to do it?
Thanks a lot!!!
OK, this shows some effort.
When you use mouseClickDrag, you have to be absolutely sure that the text will ALWAYS be at those exact locations, which is very unlikely, think about a menu bar moving the webpage down, or about using F11, doing the opposite, changing the font style/size, just zooming in/out, or making the window smaller, such that the text block becomes smaller in width but longer in length, having another banner add that is smaller or larger, et cetera. If you can use an other method (e.g. Find text and from that position, jump 10 words to the left (^{Left 10}) and then select the next 5 words (+^{Right 5}), would be much more reliable.
#NoEnv
#SingleInstance Force
#installKeybdHook
#Persistent
Return ; Stop here on startup to prevent running the whole script on startup
+Insert:: ; Using the [Shift]+[Insert] Key as the hotkey here.
MouseClickDrag,left, 540, 295, 602, 295 ; HighLight area1
Send, ^c
ClipWait, 2
MyVar1:=ClipBoard ; OR MyVar1 = %ClipBoard%
MouseClickDrag,left, 540, 295, 602, 295 ; HighLight area2
Send, ^c
ClipWait, 2
MyVar2:=ClipBoard ; OR MyVar2 = %ClipBoard%
If (MyVar1 = MyVar2)
{
MsgBox, The values %MyVar1% and %MyVar2% are equal
Send, %MyVar1%
; ClipBoard:=MyVar1 ; OR ClipBoard = %MyVar1% is alternative way (Faster)
; Send, ^v
}
Else
{
MsgBox, The values %MyVar1% and %MyVar2% are NOT equal
Send, %MyVar1% AND %MyVar2%
; ClipBoard = %MyVar1% AND %MyVar2% ; is alternative way (Faster)
; Send, ^v
}
Return
You could add some tests to only execute this when Chrome, FireFox or IE is active, but I have left that out. First chew on this code.

How can I create a 3 state custom push button?

I need to create a custom push button which will have 3 different background images corresponding to the following states:
normal
mouse over
mouse down
I would like to have a QHBoxLayout with 3 parts for left side, right side and middle side (stretching side) for the button.
Inside the middle size, I would like to have a label to show the text.
I need this button to have a "clicked" event as well.
I have been doing a lot of search to achieve this but I am really lost. I tried many things including custom widget from QWidget or styling QPushButton with stylesheets but I failed to achieve having 3 images for 3 mouse states and the clicked event.
I am looking for help.
You can use the border-image property, by composing a single image for each state like this:
| |
Left Image | Middle Image | Right Image
| |
then by specifying the left and right image sizes as the border slice sizes and in the border widths of the stylesheet. For example, if the right images were 25 pixel wide and the left ones 20, you would have:
QPushButton {
border-image: url(:/normal.png) 0 25 0 20 stretch stretch;
border-width:0 25 0 20; /* without it, only the middle images would show */
}
QPushButton:hover {
border-image: url(:/hover.png) 0 25 0 20 stretch stretch;
}
QPushButton:pressed {
border-image: url(:/pressed.png) 0 25 0 20 stretch stretch;
}
The values represent the distance between the top, right, bottom and left sides of the image.
well,first,you should have 3 picture for 3 states,and then you can use function setStyleSheet .
QPushButton *btn = new QPushButton;
btn->setStyleSheet("QPushButton{background:url(:/Resources/pause_nor.png);border:0px;}"
"QPushButton:hover{background:url(:/Resources/pause_over.png);border:0px}"
"QPushButton:pressed{background:url(:/Resources/pause_over.png); position: relative;top: 1px; left: 1px;}");