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.
Related
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.
So I have a part of my game where the character is selecting an area of the map. And it opening up a panel. I have made it so that happens but an=m now stuck on the other part of it. I want only certain area of the map to be intractable, so that I can bar the player from selecting areas of the map that they aren't ready for. I have no idea how to make game objects in the game uninteractable. I have looked on Stack overflow, Youtube an d the Unity API to no success. Can someone help me with that.
How to make things un-interactable will vary depending on your situation. I'll be presuming that you're map is broken up into a grid of sorts.
The basic setup would involve a bool, probably called 'CanAccessZone'.
Then you'll need a class, to store any access info and popup logic, by popup logic I mean make the element either non-interactable or show a popup, with the shown popup being dependant on 'CanAccessZone'. This class can then be set up by your Map class when the level is loaded, or you could let the popup class grab the necessary values from the Map class.
If you're using Unity's UI buttons for the map pieces, then you could set interactable to false, until you want to let the player access the zone. If you want to display a popup informing the player that they can't access the zone, then your button will be interactable, but the click will delegate to your popup logic method.
It's a similiar principle if you're using gameobjects as buttons. You'd be using any of the OnMouse events to handle click events. https://docs.unity3d.com/ScriptReference/MonoBehaviour.html
Hopefully this'll lead you in the right direction.
I have a Widget a_i that relies on a base Widget b. b contains Javascript that a requires to work.
Currently, the widgets are included on a page like so:
getHomeR = defaultLayout $ do
b
a_1
a_2
I want to automatically include b if a_i is used but only do this once for any particular handler run.
Widget appears to use IO underneath - can I use this to set some kind of flag which allow b only to be included once? Is there already functionality to set some kind of flag that is exclusive to a single handler thread?
I think that's the purpose of widget, to allow to insert javascript only once. Your use case seemt to correspond to the described there. You should use addScript in a and it should be only added once.
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
I have a Yesod form for editing the contents of some static pages which are written using markdown (processed using Pandoc). I want to have two buttons - a 'preview' button which processes the markup and displays the result underneath the form, and a 'submit' button which saves the contents to the database.
What is the simplest way to do this with Yesod? All the form examples in the Yesod book have exactly one button. I've looked at the exposed functions / api, but I even if I add more than one submit button with different names and/or values to the form I can't figure out how to get Yesod to tell me which one was pressed.
Can anyone give me a simple example of a form with more than one button in Yesod, which trigger different actions?
You can just use the Input form functions to get the raw values, and explicitly set a name attribute on the various buttons. Something like this in the HTML:
<input type="submit" name="preview" value="Preview">
And in the Haskell code:
res <- runFormPost ...
isPreview <- runInputPost $ iopt boolField "preview"
if isPreview then ... else ...
Sorry if this doesn't typecheck, I don't have my normal development system right now. But I think this is the right general approach.