BookmarkSubscribe
Choose Language Hide Translation Bar
gzmorgan0
Super User

Can a scripted "widget" be converted to a Class?

This discussion and the enclosed scripts were instigated by:

I voted for Vince's wish for a TextEditBox autocompleter since it was similar to my "wish" for a built-in ListBox filter. I had programmed specific UI's (dialogs/windows) achieving similar functionality for both items. However, I decided to try creating a function to automatically build these "widgets", and once successful, determine if a Class can be defined to take the place of a function.

 

There are 3 scripts attached:

  • TEB_LB_Widget.jsl - This script defines supporting functions and two main functions to build these widgets: MakeLBFilter() and MakeTEBSelector().
  • TestMakeLBFilter.jsl - This script includes the script above (you will need to change the path to the location of that script), then builds a simple window with two different list boxes, then creates a listbox filter for each. Note the script has wait statements, just for demonstration.  There are several test case at the bottom of the script. (Code snippet and display shown below.)
  • TestTEBSelector.jsl - This is similar to script 2. Check the indcluded path.  This widget is less developed.

Both widgets could have additional features added, but I decided to pursuit the question of whether each widget and its features can be created as instances of a user defined Class.

 

I read the discussion Object Oriented JSL Examples 8/18/2016.  The syntax still has not "clicked" with me, and I am looking for direction on:

  1. Can a JMP class be used to define an object widget? In this case, the class needs an existing object ( and likely its container) and a function to add a new object, and in each case a list.
  2. If yes, a class is a better way to go, and someone has a simple example or a link to documentation other than that included in the 2016 link, I would appreciate it. Then I'll pursuit the conversion.  I am adding names, from the 2016 discussion:  @drewfoglia , @Phil_Brown@msharp  

@vince_faller , I agree with your wish list, a built-in would be best. However, it would be nice to know how to prototype new examples.

 

 

Names Default to Here(1);

Include("C:\temp\TEB_LB_Widget.jsl");

myList1 = {"cat", "dog", "head", "cow", "heel", "help"};
dt = Open("$sample_data/semiconductor capability.jmp",Invisible);
myList2 = dt << get column names("Continuous", "string");

nw = New Window( "Example ListBox Filter",
 HListBox( 
 VlistBox(
   lb1 = ListBox(mylist1,
    <<set size(100,200),
 	<<set auto stretching( 1, 1 ),
	<<set min size( 5, 20 ),
	<<set max size( 100000, 10000 )
   )), //end lb1, VListBox
   SpacerBox(Size(50,10)),
   VListBox(
    lb2 = ListBox(mylist2,
      <<set size(200, 200),
 	  <<set auto stretching( 1, 1 ),
	  <<set min size( 5, 20 ),
	  <<set max size( 100000, 10000 )
   ) ),//end lb2 VListBox
   SpacerBox(Size(20,10) ),

 ) //end HListBox
);

wait(2);
lb_filt1 = MakeLBFilter(lb1);

wait(5);

lb_filt2 = MakeLBFilter(lb2);

image.pngNo text - full list displayedimage.pngLeft uses "Contains", right uses "Starts With"

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
vince_faller
Super User

Re: Can a scripted "widget" be converted to a Class?

So I still think the classes need some work. Subclassing/inheriting seems to be a bit wonky. There's no native self reference in the class so methods using display boxes can't have their functions use anything of the class attributes. But there are work arounds to the things that @Justin_Chilton showed here. Based on that I made Autocompleter. 

But I've also made it functionally using completer_box.jsl.  And according to this, special namespaces will allow namespace calls so I made it with context box as well.  Personally right now, I like the context box method the best for this.  

Vince Faller - Predictum
5 REPLIES 5
Highlighted
gzmorgan0
Super User

Re: Can a scripted "widget" be converted to a Class?

Update: The syntax is finally making sense, and I have created instances of class objects. So I have answered my question; the answer is yes. 

 

I will update this post to define and use classes called LBFilter and TEBSelector, once the functions and methods are scripted. I find the JMP14 class syntax easier to use.

msharp
Super User

Re: Can a scripted "widget" be converted to a Class?

Don't have time to dig into this, but from the time of that conversation in 2016, JMP 14 has brought in OOP to JSL with classes.  I previously recommend not implementing OOP in JSL and the methods suggested in that older post were very hacky.  In my opinion, they were more an excercise in determining if it could be done rather than an excercise in creating production level code.  I just want to officially recant that opinion now that JMP 14 supports classes and OOP, and the built in methods will be better to use.  It appears you have already figured this out.  OOP should be a great methodology to create user defined widgets.  I'm interested in seeing your final product.


uday_guntupalli
Community Trekker

Re: Can a scripted "widget" be converted to a Class?

@gzmorgan, 
   When you are done figuring it out, if you can update and tag me on the update. I would greatly appreciate it. I definitely would love to levrage classes with JSL and I would love to be able to learn from your learning exercise. 

 

 

Best
Uday
0 Kudos
vince_faller
Super User

Re: Can a scripted "widget" be converted to a Class?

So I still think the classes need some work. Subclassing/inheriting seems to be a bit wonky. There's no native self reference in the class so methods using display boxes can't have their functions use anything of the class attributes. But there are work arounds to the things that @Justin_Chilton showed here. Based on that I made Autocompleter. 

But I've also made it functionally using completer_box.jsl.  And according to this, special namespaces will allow namespace calls so I made it with context box as well.  Personally right now, I like the context box method the best for this.  

Vince Faller - Predictum
gzmorgan0
Super User

Re: Can a scripted "widget" be converted to a Class?

@vince_faller,  your AutoCompleter script using JMP classes was very informative.  I didn't have time to work on my script until about an hour ago and I hit a wall immediately.  I decided to refer to your suggested links and saw your response.  The key piece of your code to get me out of my corner was using self and obj = Expr(self).

<<Set Text Changed( 
	Function( {this, text, obj = Expr(self)}, 
		obj:doFilter(obj, this, text ) ) 
    )

I wasn't sure how to to refer to owner class for the << Set Text Changed().  Very nice!

And I found this JMP Scripting Guide blurb regarding the JMP Class object quite confusing (page 293):

 Notes:
• All methods, member variables, and functions are public.
• Functions defined within a class cannot access method variables or methods within the
class.

 

I think I would have been stuck for a long time without your example. This is worth 5 Kudos!