ZXingWidget header search path - iphone

Have imported the ZXingWidget project and it seems to be working as expected (after quite a bit of trail and error). What it can do now is to be activated, display a white framed view finder, scan a QRCode and return the result.
What I wish to add is to have ZXingWidget to turn the white view finder frame red when the scan result does not match any predefined strings.
My strategy is to update a global flag in my own project for the string matching result and have ZXingWidget read it.
My problem is, ZXingWidget cannot find the header file (where the global flag variable is declared) despite having set its header search path.
My feeling is, it is either because the search path is wrong or the strategy is flawed. Please advise.

Well, it kinda sounds like a hack, so if you're not concerned about cleanliness, just extern it in the widget rather than bothering it to include a header.
At the point of defintion:
bool my_red_flag;
In the hacked widget:
extern bool my_red_flag.
The "proper" way to do it would be add an API for the widget, but that might not be worth the effort to you. (Polling that variable somehow would seem to be required: the widget draws the frame directly and won't generally redraw it unless given a reason.)

Related

NSTextStorage easily / background attribute change

I'm finishing a nice app with a relatively small text editor. During implementation of the syntax highlight I found myself in need to change foreground colour attribute of recognized tokens. I noticed that there is a property of NSTextStorage:
var fixesAttributesLazily: Bool { get }
The documentation, regarding it is:
A Boolean value indicating whether the text storage object fixes attributes lazily. (read-only)
Discussion
When subclassing, the default value of this property is NO, meaning that your subclass fixes attributes immediately when they are changed. The system’s concrete subclass overrides this property and sets it to YES.
I really don't know how to interpret this ... but this is what I did:
I'm changing the attributes of th recognised tokens inside textStorage(textStorage: NSTextStorage, didProcessEditing editedMask: NSTextStorageEditActions, range editedRange: NSRange, changeInLength delta: Int) (which is a delegate method of NSTextStorage). Here I'm checking the value of this property - it's FALSE.
I subclassed NSTextStorage exactly as Apple suggest (https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/TextStorageLayer/Tasks/Subclassing.html) and overrode the property. The text view started to behave very strange. Actually with small text it performs OK, but as soon as I open a 4 Mbytes file - it hangs and ... well ... bad things start to happen to my mac. Actually this behaviour doesn't depend on the value of the fixesAttributesLazily property. Maybe my implementation of NSTextStorage is bad or at least not sophisticated.
Any trick of applying attributes in background or lazily or ... something like this is welcomed.
In additional: I know that there are many ways to optimise a syntax highlighted. It may highlight partially, use some kind of logic, based on the changed range ... etc. What I'm looking for is a way to process attribute changes in background. For example currently when I paste 4 Mbyte file to the text view, it first highlights it (which takes 2-3 seconds) and then it visualises it. The effect I'm looking for is the text to appear right away and after time - the colors.
The project I'm working on is written in Swift.
Thanks to everyone in advance for the help. You may reach me via ivailon at gmail dot com for specifics, since I don't want to expose the app here ... at least not yet ;-)

Get NetLogo widgets in headless mode

I need to get the list of all defined widgets in a nlogo script in headless mode. I basically need to the targeted variables and the default values. But I just find private methods in the API to achieve this (https://github.com/NetLogo/NetLogo/blob/5.x/src/main/org/nlogo/headless/HeadlessModelOpener.scala#L136-L234). Is there a public method from the API to achieve this ?
Thanks
Mike Horn solved this by parsing through the .nlogo file in his NetTango project. If you're okay with that, take a look at his Model.java load() method, and initSlider(), initSwitch(), and initPlot() methods. I don't remember the exact relative line location of default value for the other widget types, but if you open a .nlogo file in a text editor, you should be able to figure it out.

How do I find the next widget in a given direction in GTK+?

I want to find out which widget is in a given direction in GTK+, i.e. doing what the "move-focus" signal does, but without actually changing the focus. What I have in mind is a function that takes a GtkWidget * and a GtkDirectionType and returns the GtkWidget in the given direction (if any).
What I want this for is to ultimately enumerate the widgets inside a specific GtkFrame in my UI definition, in order from left to right. I.e. basically create a list of widgets from leftmost to rightmost, inside my GtkFrame (or in the general case, inside any container).
I've tried to search the GTK documentation but haven't found anything that doesn't also change focus.
Failing any other approach, the way I'm going forward with is to copy a selected set of static functions from the library implementation of GtkContainer and put them in a file in my own application, modifying them to suit my needs.
More specifically, the function gtk_container_focus_sort_left_right() and any local functions that it depends on. This includes the GCompareFunc left_right_compare() and get_allocation_coords().
Assuming the directions you care about are "Forward" and "Backward", it sounds like you want to use gtk_container_get_focus_chain() on the frame: it does pretty much what it says on the tin: you get a list of widgets in order of focus when tabbing.

Clone a Gtk.Button from gjs

How would I go about cloning any widget from gjs, similar to the C response given in https://stackoverflow.com/a/3030603/1829961? I have not been able to find a way to call list_properties although it is listed in the GModule gir file. Or do I have to use GIRepository, manually walk the GIR type hierarchy, emulating that which g_object_class_list_properties is supposed to do? Or another straight forward way I'm totally missing here?
Here is some code that will do that.
It takes a similar approach to the quesion you linked, but since there is no G_OBJECT_GET_CLASS() in GJS, it uses GIRepository instead -- which is an extra dependency that you need compared to the C solution.

Highlight some text in a Jasper Reports viewer

I want to highlight some parts of the reports i'm generating for display.
I don't want to change the report definition. I want to highlight the output at runtime.
But the JRViewer i'm using doesn't really have much of an API.
And manipulating the JasperPrint object with setForecolor/setBackcolor before displaying it, didn't seem to change the output.
Any ideas? Or do i have to overload/reimplement the viewer? Wouldn't be much of a problem since it's open source, but i'd like to prevent reinventing the wheel.
Looks like i have to answer my questions myself... again.
I overloaded the JRViewer class (actually copied the code of JRViewer because none of the interesting panels were accessible) and added some highlighting methods to do the following:
Template based JasperPrint data uses - like the name suggests - templates. Meaning the text objects don't have a style of their own, they use their template's style.
That is the reason why setForecolor didn't do anything - the JRTemplatePrintElement implementation is plain empty.
But if i would set the highlight on the text template i would end up with a full column of highlighted texts, since they share the template instance.
Instead i create a new template as a copy of the original with highlighting and use that in the highlighted print elements. Btw, those jasper elements could really use a clone() method.
Feels like a hack, but i don't see a better way.
UPDATE:
However this has a nasty sideeffect for file based (virtualized) reports.
These apparently save any changes you make to the elements while you walk the pages.
If however the viewer in the meantime causes the virtualizer to discard the elements you reference (for example by flipping pages), your further changes won't be saved...
So that made me reconsider and now i'm just drawing my highlighting on top of the Graphics object painted by Jasper's PageRenderer.
Much simpler and cleaner. Only highlighting the background won't work this way.