Can I access the GtkTreeView associated with a GtkEntryCompletion? I'd like to connect to the move-cursor signal to trigger a function whenever the user presses ↑ / ↓ to change the highlighted match.
The description of GtkEntryCompletion indeed says, "GtkEntryCompletion is an auxiliary object to be used in conjunction with GtkEntry to provide the completion functionality. It implements the GtkCellLayout interface, to allow the user to add extra cells to the GtkTreeView with completion matches."
(I thought I might be able to do this with the cursor-on-match signal for the GtkEntryCompletion itself, but I can't get that signal to fire no matter what I try. I'm using the Ruby bindings, if that makes any difference.)
Related
The documentation for -[NSObject scriptingValueForSpecifier:] says:
You can override this method to customize the evaluation of object specifiers…
I want to do this to make AppleScript lookups in my app more efficient. There are certain types of whose tests where I could do a hash lookup instead of having AppleScript ask for every single object and then query their properties one-by-one. The problem is that if I receive a NSWhoseSpecifier, I can get its test, which is a NSSpecifierTest, but there doesn’t seem to be a way to look inside the NSSpecifierTest to figure out the property being tested. Everything but the initializers and the -isTrue method are private.
Let's make a distinction. If you merely want to customize the values returned by a whose clause — in the sense of fine-tuning results — then you would override scriptingValueForSpecifier for the object in question. For example, say you have an object called 'box' that has a property called 'color,' and you want a statement like every box whose color is blue to also return boxes whose color is 'aqua,' 'teal,' or 'navy' (which are all shades of blue), then you would override scriptingValueForSpecifier to implement that.
However, if your goal is to make a more efficient form of whose test, you're probably going to have to implement appropriate methods from the NSScriptingComparisonMethods protocol. These are the routines that AppleScript uses to evaluate scripting object comparisons through NSSpecifierTest (which is what NSWhoseSpecifier) relies on). Again, you'd override these methods on your object(s) to provide different methods for doing evaluations.
As a last resort, you might try subclassing NSWhoseSpecifier or NSSpecifierTest, with the understanding that these are opaque classes for which Apple discourages subclassing. I'm not entirely certain how you would implement those subclasses; you'd probably have to register your subclass with NSScriptSuiteRegistry commands.
It looks like it will be possible to override -scriptingValueForSpecifier: and then ask the NSScriptObjectSpecifier for its descriptor. This produces an NSAppleEventDescriptor that has the needed information, but it has to be interpreted manually.
I guess my question is relatively easy for those of you who spent time dealing with Win32 API.
So my question is:
After initializing a WNDCLASSEX instance we need to "register" it using the "RegisterClassEx" function, why? Why do we do that? What's the meaning of this registration and in what cases I need to register things?
The ATOM returned by RegisterClassEx uniquely identifies your "window class" which can then be referred to in other windows APIs. [MSDN]
Effectively it is a hash so as to reduce the amount of data processed each time a window is created or looked for. It does also mean that multiple windows with same features can be easily created and identified.
I was addressing the practical reasons above. Hans Passant's answer correctly explains this is the OO class concept provided for C. Further MSDN example.
The word Class in the function name is significant. When you write code in an object oriented language, like C++, Delphi, Java or C# etcetera, then you use the class keyword to create objects that have behavior. But the winapi was designed to be used from C, a language that doesn't have such functionality. The RegisterClassEx() function is an emulation of that, it lets you create a window that "derives" its behavior from a named class, behavior that you can override. With every window that you create using that class name behaving identically.
The WNDCLASSEX structure you pass gives a window its default behavior. The most significant members of this structure are:
lpszClassName. That's the equivalent of the C++ class name. You can later call CreateWindowEx() and pass that name to get a window that behaves a certain way. Windows itself calls RegisterClassEx() to register several of its built-in window classes that you then can readily re-use in your own code. "EDIT", "BUTTON" and "LISTBOX" are good examples of that.
lpfnWndProc. This is what gives a window class its specific default behavior. The address of its window procedure that implement message handlers for specific messages. You can further customize the default behavior, in other words "derive" your own class from the base class, by specifying another window procedure in the CreateWindowEx() call. Such a window procedure must always call DefWindowProc(), the equivalent of calling the base class method. Or in other words, a window has one virtual method.
hIcon, etcetera. These are the equivalent of properties of the base class, they set default values that affect the default message handlers. Helping you to keep your window procedure simple. It is for example rarely necessary to write a message handler for WM_ERASEBKGND, the hbrBackground member sets the default background for a window.
Windows requires you to call RegisterClassEx() even if you don't plan on re-using a window. Which is by far the most common usage of the function in your own code. You don't start to really take advantage of it until you write a library that implements controls, windows that other code can use. Like "EDIT".
I have a user specified global hotkey and want to check and make sure it's not going to collide with other applications. Is there any API that can ask other applications for their shortcuts or am I stuck manually checking if the selected shortcut is a common one (Cmd+v, Cmd+C etc.)?
Thanks
You have to ask the responder chain, in particular [NSResponder tryToPerform:with:] method will return if anything handles your action. Don't worry about what other apps are doing, just check if the user's shortcut is already in use.
tryToPerform:with:
Attempts to perform the action indicated method with a specified argument.
(BOOL)tryToPerform:(SEL)anAction with:(id)anObject
Parameters
anAction
The selector identifying the action method.
anObject
The object to use as the sole argument of the action method.
Return Value
Returns NO if no responder is found that responds to anAction, YES otherwise.
Discussion
If the receiver responds to anAction, it invokes the method with anObject as the argument and returns YES. If the receiver doesn’t respond, it sends this message to its next responder with the same selector and object.
Availability
Available in OS X v10.0 and later.
See Also
– doCommandBySelector:
sendAction:to:from: (NSApplication)
Declared In
NSResponder.h
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/nsresponder_Class/Reference/Reference.html#//apple_ref/occ/instm/NSResponder/tryToPerform:with:
I'm adding a GUI to an existing command line app. The properties used by the app are held in class(es) and I'm creating a dialog that binds to those options objects. However, if I want to cancel out of that dialog I then have reset the values of my options objects, which is where I'm running into probs.
I could take an internal copy of the option objects and use that to re-populate the original object to allow the cancel/rollback but that seems cumbersome.
I can (somehow) implement an undo function on each class - is there a pattern for that?
I use the GUI controls standalone to hold values and only update the options objects when the dialog has been confirmed.
What's best practise?
You should consider creating a new class to be used just by the GUI.
GUIs have their own needs.
Make sure to take care of multi thread issues if you have more than one thread accessing the options object.
The design patterns that address undo functionality are called Command and Memento.
I think Memento would fit better on this case.
Take a look on this question on SO: Design Pattern for Undo Engine.
The following links are of interest (and many more):
http://www.coderanch.com/t/100676/patterns/Memento-Vs-Command-pattern
http://www.developer.com/design/article.php/3720566/Working-With-Design-Patterns-Memento.htm
http://www.colourcoding.net/blog/archive/2009/07/23/reversibility-patterns-memento-and-command.aspx
There is signal in QStandardItemModel which is emitted when data of an item is changed.
Usually we connect a handler for this signal and do all the work in the handler routine.
Such handle routine only gets pointer to the item.
Using this pointer it is possible to access the data of the item.
However, we do not know what exactly has changed... we only have updated value.
If item data has several roles I want to be able to get exactly which role (data) has been changed and what was the previous value.
In general, QStandardItemModel is for very simple data modeling. If you want to get into more advanced things like you desribe, you should look into subclassing QAbstractItemModel or one of it's abstract derivatives: Model/View classes
It may seem like a lot of work, but use the examples and refernce guides: Model/View programming, Model subclassing and the rewards will be great.
This is not possible with the standard signals of Qt. I suggest to add another signal for that.
For my own models, I usually use this approach: I have a root instance which contains pointers to all parts of my data model. Items in my model use this root instance to send signals like
itemChanged(item, attribute, oldValue, newValue)
for simple properties. The same goes for lists and the like; only here, I have several signals depending on the action, for example:
itemAdded(list, item, index)
[EDIT] The QT signal handling is very basic. Usually, it will only tell "something has changed". There is no support for "what exactly has changed?" since you don't need it most of the time. So if you need that information, you must do it yourself. You can't use a role alone, because roles must be backed by something in your item. What you can do is add change information to your items and read that when the role is requested. But this is not something that is supported "out of the box".