Code Monkey home page Code Monkey logo

gtk-simple's Introduction

badge

GTK::Simple

GTK::Simple is a set of simple GTK 3 bindings using NativeCall. Only some GTK widgets are currently implemented. However, these are enough to create a reasonable interactive GUI for an idiomatic Raku program.

The GTK Widgets in this distribution include the following:

Widget Description
ActionBar Group multiple buttons and arrange in 'left', 'middle', and 'right'
Button A simple button with a label and a callback
Calendar A calendar for selecting a date
CheckButton A check button with a label
CheckMenuItem A checkable menu item
ComboBoxText A simple combo box
DrawingArea A drawing area (requires the 'Cairo' module)
Entry Allows for text to be provided by the user
FileChooserButton A button that opens a file chooser dialog
Frame A bin with a decorative frame and optional label
Grid A table-like container for widgets for window design
Label Adds a line of text
LevelBar A bar that can used as a level indicator
LinkButton Create buttons bound to a URL
ListBox A vertical listbox where each row is selectable
MarkUpLabel Adds text with GTK mark up (e.g. color and font manipulation)
Menu A simple menu with a menu item label
MenuBar A simple menu bar that contain one or more menus
MenuItem A simple menu item that can have a sub menu
MenuToolButton A menu tool button with a label or an icon
PlacesSidebar Sidebar that displays frequently-used places in the file system
ProgressBar Show progress via a filling bar
Scale Allows for a number to be provided by the user
ScrolledWindow Container for widgets needing scrolling, eg., multiline texts
RadioButton A choice from multiple radio buttons
Spinner Showing that something is happening
TextView Adds multiple lines of text
ToggleButton A toggle-able button
Toolbar A tool bar that can contain one or more menu tool buttons
VBox, HBox Widget containers which enable window layout design

Example

use GTK::Simple;

my $app = GTK::Simple::App.new( title => "Hello GTK!" );

$app.set-content(
    GTK::Simple::VBox.new(
        my $button = GTK::Simple::Button.new(label => "Hello World!"),
        my $second = GTK::Simple::Button.new(label => "Goodbye!")
    )
);

$app.border-width = 20;
$second.sensitive = False;
$button.clicked.tap({ .sensitive = False; $second.sensitive = True });
$second.clicked.tap({ $app.exit; });
$app.run;

Using :subs option

Another approach is to specify :subs on import. This provides subroutine aliases for the constructors of all of the available GTK::Simple widgets, converted from CamelCase to kebab-case.

GTK::Simple::MenuToolButton becomes menu-tool-button, GTK::Simple::ProgressBar becomes progress-bar, etc.

The above example can be equivalently written as:

use GTK::Simple :subs;

my $app = app(title => "Hello GTK!");

$app.set-content(
    v-box(
        my $button1 = button(label => "Hello World"),
        my $button2 = button(label => "Goodbye!")
    )
);

# ...

Further examples

The first four examples were written as mini tutorials to show how the system works:

For more examples, please see the examples/ folder.

Limitations

The full functionality of GTK 3 is not available in this module.

Prerequisites

This module requires the GTK3 library to be installed. Please follow the instructions below based on your platform:

Debian Linux

sudo apt-get install libgtk-3-dev

Mac OS X

brew update
brew install gtk+3

Windows

The GTK team describes how to do this for Windows at Setting up GTK for Window

Installation and sanity tests

Use the zef package manager

$ zef install GTK::Simple

Author

Jonathan Worthington, jnthn on #raku, https://github.com/jnthn/

Contributors

The Raku team

License

The Artistic License 2.0

gtk-simple's People

Contributors

ab5tract avatar altai-man avatar andreoss avatar azawawi avatar colomon avatar dwarring avatar finanalyst avatar hankache avatar jj avatar jobegrabber avatar jonathanstowe avatar lizmat avatar masterduke17 avatar mattoates avatar moritz avatar mouq avatar niner avatar retupmoca avatar samcv avatar slobo avatar smls avatar stmuk avatar teodozjan avatar timo avatar trosel avatar ugexe avatar vendethiel avatar zoffixznet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

gtk-simple's Issues

Kebab the public interface

Parts of the public interface are using snake_case while I have been adding the new stuff with kebab-case, obviously consistency would be better and I think that the consensus has largely converged on using kebab-case in new code.

