Re: DSFML linking fails

2018-12-24 Thread number via Digitalmars-d-learn

On Monday, 24 December 2018 at 10:08:25 UTC, Dmitriy wrote:

Hello.

I'm using https://github.com/Jebbs/DSFML library

...

The problem when I build my project using these libraries. The 
problem in linking:




Did you look at http://dsfml.com/docs/firstprogram.html ?

I remember having to link also the dsfmlc-.. libraries.


Re: Another Tuesday (Friday?), Another GtkDcoding Blog Post

2019-03-21 Thread number via Digitalmars-d-learn

On Tuesday, 12 March 2019 at 14:44:59 UTC, Ron Tarrant wrote:

another post on the gtkDcoding blog.


0010 says

Here’s the code file.
Here’s a second code file for you.


but no links. I guess it's
https://github.com/rontarrant/gtkDcoding/blob/master/003_box/box_003_03_checkbutton.d
and
https://github.com/rontarrant/gtkDcoding/blob/master/003_box/box_003_04_togglebutton.d



Re: Another Tuesday (Friday?), Another GtkDcoding Blog Post

2019-03-22 Thread number via Digitalmars-d-learn

On Tuesday, 12 March 2019 at 14:44:59 UTC, Ron Tarrant wrote:

another post on the gtkDcoding blog.


0013 says

... with *setTooltipText()*.

Maybe a formatting error?

Thanks again for the Blog.
FYI: I also had dropped a note in some of the previous gtkdcoding 
forum threads


Re: Another Tuesday (Friday?), Another GtkDcoding Blog Post

2019-03-22 Thread number via Digitalmars-d-learn

On Friday, 22 March 2019 at 11:19:56 UTC, Ron Tarrant wrote:
Hmm... I'm not sure why the links didn't show up for you. I 
just double-checked and they're in the .md file and version of 
the file has been in place for at least 10 days.


Still, no harm in having them on this forum as well.

Thanks for taking an interest.


Not sure about .md or file version, but there are no links in the 
actual blog post:

http://gtkdcoding.com/2019/02/15/0010-checkbutton.html
and apparently also not in in this .md file:
https://raw.githubusercontent.com/rontarrant/gtkDcoding/master/docs/_posts/2019-02-15-0010-checkbutton.md



Re: Another Tuesday (Friday?), Another GtkDcoding Blog Post

2019-03-22 Thread number via Digitalmars-d-learn

On Tuesday, 12 March 2019 at 14:44:59 UTC, Ron Tarrant wrote:




As a side note, in 0004 you say:
We can still call the constructor, even though strictly 
speaking it’s private, because by using ‘new MyButton()’ the 
constructor isn’t being called directly, but as part of a 
lower-level process for instantiating the object.


I'm still new to D too, but I think it works in this scenario 
because private in D works on the module/file level. 
main/TestRigWindow/MyButton are defined in the same file (module) 
and thus can access each others private members. If you put the 
button class in its own file/module and import it then you would 
have to make its constructor public to access it.


button_002_04_oop_arg.d(22): Error: class 
`button_002_04_oop_arg_2.MyButton` member this is not accessible




Re: Another Tuesday (Friday?), Another GtkDcoding Blog Post

2019-03-22 Thread number via Digitalmars-d-learn

On Tuesday, 19 March 2019 at 12:33:08 UTC, Ron Tarrant wrote:
Tuesday again. This blog post is about invisible Entry widgets 
and the FontButton. Really stimulating stuff and you'll find it 
at: 
http://gtkdcoding.com/2019/03/19/0019-disappearing-text-entry.html


A little copy/paste glitch..
code (on blog and on github) says 'text entry box' where a 
FontButton is used:



writeln("The text entry box holds: ", fontButton.getFontName());





Re: Another Tuesday (Friday?), Another GtkDcoding Blog Post

2019-03-23 Thread number via Digitalmars-d-learn

On Friday, 22 March 2019 at 23:34:08 UTC, Ron Tarrant wrote:

It's fixed now.



The first one :), now there's still the other one "Here’s a 
second code file for you."


design question, gtkd object interdependence

2019-03-25 Thread number via Digitalmars-d-learn
I have a design question about (i guess) object interdependence 
using gtkd.


There is an application class which sets its property mAppWin. 
The app is passed as an argument to the window constructor. 
During the window constructor a scale (trackbar) is created which 
also receives and stores an app reference to later update other 
elements during an onChange event. The scale can access 
mApp.mSomeData to set its initial value because app has been 
passed down. The call to setValue() now triggers onValueChanged() 
which wants to access the mAppWin property of the app to update a 
canvas. Since all this happens during the initial 'new AppWin()' 
call in App, the app's mAppWin property is not set yet, so 
onValueChanged() will crash.




