Using handles to nested function for GUI callbacks in Octave - user-interface

I am trying to develop a GUI in Octave (4.0.1, using the GUI version) with the code as follows:
Main GUI function
Function to create figure & various uicontrol
Callback function for uicontrol #1
Callback function for uicontrol #2
Callback function for uicontrol #3
etc...
Each function is delimited by function & end. The first callback I tried to write looks like this: the button is defined in the "graphical creation" function as:
gui.select_btn = uicontrol('Style','pushbutton','String','Select log file ...',...
'Units','normalized','Position',[0.01 0.52 0.25 0.47],...
'BackgroundColor',get(gui.Window,'Color'),'Parent',gui.file_panel,...
'Enable','on','Callback',{#browse_log_file,gui});
and the callback for it is defined in the callback function later as:
function browse_log_file(src,data,gui)
% Called when user presses the "Select log file ..." button
[fname, pname] = uigetfile({'*.log'},'Select log file');
set(gui.log_file_edit,'String',[pname,fname]);
end
whi gui being a struct defined in the main GUI function by calling the "graphical creation" function & accessible by all nested functions.
However, when I try to run the code, I get the following error message:
error: handles to nested functions are not yet supported
error: called from
GUI_analyser>create_interface at line 71 column 20
GUI_analyser at line 8 column 7
error: evaluating argument list element number 1
error: called from
GUI_analyser>create_interface at line 71 column 20
GUI_analyser at line 8 column 7
error: evaluating argument list element number 16
error: called from
GUI_analyser>create_interface at line 71 column 20
GUI_analyser at line 8 column 7
pointing to the line with {#browse_log_file,gui}.
Any suggestions on how to work round this problem?

Related

Why won't Scilab open an image file?

I am trying to work with image files under Scilab, and I get stuck at the very beginning, unable to load an image file.
I have searched the help system as well as the Web, tried two versions of Scilab (because some of the answers I found say that 6.0 is incompatible with some image functions) and still drew a blank. Whatever I try, the imread function is simply not there.
Here is what I get:
Under Scilab 6.0.2:
--> clear
--> atomsSystemUpdate()
Scanning repository http://atoms.scilab.org/6.0 ... Done
--> atomsInstall("SIVP")
atomsInstallList: The package "SIVP" is not registered.
Please check on the ATOMS repository that it is available for Scilab 6.0 on Windows.
If it is, run atomsSystemUpdate() before trying atomsInstall(..) again.
at line 52 of function atomsError ( C:\Program Files\scilab-6.0.2\modules\atoms\macros\atoms_internals\atomsError.sci line 66 )
at line 78 of function atomsInstallList ( C:\Program Files\scilab-6.0.2\modules\atoms\macros\atoms_internals\atomsInstallList.sci line 117 )
at line 233 of function atomsInstall ( C:\Program Files\scilab-6.0.2\modules\atoms\macros\atomsInstall.sci line 249 )
--> atomsInstall("IPCV")
ans =
[]
--> disp( atomsGetInstalled() );
!IPCV 4.1.2 user SCIHOME\atoms\x64\IPCV\4.1.2 I !
--> im=imread("Kratka220.tif")
Undefined variable: imread
Under Scilab 5.5.2:
-->clear
-->atomsSystemUpdate()
Scanning repository http://atoms.scilab.org/5.5 ... Done
-->atomsInstall("SIVP")
ans =
[]
-->atomsInstall("IPCV")
atomsInstallList: Pakiet IPCV nie jest dostępny.
<this is Polish for "Package IPCV is not available"; I installed 5.5.2 in Polish>
!--error 10000
at line 51 of function atomsError called by :
at line 76 of function atomsInstallList called by :
at line 233 of function atomsInstall called by :
atomsInstall("IPCV")
-->disp( atomsGetInstalled() );
column 1 to 4
!SIVP 0.5.3.2 user SCIHOME\atoms\x64\SIVP\0.5.3.2 !
column 5
!I !
-->im=imread("Kratka220.tif")
!--error 4
Niezdefiniowana zmienna: imread
<this is Polish for "undefined variable">
What am I doing wrong?
After atomsInstall you have to restart Scilab to load the toolbox.

How can I run all functions in a bash script, in the order in which they are declared without explicitly calling the function? [duplicate]

This question already has answers here:
Get a list of function names in a shell script [duplicate]
(4 answers)
Closed 6 years ago.
Lets say I have a script that has a bunch of functions that act like test cases. So for example:
#!/bin/bash
...
function testAssertEqualsWithStrings () {
assertEquals "something" "something"
}
testAssertEqualsWithStrings <--- I dont want to do this
function testAssertEqualsWithIntegers () {
assertEquals 10 10
}
testAssertEqualsWithIntegers <--- I dont want to do this
function testAssertEqualsWithIntegers2 () {
assertEquals 5 $((10 - 5))
}
testAssertEqualsWithIntegers2 <--- I dont want to do this
function testAssertEqualsWithDoubles () {
assertEquals 5.5 5.5
}
testAssertEqualsWithDoubles <--- I dont want to do this
...
Is there a way I can call of these functions in order without having to actually use that explicit function call underneath each test case? The idea is that the user shouldnt have to manage calling the functions. Ideally, the test suite library would do it for them. I just need to know if this is even possible.
Edit: The reason why I dont use just the assert methods is so I can have meaningful output. My current setup allows me to have output such as this:
...
LineNo 14: Passed - testAssertEqualsWithStrings
LineNo 19: Passed - testAssertEqualsWithIntegers
LineNo 24: Passed - testAssertEqualsWithIntegers2
LineNo 29: Passed - testAssertEqualsWithDoubles
LineNo 34: Passed - testAssertEqualsWithDoubles2
...
LineNo 103: testAssertEqualsWithStringsFailure: assertEquals() failed. Expected "something", but got "something else".
LineNo 108: testAssertEqualsWithIntegersFailure: assertEquals() failed. Expected "5", but got "10".
LineNo 115: testAssertEqualsWithArraysFailure: assertEquals() failed. Expected "1,2,3", but got "4,5,6".
LineNo 120: testAssertNotSameWithIntegersFailure: assertNotSame() failed. Expected not "5", but got "5".
LineNo 125: testAssertNotSameWithStringsFailure: assertNotSame() failed. Expected not "same", but got "same".
...
EDIT: Solution that worked for me
function runUnitTests () {
testNames=$(grep "^function" $0 | awk '{print $2}')
testNamesArray=($testNames)
beginUnitTests #prints some pretty output
for testCase in "${testNamesArray[#]}"
do
:
eval $testCase
done
endUnitTests #prints some more pretty output
}
Then I call runUnitTests at the bottom of my test suite.
If you just want to run these functions without calling them, why declare them as functions in the first place?
You either need them to be functions because you are using them multiple times and need the calls to be different each time, in which case I don't see an issue.
Otherwise you just want to run each function once without calling them, which is just running the command. Remove all the function declarations and just call each line.
For this example
#!/bin/bash
...
assertEquals "something" "something" #testAssertEqualsWithStrings
assertEquals 10 10 #testAssertEqualsWithIntegers
assertEquals 5 $((10 - 5)) #testAssertEqualsWithIntegers2
assertEquals 5.5 5.5 #testAssertEqualsWithDoubles
...

C++: C2511: Overloaded member function not found. problems when using 'this'

I have this one object that tries to call a function in another class's function. That function looks like this (Belongs to class 'Player' ):
void play(Game *const currentGame, int x, int y);
When I try to call this function from another object (of the Game class) like this :
player->play(this, x, y)
And during compilation I get these errors:
Error 1 error C2061: syntax error : identifier 'Game' c:\users\shaqed\documents\visual studio 2013\projects\exe3\tictactoe.h 24 1 Exe3
Error 3 error C2511: 'void Player::play(Game *const ,int,int)' : overloaded member function not found in 'Player' c:\users\shaqed\documents\visual studio 2013\projects\exe3\tictactoe.cpp 40 1 Exe3
Error 4 error C2660: 'Player::play' : function does not take 3 arguments c:\users\shaqed\documents\visual studio 2013\projects\exe3\tictactoe.cpp 158 1 Exe3
I came from Java, so maybe I lack some of the core principles about pointers and reference, however I could figure out why there's a type mismatch in here.
Thanks in advance
I have repeated your problem with the same compile errors. I think you have forgotten to add at the end of your method the body. Like:
void play(const Game *currentGame, int x, int y){}

XML Parsing Error : AJAX Chat

I am just trying to plant AJAX Chat for my website users. I have successfully completed the installation process with database configuration. But when I am trying to brows the domain.com/ajaxchat/index.php its returning this error given below:
XML Parsing Error: junk after document element Location: http://futurenext.esy.es/inc/chat/ Line Number 2, Column 1:
I think that the problem is in AJAXChatTemplate.php , and here the code is:
function getContent() {
if(!$this->_content) {
$this->_content = AJAXChatFileSystem::getFileContents($this->_templateFile);
}
return $this->_content;
And the error message is like:
" Non-static method AJAXChatFileSystem::getFileContents() should not be called statically, assuming $this from incompatible context in line 37"
Now please any one can help me to fix the problem. What is the problem here I can't really understand. Thanks.

Fortran formatted write function triggers "has exited with code 408 (0x198)" on IF Composer 2013

When following Fortran code is executed on the Intel Fortran Composer 2013 the compiler triggers a breakpoint at write function and retuns code 408:
character*20 date_char
character*10 LADATE
...
if (date_char(3:3) .EQ. "") date_char(3:3)="0"
if (date_char(7:7) .EQ. "") date_char(7:7)="0"
write(LADATE,"(2A2,A4)")
S date_char(3:4),date_char(7:8),date_char(9:12)
It is a fixed line-length format and the S represents the line continuation.
The date_char has a value of ' 29 012013 ' and the LADATE ' '
As soon as the write statement is reached the debugger triggers a breakpoint and the Call Stack shows following system functions being called:
for_issue_diagnostics()
_for_emit_diagnostics()
Your time is appreciated
The problem was that the LADATE variable was actually a call-by-reference argument (FORTRAN77 default passing convention):
SUBROUTINE MDATE(LADATE)
character*20 date_char
character*10 LADATE
...
write(LADATE,"(2A2,A4)")
S date_char(3:4),date_char(7:8),date_char(9:12)
RETURN
END
and it was passed as an argument several subroutines above as a just an 8-character string. Simply written, the call would be equivalent to:
...
CHARACTER VAR*20
...
CALL MDATE(VAR(10:17))
...
The program started, but after an attempt to access an inaccessible array addresses by the write function the breakpoint was triggered.

Resources