Machsupport Forum

Mach Discussion => Mach4 General Discussion => Topic started by: joeaverage on January 20, 2019, 01:27:32 PM

Title: Un-Supported wxNumberEntryDialog
Post by: joeaverage on January 20, 2019, 01:27:32 PM
Hi All,
I have always struggled to make sense of wxLua. I have started doing some reading and experimenting and a glimmer of
understanding/hope is coming.

I have encountered a difficulty that maybe someone can explain.

I was experimenting with wx.wxNumberEntryDialog() As found in the wxWidgets web pages but found that neither
ZeroBrane supported it neither would the dialog execute.

I found that the convenience dialog wx.wxGetNumberFromUser() works but that is limited to positive integers only.

I was hoping that wx.wxNumberEntryDialog would allow the entry of real numbers which would be appropriate for
a dimension in a CNC job say.

Is there a means of real number entry in wxLua?

Craig
Title: Re: Un-Supported wxNumberEntryDialog
Post by: smurph on January 20, 2019, 03:23:17 PM
Just use a text entry and convert the text to a real with tonumber().

One thing that you guys may not know is wxFormBuilder generates code for wxLua.  Just build you own dialog in wxFormBuilder and do what ever you need.  There will be a learning curve, but it is worth it. 

Steve
Title: Re: Un-Supported wxNumberEntryDialog
Post by: Cbyrdtopper on January 20, 2019, 04:50:34 PM
Steve, great suggestion converting text to number; I just had to try it out, works great!