class App : Application
{
AppWin mAppWin;

void onActivate(GioApplication gioApp)
{
mSomeData = 123;

mAppWin = new AppWin(app, [...]);



class AppWin : ApplicationWindow
{
Scale1 mScale1;

this(Application application, [...])
{
		mScale1 = new Scale1(0, 100, 1, app);   // (app is application 
casted)




class Scale1 : VScale
{
App mApp;

this([...], App app)
{
[...]
mApp = app;
[...]
setValue(max * mApp.mSomeData);
}

void onValueChanged(Range range)
{
//if (mApp.mAppWin)
mApp.mAppWin.mCanvas.update();   // mAppWin not set 
yet, 0



I have several question in mind:
- Is it a bad idea to pass an app around that contains everything 
for everywhere?
- Should the app pass the data for the initial scale value 
through the window constructor? Or should it set the scale value 
after initialization is done?
- How would the scale update the canvas without keeping/walking 
through a DOM like this. Maybe some asynchronous messaging?


While I could make it work, I wonder what the actual problem is 
and what it's called like.




Re: Another Tuesday (Friday?), Another GtkDcoding Blog Post

2019-03-26 Thread number via Digitalmars-d-learn

On Sunday, 24 March 2019 at 19:20:47 UTC, Ron Tarrant wrote:
Sunday Blog eXtra: Installing and Using a Linux Build 
Environment


URL: 
http://gtkdcoding.com/2019/03/24/x0002-gtkd-in-a-linux-environment.html


Thanks for the new posts.

Link dead? It's also not listed on the blog post list. But I have 
read it some days before, and what I noticed is that you used the 
sources from ~/.dub/packages/gtk-d-...
I suspect you played with dub + gtkd by that time because I think 
they wouldn't be there otherwise. So if you use dmd in the 
example you might want to better use /usr/include/dmd/gtkd3/ 
(after installing gtkd).


I installed gtkd recently like shown here
https://github.com/gtkd-developers/GtkD/wiki
and here
https://d-apt.sourceforge.io/

which was basically this (-85 being my dmd version):

sudo wget 
https://netcologne.dl.sourceforge.net/project/d-apt/files/d-apt.list -O /etc/apt/sources.list.d/d-apt.list
sudo apt-get update --allow-insecure-repositories && sudo apt-get 
-y --allow-unauthenticated install --reinstall d-apt-keyring && 
sudo apt-get update

sudo apt install libgtkd3-85 libgtkd3-dev libgtkd3-doc

and I compile like this:
dmd -de -w -m64 -I/usr/include/dmd/gtkd3/ -L-lgtkd-3 -run 
label_008_02_markup.d


Not sure if you need the -m64 on x64 linux with a dmd64, should 
be the default then and works without.




Re: gtkDcoding Blog Post for 2019-03-29 - Grid

2019-03-30 Thread number via Digitalmars-d-learn

On Friday, 29 March 2019 at 14:25:16 UTC, Ron Tarrant wrote:
There's a new tutorial for using a GTK Grid. You can find it 
here: http://gtkdcoding.com/2019/03/29/0022-grids.html


Thanks!

The first link in the blog post to '..the last blog post' links 
to the 0022 article itself, not to a previous one.


BTW, it compiles fine without 'import gtk.c.types', too.
Main.d (and maybe others) contains a 'public  import gtk.c.types;'


Re: gtkDcoding Blog Post for 2019-03-29 - Grid

2019-04-02 Thread number via Digitalmars-d-learn

On Tuesday, 2 April 2019 at 11:31:39 UTC, Ron Tarrant wrote:
Today's the day for (yet) another blog post over on 
gtkDcoding.com and the subjects are:


- the RadioButton, and
- the ColorButton.

You can find it here:
 
http://gtkdcoding.com/2019/04/02/0023-radio-and-color-buttons.html


Thank you!

But if we want one of the others to be active on start-up, as 
well as syncing up the observed object, we have to call that 
button’s setActive(true) function. To simplify this two-step 
process, I broke it out into its own function, 
setActiveButton().


The function ignores its argument and always uses member variable 
button2 instead. Changing the parameter type to MyRadioButton and 
using 'button' instead of 'button2' in the body works, so you 
could pass another default in RadioBox.this().



Can somebody explain why getRgba() (apparently inherited from 
ColorChooser) does take an out parameter instead of returning an 
Gdk.RGBA?


Re: gtkDcoding Blog Post # 26 - Menu Basics

2019-04-12 Thread number via Digitalmars-d-learn

On Friday, 12 April 2019 at 09:05:11 UTC, Ron Tarrant wrote:
Today starts a series on GtkD menus. Over the next four weeks, 
we'll cover enough ground to get you up-n-running with most 
menu-related topics. And it all starts right here: 
http://gtkdcoding.com/2019/04/12/0026-menu-basics.html


Thanks, I'm still a reader!
Are you planning to cover messagebox-like stuff (i.e. gtkdialog.. 
i guess?)


Re: gtkDcoding Blog Post # 26 - Menu Basics

2019-04-13 Thread number via Digitalmars-d-learn

On Saturday, 13 April 2019 at 00:25:21 UTC, Ron Tarrant wrote:

On Friday, 12 April 2019 at 13:56:51 UTC, number wrote:

Are you planning to cover messagebox-like stuff (i.e. 
gtkdialog.. i guess?)


Yes. Right after this series on menus, I start on Dialogs. The 
first couple of those are already in the grist mill 
(HelpDialog, FileChooserDialog) giving that series five 
articles so far. But I'll put MessageDialog next on the list 
which means it'll be posted on May 31st.


I'm asking because there was discussion elsewhere on the net 
about another programming language where a [gtk] messagebox title 
was too long so the text could not be read completely because the 
messagebox sized itself to the shorter text in the content area. 
They said it's an OS limitation (meaning gtk standard dialogs). 
It also seems dialogs are not user-resizable by default, which 
seems strange to me. So I thought to roll my own dialog, but 
didn't get to it yet.
I also wonder why I often encounter gtk apps/windows that are 
unresizable, but still have the resize-icon cursor when hovering 
the bottom-right window edge, which when used moves the window 
instead.


Re: gtkDcoding Blog Post # 26 - Menu Basics

2019-04-14 Thread number via Digitalmars-d-learn

On Saturday, 13 April 2019 at 12:42:36 UTC, Ron Tarrant wrote:

On Saturday, 13 April 2019 at 09:49:47 UTC, number wrote:

On Saturday, 13 April 2019 at 00:25:21 UTC, Ron Tarrant wrote:
I'm asking because ... the messagebox sized itself to the 
shorter text in the content area. They said it's an OS 
limitation (meaning gtk standard dialogs).


Because the Dialog class inherits from Window, you can size it 
with setSizeRequest(). On Windows, at least. I'm not sure about 
Linux. I'm about to go out for a few hours, so perhaps you 
could test this.


Yes, this work on Linux, too.



It also seems dialogs are not user-resizable by default, which 
seems strange to me. So I thought to roll my own dialog, but 
didn't get to it yet.


That's another topic I have on my list for the dialog series.



Sorry, I was unclear. By rolling my own I meant to not use a 
predefined library function MessageRequester() that exists in 
that language, but instead using gtk dialog directly which would 
be more customizable. Anyway that would only be for learning 
purposes, nothing I desperately need.


I also wonder why I often encounter gtk apps/windows that are 
unresizable, but still have the resize-icon cursor when 
hovering the bottom-right window edge, which when used moves 
the window instead.


It's because there are two flags controlling resize-ability, 
both found in generated\gtkd\gdk\c\types.d:

- a window decorations flag (GdkWMDecoration), and
- another that controls whether or not the window is allowed to 
resize (GdkWMFunction).


If the programmer turns off the resize flag, but not the 
decorator flag, well... there's your answer.


Hope that helps, number.


Ok, I understand. But then it seems still strange that the window 
can be moved by dragging the edge if it's only a decoration that 
is active.


Thanks for your explanations.




Re: gtkDcoding Blog Post # 28 - Menu II - CheckMenuItem

2019-04-19 Thread number via Digitalmars-d-learn

On Friday, 19 April 2019 at 12:12:28 UTC, Ron Tarrant wrote:
Even though it's Good Friday, there's still a new blog post. As 
the thread title says, it's about using the CheckMenuItem, two 
examples this time.


You can find it here: 
http://gtkdcoding.com/2019/04/19/0028-checkmenuitems.html


Have a great long weekend, everyone!


Hi, thanks!
The function's closing comments (first code example) need some 
maintenance, 'exit' also in the code on the page itself:

```
} // exit()
...
} // keep()
...
} // toss()
```



Re: gtkDcoding Blog Post # 29 - RadioMenuItems

2019-04-23 Thread number via Digitalmars-d-learn

On Tuesday, 23 April 2019 at 09:44:12 UTC, Ron Tarrant wrote:
Now that we've got Easter out of the way, it's time for another 
gtkDcoding blog post: 
http://gtkdcoding.com/2019/04/23/0029-radiomenuitem.html


Hi, thanks!
little typo: RadioMeniItem


Re: gtkDcoding Blog Post # 29 - RadioMenuItems

2019-04-24 Thread number via Digitalmars-d-learn

On Tuesday, 23 April 2019 at 20:40:45 UTC, Ron Tarrant wrote:

On Tuesday, 23 April 2019 at 12:21:37 UTC, number wrote:


Hi, thanks!
little typo: RadioMeniItem


How about that? The typo was in the article, not the code. 
Makes for a change. :)


Thanks for catching, number.


Are your original php gtk tutorials still available somewhere? I 
found this 
(https://php.gtk.general.narkive.com/G1Fuuk38/php-gtk-treeview-toggle) but http://www.writingup.com/ does not respond.


Re: Retrieving Column Data from a ListStore?

2019-04-25 Thread number via Digitalmars-d-learn

On Wednesday, 24 April 2019 at 18:56:50 UTC, Ron Tarrant wrote:


For anyone else who comes along looking for the same answer, 
here's what I did:




I'm trying to do it with multi-selection. It works now but I 
wonder if it's right to just create a dummy TreeModelIF to call 
getSelectedRows()? Same question for creating a TreeIter to call 
getIter()?


```
import std.stdio;

import gtk.Main;
import gtk.MainWindow;
import gtk.TreeView;
import gtk.CellRendererText;
import gtk.TreeViewColumn;
import gtk.ListStore;
import gtk.TreeStore;
import gtk.TreeIter;
import gtk.TreeSelection;
import gtk.TreePath;

void main(string[] args)
{
Main.init(args);

MainWindow window = new MainWindow("title");
window.setSizeRequest(400, 200);

TreeView treeView = new TreeView();

CellRendererText cellRendererText;
TreeViewColumn treeViewColumn;

CellRendererText cellRendererTextA = new CellRendererText();
CellRendererText cellRendererTextB = new CellRendererText();
treeViewColumn = new TreeViewColumn();
treeViewColumn.setTitle("A and B");
treeViewColumn.packStart(cellRendererTextA, true);
treeViewColumn.packStart(cellRendererTextB, true);
treeViewColumn.addAttribute(cellRendererTextA, "text", 0);
treeViewColumn.addAttribute(cellRendererTextB, "text", 1);
treeView.appendColumn(treeViewColumn);

cellRendererText = new CellRendererText();
	treeViewColumn = new TreeViewColumn("C", cellRendererText, 
"text", 2);

treeView.appendColumn(treeViewColumn);

	//ListStore listStore = new ListStore([GType.STRING, 
GType.STRING, GType.STRING]);
	TreeStore treeStore = new TreeStore([GType.STRING, GType.STRING, 
GType.STRING]);

treeView.setModel(treeStore);

TreeIter treeIter;

treeIter = treeStore.createIter();
treeStore.setValue(treeIter, 0, "a");
treeStore.setValue(treeIter, 1, "b");
treeStore.setValue(treeIter, 2, "c");

treeIter = treeStore.createIter();
treeStore.setValue(treeIter, 0, "a2");
treeStore.setValue(treeIter, 1, "b2");
treeStore.setValue(treeIter, 2, "c2");

TreeSelection treeSelection = treeView.getSelection();
treeSelection.setMode(SelectionMode.MULTIPLE);
	treeSelection.addOnChanged(delegate void(TreeSelection 
treeSelection) {

writeln("");
if (treeSelection.getMode() == SelectionMode.MULTIPLE)
{
import gtk.TreeModelIF;
TreeModelIF tm;
//writeln(tm);
TreePath[] treePaths = 
treeSelection.getSelectedRows(tm);
writeln("nb selected: ", 
treeSelection.countSelectedRows());
if (treePaths.length)
{
foreach (i, treePath; treePaths)
{
writefln("path(%s) : %s", i, treePath);
TreeIter treeIter = new TreeIter();
treeStore.getIter(treeIter, treePath);
writefln("%s, %s, %s"
, 
treeStore.getValueString(treeIter, 0)
, 
treeStore.getValueString(treeIter, 1)
, 
treeStore.getValueString(treeIter, 2)
);
}
}
else
{
writeln("nothing");
}
}
else
{
TreeIter treeIter = treeSelection.getSelected();
if (treeIter)
{
writefln("%s, %s, %s"
, treeStore.getValueString(treeIter, 0)
, treeStore.getValueString(treeIter, 1)
, treeStore.getValueString(treeIter, 2)
);
}
else
{
writeln("nothing");
}
}
});

window.add(treeView);

window.showAll();
Main.run();
}

```


Re: GTK Scale/Volume Buttons Show Muted Icon on Startup

2019-04-25 Thread number via Digitalmars-d-learn

On Thursday, 25 April 2019 at 11:36:26 UTC, Ron Tarrant wrote:

When running this example of a VolumeButton, ...


When using `setValue(initialValue)` after `setAdjustment()` the 
scale seems have the correct value. If in addition the Adjustment 
is created with an initial value different from the 
`initialValue` used with `setValue()` then the icons are also 
correct on startup. Though I don't know why that is. The loading 
issue doesn't happen here (on linux).


Re: Retrieving Column Data from a ListStore?

2019-04-25 Thread number via Digitalmars-d-learn

On Thursday, 25 April 2019 at 15:16:03 UTC, Ron Tarrant wrote:

On Thursday, 25 April 2019 at 11:29:04 UTC, number wrote:

I'm trying to do it with multi-selection. It works now but I 
wonder if it's right to just create a dummy TreeModelIF to 
call getSelectedRows()? Same question for creating a TreeIter 
to call getIter()?


Whatever works, I guess. Just looking over what you've got, I 
don't really see anyway around creating the dummy for either 
one since they each have to be passed into functions.


I wasn't sure if it wants the actual tree model used with the 
tree view, but passing my treeStore didn't work, so I used a 
dummy. Don't know what it's for though.


Re: gtkDcoding Blog: Post #0030 - A More Practical RadioMenuItem Example

2019-04-27 Thread number via Digitalmars-d-learn

On Friday, 26 April 2019 at 11:14:23 UTC, Ron Tarrant wrote:
Once again it's Friday and a new blog post is up. And just a 
room at the Hotel California (any time of year) you can find it 
here: 
http://gtkdcoding.com/2019/04/26/0030-radiomenuitem-practical.html


There are links to the previous blog post and github code but 
there is no link to the github code for this one. It's probably 
this one:

https://github.com/rontarrant/gtkDcoding/blob/master/012_menus/menu_012_12_observed_radiomenuitems.d


srand time error uint/long

2019-04-29 Thread number via Digitalmars-d-learn

How to call srand() with time()?

```
void main()
{
import core.stdc.stdlib : rand, srand;
import core.stdc.time : time;
srand(time(null));
}
```

Error: function core.stdc.stdlib.srand(uint seed) is not callable 
using argument types (long)
cannot pass argument time(null) of type long to parameter uint 
seed


https://run.dlang.io/is/ner0Lx


And how to use the d libs instead? is this the way to go?

```
Random rnd = Random(Clock.currTime().second);
uniform01(rnd); //(or whatever)
```


Re: srand time error uint/long

2019-04-29 Thread number via Digitalmars-d-learn

On Monday, 29 April 2019 at 14:39:29 UTC, rikki cattermole wrote:

float f = uniform01();

Its already initialized on module load.

If you do want to custom seed it, you'll probably want to cast 
the seed to uint instead and have your own instance of the 
random number generator.


On Monday, 29 April 2019 at 15:24:41 UTC, Paul Backus wrote:

https://dlang.org/phobos/std_random.html#unpredictableSeed


Thanks!


Re: Blog Post #0033 - Faking an ImageMenuItem with an AccelKey

2019-05-07 Thread number via Digitalmars-d-learn

On Tuesday, 7 May 2019 at 09:39:55 UTC, Ron Tarrant wrote:
But the result is today's post: how to produce a MenuItem with 
an image AND and AccelKey.


Here's the link: 
http://gtkdcoding.com/2019/05/07/0033-fake_image_menu_and_accel.html


Thanks!

the github link links to file .._16_.. from 0032 instead of 
.._17_..



some end block comments need update:


class FileMenuHeader
...
} // class FileMenu



void reportStuff
} // exit()



void doSomething(MenuItem mi)
} // exit()




Re: Blog Post #0032 - Menu Accelerator Keys

2019-05-07 Thread number via Digitalmars-d-learn

On Friday, 3 May 2019 at 12:12:32 UTC, Ron Tarrant wrote:
An accelerating post for a rainy Friday (well, it's raining 
here, at least) all about menu accelerator keys. Here's the 
link: 
http://gtkdcoding.com/2019/05/03/0032-accelerator_keys.html


some end block comments need update:


class FileMenuHeader
} // class MenuHeader



class EditMenuHeader
} // class MenuHeader



