I have a working progress bar, and wanted to move it to top left corner of the screen. I used x0 y0 w300 to control the position and size.
But doing so my %progress_bar_percentage% stopped updating. I want to ask, is it possible to have the position and progress bar % working at the same time?
a = %counter%
b = %CaseArrayCount%
progress_bar_percentage := Round(((a/b) * 100), 2)
; Draw the progress bar on the screen
Progress, x0 y0 w300, %progress_bar_percentage%, %progress_bar_percentage%`%, System Processing , Sample APP
Reference: https://autohotkey.com/docs/commands/Progress.htm
The documentation actually says that options can only be used if the progress window does not yet exist.
If the progress window does not exist: A new progress window is
created (replacing any old one), and Param1 is a string of zero or
more options from the list below.
That means you can only set the position in the very beginning when creating the progress bar window:
Progress, x0 y0, 0`%, System Processing , Sample APP
Loop, 100 {
Progress, %A_Index%, %A_Index%`%, System Processing , Sample APP
Sleep, 100
}
If you try to use options within the loop, you'll see the progress window being destroyed and newly created with every iteration and the progress value is ignored. According to the documentation if Param1 is an pure number, its bar's position is changed to that value, so you can't actually do both options and progress value at the same time.
Without hacks, the best thing you could do is probably:
Loop, 10 {
value := A_Index*10
Progress, x%value% y%value%, %A_Index%`%, System Processing , Sample APP
Progress, % value, % value "%", System Processing , Sample APP
Sleep, 1000
}
Related
I'm attempting to create an animated plot in app designer. So i've got 2 variables u and x displayed on a graph in respect to time with a time slider and a button under it. I wanted to know if it was possible to have a loop always checking in the background if the button is showing '||' so that it would increment uiaxis to display the new set of u and x variable associated with a time increment. And it would keep looping until the button has been pressed or time is tmax where it will restart at 0 and stop incrementing. I've attempted it with a changing value callback however it doesn't seem to loop correctly.
I'm using a programmatic GUI in MATLAB which uses multiple figure windows. When I press the button 'Redraw' in Figure A, a new figure appears (Figure B) with some data plotted. I want the focus to immediately switch back to Figure A because there are many hotkeys (WindowKeyPressFcn) that I use in that window to update the plots in Figure B.
There are two problems here:
1) The last line of the callback for the button 'Redraw' does switch focus back to Figure A, BUT only if Figure B exists already. That is, the first time Figure B is created, it remains in focus. If I then use Figure A to update the plots in Figure B, the focus correctly switches back to Figure A. I can't think of why it behaves differently during the first redraw and all subsequent calls.
2) The even bigger issue is that if I set a breakpoint anywhere in the code and then resume execution, the focus switches back to Figure A as I want. So, why does entering the debugger and doing nothing else fix the problem? How can I find the issue if everything works in the debugger?
Thanks in advance!
EDIT: To my great surprise, I was able to reproduce this "Heisenbug" by writing my first ever programmatic GUI. This should be the simplest example of my problem. To see it in action, simply run the code below and click on the push button. For some reason, when Window 2 is created for the first time, the focus does NOT switch back to Window 1 as intended. It works properly for all subsequent button presses. Try closing Window 2 and pushing the button again, the error will keep occurring.
As mentioned in the original post, setting a breakpoint in the code resolves the issue. Set a breakpoint at line 27, then resume execution and Window 1 will be in focus.
What is happening here?
function heisenbug
%% Main problem:
% After clicking the push button, I want the focus to
% always switch back to Window 1 (the one containing the button).
% However, this does not work when Window 2 is first created.
%%
%% Create and then hide the GUI as it is being constructed
f = figure('Visible','off','name','Window 1','units','normalized','Position',[0.1 0.1 0.5 0.5]);
%% Initialize handles structure
handles = guihandles(f);
handles.window2 = [];
guidata(f,handles)
%% Make a button
hbutton = uicontrol('Style','pushbutton','String','Push me','units','normalized',...
'Position',[0.1 0.1 0.8 0.8],...
'Callback',#button_Callback);
%% Make the GUI visible
f.Visible = 'on';
%% Button callback
function button_Callback(source,eventData)
handles = guidata(gcbo);
% If Window 2 already exists, plot a circle, then switch focus back to Window 1.
if ~isempty(handles.window2) && ishandle(handles.window2)
figure(handles.window2);
plot(1,1,'bo')
figure(f);
% Otherwise, create Window 2 and do the same thing.
else
handles.window2 = figure('Name','Window 2','units','normalized','position',[0.4 0.1 0.5 0.5]);
plot(1,1,'bo')
figure(f)
end
guidata(source,handles)
end
end
My post was quickly answered by Adam (thanks!) on the MathWorks site: http://se.mathworks.com/matlabcentral/answers/299607-simply-entering-the-debugger-during-execution-of-matlab-gui-fixes-error-that-persists-during-normal.
I needed to insert a pause(0.05) after Window 2 is created, before trying to switch the focus back with figure(f). Otherwise the focus is stolen back to Window 2 when it finishes plotting.
I made a GUI where i would like to have the position from, in pixels. I set the "Resize behaviour" to "Proportional"
Now i use
Position = getpixelposition(Test)
Test is the name of the GUI. I added a button to the Gui. Once i click on the button the code runs. But what happens, is that the screen shifts location. It was full size, now it shifts. 38 pixels to the right and 61 down.
Anybody an idea why this is?
Maybe other solutions to get the postition of my GUI?
I can't reproduce this behavior on my system (Win32 + MATLAB2012a).
However, to see what causes it:
type in your Command Window:
edit getpixelposition
set a breakpoint at the beginning of the function;
trigger the code tha calls getpixelposition;
step into the function (F11 preferably), and notice when the change of the position takes place; the executed statement would be the cause.
To get the position in pixels, you may use the undocumented hgconvertunits. From the .m file:
Y = HGCONVERTUNITS(FIG, X, SRCUNITS, DESTUNITS, REF) converts
rectangle X in figure FIG from units SRCUNITS to DESTUNITS
using the object with handle REF as the reference container for
normalized units. REF can be the root object.
I want to detect how many times the user click spacebar in 5 seconds
Is there any good way to fix this problem?
Thanks
One way to easily read user inputs from the keyboard is to create a new figure and specify a KeyPressFcn callback function, which is executed automatically if any key is pressed.
Lets start off by creating a new figure. As we don't need the figure to display anything, let's make it as small as possible (i.e. 1 by 1 pixel) and place it at the lower corner of the display:
f = figure('Position',[0,0,1,1]);
Now we'll set the UserData property of the figure - which we will use as counter - to zero:
set(f,'UserData',0);
Now let's see what to do when a key is pressed: We can create a small callback function which checks if the pressed button was a space and increases the UserData counter if that was the case. We'll call that function isspace:
function isspace(hObject,callbackData)
if get(hObject,'CurrentCharacter') == ' '
set(hObject,'UserData',get(hObject,'UserData')+1);
end
end
Now simply set up the figure to use this function as KeyPressFcn by
set(f,'KeyPressFcn',#isspace);
This already counts the number of times space is pressed. The current value of the counter is read by
get(f,'UserData');
Now we need the time measurement. This can be done using a timer. We'll configure it to go off after 5 seconds and then assing a new value in the base workspace. For that we need a callback function timerCallback.m
function timerCallback(hObj,eventData)
assignin('base','nSpace',get(gcf,'UserData'));
delete(gcf);
stop(hObj);
delete(hObj);
end
t = timer('StartDelay',5,'TimerFcn',#timerCallback);
start(t);
And that's it: First create the figure, create the timer and after 5 seconds you get the number of key presses in the variable nSpace in your workspace and the window is closed.
So how to click 2 screen regions at the same time or very fast one after another by using a single hotkey. The intent is to cover clicking on an object that can appear in 2 random areas of the screen by using a single key.
As an example I have tried using
a::click 735, 626 send, 750, 204 send, but it creates a loop for a few seconds, where the mouse is unresponsive and hovers in those areas, and using 2 separate hotkeys takes more time than i would wish.
I would also like to know if it is possible to issue a click command via a hotkey but not move the mouse pointer at all. I would like to set a hotkey that pressed will issue a left click command on a determined area of the screen but not move the mouse pointer in order to do so.
You definitely need to take a look at the help docs or FAQ again as well as some other examples to understand basic syntax. It is only one command per line. Here is an example of code that will get you going.
CoordMode, Mouse, Screen
SetDefaultMouseSpeed, 0 ; Sets default mouse speed to maximum
a::
MouseGetPos, X, Y ; Stores current mouse position
Click 735, 626
Click 735, 500
MouseMove, % X, % Y ; Moves mouse back to original position
Return
For the second question about issuing a click command without using the pointer, I suggest you look at the ControlClick documentation here: http://www.autohotkey.com/docs/commands/ControlClick.htm