Re: GTKD - CSS class color "flash" delay

2016-06-26 Thread TheDGuy via Digitalmars-d-learn

On Sunday, 26 June 2016 at 16:29:52 UTC, Mike Wey wrote:


How about this:

private void letButtonsFlash(){
foreach(Button btn;bArr){
btn.setSensitive(false);
}
for(int i = 0; i < level; i++){
Button currentButton = bArr[rndButtonBlink[i]];
ListG list = 
currentButton.getStyleContext().listClasses();
string CSSClassName = 
to!string(cast(char*)list.next().data);
currentButton.getStyleContext().addClass(CSSClassName ~ 
"-flash");

}
Timeout t = new Timeout(&timeout_delay,1,false);
}

bool timeout_delay(){
for(int i = 0; i < level; i++){
Button currentButton = bArr[rndButtonBlink[i]];
ListG list = 
currentButton.getStyleContext().listClasses();
string CSSClassName = 
to!string(cast(char*)list.next().data);

currentButton.getStyleContext().removeClass(CSSClassName ~ 
"-flash");

}
foreach(Button btn;bArr){
btn.setSensitive(true);
}
return false;
}

Sets all the buttons to the flash color and after an timeout 
removes the flash color from all the buttons.


Thanks for your answer,

but as i said before, i want to flash each button on it's own 
(the game is kinda like 'Simon Says').


Re: executeShell doesn't work but system does

2016-06-26 Thread cym13 via Digitalmars-d-learn

On Sunday, 26 June 2016 at 17:56:08 UTC, Satoshi wrote:

On Sunday, 26 June 2016 at 15:37:03 UTC, "Smoke" Adams wrote:
system("cls") works but executeShell doesn't. system is 
depreciated.


What's going on? The docs say that it creates a new process. I 
simply want to clear the console!



I have problem with executeShell on windows 10 (LDC 1.0.0) too.
When I rewrote it into http://prntscr.com/blc9j8 it works.


OT but please, refrain from using screenshots. I know it's very 
customary on windows but I can't copy paste code from a 
screenshot to play with it and manually copying is error-prone. 
We manipulate text, let's stay with it.


Re: executeShell doesn't work but system does

2016-06-26 Thread Satoshi via Digitalmars-d-learn

On Sunday, 26 June 2016 at 15:37:03 UTC, "Smoke" Adams wrote:
system("cls") works but executeShell doesn't. system is 
depreciated.


What's going on? The docs say that it creates a new process. I 
simply want to clear the console!



I have problem with executeShell on windows 10 (LDC 1.0.0) too.
When I rewrote it into http://prntscr.com/blc9j8 it works.


Re: GTKD - CSS class color "flash" delay

2016-06-26 Thread Mike Wey via Digitalmars-d-learn

On 06/26/2016 05:03 PM, TheDGuy wrote:

On Sunday, 26 June 2016 at 12:30:22 UTC, Mike Wey wrote:


You should probably increment the index in the timeout_delay function.


This leads to a Range violation exception...


How about this:

private void letButtonsFlash(){
foreach(Button btn;bArr){
btn.setSensitive(false);
}
for(int i = 0; i < level; i++){
Button currentButton = bArr[rndButtonBlink[i]];
ListG list = currentButton.getStyleContext().listClasses();
string CSSClassName = to!string(cast(char*)list.next().data);
currentButton.getStyleContext().addClass(CSSClassName ~ "-flash");
}
Timeout t = new Timeout(&timeout_delay,1,false);
}

bool timeout_delay(){
for(int i = 0; i < level; i++){
Button currentButton = bArr[rndButtonBlink[i]];
ListG list = currentButton.getStyleContext().listClasses();
string CSSClassName = to!string(cast(char*)list.next().data);
currentButton.getStyleContext().removeClass(CSSClassName ~ 
"-flash");

}
foreach(Button btn;bArr){
btn.setSensitive(true);
}
return false;
}

Sets all the buttons to the flash color and after an timeout removes the 
flash color from all the buttons.


--
Mike Wey


Re: executeShell doesn't work but system does

2016-06-26 Thread ag0aep6g via Digitalmars-d-learn

On 06/26/2016 05:37 PM, Smoke Adams wrote:

system("cls") works but executeShell doesn't. system is depreciated.


Unsolicited spelling correction: no 'i' in "deprecated".


What's going on? The docs say that it creates a new process. I simply
want to clear the console!


`system` directly prints its output, `executeShell` returns it in a 
tuple with the status code. Maybe cls works by printing some specific 
clear code. If so, you have to print the output of the command.


This works with `clear` on Linux which seems to behave similarly to 
Windows' cls:



void main()
{
import std.stdio: write, writeln;
import std.process: executeShell;
import std.exception: enforce;
writeln("A");
auto r = executeShell("clear");
enforce(r.status == 0);
write(r.output);
writeln("B");
}


`wait(spawnShell(...))` is the other suggestion from `system`'s 
deprecation message. It works for `clear`, too:



void main()
{
import std.stdio: writeln;
import std.process: spawnShell, wait;
writeln("A");
wait(spawnShell("clear"));
writeln("B");
}



executeShell doesn't work but system does

2016-06-26 Thread Smoke Adams via Digitalmars-d-learn
system("cls") works but executeShell doesn't. system is 
depreciated.


What's going on? The docs say that it creates a new process. I 
simply want to clear the console!