void doSomething(MenuItem mi)
} // exit()

(above also on the blog page)


void doSomething(MenuItem mi)
} // doSomethingNew()



There is also 4 times a comment '// arg: ...' that doesn't make 
sense in that context.




Re: Blog Post #0032 - Menu Accelerator Keys

2019-05-08 Thread number via Digitalmars-d-learn

On Tuesday, 7 May 2019 at 17:41:42 UTC, Ron Tarrant wrote:
It always makes me happy when you point out the small stuff. It 
means I got the big stuff right. :)


I do feel a bit pedantic about it too :), on the other hand wrong 
comments are worse than no comments.


I guess you've been away a while? Or do you save up and read a 
bunch all at once?


not away, just reading it when i feel like it, yes.


dirEntries returns relative, not absolute paths

2018-02-06 Thread number via Digitalmars-d-learn

https://dlang.org/phobos/std_file.html#dirEntries
The name of each iterated directory entry contains the 
absolute path.


it seems to be absolute only if the specified path is absolute, 
or always relative to the parent dir of the specified path.


import std.stdio;import std.stdio;

void main()
{
import std.file;
import std.path;

assert(!"dir".exists);
scope(exit) if ("dir".exists) rmdirRecurse("dir");
mkdirRecurse("dir/dir1/dir2/dir3");

writeln("-");
foreach (DirEntry e; dirEntries("dir", SpanMode.breadth))
{
writeln("e: " ~ e);
}

writeln("-");
	foreach (DirEntry e; dirEntries("../" ~ getcwd.baseName ~ 
"/dir", SpanMode.breadth))

{
writeln("e: " ~ e);
}

writeln("-");
	foreach (DirEntry e; dirEntries(getcwd ~ "/dir", 
SpanMode.breadth))

{
writeln("e: " ~ e);
}

//  -
//  e: dir/dir1
//  e: dir/dir1/dir2
//  e: dir/dir1/dir2/dir3
//  -
//  e: ../dTests/dir/dir1
//  e: ../dTests/dir/dir1/dir2
//  e: ../dTests/dir/dir1/dir2/dir3
//  -
//  e: /home/user/dTests/dir/dir1
//  e: /home/user/dTests/dir/dir1/dir2
//  e: /home/user/dTests/dir/dir1/dir2/dir3
}



