I'm adding labels to a plot. I've followed this tutorial for moving label to best position with the mouse and was glad to discover label can be rewritten at mouse position.
But once it's done, I haven't found any way to get the text value of the label if one wants to move the label at a later time (if in need to adjust position more accurately when zooming say) without copying/pasting the label's text.
In the script, the text is entered and kept around, but I would like to move the label with its id only and get the text or any other way to move the label.
gnuplot> set label 1 "square" at 0,0
> show label
label 1 "square" at (0.00000, 0.00000, 0.00000)
> moveLabel(labelId, text) = sprintf('call "label_loop.gnu" "%s" "%d"', text, labelId)
> eval moveLabel(1, "square") -> should be: eval moveLabel(1)
'label_loop.gnu' for gnuplot-5.0 is the comment part.
Since you mention that you want to call the function just as eval moveLabel(1), I assume that the label has been previously set within your script using set label .... If this is the case, you could modify label_loop.gnu as:
#make sure that label_number is an integer and not a string so that
#it is not "misinterpreted" in "set label"
label_number = int(ARG1);
pause mouse any "adjust label"
#any other button will quit the loop
if( MOUSE_BUTTON == 1 ) {
#using ARG1 instead of label_number or int(ARG1) would
#create a new label with the content of ARG1 as its text
set label label_number at MOUSE_X,MOUSE_Y
print "\n moved label ".ARG1." to position: ",MOUSE_X,MOUSE_Y
replot
call 'label_loop.gnu' ARG1
}
and then use it from the main script for example as:
set term x11
set mouse
set label 1 "square" at 0,0
moveLabel(labelId) = sprintf('call "label_loop.gnu" "%d"', labelId)
plot x
eval moveLabel(1)
The "trick" here is that if you call the set label command without any text, Gnuplot just updates the position and keeps the text as it was...
Related
I have a NSTextField with some text "sometext". How can I place the cursor between e and t: "some|text" programmatically?
You need to set your text field current editor selected range property. Try like this:
textField.currentEditor()?.selectedRange = NSRange(location: 4, length: 0)
You will need to call displayIfNeeded
textField.displayIfNeeded()
The ruby code below prints two windows (overlapping) via Curses. The first "border" window prints in black/cyan and the "content" window prints in blue on cyan.
The content window only displays the background color where text is printed. The rest of the content window remains black. The ruby dox describe ways to manipulate window backgrounds using either color_set, bkgd or bkgdset methods. I can only get color_set() to work however and only for text that is being printed:
How can I fill the reset of the content window with the appropriate background color? I found some code to Set a window's background color in Ruby curses but it does not seem to work and is quite old. The only other idea I have is to right-pad the string with spaces to fill the entire window with the background character but this seems reeealy hacky.
EDIT: added code
EDIT2: added "hacky padding" work around
#!/usr/bin/ruby
require 'curses'
Curses.init_screen
Curses.start_color
Curses.noecho
Curses.cbreak
Curses.refresh # Refresh the screen
xulc = 10
yulc = 10
width = 30
height = 8
# text color for border window
Curses.init_pair(1, Curses::COLOR_BLACK, Curses::COLOR_CYAN)
Curses.attrset(Curses.color_pair(1) | Curses::A_BOLD)
# Text color for content window
Curses.init_pair(2, Curses::COLOR_BLUE, Curses::COLOR_CYAN)
Curses.attrset(Curses.color_pair(2) | Curses::A_NORMAL)
# border window
win1 = Curses::Window.new(height, width, yulc, xulc)
win1.color_set(1)
win1.box("|", "-")
# content window
win2 = Curses::Window.new(height - 2, width - 2, yulc + 1, xulc + 1)
win2.color_set(2)
win2.setpos(0, 0)
# only prints in background color where there is text!
# add hacky padding to fill background then go back and print message
bg_padding = " " * ((width - 2) * (height - 2));
win2.addstr(bg_padding);
win2.setpos(0, 0)
win2.addstr("blah")
# prints without the color_set() attributes
#win2.bkgd ('.'.ord)
# make content visisble
win1.refresh
win2.refresh
# hit a key to exit curses
Curses.getch
Curses.close_screen
Ok, so I found this, the actual code is here:
It's been a while, but maybe my examples are still useful:
It is the same "diamonds" for me when using
window.bkgd(COLOR_RED) This seems to appear, because the bkgd method
takes a char and prints it to all free spaces of the window (see old
doc).
However, then you can use a color pair with the wanted background
color and apply it to all screen positions before writing oher stuff.
Here is how I solved it:
require 'curses'
init_screen
start_color
init_pair(COLOR_RED, COLOR_WHITE, COLOR_RED)
window = Curses::Window.new(0, 0, 0, 0)
window.attron(color_pair(COLOR_RED)) do
lines.times do |line|
window.setpos(line, 0)
window << ' ' * cols
end
end
Also found this:
# color_set(col)
# Sets the current color of the given window to the foreground/background
# combination described by the Fixnum col.
main_window.color_set(1)
tutorial.html#colors-initialization
Guess I'll use the hacky padding workaround. Seems to be all I've found so far
I have made a simple script application which accepts radius as input from user and calculates and displays area of circle based on input:
-- initializing radius variable to some text
set radius to "Some text"
repeat until class of radius is number
-- asking user for radius
display dialog "Enter radius: " default answer "" buttons {"Done"} default button 1
set userInput to text returned of result
-- try to check if user enters radius as number
try
-- converting input from user to number
set radius to userInput as number
-- if input is found as number then below code is executed
-- obtaining radius from handler
set circleArea to calculateCircleArea(radius)
-- displaying radius and area of circle obtained to user
display dialog "Circle area for radius: " & radius & " is: " & circleArea buttons {"OK"} default button 1
end try
end repeat
-- handler definition
on calculateCircleArea(parameterRadius)
set areaOfCircle to pi * (parameterRadius ^ 2)
end calculateCircleArea
When I executed the above script and entered some text for the first time, it again asked me to enter the radius, this time I entered some number and it displayed the area of circle but it again started asking for radius as input from user.
Can anyone suggest me where I am wrong in the above script?
Thanks,
Miraaj
repeat until class of radius is integer or class of radius is real
I have such code:
a=5;
b=a;
c=10;
u = (0:0.05*pi:2*pi)'; %'
v = [0:0.05*pi:2*pi];
X = a*sin(u)*cos(v);
Y = a*sin(u)*sin(v);
Z = c*cos(u)*ones(size(v));
Z(Z>0)=0; % cut upper
V1=4/3*pi*a*b*c;
d=1/2;
e=2^d;
a2=a/e;
b2=a/e;
c2=c;
V2=4/3*pi*a2*b2*c2;
X2 = a2*sin(u)*cos(v);%-2.5;
Y2 = b2*sin(u)*sin(v);
Z2 = c2*cos(u)*ones(size(v));%+0.25;
Z2(Z2>0)=0; % cut
h=1/3;
for j = 1:20
k1=(sin(pi*j/20)+0.5)^h;
a=a*k1;
c=c*k1;
X = a*sin(u)*cos(v);
Y = a*sin(u)*sin(v);
Z = c*cos(u)*ones(size(v));
Z(Z>0)=0;
a2=a2*k1;
b2=a2*k1;
c2=c2*k1;
X2 = a2*sin(u)*cos(v)+5;%-2.5;
Y2 = b2*sin(u)*sin(v);
Z2 = c2*cos(u)*ones(size(v));%+0.25;
Z2(Z2>0)=0;
hS1=surf(X,Y,Z);
alpha(.11)
hold on
hS2=surf(X2,Y2,Z2);
hold off
axis([-20 20 -20 20 -20 20]);
F(j) = getframe;
end
movie(F,4)
I have to input parameters a,b,c from the keyboard. I've made GUI & tried to do it by using "Edit text" with a function below, but it's not working((.
I can't understand what's the problem with it.
function a_edit_Callback(hObject, eventdata, handles)
user_entry = str2double(get(hObject,'string'));...
a=user_entry;
The problem is that your callback function executing your code is not 'seeing' the parameters you defined in your edit text callbacks. You need to establish your variables in the subfunction, since they aren't global.
Using guide, set up a uicontrol button to click when you've entered your parameters into your uicontrol edit text boxes. Under the callback of your button, place your above code, with the following at the top:
a=str2double(get(handles.a_edit,'String'));
b=str2double(get(handles.b_edit,'String'));
c=str2double(get(handles.c_edit,'String'));
This will pull in the current strings of your edit text uicontrols. (Assuming you've assigned the tag format x_edit for each of the edit text boxes in guide.)
EDIT:
Open the figure you already created with the edit text boxes. Next, check to make sure each of your text boxes have the tag a_edit, b_edit, c_edit by using the property inspector. Then create a button using guide, and open the property inspector by double clicking on it. Find the 'tag' field, and name it run. Save your figure, and open the corresponding M-file.
Next, find the line with run_Callback(hObject, eventdata, handles). Place the following under it:
a=str2double(get(handles.a_edit,'String'));
b=str2double(get(handles.b_edit,'String'));
c=str2double(get(handles.c_edit,'String'));
%# Add the rest of your code from above verbatim, minus the first three lines
This should be the ONLY code you add to the auto-generated M-file - don't mess with anything else until you get this much working. If you don't want the animation popping up randomly in your figure window, you can add a set of axes using guide as well.
From the looks of the code, it appears to be a 'script' and not a 'function'.
Did you just want a 'dialog (built-in GUI dialog)'? If so, you can add the following at the beginning of your script:
prompt = {'Enter the parameter value "a":','Enter the parameter value
"b":','Enter the parameter value "c":'};
dlg_title = 'Input the Parameter Values';
num_lines = 1;
def = {'5','5','10'};
answer = inputdlg(prompt,dlg_title,num_lines,def);
a=answer{1};a=str2double(a);
b=answer{2};b=str2double(b);
c=answer{3};c=str2double(c);
% Y.T.
I'm working with some legacy code and need to change the background color of a row (and the font color) in a ListView in VB6 based on some criteria. I need to change the color of the row when the row is selected and not selected. I can change the font color of a non-selected row via the .Foreground property but I can't change the color in any of the other scenarios.
Check out this forum post. Here's an sample from the code which colors every other row:
'\\ loop through the rows to select every other row
For i = 1 To lvwBackColour.ListItems.Count
If (lvwBackColour.ListItems(i).Index Mod 2) = 0 Then
'\\ add a tick to the checkbox
lvwBackColour.ListItems(i).Checked = True
'\\ add the colour to the picturebox
'\\ See Here (http://msdn2.microsoft.com/en-us/library/aa230480(VS.60).aspx)
'\\ for information about the Line method
picBG.Line (0, i - 1)-(1, i), &H4000FF, BF
'\\ update column four caption
lvwBackColour.ListItems(i).SubItems(3) = "Hidden column value = 1"
Else
'\\ remove the tick from the checkbox
lvwBackColour.ListItems(i).Checked = False
'\\ reset backcolour to white
picBG.Line (0, i - 1)-(1, i), &HFFFFFF, BF
'\\ reset the Column Four caption
lvwBackColour.ListItems(i).SubItems(3) = "Hidden column value = 0"
End If
Next i
'\\ set the listview to use the picturebox image
lvwBackColour.Picture = picBG.Image
Here's the link to the msdn article which talks about the Line method.
The background color of selected rows is controlled by the system. You cannot change it to anything else.
If you have to be able to change the background of the selected rows, you will need to custom draw the listview -- which, to be honest, is too much of a pain to seriously consider :)