ImageSearch command failing - autohotkey

I'm trying to create a hotkey that will find the google sheets "tools" menu, click on it, move down a few pixels and click on script editor. I could do this within google sheets but it doesn't have universal keybinds for this, I'd have to make a macro and I'd rather it just be universal.
SC163::
{
ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, C:\Users\xx\Documents\AHK Scripts\gsheets-tools.bmp
if ErrorLevel = 2
tooltip Could not conduct the search.
else if ErrorLevel = 1
tooltip Image could not be found on the screen.
else
{
mousemove, %FoundX%, %FoundY%, 50
tooltip The image was found at %FoundX%x%FoundY%.
}
return
}
It was throwing error 2 until I hardcoded the entire image name. Now it only throws error 1, even if I have three copies of sheets open (one on each monitor). Is BMP not the best format to use here? I tried using
ImageSearch, FoundX, FoundY, 0, 0, A_ScreenWidth, A_ScreenHeight, *n30 C:\Users\xx\Documents\AHK Scripts\gsheets-tools.bmp
to see if adding that allowance would helps, but failure. Any tips for using image search correctly? This isn't some sophisticated game function, just trying to find a toolbar and click on it!

Try changing *n30 to just *30.
Also, by default, ImageSearch coordinates are per the active window and not the entire desktop, so using A_ScreenWidth and A_SreeenHeight might be problematic. While this isn't an issue if the window is maximized on your primary screen, it may present a problem if it's not maximized or is on a screen with a different resolution. If it's not maximized, it could be searching an area that goes beyond your display area, which might be an issue.
Possibly another issue (unverified) could be with Windows scaling. A lot of times a 2160p monitor defaults to 200% scaling (or is it 150%? w/e).
Since you're using BMP images, you may want to verify that it was saved as 16-bit or higher.
Notable quotes from the help file:
All operating systems support GIF, JPG, BMP, ICO, CUR, and ANI images (BMP images must be 16-bit or higher).
. . .
The region to be searched must be visible; in other words, it is not possible to search a region of a window hidden behind another window. By contrast, images that lie partially beneath the mouse cursor can usually be detected. The exception to this is game cursors, which in most cases will obstruct any images beneath them.

I suggest you using this for Image Search
https://www.youtube.com/watch?v=aWRAtvJq9ZE
It is very simple and works pretty good!

Related

Dymola Command to Maximize or Manipulate Size or Placement of Plot Window

Is there a command to maximize or manipulate in any way the size and placement of a plot window in Dymola?
After creating a plot using createPlot(), I would like to maximize that window within its allowed area of the screen.
No resource, either online or printed, has indicated how to do this, and none has said it couldn't be done. I am hoping someone can point me to a source that tells me how, or tells me to stop trying.
Here is the entirety of my test script:
simulateModel("TIL_AddOnTraining.Example07a", stopTime=300, method="dassl", tolerance=1e-005, resultFile="Example07a");
createPlot(
id=0,
position={0, 0, 857, 705},
x="valve.summary.dp",
y={"valve.summary.m_flow_A"},
grid=true,
colors={{255,0,0}},
thicknesses={0.7},
autoscale = true
);
[Here is where I would like the command to maximize window called "Plot [0*]".]
Thanks in advance.
Not an answer to the feasibility of doing this in Dymola, but here's a way to create and fine tune plot windows for Modelica using Mathematica and SystemModeler.
Needs["WSMLink`"]
sim=WSMSimulate["HelloWorld"];
plot=WSMPlot[sim,{"x","der(x)"},PlotLabel->"Very Interesting Plot\[Dash]Full Screen"];
CreateDocument[plot,WindowSize->Full]
The setting WindowSize can be changed to different options to select a fraction of the window, full screen, pixel size, and so on.

How to display a big figure with mlpd3 inside jupyter notebook?

I am using jupyter-notebook to write some python code and generate figures. As I wanted to add tooltips on mouse hovering and other interactions with the generated graphs, I now use mpld3 to display the graph.
However, as I have quite a lot of things to plot, I need to increase the figure size. So, I putfig = plt.figure(figsize=(20, 10)).
When I display with the standard way, I can see all the figure in my notebook (with horizontal sliders if I increase a bit more the figsize).
But with the mpld3 display, the size of the zone where the figure is displayed seems to be fixed, and hence, I can only see the upper left part of my figure. There are no sliders or anything to increase the displaying zone size.
For example, this code generate a graphic, for which you will see only the upper left part:
fig = plt.figure(figsize=(20, 10))
plt.plot([3,1,4,1,5], 'ks-')
mpld3.display(fig)
Does anyone know how to deal with this ? That is, how to increase the default display zone size, in order to have bigger graphs ?
Thanks
Edit after comment:
Here is a screenshot of how it is displayed on my machine...
And I would like it to be displayed just as it is on yours !
So I guess the problem comes from elsewhere... do you have any idea of how to solve this ?
I hope I do understand your question correctly but in Ipython Notebooks you can only use excisting space and not flip the notebook into wide screen mode or alike. In my notebook the graphic is also displayed like you show.
However, there is an easy fix, simply reduce the figsize to for example (10, 5). The main idea with interactive plotting with mpld3 is that the user can zoom in to specific interesting details. For the presented example it would not make much sense but richer graphs are great to be explored interactively.