unable to fork: Cannot allocate memory / core.checkedint / gtkd

2018-02-11 Thread number via Digitalmars-d-learn

I get dmd ouput:
"unable to fork: Cannot allocate memory"

when compiling the following code:


import std.stdio;

import gio.Application : GioApplication = Application;
import gtk.Application;
import gtk.ApplicationWindow;
import gtk.Widget;
import gdk.Keysyms;

int main(string[] args)
{
Application application;

bool onKeyPress(GdkEventKey* eventKey, Widget widget)
{
writeln(GdkKeysyms.GDK_Escape);
return false;
}

void activate(GioApplication app)
{
ApplicationWindow win = new ApplicationWindow(application);
win.addOnKeyPress(&onKeyPress);
win.showAll();
}

	application = new Application("org.gtkd.demo.cairo.clock", 
GApplicationFlags.FLAGS_NONE);

application.addOnActivate(&activate);
return application.run(args);
}


with this commandline..
dmd -v -L-lgtkd-3 -run test2.d

..it hangs for a some seconds at..
import
core.checkedint	(/usr/include/dmd/druntime/import/core/checkedint.d)


..while memory usage grows up to 100%, then continues with other 
imports..

code  test2
function  D main
function  test2.main.onKeyPress
function  test2.main.activate
function  std.stdio.writeln!(GdkKeysyms).writeln
function  std.stdio.File.write!(GdkKeysyms, char).write
function  std.format.formattedWrite!(LockingTextWriter, char, 
GdkKeysyms).formattedWrite

