I am new with gtk.
Can we use builder to build GtkApplication itself.
using code like:
<object class="GtkApplication">
Yes, but you'll need code that instantiates the GtkBuilder, gets the application object from it, and runs it.
It's more usual to subclass GtkApplication in your code and override its virtual functions, and then inside your GtkApplication instantiate your GtkBuilder.
Related
Based from a video from Brian Lagunas (YouTube Link) I started using Prism 6. I am a little bit confused, where the constructor of the MainWindowViewModel is getting called. I nearly copied his project and can't find the part. If i set a break point in the constructor, it never gets there.
Was he no showing something in the video or something?
If you have a look at the code for this presentation, you can see that Brian is using Prism's attached dependency property to couple view and viewmodel through the ViewModelLocator.
prism:ViewModelLocator.AutoWireViewModel="True"
In the video around 33:00 he gives the full explanation how this ViewModelLocator works: first it builds the viewmodel name out of the view's name through convention. Then it either resolves this name to a type through an IoC container or reflection. IoC is pretty straight forward: give a type or name and it will give you an instance. For the reflection part (when you run without a container), Prism uses the Activator type to create a new instance.
In the final code available on GitHub, Brian is using Unity as IoC container. Custom mappings for his sub-views (ViewA/ViewB) are made in the Bootstrapper. As there is no custom mapping for MainViewModel, following process happens:
The app starts with MainWindow as the startup window.
The attached property for the ViewModelLocator gets 'triggered', internal logic will map from MainWindow to MainWindowViewModel
As we're using Unity, the ViewModelLocator asks for an instance of the viewmodel
Unity will create a new MainWindowViewModel object and the constructor will get hit
So you won't see new xxxViewModel() in code, but it does get created. This means you have much greater flexibility over hardcoded object creation when it comes down to adding dependencies.
I'm developing a web app for different formfactors. Each has its own client factory to create formfactor dependent views. Everythings works fine so far but I'm stuck when it comes to the Editor Framework.
To make use of the framework I have to declare a marker interface like so:
interface Driver extends SimpleBeanEditorDriver<User, UserEditor> {}
Since this happens in my formfactor agnostic activity I want the type UserEditor to refer to the actual implementation based on the formfactor, i.e. UserEditorPhone, UserEditorTablet, UserEditorYouNameIt.
To no avail I tried using deferred binding in module.gwt.xml:
<replace-with class="com.example.client.desktop.UserEditorDesktop">
<when-type-is class="com.example.client.view.UserEditor"/>
</replace-with>
Any ideas on what I'm missing and how to avoid having a one-to-one-relationship between formfactors and UserEditor-activities?
You'll want your formfactor-agnostic activity to only know about SimpleBeanEditorDriver<User, ?>, and move the Driver interface into each one of UserEditorDesktop, UserEditorTable and UserEditorPhone.
The activity will then ask a formfact-dependent object (e.g. its view, if you use MVP and the activity is the presenter) for an instance of the editor driver rather than using GWT.create() directly.
(I can give code sample if you detail how your code is organized: are you using MVP? is the editor your view? how's it instantiated? etc.)
I have a tricky question on interface. Please try to give me a solution for it.
Scenario:
I have written an interface with five methods. Also I have implemented more than 100 classes using this interface. Now, I need to add one more method to the interface. Consequently, I will need to define the same method in all classes. How can I avoid this???
Please reply...
Thanks,
Akif
Could you avoid adding a method to the interface by instead creating a new interface which inherits from that first interface and then only changing the classes you need that new method on? Hence, if foo didn't need the new method, leave it alone but if bar did, change it to the new interface.
Java 8 has default method which you could add to an interface
https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html
All the subclasses which do not override this method will resort to the default implementation in the interface
I'm developing an application with Gtk and Glade. My impression is that it's common practice to create a subclass of GtkWindow for your main window, but I'm stuck on how I would construct my subclass from a GtkBuilder definition. Does anyone know how?
Subclassing GtkWindow is more common in GTK's various language bindings than it is in plain C. You didn't mention which language you were using.
That said, the way I subclass GtkWindow in C is to create the contents of the window in Glade, but not the window itself. In Glade 3 (IIRC) you can right-click on a widget in the palette and choose "Add widget as toplevel" to place a non-toplevel widget without a container.
Then write code for your subclass of GtkWindow, let's call it MyAppWindow. I won't go into that in this answer since there are plenty of examples in the GObject documentation. In the init function (my_app_window_init()) load the Glade file, use gtk_builder_get_object() to get a pointer to the outermost widget in the Glade file, and use gtk_container_add() to add it to the window you are constructing. Then use gtk_builder_connect_signals() as you normally would.
You have to set all the window's properties manually this way, since you can't do it in Glade, but other than that I've found it works quite well.
it is not common practice to subclass GtkWindow.
i don't think it is possible to subclass toplevel window created from gtkbuilder definition.
gtkbuilder needs to know about your subclassed widget before creation.
If you really want to create your own subclass of GtkWindow ptomato describes the basic steps well. It is also possible to create plugins for glade to make your custom widgets available. But this is not very easy, and most likely not what you want to do.
Most applications only use standard widgets without subclassing any of them. Then loading a glade file with gtkbuilder (or libglade) you don't need to have a special class for your GUI (like in some other RAD tools) instead you just get a set of objects. The API lets you look them up by name (and the window is basically just one of them). A common approach is to look up all widgets you are going to interact with and store them in global variables when the program starts up. Or if you need several instances of the window you can create a struct to store them in. Or you can simple lookup the widgets each time you need them. Note that the set of objects you get is completely dynamic. You can for example move the widgets between different windows just as if you created the GUI programmatically.
What is the difference between creating an IPhone application using Interface Builder and without it?
Interface builder is simply an application that can help you place GUI elements and then associate IBOutlets and other in-code functions. you can go into Dashcode and actually read the code generated by Interface Builder but I think you will find that it is LONG and repetitive. Interface builder simply makes it easier to get the interface elements where and how you want them using a GUI. you don't NEED it but its sure useful.
you can create a full interface without an .xib or interfacebuilder you just have to write more code.