manage signals in GTK .ui files in vala - gtk3

from the following .ui files, I have the signal :
<object class="GtkButton" id="button2">
<property name="label">Button 2</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="receives_default">False</property>
<signal name="clicked" handler="on_button2_clicked" swapped="no"/>
</object>
the name of signal on_button2_clicked and the following code I used to handle event by add_callback_symbool :
// Create Builder
var build = new Gtk.Builder ();
build.add_from_resource ("/me/rush/Rush/main.ui");
// Create an instance
var window = (Gtk.ApplicationWindow) build.get_object ("window");
// handle event
build.add_callback_symbol ("on_button2_clicked", ()=> {print ("click");});
window.application = app;
window.show_all ();
GUI appeard in screen but handling of event on_button2_clicked doesnt work, I tried to handle event with build.connect_signals (null) and defiend function with same name but also doesnt work
when googling I found a way to work with callbaks in templates, but what I want to do is handle event with connect.signals or add_callback_symbol
also I tried example here but it doesnt work

I also replied this to your question on GNOME's discourse, but I'll post the answer again here for visibility:
It's maybe good to know that Vala has built-in support for GtkTemplates, which means you don't need to explicitly call the GtkBuilder API anymore. Vala will do the necessary checks for you (at compile-time even).
You can find multiple examples for this in the GNOME Contacts repository, but to give a concrete one, let's show the SetupWindow:
The UI definition
The GResources XML where it gets included
The Vala source code. Look especially for [GtkTemplate] and [GtkChild]. A speicifcally callback isn't part of this class, but there are examples of this if you look for [GtkCallback]

Related

ObservableValidator in .NET MAUI Toolkit - doc for EventTriggerBehavior?

In the .NET MAUI Community Toolkit MVVM samples there is this XAML:
<Grid>
<muxc:InfoBar
x:Name="SuccessInfoBar"
Title="Success"
Message="The form was filled in correctly."
Severity="Success">
<interactivity:Interaction.Behaviors>
<interactions:EventTriggerBehavior EventName="FormSubmissionCompleted" SourceObject="{x:Bind ViewModel}">
<interactions:ChangePropertyAction
PropertyName="IsOpen"
TargetObject="{x:Bind SuccessInfoBar}"
Value="True" />
<interactions:ChangePropertyAction
PropertyName="IsOpen"
TargetObject="{x:Bind FailureInfoBar}"
Value="False" />
</interactions:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</muxc:InfoBar>
Can you tell me where I find documentation on EventTriggerBehavior? Or for that matter, where I find interactivity and Interaction.Behaviors and ChangePropertyAction?
I don't see this documented, despite searching.
Also, while I have you, this same code says
SourceObject="{x:Bind ViewModel}
Is Bind the same things as Binding?
EventTriggerBehavior: Listens for a specific event on its source and executes an action when the event is fired, it has two configurable properties (EventName and SourceObject).
ChangePropertyAction: Action that will change a specified property to a specified value when invoked.
For more information about Behaviors, you can check the documentation: XamlBehaviors
Regarding Bind and Binding, the {x:Bind} markup extension official document explains:
The {x:Bind} markup extension—new for Windows 10—is an alternative to
{Binding}. {x:Bind} runs in less time and less memory than {Binding}
and supports better debugging.
The difference to note is that the default mode of {x:Bind} is OneTime, which is different from {Binding}, whose default mode is OneWay.
For a comprehensive comparison between {x:Bind} and {Binding}, you can read Data binding in depth.

How to disable options as printing in generated PDF file?

When I generate a PDF with jasper reports I don't want the user to be able to print it.
Is there some option to make it from the code or does it only depend on the program which visualize it (web browser,adobe etc.).
You can achive this both by using jrxml properties or setting values to the SimplePdfExporterConfiguration if you are exporting from java.
To protected your pdf document (hence in this case disallow printing), first thing you need to do is to encrypt it and be sure that you have nessary libraries for encryption in classpath see How to configure PDF encryption in JasperReports Server 5.6.1
jrxml properties
<property name="net.sf.jasperreports.export.pdf.encrypted" value="true"/>
<property name="net.sf.jasperreports.export.pdf.128.bit.key" value="true"/>
<property name="net.sf.jasperreports.export.pdf.owner.password" value="12345"/>
or
java code
SimplePdfExporterConfiguration configuration = new SimplePdfExporterConfiguration();
configuration.setEncrypted(true);
configuration.set128BitKey(true);
configuration.setOwnerPassword("1234");
Note we are setting owner password not user password, hence user will be allowed to open without.
Now set the user permissions
net.sf.jasperreports.export.pdf.permissions.allowed
In your case I guess you only like to allow screen readers, if you like to also allow COPY or other actions (see link above) add these with | to your properties
jrxml property
<property name="net.sf.jasperreports.export.pdf.permissions.allowed" value="SCREENREADERS"/>
or
java code
configuration.setPermissions(PdfWriter.ALLOW_SCREENREADERS);
Notice: it is up to the reader/application to respect the permission, hence a developer can always open and do what they want with any PDF document. As example iText contains a flag unethicalreading, if you set it to true, you will be able to have owner access to these documents without knowing the password.

