Hello Guest it is October 17, 2019, 02:50:33 PM

Author Topic: mach4 script buttons help  (Read 242 times)

0 Members and 1 Guest are viewing this topic.

Offline gorf23

*
  •  134 134
    • View Profile
mach4 script buttons help
« on: December 29, 2018, 09:43:23 PM »
it doesn't seen that mach4 supports the image button function SetBitmapSelected…

Is there another way to change the buttons inage when pressed in a lua panel ?

Thanks gary

Offline DazTheGas

*
  •  750 750
  • DazTheGas
    • View Profile
Re: mach4 script buttons help
« Reply #1 on: December 31, 2018, 11:49:22 AM »
You will need to use the screen (scr) api, first load an image via the image editor then you can call it from a script.

Lets say you have a bitmap button called enable that has an image assigned to it and when pressed you want it to change then you would use scr.SetProperty('ButtonName','Image','NewImageName')

DazTheGas
Theres always time for a choccy biccy

Offline gorf23

*
  •  134 134
    • View Profile
Re: mach4 script buttons help
« Reply #2 on: December 31, 2018, 05:05:00 PM »
Thanks Daz

I don't think that will work I have a lua panel and button events

I created a bitmap button like this
My_bpButton = wx.wxBitmapButton( MyPanel, wx.wxID_ANY, wx.wxBitmap( "C:\\Mach4Hobby\\images\\downarrow.png", wx.wxBITMAP_TYPE_ANY ), wx.wxDefaultPosition, wx.wxDefaultSize, wx.wxBU_AUTODRAW )

So when the button event is called I want to change the button image...

I have the images loaded into mach4 editor
and did try scr, doesn't seem to work in the lua panel

it does work if I create a button on the screen...

Thanks gary

Offline gorf23

*
  •  134 134
    • View Profile
Re: mach4 script buttons help
« Reply #3 on: December 31, 2018, 05:39:28 PM »
Daz I think I have it figured out I am using
My_bmpButton:SetBitmapPressed( wx.wxBitmap ("C:\\Mach4Hobby\\images\\downarrowdark.png") )

This seems to work

Gary

Offline DazTheGas

*
  •  750 750
  • DazTheGas
    • View Profile
Re: mach4 script buttons help
« Reply #4 on: December 31, 2018, 06:49:08 PM »
Heres a couple of small snippets from one of my old screens how I did a button

Code: [Select]
local sethome_btn_dis = btn_path.."sethome_dis.png"
local sethome_btn_dwn = btn_path.."sethome_dwn.png"
local sethome_btn_up = btn_path.."sethome_up.png"
local sethome_btn_hov = btn_path.."sethome_hov.png"

Cont.sethome_btn = wx.wxBitmapButton( Cont.Panel, wx.wxID_ANY, wx.wxBitmap( sethome_btn_up, wx.wxBITMAP_TYPE_ANY ), wx.wxPoint(10,440), wx.wxDefaultSize, wx.wxBU_AUTODRAW + wx.wxNO_BORDER)
Cont.sethome_btn:SetBackgroundColour( wx.wxSystemSettings.GetColour( wx.wxSYS_COLOUR_ACTIVECAPTION ) )

Cont.sethome_btn:SetBitmapDisabled( wx.wxBitmap( sethome_btn_dis, wx.wxBITMAP_TYPE_ANY ) )
Cont.sethome_btn:SetBitmapSelected( wx.wxBitmap( sethome_btn_dwn, wx.wxBITMAP_TYPE_ANY ) )
Cont.sethome_btn:SetBitmapFocus( wx.wxBitmap( sethome_btn_up, wx.wxBITMAP_TYPE_ANY ) )
Cont.sethome_btn:SetBitmapHover( wx.wxBitmap( sethome_btn_hov, wx.wxBITMAP_TYPE_ANY ) )
--Cont.sethome_btn:SetToolTip( "Cycle Start" )


