Gtk absolute/relative/ or "no" path (Windows) - gtk

Using Gtk+, we introduce some of the icons into the app via gtk_image_new_from_file(). We found that if the icon file is directly in the apps Dir, then it all works well with "no path", eg.
FString255 = "Icon_Charts.png"
IconImage_Ptr = gtk_image_new_from_file( Trim(FString255)//c_Null_Char )
However, when we tried to move the icons to a sub-Dir (what a surprise, called "Icons"), we could not get Gtk to recognise the png's. We tried every permutation we could think of using absolute and relative variations (e.g. with ".\" with "./", with "double slashes", with "C:.....\Icons..." etc.) ... no joy.
Does anybody know the syntax Gtk expects for relative path, e.g. something like:
FString255 = ".\Icons\Icon_Charts.png"
???
Or perhaps is there something "special" about gtk_image_new_from_file() and perhaps it can ONLY accept "no path" file-names?
We get the feeling it must be something super simple that we missed.

To avoid any non-obvious behavior you should always use absolute paths.
GLib provides the g_win32_get_package_installation_directory_of_module() function to allow getting the path of the current project (assuming standard directory layout). For example:
char *path, *package_dir;
package_dir = g_win32_get_package_installation_directory_of_module (NULL);
g_assert (package_dir != NULL);
path = g_build_filename (package_dir, "Icons", "Icon_Charts.png", NULL);
g_free (package_dir);

OK, sussed it, and we are feeling extremely stupid and embarrassed. As our OP suspected:
" We get the feeling it must be something super simple that we missed."
... well, it was :-(.
Before the "actual answer", TingPing's answer would be a possibility, if the real issue was not something else entirely. However, even then, if we were to go that route, we would use something like (keeping our submissions "Fortran-consistent" with the OP):
Temp_cPtr = g_get_current_dir_utf8 ()
!
If( c_Associated(Temp_cPtr) ) Then
!
!
n = c_StrLen( Temp_cPtr )
!
FString255Path = ""
!
Call C_F_String( Temp_cPtr, FString255Path(1:n) )
!
End if
!
!
FString255 = FString255Path(1:n)//"\Icons\Icon_Charts.png"
IconImage_Ptr(j) = gtk_image_new_from_file( Trim(FString255)//c_Null_Char )
or set "\Icons" as var and adjust the path variable at the outset, eg.
FString255Path = FString255Path(1:n)//"\Icons\"
FString255 = Trim(FString255Path)//"Icon_Charts.png"
... yes, we could have used Allocatable strings also, there is a reason why we used fixed len strings here.
In the event, the usual "simple" thing does actually work, for example, the desired relative path approach really is, as initially thought:
FString255 = ".\Icons\Icon_Charts.png"
IconImage_Ptr(j) = gtk_image_new_from_file( Trim(FString255)//c_Null_Char )
OK, now for the "actual answer", and our "monument to stupidity du jour"; in fact this Gtk app is quite large, with some parts of the front end created with Glade and "builder", while other parts are written explicitly in code. Some of the same icons are used by both the Glade/builder bits, as well as the explicit code bits. As it happens, we had used the correct (relative) path at the outset ... unfortunately, we looked for the results in a part of the GUI that is generated by the Glade/builder bits, and which of course have their own independent mechanism for loading icons (even if the same icons are re-used in the "code"), and so no amount of fiddling with the "code/paths" would make any difference there.
... this is rather a "bush-league" mistake on our part, and would feel better if the entire question/post was deleted ... but perhaps we should "honour our monument to stupidity" :-).
... our apologies for wasting anybody's time.

Related

Cimplicity Screen - one object/button that is dependent on hundreds of points

So I have created a huge screen that essentially just shows the robot status for every robot in this factory (individually)… At the very end of the project, they decided they want one object on the screen that blinks if any of the 300 robots fault. I am trying to think of a way to make this work. Maybe a global script of some kind? Problem is, I do not do much scripting in Cimplicity, so any help is appreciated.
All the points that are currently used on this screen (to indicate a fault) have very similar names… as in, the beginning is the same… so I was thinking of a script that could maybe recognize if a bit is high based on PART of it's string name characteristic. The end will change a little each time, but I am sure there is a way to only look for part of a string and negate the rest. If the end has to be hard coded, that's fine.
You can use a Python script in Cimplicity.
I will not go into detail on the use of python in Cimplicity, which is well described in the documentation indicated above.
Here's an example of what can be done... note that I don't have a way to test it and, of course, this will work if the name of your robots in the declaration follows the format Robot_1, Robot_2, Robot_3 ... Robot_10 ... Robot_300 and it also depends on the Name and the Type of the fault variable... as you didn't define it, I imagine it can be an integer, with ZERO indicating no error. But if you use something other than that, you can easily change it.
import cimplicity
(...)
OneRobotWithFault = False
# Here you get the values and check for fault
for i in range(0, 300):
pointName = f'MyFactory.Robot_{i}.FaultCode'
robotFaultCode = cimplicity.point_get(pointName)
if robotFaultCode > 0:
OneRobotWithFault = True
break
# Set the status to the variable "WeHaveRobotWithFault"
cimplicity.point_set("WeHaveRobotWithFault", OneRobotWithFault)

Swift - Getting Error while using replacingOccurrence

So I'm taking Udacity's Swift for Developers course. I attempted to look at the forums for this question but oddly, they were quiet. This is the programming prompt:
var forwardString = "stressed"
var backwardsString = forwardString.characters.reversed()
print(backwardsString)
var lottaLikes = "If likeyou wanna learn Swift likeyou should build lots of small apps cuz it's likea good way to practice."
var noLikes = lottaLikes.replacingOccurrences(of:"like", with:"")
print(noLikes)
For whatever reason, I keep getting this error message:
Be sure that you have replaced all occurences of the word "like" and removed any extra spaces.
What am I missing here? If you need clarification on this I would be happy to provide it.
Thank you
It may be that your code gets the job done, but only because your variable lottaLikes is written in a weird way. You usually would have two spaces surrounding the word "like" so just removing the word would leave 2 spaces in a row. I would suggest writing the following line:
var noLikes = lottaLikes.replacingOccurrences(of:"like ", with:"")
It may be that Udacity is not checking the actual output, but the code itself. If so, It may be looking for something like I wrote above.
If this still does not work, you may want to write another line like so:
var noExtraSpaces = noLikes.replacingOccurences(of: " ", with: " ")

Why would value passed through $m->comp() lose its value irregularly?

I have a perl mason component which is called to display an html page containing threaded comments. It uses Class DBI for loading from a MySQL database.
The problem is that sometimes, and I mean sometimes, very irregularly a variable loses its value partway through the code. I am not changing the code between when it starts and stops happening, just reloading the page. It's not even that it just has the value on one page load and not the next. It's that on one page load you can print something to show that the variable contains a ref to an object (a "Person" with a name, etc.) and later on in the code on that same page load you can print that again and show that it doesn't. On the next page load the variable may retain its value all the way through. The only thing that is happening is that the variable gets passed through a call to $m->comp(), and a default gets applied if it is empty.
Further, it happens for each and every comment, effectively losing its value many times in the same page load.
Unfortunately (or fortunately, depending on how you look at it) I can't post all the code involved verbatim, but it boils down to the following, note the two commented lines marked "HERE":
<%init>
my #comments = $dc->document->search("type = 'comment'");
</%init>
<div>
<& '.comments', all_comments => \#comments &>
</div>
<%def .comments>
<%args>
$all_comments
</%args>
<%init>
my #comments;
#comments = #$all_comments;
</%init>
% for my $c (#comments) {
% my $poster = p($c->get_value('poster'));
% $poster = Person->get_anonymous unless ref $poster;
% # HERE: The variable is a ref to a given Person.
% $m->comp('.comment', poster => $poster);
% }
</%def>
<%def .comment>
<%args>
$poster => Person->get_anonymous
</%args>
<%init>
# HERE: The variable is now the result of Person->get_anonymous instead.
unless (ref $poster) {
$poster = Person->get_anonymous;
}
</%init>
<p><% $poster->id == 1 ? ' (anonymous)' : $poster->fullname %></p>
</%def>
I've tried removing that default, in which case I get an empty variable.
This is a years old problem scrutinized down to these few lines of code where, programmatically speaking, something impossible seems to be happening. I'm left with a possible bug in Mason, or maybe some combination of things like some voodoo between Class DBI and the database losing a connection, or something I don't know about $m->comp().
The only other clue I have is that when I've added something to the page, I've had the problem show up to an entirely new variable. Unfortunately, I never know when the problem is going to happen, and it happens seldom enough that I won't be able to go throw some suggested debugging code into it that will immediately give me something to report back. I'm only hoping for the off chance that somebody has experienced something similar or knows some possible problem that might explain what is going on.

Get all top level entry values from NotesView

What is the easiest way to get all top level entry values from a notes view? I have found the property "TopLevelEntryCount" returning the number of alle categories, but I want the values, too.
To iterate the view entries and column values need too much time.
Set ecl = view.Allentries
Set ve = ecl.Getfirstentry()
While Not(ve Is Nothing)
If IsArray(ve.Columnvalues(0)) Then
If flag = "" Then
arr = ve.Columnvalues(0)
Else
arr = ArrayUnique(ArrayAppend(arr, ve.Columnvalues(0)))
End If
Else
'error if arr is not already an array
arr = ArrayUnique(ArrayAppend(arr, ve.Columnvalues(0)))
End If
flag = "1"
Set ve = ecl.Getnextentry(ve)
Wend
Anyone know a faster way? It must not be written in LotusScript, actually I would prefer Java, JS or SSJS.
Idea 1: You can use the NotesViewNavigator class, and call the getFirst() and getNextCategory() methods. This should be faster than walking all the entries.
Idea 2: You can use NotesSession.Evaluate() with a formula that does an #Unique on #DbColumn for the first column of view. That should bring you back an array, and you can get the ubound of the array. Formulas tend to be very fast, but evaluate() has to compile them first, so I don't know if this will be faster or not. The disadvantage of this approach is that for very large views, this could exceed formula language's size limits. But if it does prove to be faster, you could catch the exception and fall-back to the slower method of iterating.
Richard's response is perfect!
For a java version it's almost the same:
see the Domino help for getNextCategory the given example below ViewNavigator really answer your need: link here
The evaluate method is also available in java Session

How do I Benchmark RESTful Service with Variable Parameters?

I'm currently working on benchmarking a RESTful service I've made, and part of that is making sure it runs in a reasonable amount of times for a large array of parameters. For example, let's say I have RESTful API of the form some_site.com/item?item_id=y. In that case to be sure my service is working as fast as I'd like it to work, I'd want to try out many values for y one by one, preferably coming from some text file. I can't figure out any way of doing this in ab or httperf. I'm open to using a different benchmarking program if I have, but would prefer something simple and light. What I want to do seems like something pretty standard, so I'm guessing there must already be a program that let's me do it, but an hour or so of googling hasn't gotten me an answer. Ideas?
Answer: Jmeter (which is apparently awesome). This faq explains how to do it. Hopefully this helps someone else, as it took me like a day of searching to figure this out.
I have just had some good experience with using JavaScript (via BSF/Rhino) in JMeter.
I have put one thread group in my test plan and stick a 'Simple Controller' with two elements under it - 'HTTP Request' sampler and 'BSF PreProcessor'.
Set BSF language to 'javascript' and either type the code into the text box or point it to a file (use full path or relative to CWD of JMeter process).
/* Since `Math.random()` gives us float, we use `java.util.Random()`
* see: http://docs.oracle.com/javase/7/docs/api/java/util/Random.html */
var Random = new Packages.java.util.Random();
var min = 10-1;
var max = 2;
var maxLines = (min)+Random.nextInt(max-min);
var s = '';
for (var d = 0; d <= maxLines; d++) {
s += d.toString()+','+Random.nextInt(1000).toString()+'\n';
}
// s => '0,312\n1,104\n2,608\n'
vars.put('PAYLOAD', s);
Now I can refer to ${PAYLOAD} in the HTTP request!
You can generate JSON, but you will need to upgrade jakarta-jmeter-2.5.1/lib/js-1.6R5.jar with the newest version of Rhino to get JSON.stringify and JSON.parse. That worked perfectly for me also, though I thought I'd put a simple example here.
You can use BSF pre-processor for URL params as well, just set another variable with vars.put('X', 'some value') and pass it as ${X} in the request parameter.
This blog post helped quite a bit, by the way.