Obviously this would be an in-compatible change so there would need to be a short deprecation cycle (though as it currently stands the module isn't properly versioned so this in itself is somewhat problematic,)

I'll leave this for discussion for a bit before I do anything.

Deprecated warnings with GTK 3.16.4_1 on OS X

On OSX using GTK 3.16.4_1 I get the following output when using GTK::Simple with the built in examples.

2015-07-02 12:10:34.731 moar[99714:662363] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead.

Trying to use Cairo in DrawingArea

The Cairo documentation is sparse and there is no example for the use of DrawingArea.

Also the following error is puzzling:
$perl6 test_lib.p6
Could not find symbol '&ConnectionHandler'
in method add-draw-handler at /home/richard/perl6/rakudo-star-2016.07/install/share/perl6/site/sources/A6D434FC7BEE2A422FB2B8F6CF413E78905D1848 (GTK::Simple::DrawingArea) line 33
in block at test_lib.p6 line 20
Actually thrown at:
in method add-draw-handler at /home/richard/perl6/rakudo-star-2016.07/install/share/perl6/site/sources/A6D434FC7BEE2A422FB2B8F6CF413E78905D1848 (GTK::Simple::DrawingArea) line 33
in block at test_lib.p6 line 20

$ cat test_lib.p6
#!/usr/bin/env perl6
use v6.c;
use GTK::Simple;
use Cairo;
use GTK::Simple::DrawingArea;

my $app = GTK::Simple::App.new(:title);
my $da = GTK::Simple::DrawingArea.new;
gtk_simple_use_cairo;

$app.set-content( $da );
$app.border-width = 20;
$da.size-request(300,300);
my $ctx = $da.add-draw-handler( &rect-do );
$app.run;

sub rect-do( $d, $ctx ) {
given $ctx {
.rgb(0, 0.7, 0.9);
.rectangle(10, 10, 50, 50);
.fill :preserve; .rgb(1, 1, 1);
.stroke
};
}

Provide widget constructor candidate that takes GtkWidget

It would be useful to implementing parts of the API and necessary to move GtkBuilder forward if a constructor candidate was available which took the raw GtkWidget object.

It would be nice if this could happen without adding it to each widget class.

how install Cairo

Hi,

I don't understand how install Cairo on Debian Stretch.
I do
apt install libcairo2-dev (and i ha ve libcairo2-dev is already the newest version )
but I have always 'Cairo' module is not installed - can't run example

Have an idea ?

NativeLib.pm6 using @*INC breaks usage on Windows

Trying to build/test GTK::Simple on Windows 7 x64 fails, presumably due to NativeLib.pm6 using @*INC:

PS C:\Users\jgrabber.INT> zef install GTK::Simpler
===> Searching for: GTK::Simpler
===> Searching for missing dependencies: GTK::Simple
===> Fetching: GTK::Simpler
===> Fetching: GTK::Simple
===> Building: GTK::Simple:ver('0.1.4')
===> Building [OK] for GTK::Simple:ver('0.1.4')
===> Testing: GTK::Simple:ver('0.1.4')

# Failed test at t\01-sanity.t line 10
# Dynamic variable @*INC not found

# Failed test at t\01-sanity.t line 11
# Dynamic variable @*INC not found

# Failed test at t\01-sanity.t line 12
# Method 'run' not found for invocant of class 'Any'
# Looks like you failed 3 tests of 3
===> Testing [FAIL]: GTK::Simple:ver('0.1.4')
Aborting due to test failure: GTK::Simple:ver('0.1.4') (use --force to override)

  in code  at C:\rakudo\share\perl6\site\sources\1DC0BAA246D0774E7EB4F5119C6168E
0D8266EFA (Zef::Client) line 290
  in method test at C:\rakudo\share\perl6\site\sources\1DC0BAA246D0774E7EB4F5119
C6168E0D8266EFA (Zef::Client) line 269
  in code  at C:\rakudo\share\perl6\site\sources\1DC0BAA246D0774E7EB4F5119C6168E
0D8266EFA (Zef::Client) line 440
  in sub  at C:\rakudo\share\perl6\site\sources\1DC0BAA246D0774E7EB4F5119C6168E0
D8266EFA (Zef::Client) line 437
  in method install at C:\rakudo\share\perl6\site\sources\1DC0BAA246D0774E7EB4F5
119C6168E0D8266EFA (Zef::Client) line 532
  in sub MAIN at C:\rakudo\share\perl6\site\sources\A9948E7371E0EB9AFDF1EEEB07B5
2A1B75537C31 (Zef::CLI) line 118
  in block <unit> at C:\rakudo\share\perl6\site\resources\1BB781E6A0355D520C9B0E
40400A3186CFE69967 line 1

@*INC is mentioned and used here .

Also see a similiar problem on stackoverflow here.

Scrolling

I need a scrolled window as too much data is flooding a textview.

gtk documentation puts a textview into a scrolled window.

So we need a scrolled window widget. Which I am working on for myself.

However, it seems to me that rather than creating a scrolled window, and then putting each widget that needs scrolling into it, it would be more natural in perl6 for a role / trait, eg.,
my $label = GTK::Simple::Label.new(text=>'something') :scrolled;
or maybe
$label does GTK::Simple::Scrolled;

However, I'm not confident about how to do this consistently, or if this is the right syntax or approach.

RFE: example of a fill in form

Dear gtk-simple:

Request for Enhancement (RFE):

Would you please consider an example of a fill in form: city, state, zip, etc. where you fill in the data or just accept the defaults, then press okay or cancel.

Many thanks,
-T

Add notes on how to compile this and how to run the tests.

I tried prove -r -e "perl6 -Ilib" t

and got

t/01_sanity.t .. 1/3 
# Failed test at t/01_sanity.t line 6
# Cannot locate native library 'libgtk-3.dylib': dlopen(libgtk-3.dylib, 1): image not found

# Failed test at t/01_sanity.t line 8
# Method 'run' not found for invocant of class 'Any'
# Looks like you failed 2 tests of 3
t/01_sanity.t .. Dubious, test returned 2 (wstat 512, 0x200)
Failed 2/3 subtests 

Test Summary Report
-------------------
t/01_sanity.t (Wstat: 512 Tests: 3 Failed: 2)
  Failed tests:  1, 3
  Non-zero exit status: 2
Files=1, Tests=3,  9 wallclock secs ( 0.03 usr  0.00 sys +  8.77 cusr  0.25 csys =  9.05 CPU)
Result: FAIL

use just Github Actions for CI

since Github Actions now available to all open source projects, and highly integrated with Github, also offers Windows and self hosted build as options...I think we can start replacing appveyor and travis ci with github actions CI instead of using two

HBox, VBox are deprecated.

The HBox and VBox widgets have been deprecated since Gtk+ 3.2 in favour of using a plain Box with the appropriate orientation property. (It is also hinted that Box itself may be deprecated in the future.)

In order to maintain backward compatibility, the HBox and VBox should probably re-implemented in terms of the box constructor.

I'll implement if no-one else does it first.

cannot install GTK::Simple using panda

panda install GTK::Simple
==> Fetching GTK::Simple
==> Building GTK::Simple
===SORRY!=== Error while compiling /home/grizzlysmit/.rakudobrew/moar-nom/install/share/perl6/site/sources/364074153E7AD72F9C60425645AC9871DF10C969
Malformed parameter
at /home/grizzlysmit/.rakudobrew/moar-nom/install/share/perl6/site/sources/364074153E7AD72F9C60425645AC9871DF10C969:207
------> RequestType $rt, $host, $portโ as Int, $path, %headers, $content?, :$s
expecting any of:
constraint
===SORRY!=== Error while compiling /home/grizzlysmit/.rakudobrew/moar-nom/install/share/perl6/site/sources/364074153E7AD72F9C60425645AC9871DF10C969
Malformed parameter
at /home/grizzlysmit/.rakudobrew/moar-nom/install/share/perl6/site/sources/364074153E7AD72F9C60425645AC9871DF10C969:207
------> RequestType $rt, $host, $portโ as Int, $path, %headers, $content?, :$s
expecting any of:
constraint

Install fails on Windows

Spotted this problem on reddit thread

Install fails on Win8:

C:\rakudo\bin>zef install Gtk::Simple
===> Searching for: Gtk::Simple
===> Building: GTK::Simple:ver<0.1.5>
At line:1 char:192
+ ... )) -replace \"-\",\"\" } get-sha256 C:\Users\bit\.zef\store\gtk-simple.git\df15c ...
+                    ~
You must provide a value expression following the '-' operator.
At line:1 char:192
+ "function get-sha256 { param($file);[system.bitconverter]::tostring([System.Secu ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token '\",\"\" } get-sha256 C:\Users\bit\.zef\store\gtk-simple.git\df15c903afdeb207a7115e8a0ff709f783559d05\resources\blib\lib\GTK\libatk-1.0-0.dll"' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : ExpectedValueExpression