...

then finally..
cc test2.o -o /tmp/dmd_run6k9PhI -m64 -L/usr/lib/x86_64-linux-gnu 
-Xlinker --export-dynamic -Xlinker -Bstatic -lphobos2 -Xlinker 
-Bdynamic -lpthread -lm -lrt -ldl

unable to fork: Cannot allocate memory

if i comment-out the line..
writeln(GdkKeysyms.GDK_Escape);

then it compiles/links/runs fine.


I actually want to close the application if escape key is pressed 
with

if (eventKey.keyval == GdkKeysyms.GDK_Escape) ...

but i don't know if my imports and the event handler are correct, 
and i dont know how to close the application yet.

I guess there is something wrong during the compilation process?


DMD64 D Compiler v2.078.1

gtkd import path is in /etc/dmd.conf:
...
[Environment64]
DFLAGS=-I/usr/include/dmd/phobos 
-I/usr/include/dmd/druntime/import -I/usr/include/dmd/gtkd3 
-L-L/usr/lib/x86_64-linux-gnu -L--export-dynamic -fPIC

...



Re: unable to fork: Cannot allocate memory / core.checkedint / gtkd

2018-02-11 Thread number via Digitalmars-d-learn

On Sunday, 11 February 2018 at 13:17:13 UTC, number wrote:

