cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
Ressel
Level VI

Changing picture size in scrollable table where user selects a row and the corresponding picture is displayed

I've found some interesting code here Supercharge Your User Interfaces in JSL ( US 2018 113 ) and am trying to implement this with minor modifications as a table script (demo table attached). 

The final touches I want to apply are these:

  • Set the picture size in the script (ideally, preserving the original aspect ratio.
    I've tried; for example 'one_pic << Set Size({200,200})' and 'one_pic << scale (.2)'; in different positions inside the if() function starting at line 43, and I've also tried these messages in other places. No success.
  • Not being confident when it comes to using namespaces and neither highly experienced with regards to variables and references, the script uses 'dt = current data table()' to refer back to the table the script is stored in.
    Is this the right, computational approach or this what an inexperienced scripter would do?

Thanks for helping.

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Changing picture size in scrollable table where user selects a row and the corresponding picture is displayed

Not exactly sure why using one extra variable is required here (maybe it otherwise tries to resize the image in the table and cannot do it)

Names Default To Here(1);

dt = Current Data Table();

name_list = dt:name << get values;
num_list = dt:number << get values;
pic_list = dt:picture << get values;

nw = New Window("row",
	V List Box(
		tb = Text Box("some row"),
		H List Box(
			Panel Box("names & numbers",
				V Scroll Box(
					tbox = Table Box(String Col Box("Name", name_list), String Col Box("Number", num_list), )
				)
			),
			Panel Box("pics", 
				pb = picture box()
			)
		)
	)
);

tb << set font style("Italic") << font color("Dark Blue") << set font("Stencil", 16) << set width(450);
tbox << set underline headings(1) << set heading column borders(1) << set column borders(1) <<
set row borders(1) << set shade alternate rows(1) << set selectable rows(1);

tbox << set row change function(Function({this},
		row_list = this << get selected rows;
		If(N Rows(row_list) > 0,
			k = row_list[1];
			one_pic = pic_list[k];
			pic = one_pic;
			pic << Scale(0.2);
			pb << set image(pic);
		);
	)
);

I don't generally use table scripts, but I think in cases like this using Current Data Table() should be fine. In some cases it might refer to wrong table (like if you immediately change table after running the table script) but most likely it isn't an issue here. Other option could be to just drop dt and current datatable() and just use :name, :number, :picture and hope table script knows to refer always the correct table (this might work better than using current data table() when you have simple table script like this).

-Jarmo

View solution in original post

2 REPLIES 2
jthi
Super User

Re: Changing picture size in scrollable table where user selects a row and the corresponding picture is displayed

Not exactly sure why using one extra variable is required here (maybe it otherwise tries to resize the image in the table and cannot do it)

Names Default To Here(1);

dt = Current Data Table();

name_list = dt:name << get values;
num_list = dt:number << get values;
pic_list = dt:picture << get values;

nw = New Window("row",
	V List Box(
		tb = Text Box("some row"),
		H List Box(
			Panel Box("names & numbers",
				V Scroll Box(
					tbox = Table Box(String Col Box("Name", name_list), String Col Box("Number", num_list), )
				)
			),
			Panel Box("pics", 
				pb = picture box()
			)
		)
	)
);

tb << set font style("Italic") << font color("Dark Blue") << set font("Stencil", 16) << set width(450);
tbox << set underline headings(1) << set heading column borders(1) << set column borders(1) <<
set row borders(1) << set shade alternate rows(1) << set selectable rows(1);

tbox << set row change function(Function({this},
		row_list = this << get selected rows;
		If(N Rows(row_list) > 0,
			k = row_list[1];
			one_pic = pic_list[k];
			pic = one_pic;
			pic << Scale(0.2);
			pb << set image(pic);
		);
	)
);

I don't generally use table scripts, but I think in cases like this using Current Data Table() should be fine. In some cases it might refer to wrong table (like if you immediately change table after running the table script) but most likely it isn't an issue here. Other option could be to just drop dt and current datatable() and just use :name, :number, :picture and hope table script knows to refer always the correct table (this might work better than using current data table() when you have simple table script like this).

-Jarmo
Ressel
Level VI

Re: Changing picture size in scrollable table where user selects a row and the corresponding picture is displayed

@jthi always helpful. Thanks!