Effective index out of range. Is: -1, should be in 0..^Inf
  in block  at C:\Users\bit\.zef\store\gtk-simple.git\df15c903afdeb207a7115e8a0ff709f783559d05\Build.pm line 55
  in method build at C:\Users\bit\.zef\store\gtk-simple.git\df15c903afdeb207a7115e8a0ff709f783559d05\Build.pm line 49
  in block <unit> at -e line 1

Actually thrown at:
  in block  at C:\Users\bit\.zef\store\gtk-simple.git\df15c903afdeb207a7115e8a0ff709f783559d05\Build.pm line 92
  in method build at C:\Users\bit\.zef\store\gtk-simple.git\df15c903afdeb207a7115e8a0ff709f783559d05\Build.pm line 49
  in block <unit> at -e line 1

===> Building [OK] for GTK::Simple:ver<0.1.5>
===> Testing: GTK::Simple:ver<0.1.5>
# Failed test at t\01-sanity.t line 12
# Failed to copy 'C:\Users\bit\.zef\store\gtk-simple.git\df15c903afdeb207a7115e8a0ff709f783559d05\resources\blib\lib\GTK\libgtk-3-0.dll' to 'C:\Users\bit\AppData\Local\Temp\libgtk-3-0.dll': Failed to copy file: no such file or directory
# Failed test at t\01-sanity.t line 13
# Failed to copy 'C:\Users\bit\.zef\store\gtk-simple.git\df15c903afdeb207a7115e8a0ff709f783559d05\resources\blib\lib\GTK\libglib-2.0-0.dll' to 'C:\Users\bit\AppData\Local\Temp\libglib-2.0-0.dll': Failed to copy file: no such file or directo
ry
# Failed test at t\01-sanity.t line 14
# No such method 'run' for invocant of type 'Any'
# Looks like you failed 3 tests of 3
===> Testing [FAIL]: GTK::Simple:ver<0.1.5>
Aborting due to test failure: GTK::Simple:ver<0.1.5> (use --force-test to override)
  in code  at C:\rakudo\share\perl6\site\sources\9062A39D0256C0BD797016C3FE93D839191AFE2B (Zef::Client) line 385
  in method test at C:\rakudo\share\perl6\site\sources\9062A39D0256C0BD797016C3FE93D839191AFE2B (Zef::Client) line 363
  in code  at C:\rakudo\share\perl6\site\sources\9062A39D0256C0BD797016C3FE93D839191AFE2B (Zef::Client) line 540
  in sub  at C:\rakudo\share\perl6\site\sources\9062A39D0256C0BD797016C3FE93D839191AFE2B (Zef::Client) line 537
  in method install at C:\rakudo\share\perl6\site\sources\9062A39D0256C0BD797016C3FE93D839191AFE2B (Zef::Client) line 643
  in sub MAIN at C:\rakudo\share\perl6\site\sources\9E04C517E18C976DC9F459E2CE31A87142034020 (Zef::CLI) line 152
  in block <unit> at C:\rakudo\share\perl6\site\resources\3DCC2E58BBBF1E42EA4C8C976F9BE97162B9EFA2 line 3
  in sub MAIN at C:\rakudo\share\perl6\site\bin\zef line 2
  in block <unit> at C:\rakudo\share\perl6\site\bin\zef line 2

