I'm trying to write a macro to save preferences and read them after closing and reopening ImageJ.
The saving works, but the macro isn't reading the file. Moreover when I try to use one of these two lines an error occurs that the variable "Prefs" is unknown.
int myNumber = Prefs.get("my.persistent.number", 0);
Prefs.savePreferences();
What am I doing wrong? please help me :-)
The ImageJ macro language itself does not support storing custom preferences. (Only the set of built-in options (accessible via Edit > Options in the menu) can be saved, restored and adjusted.) You need to resort to calling the Java class via call("ij.Prefs.get", "my.persistent.number", "0");.
The following ImageJ macro works in an up-to-date Fiji/ImageJ installation:
myNumber = call("ij.Prefs.get", "my.persistent.number", "0");
print(myNumber);
call("ij.Prefs.set", "my.persistent.number", 3);
In the first run, it prints 0; every following run will print 3; after restarting Fiji, it will print 3 again. In case it does not work for you even after updating to the newest version, please report a bug via Help > Report a bug, which will also submit essential information about your installation to the developers to help them fix the issue.
Using one of the many scripting languages however, you can access the ij.Prefs java class directly, as you are trying to do it. Just do not forget to import the class before using it. This is an example Javascript:
importClass(Packages.ij.Prefs);
myNumber = Prefs.get("my.persistent.number", 0);
Prefs.set("my.persistent.number", myNumber);
Hope that helps.
Related
I am making a Minecraft Mod with Eclipse Mars and I got errors when typing the following:
#SidedProxy(clientSide = Reference.CLIENT_PROXY_CLASS, serverSide = Reference.SERVER_PROXY_CLASS)
What did I do wrong? It said "the attribute clientSide/serverSide is undefined for the annotation type SidedProxy" .
I cannot run Minecraft to test my mod without it, so I need to fix this error.
For a definitive answer you need to give us more information.
What version of minecraft forge are you using?
Have you correctly imported SidedProxy?
In eclipse, hold ctrl and click on #SidedProxy to open where it is declared, and check that you are using the correct attribute names (it may have changed between versions, so you may need to put something different)
hi I am new to jedit and I am trying to install a feature that lets me copy the current line when nothing is selected. I found this macro here http://www.jedit.org/users-guide/macros-clipboard.html under Copy_Selection_or_Line.bsh.
it seems like it is a default macro and I should be able to just use it without installing anything. but I can't find it in the list.
then I tried using the code for this macro here https://github.com/aismail/sedemo2011/blob/master/lib/jason/bin/jedit/macros/Clipboard/Copy_Selection_or_Line.bsh
I installed it and I can now enable it, but it doesn't work.
I spent ages trying to get this macro working but it's just not working. anyone able to give me a hand? thanks
The Copy_Selection_or_Line.bsh macro was renamed 7 years ago as can bee seen here: https://sourceforge.net/p/jedit/svn/11860.
It seems the documentation was not updated accordingly.
Would be great if you open a documentation bug here: https://sourceforge.net/p/jedit/bugs/new/
This shipped macro should work without any problems.
What you linked above is the macro as it was before that change I linked. It could well be that some API changed since 7 years ago and that the macro is not usable as is. Is the Copy_Lines.bsh macro doing what you want? If not, it could maybe at least help in updating the old Copy_Selection_or_Line.bsh macro to work with current jEdit.
I modified the macro (attached below):
// My Copy_Selection_or_Line.bsh
if (textArea.getSelectionCount() == 0) {
caretLine = textArea.getCaretLine();
lineEndOffset = textArea.getLineEndOffset(caretLine);
textArea.setSelection(new Selection.Range(textArea.getLineStartOffset(caretLine), textArea.getBufferLength() >= lineEndOffset? lineEndOffset : lineEndOffset-1));
}
Registers.copy(textArea,'$');
This might be a very simple question, but I am writing a little Macro for ImageJ and I cannot access the values in the Results log. Here is the code that does NOT work:
selectWindow("Results");
test=getResult("channel",0);
print("test");
Any tips on how this could be done? Thanks.
You were correct in pointing out that it might be due to a plugin not using the standard results table of ImageJ. The Color_Histogram plugin uses a non-standard way to report the results.
I filed a pull request on github.com that fixes this. When this pull request is merged and uploaded to the Fiji updater, the following macro code works as expected after running Analyze > Color Histogram:
test1 = getResultString("channel", 0);
print(test1);
test2 = getResult("mean", 0);
print(test2);
I am trying to work with xrc resource in wxpython.
It is good but where is one big "no" - there is no autocomplete of wxFrame class loadet from xrc. And other loaded from xrc classes too.
Is this right or I'am doing somthing wgong?
here is the part of code for example:
import wx
from wx import xrc
class MyApp(wx.App):
def OnInit(self):
if os.path.exists("phc.xrc"):
self.res = xrc.XmlResource("phc.xrc")
self.frame = self.res.LoadFrame(None, 'MyFrame')
self.list_box = xrc.XRCCTRL(self.frame, "list_box_1")
self.notebook = xrc.XRCCTRL(self.frame, "Notebook")
self.StatusBar= xrc.XRCCTRL(self.frame, "MFrame_statusbar")
self.list_ctrl= xrc.XRCCTRL(self.frame, "list_ctr_1")
Well, how good the autocomplete function is depends entirely on the editor/IDE that you are using. You didn't specify what you are using to write python scripts, but from personal experience I would say that it is probably true, that there is no autocomplete.
I've used Eclipse/PyDev, Spyder, SPE and PyCharm in the past and they all did not show an ability to autocomplete widgets created with XRC. You could still try to get the Emacs autocomplete for Python to work and try it there, but I doubt it'll work.
I did not find this a particular hindrance, but everyone's different, I guess. Hopefully, that answers your question.
Yes autocomplete wouldn't work here since our code doesn't know what the xrc is going to return. Your code gets to know about the type of variable (in this case, frame) only during runtime.
And, unfortunately/fortunately, we cannot assign 'type' to a variable in Python for the autocompletion to work.
But in Eclipse + PyDev plugin
you can add this statement for autocomplete to work:
assert isinstance(self.frame, wx.Frame)
autocomplete works after this statement.
I want to implement the function like embedding the socket function in my Lua build.
So I don't need to copy socket.core.dll any more (just for fun).
I search the maillist, and see some guys discuss the topic,
http://lua-users.org/lists/lua-l/2005-10/msg00269.html
But I have question for the details steps, who could give me a detailed steps for changing the lua and luasocket code to make them work together (not with dll method).
I tried these steps in windows xp with VC2008:
1) copy luasocket code to Lua project.
2) add some code
static const luaL_Reg lualibs[] = {
{"", luaopen_base},
{LUA_LOADLIBNAME, luaopen_package},
{LUA_TABLIBNAME, luaopen_table},
{LUA_IOLIBNAME, luaopen_io},
{LUA_OSLIBNAME, luaopen_os},
{LUA_STRLIBNAME, luaopen_string},
{LUA_MATHLIBNAME, luaopen_math},
{LUA_DBLIBNAME, luaopen_debug},
{LUA_SOCKETLIBNAME, luaopen_socket_core}, // add this line
{LUA_MIMELIBNAME, luaopen_socket_core}, // add this line
{NULL, NULL}
};
3) build the project, and run it.
When I type print(socket._VERSION), it shows luasocket 2.0.2, it is correct.
When I type print(socket.dns.toip("localhost")), it shows 127.0.0.1 table: 00480AD0, it is correct too.
But when I try to use other features, for example bind, it can't work.
Who could tell me the reason?
you need put luasocket stuff into the package.preload table, in this way:
lua_getfield(L, LUA_GLOBALSINDEX, "package");
lua_getfield(L, -1, "preload");
lua_pushcfunction(L, luaopen_socket_core);
lua_setfield(L, -2, "socket.core");
// add mime.core yourself...
luasocket is a mixed C/lua module, you need to bundle both versions into your application if you want it to work without any extra files.
socket.lua loads socket.core (from socket/core.dll)
mime.lua loads mime.core (from mime/core.dll)
So in order for your application to work you will need to build all the .dll files and the .lua files into your application and manually load them (or set them up to be loaded correctly via custom package loaders).
The email you quoted is tweaking the package.preload table (in a way that appears a tad odd now but might work anyway) to get the built-in C code to be loaded correctly when require is called.
Try running
for k, v in pairs(socket) do print(k, v) end
and maybe we'll be able to help.