Gtk2Hs make its own Signal (or Event) - haskell

I'm trying to create a program with Gtk2Hs and Haskell and I wonder if it is possible to create a new signal with Gtk.
For example I created a hBox containing a button and a text entry. This component can be added at differents places in the window and I would like to trigger some action when the button is pressed or when the entry is edited.
Is it possible to create and force the widget (the hBox?) to emit a custom my_own_signal with something like :
onbuttonPressed button $ do emit my_own_signal
onEntryActivate entry $ do emit my_own_signal
which could be captured by making a
on hbox my_own_signal $ do somethings
or
on my_widget my_own_signal $ do somethings
This way I could have a "global" signal for my widget/hbox
I'm using GHC 7.4.1 and Gtk2Hs 0.12.3

Related

How do you pass data into a chosen scene

Assume we have a main menu with multiple buttons, and we have a text file which contains data behind button 1, button 2, etc.... The text data is loaded into an array of dictionaries.
We are loading a scene like this:
# Global singleton provides a data set, i.e.
var mydata = [{...}, { ... }, etc...]
# On the main menu scene we have buttons
func _on_Button1_pressed():
get_tree().change_scene("res://DataList.tscn")
newscene???.send_data(mydata[0]) # ????
How do I pass the preloaded dictionary object associated with Button1 into the scene that is about to appear?
I understand that change_scene() is "deferred" so we cant just straight away call a "setter" function for this scene, or can we? I am still learning godot so I am a bit lost as to know how to do this
Note that I am expecting to "build up" and "rebuild" the new scene when the user presses the button, and "teardown" when a user exits the scene.
# Global singleton provides a data set, i.e.
If you already have an autoload (singleton), I would put there the information you want to give the other scene, and have the other scene read it.
I understand that change_scene() is "deferred" so we cant just straight away call a "setter" function for this scene, or can we?
Correct, you can't. For the instant where the new scene is loaded the current one is already unloaded, so it can't really call a method on the new one.
Unless you take control of the process. See Change scenes manually.

Python3 Qt5 MainWindow

I have an application flow which looks like this. At startup a MainWindow is shown and asks the user to choose a project or create a new one. After a project is created or chosen from the list, I want to close this MainWindow and open another MainWindow.
In my main.py the code looks like this:
app = QApplication([])
ui_project_list_view = ProjectListView()
ui_project_list_view.show()
app.exec_()
Now I want to close the first main window (ui_project_list_view) and open the other main window (ui_project_view). This code is called from within ui_project_list_view.
ui_project_view = ProjectView()
ui_project_view.show()
main_view.close()
No matter in which order I show or close, the application quits. How should I design my "window-flow" ?
Thanks for your help.
If you open most programs like Word or Excel- or QtDesigner for example- you'll see a blank main window initialize, and then a popup will appear asking you to choose your project.
If you wanted to apply this to your code, the ProjectView should be the main window and the ProjectListView would be the popup. The ProjectView would call this after initializing, in a setup function perhaps. After ProjectListView finishes, then ProjectView would just need to update the screen with the information that ProjectListView has.

Gtk2Hs : Widget interaction

I'm trying to create a program with Gtk2Hs and Haskell and I wonder whether it is possible to make different widgets communicate with one another.
I have a text entry, which is used to write commands, a drawing area, which draws something when the text entry is validated. These two widgets works together fine.
However, I would like to add an "optional" treeview in a different window, which would be updated when all commands in the text entry have been executed (this can take a long time).
As the treeview is "optional" and created only afterwards, I can't define callbacks to its update in the text entry definition (like the drawing area).
I would to create a signal (event?) to be emitted when all the operations are done and caught by the treeview to update its data.
My questions are :
Is there a way to do that with Gtk2Hs and Glib?
Is there a module that could be used to make it (portable to Linux/Windows, if possible)?
Is there a correct way to make a widget interract/communicate with others?
I'm using GHC 7.4.1 and Gtk2Hs 0.12.3
I find a solution to my problem :
In the main program I create an IORef of a list of actions to perform :
actionsIO <- newIORef [action_to_do_1,action_to_do_2]
I create my custom combined widget for text entry
ent <- textEntry window canvas state modele parser info actionsIO
Inside, I execute the list of actions that way :
actions <- readIORef actionsIO
sequence_ actions
I create my treeview
arwin <- arrayWin modele window canvas state info actionsIO
Inside, I modify/delete/add actions to the list like this :
let newactions = [new_action_to_do_1,new_action_to_do_2]
writeIORef actionsIO newactions
These new actions are performed every time a command is validated with the special entry widget.
There is probably a "cleaner" method to do that, but this one work well and solved my problem completely.

Is this possible to use lwuit.Dialog with javax.microedition.lcdui.Canvas in wireless toolkit 2.5.2?

I am using javax.microedition.lcdui.Canvas for drawing my string on the screen. But I also need one dialog window for some purpose. So I am using lwuit package (com.sun.lwuit.Dialog) for showing dialog window when key pressing.
So in my program I just included that package and create the object of the Dialog box. While running my application, it is terminated unexpectedly.
I just included the following lines...
import javax.microedition.lcdui.Canvas;
import com.sun.lwuit.Dialog;
public class Mycanvas extends Canvas implements CommandListener
{
Dialog dialog = new Dialog();
//some other remaining codes for my canvas...
}
So, is it possible to show lwuit dialog window with lcdui canvas?
I would say it's possible but it will increase size of the app significantly. Whenever you need your dialog you can init LWUIT Display and use LWUIT Forms and Dialogs.
I would better to implement some really simple Dialog ourselves. It's not really much work. Or use another third party solution.
My Idea is create an user defined Item which extends from CustomItem for dialog.But it is difficult to code the complete implementation.Better u search for any third pary jar file which already implemented dialog box.

How do I disable Qt's behavior on Linux of capturing arrow keys for widget focus navigation

I'm working on a Qt app that is developed primarily on MacOS, but that is then built and tested on Linux as well.
We define a keyPressEvent() method in our main window class to respond to certain keyboard events. Among others, we respond to Qt::Key_Left, Qt::Key_Right and Qt::Key_Space. This works great on MacOS. On Linux, however, we never get these events.
Doing some Googling (and confirming it with our app's behavior on Linux), it seems that the reason for this is that Qt uses these keys for keyboard navigation of button widgets in the application's GUI. If I press the arrow keys on Linux, I cycle through all the active button widgets, selecting each on in turn. If I click the spacebar, the currently selected button is pressed.
All I've been able to find so far by Googling is suggestions as to how to either subclass or apply filters to specific buttons to avoid this behavior by having the button ignore the event and pass it along. But I don'w want to have to do this for every button widget I ever put into my GUI. That's just lame.
Is there a way to disable this behavior globally and allow my app code to actually get ALL of the arrow key and spacebar events?
You can set add global event listener to catch these events.
In the window constructor:
QApplication::instance()->installEventFilter(this);
In the window's eventFilter method:
bool MainWindow::eventFilter(QObject *object, QEvent *event) {
if (event->type() == QEvent::KeyPress) {
QKeyEvent* key_event = static_cast<QKeyEvent*>(event);
qDebug() << "key" << key_event->key() << "object" << object;
//...
}
return false;
}
If you have processed an event, you should return true from this function. You can use object variable to find out the source of event. For example, it can be some QPushButton. You can check if this button is a child of your main window if it's necessary (if you have multiple top windows).
Another way is to disable focus for buttons completely. Set buttons' focusPolicy to NoFocus. Then they will not catch key events.
Also you can subclass QPushButton and reimplement keyPressEvent with empty implementation.

Resources