I tried to repro on my own Win10, but it failed even earlier when trying to install OpenSSL

Finding ENUM values eg. GTK_ORIENTATION_HORIZONTAL for PANED

I am having trouble adding a 'Pane' widget.
I have added all the functions referred to the GTK3 manual page to raw. However, when I run a minimal app, I get a blank window. (The current code of example 18 in my repo is minimal. As you will see I have commented out all of the extra code to show different code). Also, I have simplified the BUILD submethod in Raw.pm6 to try to identify the problem.
GTK gives the initialisation routine as gtk_paned_new( orientation ). 'orientation' is an enumeration with two elements, GTK_ORIENTATION_HORIZONTAL and GTK_ORIENTATION_VERTICAL
I assumed the actual values are 0 and 1, but I can't actually find the .h file that defines them in the gtk sources.
The code is in finanalyst/gtk-simple. I have not done a push request because the example file is not running correctly yet.
I'm willing to keep working at this, but I have run out of ideas as to how to get this to work. I have Googled GTK Paned, but there does not seem to be any link about a problem or any special code needed.

MoarVM Panic Running Example 18, Cairo Draw Handler

I'm trying to run example 18, the Cairo Draw Handler, from the GTK::Simple module on Ubuntu 18.04 using Rakudo Star version 2018.06 built on MoarVM version 2018.06 implementing Perl 6.c.
I get the following error message.
MoarVM panic: Internal error: Unwound entire stack and missed handler

MoarVM: Invalid GC status observed

This repo contains the sample to observe the bug:

https://github.com/vendethiel/moarvm-gcerr-gtk

However, if I move the block:

$c-o.supply.schedule-on(GTK::Simple::Scheduler).tap({
  # doesn't error without this line
  $program-output.text ~= $_;
});

To after the start { } block, the bug disappears.

Running OS X Yosemite, Rakudo version 2016.05-24-gbe4e439 built on MoarVM version 2016.05.

gtk_widget_show/_hide bug

In Widget.pm6
Line 114:

method hide() {

gtk_widget_show($!gtk_widget);

}

should probably be

method hide() { 

gtk_widget_hide($!gtk_widget);

}

program crashes when GTK::Simple::App.new(...) is called later in program

When I want to organize statements in such a way that the App object is placed later in the program when it is needed instead of instantiating it at the start the program, the program will crash.
E,g,

.....
my $button = GTK::Simple::Button.new(label => "Hello World!");
my $second = GTK::Simple::Button.new(label => "Goodbye!");
$second.sensitive = False;
$button.clicked.tap({ .sensitive = False; $second.sensitive = True });
$second.clicked.tap({ app-exit; });

my GTK::Simple::App $app .= new(title => "Hello GTK!");
$app.set-content( GTK::Simple::VBox.new( $button, $second));
$app.border-width = 20;
$app.run;

sub app-exit( ) { $app.exit; }

I assume there are some side effects which are needed by the other widgets but it isn't clear when it happens.

Shown error messages are

(process:13981): Gtk-CRITICAL **: gtk_settings_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed

(process:13981): GLib-GObject-CRITICAL **: g_object_get_qdata: assertion 'G_IS_OBJECT (object)' failed
Segmentation fault (core dumped)

Install not working correctly

===> Searching for: GTK::Simple
===> Building: GTK::Simple:ver<0.1.9>
Malformed UTF-8
  in block  at C:\Users\mcsla\.zef\store\gtk-simple.git\4707622d9fd1d828b76a241713d99f0ec982c1ef\Build.pm line 62
  in block  at C:\Users\mcsla\.zef\store\gtk-simple.git\4707622d9fd1d828b76a241713d99f0ec982c1ef\Build.pm line 102
  in method build at C:\Users\mcsla\.zef\store\gtk-simple.git\4707622d9fd1d828b76a241713d99f0ec982c1ef\Build.pm line 49
  in block <unit> at -e line 1

===> Building [FAIL]: GTK::Simple:ver<0.1.9>
Aborting due to build failure: GTK::Simple:ver<0.1.9> (use --force-build to override)
  in code  at C:\rakudo\share\perl6\site\sources\7926F4F3ED4C81AA5DA2A54C8AE1E03D03424CCE (Zef::Client) line 334
  in method build at C:\rakudo\share\perl6\site\sources\7926F4F3ED4C81AA5DA2A54C8AE1E03D03424CCE (Zef::Client) line 302
  in sub  at C:\rakudo\share\perl6\site\sources\7926F4F3ED4C81AA5DA2A54C8AE1E03D03424CCE (Zef::Client) line 523
  in method install at C:\rakudo\share\perl6\site\sources\7926F4F3ED4C81AA5DA2A54C8AE1E03D03424CCE (Zef::Client) line 623
  in sub MAIN at C:\rakudo\share\perl6\site\sources\E4784A2A0FA00D16808817186E95FE74BEF3FE2D (Zef::CLI) line 152
  in block <unit> at C:\rakudo\share\perl6\site\resources\1B245F3871EB7CE9B7F4E3E11FC5912C69500928 line 3
  in sub MAIN at C:\rakudo\share\perl6\site\bin\zef line 2
  in block <unit> at C:\rakudo\share\perl6\site\bin\zef line 2