unable to fork: Cannot allocate memory

if i comment-out the line..
writeln(GdkKeysyms.GDK_Escape);

then it compiles/links/runs fine.

[...]

I actually want to close the application if escape key is 
pressed with

if (eventKey.keyval == GdkKeysyms.GDK_Escape) ...



Some gtkd demo used core.stdc.stdlib.exit to quit the application.
I use widget.destroy now, seems to work fine.

About the compilation error with writeln(), its not a problem 
anymore for me right now. Don't know if this is a [known] issue 
or what the cause is.






Re: unable to fork: Cannot allocate memory / core.checkedint / gtkd

2018-02-13 Thread number via Digitalmars-d-learn

On Sunday, 11 February 2018 at 15:05:26 UTC, number wrote:

On Sunday, 11 February 2018 at 13:17:13 UTC, number wrote:

unable to fork: Cannot allocate memory

if i comment-out the line..
writeln(GdkKeysyms.GDK_Escape);

then it compiles/links/runs fine.




I just tried again.
compiling the following code eats up my 4GB of RAM and fails. 
Please copy the enumeration
from: 
https://github.com/gtkd-developers/GtkD/blob/master/generated/gtkd/gdk/Keysyms.d

into the code.


import std.stdio;

void main()
{
writeln(GdkKeysyms.GDK_Escape);
}