Re: GTKD - CSS class color "flash" delay

2016-06-26 Thread TheDGuy via Digitalmars-d-learn

On Sunday, 26 June 2016 at 12:30:22 UTC, Mike Wey wrote:


You should probably increment the index in the timeout_delay 
function.


This leads to a Range violation exception...


Re: Overloads

2016-06-26 Thread ArturG via Digitalmars-d-learn

On Sunday, 26 June 2016 at 11:23:14 UTC, Márcio Martins wrote:

Consider this snippet:

struct X {
  int foo(Args...)(Args args) if (Args.length > 1) { return 
Args.length; }


  int foo() { return 0; }

  int foo(int y) { return 1; }

  alias Name = string;

  int field_;
}


void listMembers(T)(ref T x) {
  foreach (Member; __traits(derivedMembers, T)) {
pragma(msg, Member, " ", __traits(getOverloads, x, 
Member).length);
//pragma(msg, __traits(getProtection, __traits(getMember, 
x, Member))); // Error: argument string has no protection

  }
}

void main() {
  X x;
  listMembers(x);
  //auto fptr = &x.foo; // Error: x.foo(Args...)(Args args) if 
(Args.length > 0) is not an lvalue

}

Output:
foo 0LU
Name 0LU
field_ 0LU
foo 0LU
Name 0LU
field_ 0LU


There seems to be a few problems here:
1. It seems like getOverloads is returning 0 for 'foo' - is 
this a bug? Was expecting a 3 or at least a 2 if the template 
would be ignored.
2. That alias breaks getProtection - is this bug? Seems like it 
should be public.


These two make it quite hard to iterate over and collect info 
about arbitrary aggregates.


I want to get a list of all *public* members, including 
pointers to all public member functions and their overloads, 
excluding template member functions. This is turning out to be 
hard due to these "unexpected behaviors".


Is there anything else I can do?


__traits(getOverloads, x, Member).length works if you place the 
template after a function of the overloads and then it returns 2.


it fails as soon as the first member of the overload set is any 
template, so i guess it must be a bug.

e.g.

struct Fails
{
void foo()(){}
void foo(int){}
}

struct Works
{
void foo(int){}
void foo()(){}
}

__traits(getOverloads, Fails, "foo").length.writeln; // 0
__traits(getOverloads, Works, "foo").length.writeln; // 1


Re: GTKD - CSS class color "flash" delay

2016-06-26 Thread Mike Wey via Digitalmars-d-learn

On 06/26/2016 12:10 AM, TheDGuy wrote:

On Saturday, 25 June 2016 at 21:57:35 UTC, TheDGuy wrote:

But i want to flash (e.g. change the CSS class) the buttons one by one
and not all at the sime time? How am i going to do that?


Okay, i tried it with a new private int-variable which contains the
current index of the for-loop, like this:

private void letButtonsFlash(){
foreach(Button btn;bArr){
btn.setSensitive(false);
}
for(int i = 0; i < level; i++){
index = i; //index is public
Button currentButton = bArr[rndButtonBlink[i]];
ListG list = currentButton.getStyleContext().listClasses();
string CSSClassName = to!string(cast(char*)list.next().data);
currentButton.getStyleContext().addClass(CSSClassName ~
"-flash");
Timeout t = new Timeout(&timeout_delay,1,false);
}

foreach(Button btn;bArr){
btn.setSensitive(true);
}
}
bool timeout_delay(){
Button currentButton = bArr[rndButtonBlink[index]];
ListG list = currentButton.getStyleContext().listClasses();
string CSSClassName = to!string(cast(char*)list.next().data);
currentButton.getStyleContext().removeClass(CSSClassName ~
"-flash");
return false;
}

But now the strange thing happens, that the first button lights up as
expected but the second button remains at its "flash color" and doesn't
go back to normal color, i don't understand why this happens? Any ideas?


You should probably increment the index in the timeout_delay function.

--
Mike Wey


Overloads

2016-06-26 Thread Márcio Martins via Digitalmars-d-learn

Consider this snippet:

struct X {
  int foo(Args...)(Args args) if (Args.length > 1) { return 
Args.length; }


  int foo() { return 0; }

  int foo(int y) { return 1; }

  alias Name = string;

  int field_;
}


void listMembers(T)(ref T x) {
  foreach (Member; __traits(derivedMembers, T)) {
pragma(msg, Member, " ", __traits(getOverloads, x, 
Member).length);
//pragma(msg, __traits(getProtection, __traits(getMember, x, 
Member))); // Error: argument string has no protection

  }
}

void main() {
  X x;
  listMembers(x);
  //auto fptr = &x.foo; // Error: x.foo(Args...)(Args args) if 
(Args.length > 0) is not an lvalue

}

Output:
foo 0LU
Name 0LU
field_ 0LU
foo 0LU
Name 0LU
field_ 0LU


There seems to be a few problems here:
1. It seems like getOverloads is returning 0 for 'foo' - is this 
a bug? Was expecting a 3 or at least a 2 if the template would be 
ignored.
2. That alias breaks getProtection - is this bug? Seems like it 
should be public.


These two make it quite hard to iterate over and collect info 
about arbitrary aggregates.


I want to get a list of all *public* members, including pointers 
to all public member functions and their overloads, excluding 
template member functions. This is turning out to be hard due to 
these "unexpected behaviors".


Is there anything else I can do?