The module is not installing correctly. I'm running on Windows 10. I even tried both on command prompt and PowerShell.

Load time

GTK::Simple programs take a while to start up:

~ $ time perl6 -e 'use GTK::Simple'

real    0m10.283s
user    0m10.000s
sys 0m0.108s

Any suggestions for making that faster? :-)

Successfully runned all demos on Win32, requesting official support in this module.

I just put all official builded GTK+3 dlls under the directory rakudo\bin and replaced some text in Simple.pm6 with Notepad.
'libgtk-3.so.0' -> 'libgtk-3-0.dll'
'libgobject-2.0.so' -> 'libgobject-2.0-0.dll'
One exception is
rakudo should look for sub g_idle_add in 'libglib-2.0-0.dll' under Win32.

I hope you guys can add Win32 support to this module :) .
I am just started learning Perl 6, so my coding skill might not be enough to write patch to this module, so I wouldn't sent pull request. Just for your information.

GTK::Simple::App not exported by default or explicitly imported in examples

Most of the examples (both in the examples directory, and the quick start example in the readme docs) fail to run with the latest rakudobrew installation with the error "GTK::Simple::App is not declared." Adding a "use GTK::Simple::App" in the script resolves the error. This is true for examples 01-08 and 17.

On a related note of examples failing:

  • Example 05 fails with "Cannot locate symbol 'gtk_action_bar_new' in native library 'libgtk-3.so".
  • 07 seemingly works, but gives an error "Cannot locate symbol gtk_text_view_set_monospace"
  • 13 fails with "Cannot locate symbol gtk_places_sidebar_get_show_trash"

Trying to read the `.text` property of a TextView results in an abort.

Here is a minimal example to show the bug off:

use GTK::Simple::App;
use GTK::Simple::TextView;

my $app       = GTK::Simple::App.new(:title("Crash in 2 seconds."));
my $text-view = GTK::Simple::TextView.new;

$text-view.text = "acfd";

start { sleep 2; say $text-view.text; }

$app.set-content($text-view);
$app.show;
$app.run;

When this is ran, it correctly shows a window with a TextView containing "acdf". However, after 2 sec, instead of "acdf" (or whatever the TextView contents are at that moment) being printed into the terminal, the program crashes:

$ crash.p6
malloc(): invalid size (unsorted)
[1]    8571 abort      crash.p6

This bug also affects the example 11 (examples/11-file-chooser-button.pl6) that crashes when the file is chosen from the dialog.


The operating system is Debian bullseye/sid, Perl 6 version 2019.07.1, GTK::Simple version 0.1.11, and libgtk3 version 3.24.10-1 (coming from Debian repositories).

Of course I will be happy to provide more information as needed; I'm just not really sure what to look for. If you would like me to use some gdb on it, or get some core dumps, valgrind logs or anything like that, just ask.

Thanks!

new Issue still cannot install GTK::Simple error during tests

panda install GTK::Simple
==> Fetching GTK::Simple
==> Building GTK::Simple
Found system gtk library.
==> Testing GTK::Simple

Failed test at t/01_sanity.t line 6

Cannot locate native library 'libgtk-3': libgtk-3: cannot open shared object file: No such file or directory

Failed test at t/01_sanity.t line 7

Cannot locate native library 'libglib-2.0': libglib-2.0: cannot open shared object file: No such file or directory

Failed test at t/01_sanity.t line 8

Method 'run' not found for invocant of class 'Any'

Looks like you failed 3 tests of 3

t/01_sanity.t ..
Dubious, test returned 3 (wstat 768, 0x300)
Failed 3/3 subtests

Test Summary Report

t/01_sanity.t (Wstat: 768 Tests: 3 Failed: 3)
Failed tests: 1-3
Non-zero exit status: 3
Files=1, Tests=3, 152 wallclock secs ( 0.04 usr 0.00 sys + 43.26 cusr 1.23 csys = 44.53 CPU)
Result: FAIL
The spawned process exited unsuccessfully (exit code: 1)
in sub run-and-gather-output at /home/grizzlysmit/.rakudobrew/moar-nom/install/share/perl6/site/sources/BC95C1F03FD26FCC92CB72CD826C4739353C6CA6:85
in block at /home/grizzlysmit/.rakudobrew/moar-nom/install/share/perl6/site/sources/FC684EC9B9C25726CC880847EFF9969D1A73521D:22
in sub indir at /home/grizzlysmit/.rakudobrew/moar-nom/install/share/perl6/site/sources/BC95C1F03FD26FCC92CB72CD826C4739353C6CA6:20
in method test at /home/grizzlysmit/.rakudobrew/moar-nom/install/share/perl6/site/sources/FC684EC9B9C25726CC880847EFF9969D1A73521D:5
in method install at /home/grizzlysmit/.rakudobrew/moar-nom/install/share/perl6/site/sources/BA0F30DD085F36D1DDB7AB73A230AF22CC30C87B:141
in method resolve at /home/grizzlysmit/.rakudobrew/moar-nom/install/share/perl6/site/sources/BA0F30DD085F36D1DDB7AB73A230AF22CC30C87B:219
in sub MAIN at /home/grizzlysmit/.rakudobrew/moar-nom/install/share/perl6/site/resources/41715A941E28E09D8BF7F4B447720F8C0E01F976:18
in block at /home/grizzlysmit/.rakudobrew/moar-nom/install/share/perl6/site/resources/41715A941E28E09D8BF7F4B447720F8C0E01F976:150