public enum GdkKeysyms
{
...
}


Reducing the number of enum entries step by step finally will 
make the compilation succeed. Is it normal that it needs so much 
memory?


Re: unable to fork: Cannot allocate memory / core.checkedint / gtkd

2018-02-13 Thread number via Digitalmars-d-learn

On Tuesday, 13 February 2018 at 12:32:58 UTC, Stefan Koch wrote:

On Tuesday, 13 February 2018 at 12:17:31 UTC, number wrote:



I just tried again.
compiling the following code eats up my 4GB of RAM and fails. 
Please copy the enumeration
from: 
https://github.com/gtkd-developers/GtkD/blob/master/generated/gtkd/gdk/Keysyms.d

into the code.


import std.stdio;

void main()
{
writeln(GdkKeysyms.GDK_Escape);
}

public enum GdkKeysyms
{
...
}


Reducing the number of enum entries step by step finally will 
make the compilation succeed. Is it normal that it needs so 
much memory?


Yes unfortunately std.conv approaches the problem of printing 
enums with recursive templates  , which eat a ton of memory.


Ok, thanks for the info. I guess I'll just use printf then for 
larger enums.


Re: unable to fork: Cannot allocate memory / core.checkedint / gtkd

2018-02-14 Thread number via Digitalmars-d-learn

On Tuesday, 13 February 2018 at 21:46:31 UTC, Stefan Koch wrote:

On Tuesday, 13 February 2018 at 14:10:44 UTC, number wrote:
Ok, thanks for the info. I guess I'll just use printf then for 
larger enums.


To get the same convince you can use.
the enumToString from:

https://forum.dlang.org/post/pnggoabnnkojdonyz...@forum.dlang.org

and writeln the result oft that.
however it'll cause an error if there are two enum memebrs with 
the same value.


Thanks!


Re: Need example of usage DerelictPQ

2018-03-21 Thread number via Digitalmars-d-learn

On Wednesday, 24 December 2014 at 11:56:40 UTC, Suliman wrote:
Could anybody provide any simple examples of usage DerelictPQ. 
I do not have experience of C, and I can't understand how to 
use this driver.


I need just basics like connect, select and insert.

http://code.dlang.org/packages/derelict-pq

thanks!



A bit late, but maybe useful for others, and googling 'dlang 
derelict postgres example' brings you here..


The default ubuntu (16.04) postgres version caused runtime errors 
for me (DerelictPQ.load()), what worked was installation from 
here:

https://www.postgresql.org/download/linux/ubuntu/

the example expects a postgres user/role 'sammy' with password 
'sammypw' and a database 'sammy' with a table as shown in 
comments and set up as here:

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-postgresql-on-ubuntu-16-04

if you don't specify a host at PQconnectdb() then you might get 
an error

'Peer authentication failed for user "sammy"'
when you run the binary as a OS user different from 'sammy', or 
you would have to run the program as the postgres user like

sudo -iu sammy /path/to/prog

 dub.json
{
"name": "prog",
"targetType": "executable",
"sourceFiles": [ "prog.d" ],
"dependencies": {
"derelict-pq": "~>2.2.0"
}
}

 prog.d
import core.stdc.stdlib;
import std.stdio;
import std.conv;
import derelict.pq.pq;

/*
CREATE TABLE playground (
equip_id serial PRIMARY KEY,
type varchar (50) NOT NULL,
color varchar (25) NOT NULL,
	location varchar(25) check (location in ('north', 'south', 
'west', 'east', 'northeast', 'southeast', 'southwest', 
'northwest')),

install_date date
);

	INSERT INTO playground (type, color, location, install_date) 
VALUES ('slide', 'blue', 'south', '2014-04-28');
	INSERT INTO playground (type, color, location, install_date) 
VALUES ('swing', 'yellow', 'northwest', '2010-08-16');


 */