AutoHotKey - Make image appear relative to a set of moving pixels?

Is it possible to create an AHK script that will position a given image (not changing) relative to a different "image" that will be moving constantly on the computer screen? I put the second "image" in quotations because the program would have to constantly search for that "image" or set of pixels that make up that "image" in order to correctly position the first image relative to the second "image".
If it's not possible to do this with AHK, how else can this be done?
The "image" would have to be placed always on top (or above all other programs).
Yes this can be achieved relatively easily.
You will need to create a Loop which performs:
Pixel Search/Image Search
Using the data retrieved from (1), depending on how the image is displayed using AHK, perform a image move function. If you use a borderless window (GUI), you will need WinMove function.
See all commands here: Commands

Matlab: opening propertyeditor or plotbrowser forces correct textbox annotation; annotation fails without it

I have a generally happily running program that takes files, plots them, spits out a pdf (letter size). I use annotations to put in a title above a set of three subplots, and to use as a footer with file info and date. I would like the title to be at the top of the page, filling up from margin to margin, centered.
I have two ways of running the program: in 'batch' mode and 'interactive' mode. When in 'interactive' mode, I create the figure with a simple figure() command. When in 'batch' mode, I create the figure with figure('visible','off'). Here is my command for making the annotation:
annotation(obj.hFigure(f),'textbox',[0 0.9 1 0.1],...
'String',title,...
'HorizontalAlignment','center',...
'FontSize',18,...
'LineStyle','none',...
'FitBoxToText','off');
Here, "obj.hFigure(f)" is simply a handle to the figure I am currently processing. As you can see, I place the figure near the top of the figure, and make sure that the text runs off the bottom of the box (in case it is larger).
My problem is with margins on the above annotation. In batch mode (no figures showing), I get 10% or so margins on either side of the text, which ruins the layout. In interactive mode (figures show up), I don't get the margins: the text correctly flows from one edge to the other.
I have narrowed down the problem to the following: I can get the correct response to the ps printing in batch mode if I make the figures visible (figure('visible','on')) AND open up
propertyeditor(gcf);
plotbrowser(gcf);
after each figure is plotted. This makes the program take about twice as long (which isn't a huge deal). But what I don't understand is: what do those two commands do that drawnow or refresh don't accomplish?!
I am unsure about your specific case, but when encountering this kind of problem in the past I have had great success by explicitly setting the figure size with:
set(gcf, 'Position', [100 100 300 300])
and then, before printing/saving setting the PaperPositionMode to auto, which seems to force the printed figure to be the same size as the one shown on screen:
set(gcf, 'PaperPositionMode','auto')

How to print figure to clipboard by PRINT function with the quality identical to 'Edit-->Copy Figure' option?

Is there any way to print the figure to the clipboard so that the quality is identical to what the Edit-->Copy Figure option provides?
I used to save the figure to powerpoint file by using saveppt.m obtained from Matlab Central. It worked well until yesterday. I noticed that the stored image quality was somehow degraded. I tried to re-generate some ppt slides with exactly the same script and the same source data, but the new slides are simply of worse quality.
I investigated into this problem a little bit and discovered that when the figure is copied to clipboard by running print -dmeta, the image in the clipboard is already degraded, while if I use the Edit-->Copy Figure option in the figure window, I get the image as clear as the original image in the figure window.
Following is an example for your reference. I copied the image from a figure to the clipboard by two different methods, and paste it to Microsoft Paint program, and cut a piece of it to show below:
The image using print -dmeta:
The image using Edit-->Copy Figure:
If you compare the Xtick label '50', you may see that the image from Edit-->Copy Figure is smoother.
At the beginning I thought it was a problem of the resolution, but setting -rN to change the resolution does not seem to resolve my problem, at least not for N<=300.
Thank you for your help.
The short answer... Use the same function invoked in the callback for that menu item:
editmenufcn(gcf,'EditCopyFigure');
The longer answer... How exactly did I find this? You can look at my previous answer to a related question about reproducing what is done by a File menu option. The concept is the same, just for a different figure menu. For example, this will find the callback you want for the currently active figure window:
>> hCopyFigure = findall(gcf,'Label','Copy &Figure'); %# Handle for the "Copy
%# Figure" menu item
>> get(hCopyFigure,'Callback') %# Callback invoked when that item is selected
ans =
editmenufcn(gcbf,'EditCopyFigure')
The function EDITMENUFCN is another one of those sparsely documented functions, but looking through the code (by typing edit editmenufcn.m) shows that it either invokes Java (if you're on a Mac) or the undocumented function UIMENUFCN.
I think I found the answer myself. Using print -dmeta -painters to specify the renderer resolves my problem.
In File-->Preference-->Figure Copy Template-->Copy Option I noticed there are 3 options:
Metafile
Preserve information
Bitmap
I found that if I select 1, the Edit-->Copy Figure outputs the same image as print -dmeta. So I kind of confirmed the information I need is in the Preserve information option. A quick google search led me to the discussion about the potential difference of the applied renderer, and eventually I confirmed that using painters will print the image to the clipboard in the way I wanted.
The image in the question seems to be generated by the renderer zbuffer and painters, respectively. I still don't know why the default renderer of paint -dmeta changes, though.