// so I try to locate the missing library:
locate libgtk-3.so
/usr/lib/i386-linux-gnu/libgtk-3.so
/usr/lib/i386-linux-gnu/libgtk-3.so.0
/usr/lib/i386-linux-gnu/libgtk-3.so.0.1600.7

it's there why doesn't GTK::Simple find it should I symlink it some where??

Code runs fine first time, then gives warnings.

The problem is with the ScrolledWindow code I added a couple of days ago. At first all seems well, but ...
If I run the example (17-scrolled-window ...) from a terminal there is no error the first time. Press the exit button I have provided in the example, and the app cleans up properly. Run the example again, and there are no warnings.
HOWEVER, exit the app using the GTK window destructor (top left X on my ubuntu desktop), and the next time the app is run, warnings are generated! This should not happen.
(See below for output).

As it happens, the warnings are about a place in the code that I was unsure about.
gtk-scrolled-window-new() should be called with two arguments: x-hadjustment and y-hadjustment, that is two (complicated) C structs that can be used to customise the movement of the scrollbars. In the gtk documentation, the simple examples have these arguments set to NULL. So in the Raw.pm6, I use pointers, and in ScrolledWindow.pm6 I use Nil's. Since this is a 'Simple' model, I thought no need for complexity.
However, I am not sure whether I was using best practice.
As you can see the warnings refer to these arguments.
At the same time, clean up at the end of the program should ensure that behaviour in one run of the program does not affect the behaviour of the program again.
Hence, I am marking this as a BUG.

Sample session:
$ perl6 ../gtk-simple/examples/17-scrolled-window-with-textview.p6
==== comment. No output on stdout or stderr. The app was ended using the Exit button
$ perl6 ../gtk-simple/examples/17-scrolled-window-with-textview.p6
==== comment. ditto
$ perl6 ../gtk-simple/examples/17-scrolled-window-with-textview.p6
==== comment. This time, I exited the app by destroying the window, not exiting the app.
$ perl6 ../gtk-simple/examples/17-scrolled-window-with-textview.p6
(17-scrolled-window-with-textview.p6:8210): Gtk-CRITICAL *: gtk_scrolled_window_new: assertion 'GTK_IS_ADJUSTMENT (hadjustment)' failed
(17-scrolled-window-with-textview.p6:8210): Gtk-CRITICAL *
: gtk_scrolled_window_set_policy: assertion 'GTK_IS_SCROLLED_WINDOW (scrolled_window)' failed
(17-scrolled-window-with-textview.p6:8210): Gtk-CRITICAL *: gtk_container_add: assertion 'GTK_IS_CONTAINER (container)' failed
(17-scrolled-window-with-textview.p6:8210): Gtk-CRITICAL *
: gtk_box_pack: assertion 'GTK_IS_WIDGET (child)' failed
(17-scrolled-window-with-textview.p6:8210): Gtk-CRITICAL **: gtk_widget_show: assertion 'GTK_IS_WIDGET (widget)' failed

cannot install with panda won't compile

panda install GTK::Simple
==> Fetching GTK::Simple
==> Building GTK::Simple
==> Testing GTK::Simple
===SORRY!=== Error while compiling /home/grizzlysmit/.panda-work/1455681681_1/Build.pm
Redeclaration of symbol Build
at /home/grizzlysmit/.panda-work/1455681681_1/Build.pm:10

turning off supply

method g-timeout in GTK::Simple::App (line 53) is incomplete. I have a workaround below.

I successfully used g-timeout to end an app. But the supply cannot be turned off, so it cannot be used again. The problem is in the definition of g-timeout at line 68 in G:S:App.pm. It creates a callback function which always returns 1. In the definition of gtk_timeout_add, the function will always be called until it returns 0. Consequently, the thread is never ended.
eg: in the snippet below the first call to show_text works and lasts 5 seconds. But the second one only lasts some period under a second. The reason is that the supply created is never turned off, even though a specific call to gtk_main_quit is called in the App.exit method. That means that the tap function is not reinstantiated, so the state variable i is not reset. (I think)
use GTK::Simple;
show_text("Here",5); show_text("There",10);

sub show_text( Str $str, $time ) {
my $a = GTK::Simple::App.new();
$a.set-content(my $inf = GTK::Simple::Label.new(:text($str)));
my $sup = $a.g-timeout(1000);
$sup.tap( {
state $i = $time-1;
$inf.text = $str ~ $i;
$a.exit if ($i <= 0);
$i--;
} );
$a.run;
}

I have a work around by creating a global $continue and replacing the return value with $continue, that is copying the method into my program and making it a sub.
my $continue;
=comment
code as before to

