In glade it is possible to set an unique ID to an object. In the code one can obtain a pointer to this object by searching for it's "glade ID" via gtk_builder_get_object().
However for my current use-case I just want to read out this ID from an GObject. What's the API to do so ?
You can't. The builder ID is stored in the builder internally, not in the GObject.
The reason for this is that IDs must be unique per builder, which would be impossible to enforce if you were able to get and set them via some GObject API.
You could use gtk_widget_get_name() to identify an object.
It is possible using Gtk.Buildable.get_name(object). This method will return the Glade object id.
This snippet will print all object ids in your Glade XML:
builder = Gtk.Builder()
builder.add_from_file("my-window.glade"))
for obj in builder.get_objects():
print(Gtk.Buildable.get_name(obj))
As stated by #ptomato it's seems not possible.
I found that in that line in the documentation:
All the fields in the GObject structure are private to the
implementation and should never be accessed directly.
But you can circumvent it because at one point in your code you were refering to it by the id that you typed in (or the code you wrote type in) so you just need to store it at that point. And link it somehow (with a variable or a data structure) to the name of the variable holding the object.
Related
As the topic, when I use ortools, I want to serialize cpsolver, CpSolverSolutionCallback and cpmodel to achieve multithread computing. However, I can't just serialize those objects directly and I think I need to only serialize their configuration and reset configuration in each thread, such as all the constraint and variables in the cpmodel and parameters in cpsolver. This is the question, how can I get all those values using ortools? Is there an api or something? I can't find it when searching on Google.
Every language implements a thin wrapper above a protocol buffer file.
This file is described here
This model is accessible from each CpModel class.
Now you can distribute work using this proto directly. You will need to look at the CpSolver class to understand how the c++ Solve method is called.
See the python solve method.
The way to implement your request.
Create your model normally.
Extract the underlying protocol buffer model underneath and use it for parallelism/distribution.
Solve will returns a CpSolverResponse object. To get the value of a variable in the response, call response.Value(var.Index()), or store the index of the relevant variables and use it in the Value() method call.
How many instance does binding creates internally for converters.
<Image x:Uid="DisplayedImageUrl" Style="{StaticResource ImageStyle}"
Source="{Binding DisplayedImageURL, Converter={StaticResource ImageLogoConverter}}" />
How many instance does of ImageLogoConverter will be there?
Is it good idea to use converter in ViewModel, if not then what is the best way to access converted value of ViewModel property.
Is it good idea to use converter in ViewModel?
No. Why would you use a converter in a view model where you can return the converted value directly? Converters are used in the view, typically to convert a non-view friendly value that the view model returns.
If not then what is the best way to access converted value of ViewModel property?
You can simpy return an already converted value from the view model, i.e. instead of binding to a Uri property, you may bind directly to an ImageSource property.
This is the recommnded approach if you for example intend to display a lot of elements in a ItemsControl. Then you probably don't want to invoke a converter for each visible element for performance reasons.
I suppose you created the converter as a resource like this:
The number of instances now depends on the scope where the converter resource is declared. If you create it in <Page.Resources>, one instance will be created to be used by the page. If you create it in App.xaml in <Application.Resources> it will be an application-wide instance. Of course, you can even use a narrower scope - create it as a resource of a single control in your XAML tree for example - in any case, a single instance is created when instance of the parent is created.
The situation gets a bit more interesting if you embed it in a ItemTemplate of a list control. Thanks to virtualization, the system will not actually create one instance for each item. Instead, it will create only so many instances as fit on the screen and they get reused when the user scrolls.
Some MVVM developers don't like value converters, but others use them extensively. It really is a matter of preference. In cas you expect the underlying data to change often, it is advisable to keep the code in the converter as performant as possible as it runs on the UI thread.
I am building a JavaScript app, and have been learning JavaScript and Backbone, and have added Backbone-relational to it. It saves to a Django-tastypie REST server.
So before I was using Backbone-relational, I would create a new object, and either set the attributes when it was created, by passing them to the constructor, or passing a dictionary of attributes to the save() method.
e.g in CoffeeScript:
myModel.save {attribute:value , foreignKey_attribute : '/api/resourceUri/'}
success ->
....
Now I have switched to Backbone-relational, it solves a lot of problems fetching the data, but I cant seem to set the foreign key attribute as before.
Either passing the dictionary to the constructor, or the save method. When I look at the object in the console, or the contents of the POST, the foreign_key attribute is always null.
Is there a way around this, or another way of setting the foreign_key_attribute (given that I have the foreign key id)?
Ok, worked it out.
Rather than trying to set the flowcell to a resource_uri string, set it as the flowcell object.
Then in the relations I needed to set the following:
includeInJSON: 'resource_uri'
This serialzes the object the way the tastypie back end expects it.
I want mybatis to call a factory method to create an object instead of a constructor. So that for null valued attributes i can return a NULL object(which has overridden behavior to handle all the edge cases) instead of actual object. Can i achieve that with mapper.xml?
Define your own ObjectFactory
http://www.mybatis.org/core/configuration.html#objectFactory
To answer your specific question, there is no way to specify a factory method directly (and only) in the mapper.xml file itself, as far as I know. However, there are two options in MyBatis to do what you want:
As stated in Bhaskar's answer you can use an ObjectFactory.
In theory, you can also define a TypeHandler, but I was unable to get this to work in my recent testing.
If you would like to see a working example of how to use a MyBatis ObjectFactory to implement a Null object, see koan19 of my MyBatis koans: https://github.com/midpeter444/mybatis-koans. (Look in the completed-koans/koan19 directory for the solution I came up with.)
I am making a custom ActiveForm method, but it requires the model to have a certain custom validator attached the the attribute that is being passed through (otherwise who knows what will happen!?)
My question is simply... is there a way to run this check in the code that is reliable?
I don't want to add the validator at runtime. That would create confusion and possibly let someone use this type of field where it ought not be used.
So I want to say something like:
if( model NOT HAVE validationMethod ON property)
throw Exception;
I'm also not sure why you want to do this, but in addition to viewing the rules array you can do:
$model->getValidators($attribute)
to check which validators are active for a particular attribute (or all attributes, if the arg is null. (I'm assuming $attribute = property in your example.)
This will return all the validator objects that are active for the current scenario and you can check if a predefined or custom class exists. It also gets you a bit more info than just the rules array (i.e., the properties of the validator class).