Cont.sethome_btn:Connect( wx.wxEVT_LEFT_UP, function(event)


    event:Skip()
    end )

Now another way of doing it is to use one of your images as a container for a second image then use the :Show() and :Hide() functions - notice in the example below that the button_up is loaded over the button_dwn, by hiding button_up then you see button_dwn and by showing it you hide button down..


Code: [Select]
--************************** Start Controls *********************************
DTG.panel = mcLuaPanelParent
 
    DTG.bSizer1 = wx.wxBoxSizer( wx.wxVERTICAL )

    DTG.button_dwn = wx.wxStaticBitmap( DTG.panel, wx.wxID_ANY, wx.wxBitmap( btn_dwn, wx.wxBITMAP_TYPE_ANY ), wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
DTG.button_up = wx.wxStaticBitmap( DTG.button_dwn, wx.wxID_ANY, wx.wxBitmap( btn_up, wx.wxBITMAP_TYPE_ANY ), wx.wxDefaultPosition, wx.wxDefaultSize, 0 )
DTG.bSizer1:Add( DTG.button_dwn, 0, wx.wxALL, 0 )

DTG.panel:SetSizer( DTG.bSizer1 )
DTG.panel:Layout()
   
--***************************  End Controls  **************************************

--************************** Start Event Handlers *********************************

    DTG.button_up:Connect( wx.wxEVT_LEFT_DOWN, function(event)
DTG.button_up:Hide();
end )

DTG.button_dwn:Connect( wx.wxEVT_LEFT_UP, function(event)
DTG.button_up:Show();
    end )

DTG.button_dwn:Connect( wx.wxEVT_LEAVE_WINDOW, function(event)
DTG.button_up:Show();
end )


--***************************  End Event Handlers  *********************************

DazTheGas
Theres always time for a choccy biccy

Offline gorf23

*
  •  134 134
    • View Profile
Re: mach4 script buttons help
« Reply #5 on: January 04, 2019, 10:17:23 PM »
Here is a bit of the code I just wanted the image to change when button pressed and return to old image when released this seems to work fine and I don't need to use an event or any more code to change the image

Code: [Select]

local inst = mc.mcGetInstance()
local  panel = mcLuaPanelParent




My_button1BTN = wx.wxButton( panel, wx.wxID_ANY, "button1", wx.wxPoint( 0,5 ), wx.wxSize( 220,30 ), 0 )
My_button1BTN:SetBackgroundColour( wx.wxColour( 228, 228, 228 ) )


My_bmpButton = wx.wxBitmapButton( panel, wx.wxID_ANY, wx.wxBitmap( "C:\\Mach4Hobby\\images\\downarrow.png", wx.wxBITMAP_TYPE_ANY ), wx.wxPoint( 0,170 ), wx.wxDefaultSize, wx.wxBU_AUTODRAW )

My_bmpButton:SetBitmapPressed( wx.wxBitmap ("C:\\Mach4Hobby\\images\\downarrowdark.png") )



My_bmpButton:Connect( wx.wxEVT_LEFT_UP, function(event)
 
event:Skip()
end )

My_button1BTN:Connect( wx.wxEVT_LEFT_UP, function(event)

event:Skip()
end )


TimerLoop = wx.wxTimer(panel)
panel:Connect(wx.wxEVT_TIMER,   function (event)

event:Skip()
end)

Offline gorf23

*
  •  134 134
    • View Profile
Re: mach4 script buttons help
« Reply #6 on: January 04, 2019, 10:28:58 PM »
I do have another question for you about the scr.SetProperty('ButtonName','Image','NewImageName')
this seems to work on some off my screens I created but not on others been wracking my head over this
if I use it in the clicked up and a different image in the clicked down the image doesn't change and the image that was in where you choose the image when first created the button
is now blank after I exit and click on the button then go back to edit screen and there is no image selected now... but the image is still showing in the button..

doesn't seem to happen on all my screens sets...

may be hard to follow this post ???

thanks gary