my $sup = g-timeout(1000);
$sup.tap( {
state $i = $time-1;
$inf.text = $str ~ $i;
if ($i <= 0) { $a.exit ; $continue = 0; }
$i--;
} );
...
}
use nqp;
use NativeCall;
use GTK::Simple::Raw :DEFAULT;
sub g-timeout(Cool $usecs) {
my $s = Supplier.new;
my $starttime = nqp::time_n();
my $lasttime = nqp::time_n();
g_timeout_add($usecs.Int,
sub (*@) {
my $dt = nqp::time_n() - $lasttime;
$lasttime = nqp::time_n();
$s.emit((nqp::time_n() - $starttime, $dt));
return $continue;
}, OpaquePointer);
return $s.Supply;
}

However, I didn't want to hack the GTK::Simple::App code since I thought you might have a better way of doing this. For example, coding it into a done method on the Supplier. But I don't quite know enough about Suppliers.

Can't install new version at all.

I reinstalled perl6 from scratch, but still panda could not install. See below

Rakudo Star has been built and installed successfully.
Please make sure that the following directories are in PATH:
/home/richard/perl6/rakudo-star-2016.04/install/bin
/home/richard/perl6/rakudo-star-2016.04/install/share/perl6/site/bin

richard@ged:~/perl6/rakudo-star-2016.04$ perl6
To exit type 'exit' or '^D'

richard@ged:~/perl6/rakudo-star-2016.04$ panda install GTK::Simple
==> Fetching GTK::Simple
==> Building GTK::Simple
Found system gtk library.
==> Testing GTK::Simple
t/01-sanity.t .. ok
All tests successful.
Files=1, Tests=3, 45 wallclock secs ( 0.02 usr 0.00 sys + 42.97 cusr 1.36 csys = 44.35 CPU)
Result: PASS
==> Installing GTK::Simple
===SORRY!===
Could not find GTK::Simple::Common at line 9 in:
/home/richard/perl6/rakudo-star-2016.04
/home/richard/.perl6
/home/richard/perl6/rakudo-star-2016.04/install/share/perl6/site
/home/richard/perl6/rakudo-star-2016.04/install/share/perl6/vendor
/home/richard/perl6/rakudo-star-2016.04/install/share/perl6
CompUnit::Repository::AbsolutePath<79615456>
CompUnit::Repository::NQP<70959264>
CompUnit::Repository::Perl5<70959144>
CompUnit::Repository::AbsolutePath<79615312>
CompUnit::Repository::NQP<70959184>
CompUnit::Repository::Perl5<70959224>

in block at sources/85367160D11E565B2D089507C79BC309215430D6 (Panda::Installer) line 61
in sub indir at sources/24811C576EF8F85E7672B26955C802BB2FC94675 (Panda::Common) line 20
in method install at sources/85367160D11E565B2D089507C79BC309215430D6 (Panda::Installer) line 42
in method install at /home/richard/perl6/rakudo-star-2016.04/install/share/perl6/site/sources/582CB7486602954A4601BDCE5A0EAC54B05DA58A (Panda) line 161
in method resolve at /home/richard/perl6/rakudo-star-2016.04/install/share/perl6/site/sources/582CB7486602954A4601BDCE5A0EAC54B05DA58A (Panda) line 234
in sub MAIN at /home/richard/.bin/panda line 18
in block at /home/richard/.bin/panda line 152

TextView / Scroll Example doesn't work

The TextView in an ScrolledWindow exmaple fails. It would appear that TestViews can't be editted within the code giving an error of "Cannot modify an immutable Str ()"

Refactor widget properties

The design decision to make the gtk widget properties r/w accessors using Proxy is sound, however it results in a lot of very similar boilerplate which at best makes implementing all the properties rather tedious, but is also a maintenance and testing issue.

I'd like to re-implement the properties with a trait such as gtk-property which provides the implementation of the properties in a very similar way to AccessorFacade does (just adjusted to take into account the structure of the widget classes.)

I'd say this was relatively high priority as it would be better to do before implementing too many more properties and/or widgets.

Start versioning this module

This would let the snake-case stuff stay in a pre-1.0 version (or something else though 1.0 would follow semantic versioning)

GTK::Simple failing in Travis build

The failure seems to have started after my latest additions were committed by Jonathan, but the failure logs point to the TextView widget (I think), and do not seem to be related to my changes.

Also the failure reported on the Perl6 users list is during the Build process on Windows. I run Ubuntu, and I didn't have a problem building the latest version.

I'd like to help resolve this, but I don't actually know where to start.

01_hello_world.pm6 fails to work as expected

When the "Hello World!" button is clicked it becomes inactive and the "Goodbye!" button becomes active. When the "Goodbye!" button is clicked. Exploring a bit deeper it appears that $second.clicked.tap() code is never executed, instead the $button.clicked.tap() code is run whenever either button is clicked.

diff --git a/examples/01_hello_world.pm6 b/examples/01_hello_world.pm6
index 8e9493a..548bc54 100644
--- a/examples/01_hello_world.pm6
+++ b/examples/01_hello_world.pm6
@@ -41,7 +41,7 @@ $app.border_width = 20;
 =comment
     Using the sensitive property we can make a button unclickable.

-$second.sensitive = False;
+#$second.sensitive = False;


 =begin comment