I remember going to the class that Scott had up in Michigan when Mach4 was first released, he strongly suggested downloading wxFormBuilder to make stuff.  I have tried to mess with wxFormBuilder before, I just don't know where to start with the code.  Maybe it's worth another try, it has been a while since I have opened it up.
Title: Re: Un-Supported wxNumberEntryDialog
Post by: smurph on January 20, 2019, 07:46:31 PM
I miss the Digital Machinist shows.  :( 

The wxFormbuilder stuff isn't that hard once you realize that it puts all of the GUI code in one table called UI (I guess for User Interface).  You just paste all of that generated code into your LUA file and call it, basically.

Steve
Title: Re: Un-Supported wxNumberEntryDialog
Post by: Cbyrdtopper on January 20, 2019, 08:10:37 PM
Easy enough.   I'll open it up and try it again. 
I wonder who should show uo to a meet up if one was put together.   
Title: Re: Un-Supported wxNumberEntryDialog
Post by: smurph on January 20, 2019, 09:28:10 PM
We usually do a show called Cabin Fever (this weekend, in fact) in PA.  But the weather prevented most of us from going.  Besides that, we do IMTS and FabTech every now and then.

I LOVED doing the Cabin Fever show when it was in March and in York, PA.  Now it is back (original time anyway) in January and in Lebanon, PA.  :(  I haven't been too excited about the Jan/Lebanon combination. 

Steve
Title: Re: Un-Supported wxNumberEntryDialog
Post by: joeaverage on January 21, 2019, 12:35:57 AM
Hi,
I did try fiddling with wxFormBuilder and quite liked the idea but obviously did not put the effort to master
it. I'll have to try it again.

Putting all the code in a table is a great idea.

I guess the question is.....'for the simple dialogs I am likely to require for Mach4 macros is it necessary or even
desirable to have a utility like wxFormBuilder?'.

Craig
Title: Re: Un-Supported wxNumberEntryDialog
Post by: smurph on January 21, 2019, 12:54:39 AM
It isn't necessary.  But I would say it is desirable.  Because if you can't use the stock "data grabber" dialogs and require something juuuuust a bit more complex, the wxFormbuilder thing pays big dividends.   Otherwise, you start to have to know MORE about wxWidgets to code a dialog by hand. 

Maybe someone can do a video on how to work with wxFormBuilder.

Steve
Title: Re: Un-Supported wxNumberEntryDialog
Post by: joeaverage on January 21, 2019, 01:06:04 AM
Hi Smurph,
whether I make the effort to get wxFormBuilder working for me I still have a hankering to see and understand
the wxLua code.

I guess its not unlike the parallel between using a Wizard or a CAM program to generate Gcode without having a clue
about Gcode. I know plenty of people seem to work that way but I need to be able to scan Gcode and get a feel for what its
going to do.

One of the reasons I started really looking into wxWidgets was because I am so unfamiliar with the public member functions.
Without knowing the sorts of functionality they can confer how could I possibly know to try to use them to achieve a specific
behavior?

Craig
Title: Re: Un-Supported wxNumberEntryDialog
Post by: DazTheGas on January 21, 2019, 09:56:18 AM
If all you want to do is get NUMERIC characters from a user then just use a validator on the TextCtrl, by using the wxFILTER_NUMERIC you will get your 0-9 and your - and . oh and an e

Here`s a dirty way of getting rid of the frame too and center the dialog ;-)

Code: [Select]
coords_val = ""
coordsObj = wxlua.wxLuaObject(coords_val)

mainFrame = wx.wxFrame( wx.NULL, wx.wxID_ANY, "Dummy Frame", wx.wxDefaultPosition, wx.wxSize(0,0), wx.wxFRAME_TOOL_WINDOW)
dialog = wx.wxDialog(mainFrame, wx.wxID_ANY, "Enter Coords")
dialog:Center()
coords = wx.wxTextCtrl(dialog, wx.wxID_ANY, "",  wx.wxPoint( 10,12 ), wx.wxDefaultSize, 0,  wx.wxTextValidator(wx.wxFILTER_NUMERIC, coordsObj))
ok = wx.wxButton( dialog, wx.wxID_OK, "OK", wx.wxPoint( 10,40 ), wx.wxDefaultSize, 0 )
cancel = wx.wxButton( dialog, wx.wxID_CANCEL, "Cancel", wx.wxPoint( 100,40 ), wx.wxDefaultSize, 0 )

if dialog:ShowModal() == wx.wxID_OK then
    wx.wxMessageBox(tostring(coords:GetValue()))
else
wx.wxMessageBox('User Canx')
end

Most of these "convenience functions" are just that ;-)

DazTheGas
Title: Re: Un-Supported wxNumberEntryDialog
Post by: joeaverage on January 21, 2019, 12:38:34 PM
Hi Daz,
great stuff there. Some new concepts for me to get my head around.

For instance:
Code: [Select]
coords_val = ""
coordsObj = wxlua.wxLuaObject(coords_val)
What does this do and why is it required? Hang on......just seen it, the numeric filter requires an object on which to operate?

Another query I have is say 'dialog' is defined....is it necessary to define as global or is it permissible to define it as local?

I see mainframe has been defined with 0 size, so presumably it does not have an onscreen image but what is:
Code: [Select]
wx.wxFRAME_TOOL_WINDOW
This is exactly the sort of thing that I want.....enough new concepts included in a working example so I can work out
how all the individual pieces get put together. Thanks again.

Craig

Title: Re: Un-Supported wxNumberEntryDialog
Post by: DazTheGas on January 21, 2019, 02:37:03 PM
When creating a Frame by default it will add a menu bar and the close icon as a minimum so you still see the frame, the wxFRAME_TOOL_WINDOW doesnt so works good as a dummy frame. You can declare the dialog however you like, that code is something I just threw together as an example.

Smurph is absolutely correct about wxFormBuilder, best is to just have a play and then have a look at the code it spits out to see how things are put together and as you can see from my code you dont actually have to use sizers if you dont want too, you can make dialogs, msg`s etc absolute.

DazTheGas
Title: Re: Un-Supported wxNumberEntryDialog
Post by: smurph on January 21, 2019, 03:11:36 PM
But sizers rule!!!  That was the greatest invention since beer cans.  They can be a bit confusing at first.  But once you get them, you'll wonder how the world got along without them in the past. 

Steve
Title: Re: Un-Supported wxNumberEntryDialog
Post by: DazTheGas on January 21, 2019, 05:26:53 PM
Quote
But sizers rule!!!

Totally agree ;-)
Title: Re: Un-Supported wxNumberEntryDialog
Post by: Cbyrdtopper on January 21, 2019, 11:16:41 PM
So, I don't have any idea about wx stuff.  Looking through Daz's example makes a little bit of sense to me, but when I generate code from wxFormbuilder I don't really know what I'm looking at.
I have attached a screenshot of a simple test I made in wxFormbuilder (FB) and the code that was generated from that.
How do I get the ZeroBrane editor to run this file correctly and open up my APP. 

I haven't found any examples for FB and LUA on YouTube, just Python.

From what I understand I have to add the functionality behind the scenes outside of FB (since I can't edit anything in FB), so I will do that in ZeroBrane once I know and understand what allows it to run properly.
Title: Re: Un-Supported wxNumberEntryDialog
Post by: joeaverage on January 22, 2019, 02:13:02 AM
Hi Chad,

Quote
So, I don't have any idea about wx stuff.  Looking through Daz's example makes a little bit of sense to me, but when I generate code from wxFormbuilder I don't really know what I'm looking at.

I must say that I found the same thing when I tried using wxFB......it generated lots of code which I didn't really understand.
Even worse it seemed like the code extended for miles.....hundreds of line of code to get one number from the user????

Digesting simpler blocks of code like the file dialog I have posted or the dialog Daz has posted are much closer to my expectation
of 'code overhead' that is desirable in simple Mach scripts.

For all that, wxFB is clever and if you wanted a truly complex sequence of screen windows then probably indispensable.

Craig
Title: Re: Un-Supported wxNumberEntryDialog
Post by: smurph on January 22, 2019, 04:10:37 AM
Nah...  you guys are making too much of the generated code.  Why?  Because you don't know the paradigm that wxFormBuilder is using.  Once you understand that, it becomes a tool to help you work smarter, not harder.  :)  Anyway, I was talking to Brett and he said he might do a video on how to make something useful with wxFormBuilder.  It is one of those things that is hard to explain but easy to show.  And when you get past that, the generated code will actually teach you what is doing what by example. 

Not say you HAVE to.  But I'm just thinking you guys would be REALLY dangerous :) and have fun with it at some point. 

Steve
Title: Re: Un-Supported wxNumberEntryDialog
Post by: joeaverage on January 26, 2019, 02:03:07 PM
Hi guys,
have taken your advice and reinstalled wxFormBuilder and been experimenting with it.

I have for experimentation purposes made a grid of data values within a frame. The Lua code all looks pretty straight
forward. It includes a Create function, I have excerpted it below.

Code: [Select]
-- Grid
UI.m_grid1:CreateGrid( 8, 1 )
UI.m_grid1:EnableEditing( True )
UI.m_grid1:EnableGridLines( True )
UI.m_grid1:EnableDragGridSize( False )
UI.m_grid1:SetMargins( 0, 0 )

I have copied and pasted the code into a macro but when I run the macro the expected data input frame doesn't show up.
I suspect (hope) its something basic that I'm overlooking.

I have been trying to assign a value to a local variable by using the GetCellValue function. One potential problem I see
is that when I use Zero Brane to write the line of code GetCellValue is not supported as an auto-complete item.
Is indeed GetCellValue supported by wxLua?

Craig
Code: [Select]
local jewelWidth=UI.m_grid1:GetCellValue(1,1)
Title: Re: Un-Supported wxNumberEntryDialog
Post by: smurph on January 26, 2019, 06:03:44 PM
Did you use a frame or a dialog?  For a dialog, you use

rc = UI.<your dialog variable name>:ShowModal()

For a frame:

UI.<your frame variable name>:Show()

Code: [Select]
----------------------------------------------------------------------------
-- Lua code generated with wxFormBuilder (version Aug  8 2018)
-- http://www.wxformbuilder.org/
----------------------------------------------------------------------------

-- Load the wxLua module, does nothing if running from wxLua, wxLuaFreeze, or wxLuaEdit
package.cpath = package.cpath..";./?.dll;./?.so;../lib/?.so;../lib/vc_dll/?.dll;../lib/bcc_dll/?.dll;../lib/mingw_dll/?.dll;"
require("wx")

UI = {}


-- create MyDialog1
UI.MyDialog1 = wx.wxDialog (wx.NULL, wx.wxID_ANY, "", wx.wxDefaultPosition, wx.wxSize( 226,133 ), wx.wxDEFAULT_DIALOG_STYLE )
UI.MyDialog1:SetSizeHints( wx.wxDefaultSize, wx.wxDefaultSize )

UI.bSizer1 = wx.wxBoxSizer( wx.wxVERTICAL )

UI.bSizer2 = wx.wxBoxSizer( wx.wxHORIZONTAL )

UI.m_staticText1 = wx.wxStaticText( UI.MyDialog1, wx.wxID_ANY, "Steve:", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
UI.m_staticText1:Wrap( -1 )

UI.bSizer2:Add( UI.m_staticText1, 0, wx.wxALL, 2 )

UI.m_textCtrl1 = wx.wxTextCtrl( UI.MyDialog1, wx.wxID_ANY, "", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
UI.bSizer2:Add( UI.m_textCtrl1, 1, wx.wxALL, 2 )


UI.bSizer1:Add( UI.bSizer2, 1, wx.wxEXPAND, 5 )

UI.m_sdbSizer1 = wx.wxStdDialogButtonSizer()
UI.m_sdbSizer1OK = wx.wxButton( UI.MyDialog1, wx.wxID_OK, "" )
UI.m_sdbSizer1:AddButton( UI.m_sdbSizer1OK )
UI.m_sdbSizer1Cancel = wx.wxButton( UI.MyDialog1, wx.wxID_CANCEL, "" )
UI.m_sdbSizer1:AddButton( UI.m_sdbSizer1Cancel )
UI.m_sdbSizer1:Realize();

UI.bSizer1:Add( UI.m_sdbSizer1, 1, wx.wxEXPAND, 5 )


UI.MyDialog1:SetSizer( UI.bSizer1 )
UI.MyDialog1:Layout()

UI.MyDialog1:Centre( wx.wxBOTH )

-- Connect Events

UI.m_sdbSizer1Cancel:Connect( wx.wxEVT_COMMAND_BUTTON_CLICKED, function(event)
--implements m_Cancel()

event:Skip()
end )

UI.m_sdbSizer1OK:Connect( wx.wxEVT_COMMAND_BUTTON_CLICKED, function(event)
--implements m_OnOk

event:Skip()
end )

--wx.wxGetApp():MainLoop()

To show the above dialog code:

rc = UI.MyDialog1:ShowModal()

rc will be wx.wxID_OK or wx.wxID_CANCEL, depending on what button was pressed.

The frame's Show() method isn't modal, as it is a top level window.  Frame and dialogs each have their pros and cons.

Steve
Title: Re: Un-Supported wxNumberEntryDialog
Post by: joeaverage on January 26, 2019, 06:20:31 PM
Hi Steve,
after my post I tried a Dialog and used ShowModal() and it worked. I am a little familiar with ShowModal() syntax as
I have seen it used and I have copied/pasted and edited to use it  myself.

I have used a statments like:

if (UI.<dialogName>:ShowModal()==wx.wxID_OK) then.....

which achieves the same result as:

rc=UI.<dialogName>:ShowModal()

and then testing rc.

Either way I have some more stuff to experiment with. Thanks again.

You are correct.....letting wxFB generate the Lua code and then looking closely at the code is very illuminating.

Does your missus get sick of you being right all the time.... ;D....or does she even think that????

Craig

Title: Re: Un-Supported wxNumberEntryDialog
Post by: smurph on January 26, 2019, 07:30:33 PM
Ha!  I'm NEVER right, according to wifey.  But that's ok.  :) 
Title: Re: Un-Supported wxNumberEntryDialog
Post by: DazTheGas on January 27, 2019, 03:25:46 AM
Code: [Select]
-- Grid
UI.m_grid1:CreateGrid( 8, 1 )
UI.m_grid1:EnableEditing( True )
UI.m_grid1:EnableGridLines( True )
UI.m_grid1:EnableDragGridSize( False )
UI.m_grid1:SetMargins( 0, 0 )

wxFormbuilder is nice software but it does have its quirks, although created with wxFB the code above is actually incorrect and should be

Code: [Select]
-- Grid
UI.m_grid1:CreateGrid( 8, 1 )
UI.m_grid1:EnableEditing( true )
UI.m_grid1:EnableGridLines( true )
UI.m_grid1:EnableDragGridSize( false )
UI.m_grid1:SetMargins( 0, 0 )

true and false in lua is all lower case, try this simple example to show the effects.

Code: [Select]
local test = True -- change to true and see the difference

if test then
wx.wxMessageBox('true')
else
wx.wxMessageBox('false')
end

DazTheGas
Title: Re: Un-Supported wxNumberEntryDialog
Post by: smurph on January 27, 2019, 12:33:17 PM
Wow!  Nice catch Daz.

I guess one could do

True = true
False = false

At the top of the code. 

Steve
Title: Re: Un-Supported wxNumberEntryDialog
Post by: joeaverage on January 28, 2019, 12:47:11 AM
Hi,
yes Daz that was well spotted.
It was my intention to edit each cell to update the data but I could not edit the cells onscreen.....here was me
thinking %$FFR%&*(*&^%!!!! wxFB.....these guys are sending me up the garden path!

But despite me having checked Editing Enable and that setting apparently propagating through to code
the syntax was just not quite right.

I think smuphs quote was 'Lua syntax......is syntax only a mother could love'.

Craig
Title: Re: Un-Supported wxNumberEntryDialog
Post by: joeaverage on January 29, 2019, 03:40:27 AM
Hi Guys,
I have another lame newbie question.

I have set up a dialog with an TxtCtrl box and an OK button:
Code: [Select]
UI = {}


-- create MyDialog
UI.MyDialog = wx.wxDialog (wx.NULL, wx.wxID_ANY, "", wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxDEFAULT_DIALOG_STYLE )
UI.MyDialog:SetSizeHints( wx.wxSize( -1,-1 ), wx.wxSize( -1,-1 ) )

UI.MyDialogSizer = wx.wxBoxSizer( wx.wxVERTICAL )

UI.DataEntry = wx.wxTextCtrl( UI.MyDialog, wx.wxID_ANY, "", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
UI.MyDialogSizer:Add( UI.DataEntry, 0, wx.wxALL, 5 )

UI.m_button9 = wx.wxButton( UI.MyDialog, wx.wxID_ANY, "OK", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
UI.MyDialogSizer:Add( UI.m_button9, 0, wx.wxALL, 5 )


UI.MyDialog:SetSizer( UI.MyDialogSizer )
UI.MyDialog:Layout()
UI.MyDialogSizer:Fit( UI.MyDialog )

UI.MyDialog:Centre( wx.wxBOTH )

-- Connect Events

UI.m_button9:Connect( wx.wxEVT_COMMAND_BUTTON_CLICKED, function(event)
--implements wxID_OK

event:Skip()
return
end )
local rc=UI.MyDialog:ShowModal()
if rc==wx.wxID_OK then wx.wxMessageBox('success') end
if rc==wx.wxID_CANCEL then wx.wxMessageBox('failure')end

Note that I explicitly attached the button which result in:
 UI.m_button9:Connect( wx.wxEVT_COMMAND_BUTTON_CLICKED, function(event).

The problem is that when I single step through it all goes swimmingly until I get to the:
local rc=UI.MyDialog:ShowModal() statement. It executes and the dialog pops up, I can enter a string and exit with
a <OK> button click. The code executes the event handler function but at the end of the function re-encounters
the ShowModal()  function again and the dialog pops up again in a never ending loop.

As you can see I even tried putting a Return statement in the event handler but it returns straight to the ShowModal() function
again.

I'm struggling with what code needs to go in the handler that allows the handler to execute and then return WITHOUT
executing what amounts to its own calling statement.

I have read the explanation for event:Skip() but am far from sure that I understand its intent.

Craig
Title: Re: Un-Supported wxNumberEntryDialog
Post by: DazTheGas on January 29, 2019, 05:21:20 AM
You dont have to use a button click event  to initiate wx.wxID_OK,  within wxFB change the id of the button from wx.wxID_ANY to wx.wxID_OK and it will automatically quit the dialog for you and return the appropiate msg, also if you add a close event to the dialog as well as a cancel button you can have this return the wx.ID_CANCEL using the EndModal method and passing back wx.ID_CANCEL this should be the default return for the close but for some reason wxlUA passes back wx.wxID_OK instead??.

Code: [Select]
UI = {}


-- create MyDialog
UI.MyDialog = wx.wxDialog (wx.NULL, wx.wxID_ANY, "", wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxDEFAULT_DIALOG_STYLE )
UI.MyDialog:SetSizeHints( wx.wxSize( -1,-1 ), wx.wxSize( -1,-1 ) )

UI.MyDialogSizer = wx.wxBoxSizer( wx.wxVERTICAL )

UI.DataEntry = wx.wxTextCtrl( UI.MyDialog, wx.wxID_ANY, "", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
UI.MyDialogSizer:Add( UI.DataEntry, 0, wx.wxALL, 5 )

UI.m_button9 = wx.wxButton( UI.MyDialog, wx.wxID_OK, "OK", wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
UI.MyDialogSizer:Add( UI.m_button9, 0, wx.wxALL, 5 )


UI.MyDialog:SetSizer( UI.MyDialogSizer )
UI.MyDialog:Layout()
UI.MyDialogSizer:Fit( UI.MyDialog )

UI.MyDialog:Centre( wx.wxBOTH )

UI.MyDialog:Connect( wx.wxEVT_CLOSE_WINDOW, function(event)
UI.MyDialog:EndModal(wx.wxID_CANCEL) --End the dialog and pass back wxID_CANCEL

end )

local rc=UI.MyDialog:ShowModal()
if rc==wx.wxID_OK then wx.wxMessageBox('success') end
if rc==wx.wxID_CANCEL then wx.wxMessageBox('failure')end


DazTheGas
Title: Re: Un-Supported wxNumberEntryDialog
Post by: joeaverage on January 29, 2019, 05:49:51 AM
Hi Daz,
thanks for your reply. Slowly getting the hang of it.

It seems that wxWidgets is vast bewildering array of options/classes/conventions/syntax.
Having the code synthesized before your eyes is very impressive.

Craig