Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Apr 04 10:41

    garetxe on master

    Add a gtk4 example (compare)

  • Apr 03 22:41
    garetxe commented #286
  • Apr 03 21:40

    garetxe on master

    Be more explicit about the type… Tested with GHC 8.10.1 Avoid generating bindings for f… (compare)

  • Apr 02 09:16
    garetxe commented #280
  • Apr 02 09:03
    pmiddend commented #280
  • Apr 01 13:24
    garetxe commented #280
  • Apr 01 13:24
    garetxe commented #280
  • Apr 01 13:19
    pmiddend commented #280
  • Apr 01 13:19
    pmiddend closed #280
  • Mar 28 21:13
    goose121 edited #286
  • Mar 28 21:11
    goose121 opened #286
  • Mar 24 19:03
    garetxe commented #285
  • Mar 24 15:17
    XVilka commented #285
  • Mar 24 14:09
    garetxe commented #285
  • Mar 24 12:48
    XVilka commented #285
  • Mar 24 12:47
    XVilka commented #285
  • Mar 24 12:45
    garetxe commented #285
  • Mar 24 12:36
    XVilka commented #285
  • Mar 24 10:39
    garetxe commented #285
  • Mar 24 09:17
    XVilka opened #285
Andri Möll
@moll
Sure! I'm aiming for the most-issues-opened on Haskell GI award anyway. :P
Iñaki
@garetxe
:D It's really very helpful, thanks!
chenyulue
@chenyulue
Hi, are there some tutorials about gi-gtk? Except the hackage documents and examples
Andri Möll
@moll
I got a start with the examples in the repository, @chenyulue.
Whoops, you did mention the examples already. :innocent:
For the rest I personally went with general GTK tutorials and just translated the examples to Haskell GI-s style.
Apart from an example or two I'd say it's a better use of everyone's time to write tutorials for the original library in its original language and then separately a few on how to translate from the source language to the bindings' language. :P
chenyulue
@chenyulue
Thanks! @moll Mark Karpov's tutorial is also in my notes. Seems the general GTK tutorials is the only choice for learning haskell GUI programming with GTK+.
Karl Melvan
@kmelvn
trying to capture all key press and key release events on a GtkWindow - can't find the function for setting my handler for "key-press-event" and "key-release-event"?
I'm not using overloading, so something like onWidgetKeyReleaseEvent? can't find it in the docs...
Karl Melvan
@kmelvn
oh, I'm looking at 4.0.1 docs and using 3.0.32 ... oh, there's new version :)
due43
@due43
hello
First time using this forum
I am unclear on ManagedPtr, when do I disown or own an object? I want to be able to lookup windows by name, and figured I needed to store a map from name to weak ref
You see the lookups happen according to user input, so I want to allow that objects they indicate might have been cleaned up by gtk already, and in particular I dont want the fact that I have a name for an object to keep it from getting cleaned up if it's reference count would otherwise drop to 0...
due43
@due43
So I envisioned something like (mp :: Map Text GWeakRef) ... But I don't even know how to create a GWeakRef using haskell
and ManagedPtr's machinery makes me wonder if I can use it as a weakref, by disown/own
due43
@due43
I understand ManagedPtr is like ForeignPtr, but allows finalizers to be toggled on and off.. But I wish the documentation was more clear about what said finalizers do in the bindings, so I understood when I would want to toggle them.
Iñaki
@garetxe
Hi! Sorry for the slow reply, I just saw your message
Yes, a ManagedPtr is essentially a ForeignPtr that can be "disowned", meaning that the finalizer can be discarded.
The finalizer is almost always some sort of *_unref function, that releases the reference the Haskell value keeps to the GObject (or boxed value, etc.)
The rule of thumb is that you don't need to worry about owning/disowning from the Haskell side at all: if the annotations are correct then a reference to the underlying object will be created when the Haskell wrapper is created, and when the Haskell wrapper is garbage-collected the reference will be dropped.
Iñaki
@garetxe
I don't think that using ManagedPtr here is the right solution, at least currently, since it provides no safety net: if the underlying pointer becomes invalid the ManagedPtr will not know, and the program will probably crash.
(But adding such a safety net is a good idea, I just opened haskell-gi/haskell-gi#272)
Regarding your actual issue, I think that if I implement haskell-gi/haskell-gi#272 (and added a small API to ensure that the underlying object had not been destroyed) would cover your use case. I will try to implement this as soon as I get a chance.
Karl Melvan
@kmelvn
setting window title with windowSetTitle doesn't work for ScrolledWindow, shouldn't it work?
Karl Melvan
@kmelvn
oh, guess not... ScrolledWindow is not what I thought it is...
Lurkki14
@Lurkki14
main = do
  Gtk.init Nothing
  window <- new Gtk.Window [#title := "Hello"]
  on window #destroy Gtk.mainQuit
  adjustment <- new Gtk.Adjustment [#value := 50, #lower := 0, #upper := 100]
  slider <- new Gtk.Scale[#adjustment := adjustment, #drawValue := True]
  spinButton <- new Gtk.SpinButton [#adjustment := adjustment]

  #add window spinButton
  #showAll window
  Gtk.main
anyone know why pressing the spinbutton buttons does nothing here?
the slider works normally, and i can also input with keyboard to the spinbutton
Arthur N.
@Nimmerwoner
What do you mean by does nothing? I think you should also connect to the signal https://developer.gnome.org/gtk3/unstable/GtkAdjustment.html#GtkAdjustment-value-changed to be able to process a change in value
Iñaki
@garetxe
@Lurkki14 There were a couple of things, the main one being that you need to set the step-increment property for the adjustment to actually do something. And you probably want to pack things in a box, to see the slider and the spin button simultaneously
With those changes things work well for me, here is some example code that you can run with cabal new-run file.hs:
{-# LANGUAGE OverloadedStrings, OverloadedLabels #-}
{- cabal:
build-depends: base, haskell-gi-base, gi-gtk == 3.0.*
-}

import qualified GI.Gtk as Gtk
import Data.GI.Base

main :: IO ()
main = do
  Gtk.init Nothing
  window <- new Gtk.Window [#title := "Hello"]
  on window #destroy Gtk.mainQuit
  box <- new Gtk.Box [#orientation := Gtk.OrientationVertical]
  #add window box
  adjustment <- new Gtk.Adjustment [#value := 50, #lower := 0, #upper := 100,
                                    #stepIncrement := 1]
  slider <- new Gtk.Scale[#adjustment := adjustment, #drawValue := True]
  #add box slider
  spinButton <- new Gtk.SpinButton [#adjustment := adjustment]
  #add box spinButton

  #showAll window
  Gtk.main
Karl Melvan
@kmelvn

Trying to prototype some kind of a different editor - so I'm working directly with the low level GTK keyboard/mouse machinery. For now I've been using eventGetKeyval and keyvalName mostly and it's been working fine.

Now I'd like to go from that low level keyval (ie, Word32) to an UTF8 (preferably Text) encoded character. What would be the easiest way to do this?

There's keyvalToUnicode, but I don't see how to go from that to UTF8... is there something in GDK/GTK that does that?
Karl Melvan
@kmelvn
There's g_unichar_to_utf8 in glib, but I don't see it in bindings...
Iñaki
@garetxe
@kmelvn Does toEnum (fromIntegral c) :: Char work? Char itself is supposed to be ISO10646
(Here c is the result of keyvalToUnicode.)
You can also use chr instead of toEnum if you like
Karl Melvan
@kmelvn
not at my computer right now, I tried that - but it seems Char only works for characters in the ASCII range
it was weird, no errors, printing Chars in ASCII table works fine - anybthin beyond that I just get the hex code of the Unicode codepoint
I was kind of hoping there was something in the GTK that does this... how does a text entry go from keyboard events to text shown on the screen?
Iñaki
@garetxe
The following seems to work well for me:
{-# LANGUAGE OverloadedStrings, OverloadedLabels #-}
{- cabal:
build-depends: base, haskell-gi-base, gi-gdk, gi-gtk == 3.0.*
-}

import Data.Char (chr)

import qualified GI.Gdk as Gdk
import qualified GI.Gtk as Gtk
import Data.GI.Base

main :: IO ()
main = do
  Gtk.init Nothing
  window <- new Gtk.Window [#title := "Hello"]
  on window #destroy Gtk.mainQuit
  entry <- new Gtk.Entry []
  #add window entry
  on entry #keyPressEvent $ \keyEvent -> do
    key <- keyEvent `get` #keyval >>= Gdk.keyvalToUnicode
    putStrLn $ "Key pressed: ‘" ++ (chr (fromIntegral key) : []) ++ "’ ("
                ++ show key ++ ")"
    return False

  #showAll window
  Gtk.main
(You can run it with cabal run test.hs)
Iñaki
@garetxe
Here is a version using Text instead (via Char):
{-# LANGUAGE OverloadedStrings, OverloadedLabels #-}
{- cabal:
build-depends: base, text, haskell-gi-base, gi-gdk, gi-gtk == 3.0.*
-}

import Data.Char (chr)

import Data.Text as T
import Data.Text.IO as TIO

import qualified GI.Gdk as Gdk
import qualified GI.Gtk as Gtk
import Data.GI.Base

main :: IO ()
main = do
  Gtk.init Nothing
  window <- new Gtk.Window [#title := "Hello"]
  on window #destroy Gtk.mainQuit
  entry <- new Gtk.Entry []
  #add window entry
  on entry #keyPressEvent $ \keyEvent -> do
    key <- keyEvent `get` #keyval >>= Gdk.keyvalToUnicode
    TIO.putStrLn $ "Key pressed: ‘" <> T.singleton (chr (fromIntegral key))
                   <>"’ (" <> T.pack (show key) <> ")"
    return False

  #showAll window
  Gtk.main
Karl Melvan
@kmelvn
thanks man, it's working great! such a silly mistake, i mistook Char as a single character String ... must've been really tired, the key part is someChar : [], ie turning a Char into String :)
and I did search through Text docs, didn't see the singleton :: Char -> Text, which is exactly what I needed... so much silliness :)
Iñaki
@garetxe
No worries, glad that it's sorted now!
Karl Melvan
@kmelvn
of course, Hoogle finds Char -> Text without a problem... man I should starting using it some time :D