@@ -53,13 +53,13 @@ $second.sensitive = False;
     just C<.sensitive = 0>. The C<$second> button can then be activated.
 =end comment

-$button.clicked.tap({ .sensitive = False; $second.sensitive = True });
+$button.clicked.tap({ .sensitive = False; $second.sensitive = True; say "first button tap"; });


 =comment
     Clicking the second button shall C<exit> the application's main loop.

-$second.clicked.tap({ $app.exit; });
+$second.clicked.tap({ say "second button tap"; $app.exit; });


 =comment

With these changes, the "Goodbye!" button is active, yet when clicked I see 'first button tap' output and "Hello World!" button disabled.

I've tried with JVM/Moar backends on Rakudo Star 2014.04 and Rakudo (not Star) 2014.05 with the same results.

I assume this example worked at some point in the past. Sadly my Perl6 skills are not yet sufficient to dig much further.

depends on MIME::Base64 which fails to install

==> GTK::Simple depends on LWP::Simple
URI provides the requested URI::Escape
==> LWP::Simple depends on MIME::Base64
==> Fetching MIME::Base64
==> Building MIME::Base64
==> Testing MIME::Base64
This type does not support elems
  in any  at gen/moar/m-Metamodel.nqp line 1723
  in method decode at /path/to/.panda-work/1457223946_1/lib/MIME/Base64/Perl.pm6 line 103
  in method decode-str at /path/to/.panda-work/1457223946_1/lib/MIME/Base64.pm6 line 10
  in method decode_base64 at /path/to/.panda-work/1457223946_1/lib/MIME/Base64.pm6 line 19
  in block <unit> at t/basic.t line 14

# Looks like you planned 18 tests, but ran 1
t/basic.t ................. 
Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 17/18 subtests 
t/binary-and-long-line.t .. ok
t/oneline.t ............... ok
This type does not support elems
  in any  at gen/moar/m-Metamodel.nqp line 1723
  in method decode at /path/to/.panda-work/1457223946_1/lib/MIME/Base64/Perl.pm6 line 103
  in method decode-str at /path/to/.panda-work/1457223946_1/lib/MIME/Base64.pm6 line 10
  in block <unit> at t/rfc4648-test-vector.t line 23

# Looks like you planned 16 tests, but ran 7
t/rfc4648-test-vector.t ... 
Dubious, test returned 255 (wstat 65280, 0xff00)
Failed 9/16 subtests 

Test Summary Report
-------------------
t/basic.t               (Wstat: 65280 Tests: 1 Failed: 0)
  Non-zero exit status: 255
  Parse errors: Bad plan.  You planned 18 tests but ran 1.
t/rfc4648-test-vector.t (Wstat: 65280 Tests: 7 Failed: 0)
  Non-zero exit status: 255
  Parse errors: Bad plan.  You planned 16 tests but ran 7.
Files=4, Tests=21,  4 wallclock secs ( 0.02 usr  0.00 sys +  3.39 cusr  0.20 csys =  3.61 CPU)
Result: FAIL
The spawned process exited unsuccessfully (exit code: 1)
  in sub run-and-gather-output at /home/david/.rakudobrew/moar-nom/install/share/perl6/site/sources/DAD29535955E677E319FDF0ACA9A926766180A75 line 85
  in block  at /home/david/.rakudobrew/moar-nom/install/share/perl6/site/sources/1DCE07CA986A927E98F9EEDC8B5DF87C995E3619 line 22
  in sub indir at /home/david/.rakudobrew/moar-nom/install/share/perl6/site/sources/DAD29535955E677E319FDF0ACA9A926766180A75 line 20
  in method test at /home/david/.rakudobrew/moar-nom/install/share/perl6/site/sources/1DCE07CA986A927E98F9EEDC8B5DF87C995E3619 line 5
  in method install at /home/david/.rakudobrew/moar-nom/install/share/perl6/site/sources/5538417AF9CC9DF68B79F613F1F4897C2AEC2F05 line 156
  in block  at /home/david/.rakudobrew/moar-nom/install/share/perl6/site/sources/5538417AF9CC9DF68B79F613F1F4897C2AEC2F05 line 229
  in method resolve at /home/david/.rakudobrew/moar-nom/install/share/perl6/site/sources/5538417AF9CC9DF68B79F613F1F4897C2AEC2F05 line 223
  in sub MAIN at /home/david/.rakudobrew/moar-nom/install/share/perl6/site/resources/76CD539C815A33F2891D2EF3D6D96B1081567AD1 line 18
  in block <unit> at /home/david/.rakudobrew/moar-nom/install/share/perl6/site/resources/76CD539C815A33F2891D2EF3D6D96B1081567AD1 line 150

GObject Introspection?

I was wondering if anyone who's worked on this module has much knowledge of GIR/GObject Introspection and how easy/hard it might be to wire it up to NativeCall in a similar way to GPTrixie?

I'm mostly asking because Apache Arrow is also another project using GObject to define all of the low level memory map of its data structures. I was thinking about making a DataFrame type library for Perl 6 to go in the Stats module, and noticed there is a bit of a push towards dealing with a unified memory model for interop. Could bind the C implementation directly but there is a short cut via GObject Introspection that the Ruby binding uses that might be worth doing instead. Especially if its also useful for creating a more complete GTK+ binding at the same time?

Does anyone have any input on the feasibility of this? Or know anything about GIR/GObject Introspection already?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.