Include parent and child items of GtkTreeStore in GtkEntryCompletion

I have a GtkEntryCompletion declared as follows:
<object class="GtkEntryCompletion" id="search_entry_completion">
<property name="model">menu_treestore</property>
<property name="text_column">0</property>
</object>
The model is a GtkTreeStore with two columns, and column 0 is rendered as the text that should appear in the entry completion.
The problem is that as it is a GtkTreeStore, only the parent items are used in the completion.
So, for example, if I have:
test0
test00
test01
test1
Only test0 and test1 will be available for the entry completion. I can't change the model to a GtkListStore, so, is there a way to make all items of the GtkTreeStore available for the entry completion?
I'm using Python and Glade for the development of that task.

How to use org.jboss.varia.property.SystemPropertiesService and org.jboss.util.property.PropertyListener

All
I have seen the jboss-service.xml which use an extended SystemPropertiesService class to reference to custom property file. But I didn't totally understood this kind of usage yet.
Could someone please give me some help to understand how to use these two class? thanks.
The SystemPropertiesService is very useful to define properties that then can be accessed from your application, it's usually used to parametrize the application without having to change to code, or even the application package (provided you place the jboss-service.xml outside de war / ear / jar structure). For example, you can create a myapp-service.xml file with the following content:
<server>
<mbean code="org.jboss.varia.property.SystemPropertiesService" name="jboss:type=Service,name=MyAppProperties">
<!-- Define the properties directly in the service.xml file-->
<attribute name="Properties">
myapp.property1=property1Value
myapp.property2=property2Value
</attribute>
<!-- You can also specify a route to another file where you define properties-->
<attribute name="URLList">
/home/myuser/txtlist.properties
</attribute>
</mbean>
</server>
Then you can deploy this file directly in JBoss, the properties defined will be visible to all the applications deployed in the same JBoss and you'll be able to access them with the static method:
String System.getProperty(String propertyName)
So if you want to access to the value of myapp.property1 from your application you'd do:
String property = System.getProperty("myapp.property");
On the other hand the PropertyListener is really an interface that defines a listener that will be triggered when any event occurs with a property. The org.jboss.util.property.PropertyAdapter is an abstract implementation of this interface. To use it you've to implement its three methods (propertyAdded, propertyChanged, propertyRemoved), that will be called by the container when a property is added, changed or removed respectively. Those methods have a PropertyEvent object as parameter, which let you know the property affected.
This interface/class is useful when you want your application to do something every time a property changes (a bad implementation would be that you check every certain time for a property change), this way, when JBoss detects that a property has changed its value, it will call the respective method (that you should implement with the behaviour you want).
For example, if you want to print the new property value everytime it's changed you could implement the propertyChanged method this way:
void propertyChanged (PropertyEvent pe){
// check the property that has changed
if (pe.getPropertyName().equals("myapp.property1")){
System.out.println("The value of " + pe.getPropertyName() + " has changed to " + pe.getPropertyValue());
}
}
Look for more information in the API, and for PropertyAdapter and PropertyEvent.
In JBOSS 5.1 it only works when you put the properties or URL in properties-service.xml and this file should go under jboss.home/server/default/deploy directory.

Django-tastypie -- how to generate customized xml

I have ModelResource in tastypie for a Simple Model that has an id and a name.
The XML output is shown below. But I would like to use my model name in place of "object". I seem to endlessly struggle on how to solve this -- any quick help on this? Thanks a million-- really!
<response>
<objects type="list">
<object>
<id>1</id>
<name>foo1</name>
<resource_uri> blah </resource_uri>
</object>
<object>
<id>2</id>
<name>foo2</name>
<resource_uri> blah </resource_uri>
</object>
</objects>
</response>
You could try overloading the "alter_list_data_to_serialize(...)" method of the Resource class. As the docstring says:
A hook to alter list data just before it gets serialized & sent to the user.
Useful for restructuring/renaming aspects of the what's going to be sent.
So that's the place when you change the "data" which soon after gets transformed into XML and sent to the user.
Something like this should get you going:
def alter_list_data_to_serialize(self, request, data):
#self.object_class.lower() is the name you'd like instead of "objects"
data = { self.object_class.lower() : [ element for element in data[ 'objects' ] ] }
return data
I haven't tested this, but I'm using this method to alter how my responses look succesfully.