int main(string[] args)
{
int retval = EXIT_SUCCESS;

DerelictPQ.load();

	PGconn* conn = PQconnectdb("user = 'sammy' password = 'sammypw' 
dbname = 'sammy' host = '127.0.0.1'");

if (PQstatus(conn) != CONNECTION_OK)
{
		writefln("ERROR (connection): %s", 
to!string(PQerrorMessage(conn)));

retval = EXIT_FAILURE;
}
else
{
writeln("OK (connection)");

PGresult* result = PQexec(conn, "select * from playground");
if (PQresultStatus(result) != PGRES_TUPLES_OK)
{
			writefln("ERROR (result): %s", 
to!string(PQerrorMessage(conn)));

retval = EXIT_FAILURE;

}
else
{
writeln("OK (result)");

int nbFields = PQnfields(result);
writeln("nbFields: ", nbFields);

int nbRows = PQntuples(result);
writeln("nbRows: ", nbRows);

for (int f; f < nbFields; f++)
{
writef("%16s", to!string(PQfname(result, f)));
}
writeln("");

for (int r; r < nbRows; r++)
{
for (int f; f < nbFields; f++)
{
ubyte* ub = 
cast(ubyte*)(PQgetvalue(result, r, f));
int len = PQgetlength(result, r, f);
char[] c = cast(char[])ub[0..len];
string s = to!string(c);
writef("%16s", s);
}
writeln("");
}
}
PQclear(result);
}
PQfinish(conn);

return retval;
}



If someone has a better way to convert the PQgetvalue() to 
string, i'm interested :)

The functions are as follows:
alias da_PQgetvalue = const(ubyte)* 
function(const(PGresult)*,int,int);

alias da_PQgetlength = int function(const(PGresult)*,int,int);

have a nice day


get classname in static member

2018-03-28 Thread number via Digitalmars-d-learn
Is there a way to get the classname without specifying the class 
in the first place as required by classinfo and 
fullyQualifiedName? extracting it from __FUNCTION__ wouldn't work 
outside a function, i.e. for a classfield, and 'this' doesn't 
work in static members.


It's just about simple debugging like 'writeln(, ": 
message: ..")' ..and learning.


And could somebody explain to me why 'typeid(this).stringof' is 
returning 'typeid(this)'?

I'm using dmd v2.078.3

```
import std.stdio;

void main() {

class C
{
static void foo()
{
writeln(__FUNCTION__);  // test.main.C.foo
writeln(C.classinfo);   // test.main.C
import std.traits;  //
writeln(fullyQualifiedName!C);  // test.main.C
}

void fuu()
{
writeln(this);  // test.main.C
writeln(typeid(this));  // test.main.C
writeln(typeid(this).stringof); // typeid(this)
writeln(this.classinfo);// test.main.C
}
}

C.foo();
writeln();
C c = new C();
c.fuu;
}   
```


Re: get classname in static member

2018-03-28 Thread number via Digitalmars-d-learn

On Wednesday, 28 March 2018 at 10:10:19 UTC, Simen Kjærås wrote:
So to get the class name you'd generally use 
typeof(this).stringof.


...

And could somebody explain to me why 'typeid(this).stringof' 
is returning 'typeid(this)'?


Because that's what you're asking for. :p

typeid returns the run-time (also called dynamic) type of a 
class instance. stringof is a compile-time construct that 
resolves to a compile-time constant string representation of 
its argument. If that argument is a type, it gives the name of 
the type. If it's an expression (such as 1+2, foo(), or 
typeid(this)), it gives a string representation of the 
expression. For typeid(this), that's "typeid(this)".


If you want to know the dynamic type of a class reference at 
run-time, such as in fuu(), you'd need to write 
writeln(typeid(this)).


--
  Simen


On Wednesday, 28 March 2018 at 10:12:34 UTC, bauss wrote:

On Wednesday, 28 March 2018 at 09:44:35 UTC, number wrote:
And could somebody explain to me why 'typeid(this).stringof' 
is returning 'typeid(this)'?


stringof will return a string equivalent to the expression or 
symbol's representation, not its definition.


Meaning:

(212 + 221).stringof == "212 + 221"

(new Foo).stringof == "new Foo"

etc.


Thank you for the explanations. I somehow forgot about typeof 
though i must have seen it a lot in 'Ali Cehreli's Book.




toString contains null for struct with function/method

2018-04-08 Thread number via Digitalmars-d-learn
the write() shows a 'null' if the struct has a function/method. 
why is that?

```
import std.stdio;

void main()
{
struct S
{
int i;
}
S s;
writeln(s);// S(0)
writeln(typeid(s).sizeof); // 8

struct S2
{
int i;
this(this){}
}
S2 s2;
import std.conv: to;
writeln(s2);// S2(0, null)
writeln(typeid(s2).sizeof); // 8
}
```


Re: toString contains null for struct with function/method

2018-04-09 Thread number via Digitalmars-d-learn

On Sunday, 8 April 2018 at 15:51:05 UTC, Paul Backus wrote:

On Sunday, 8 April 2018 at 15:04:49 UTC, number wrote:

writeln(s2);// S2(0, null)


S2 is a nested struct [1], which means it has a hidden pointer 
field that's used to access its enclosing scope. If you change 
the definition to `static struct S2`, you'll get the same 
output for both structs.


[1] https://dlang.org/spec/struct.html#nested


Aha, its the nesting. And if i access the outer scope in the 
function its not null anymore.

Thank you!