Display a widget with a timeout in Awesome Wm with Lua - lua

I want to display a wibox in awesome when a combinaison of keys are pressed and I want that this wibox disappears after 3 seconds for example. I don't want to use naughty or popup because the wibox will have widgets inside.
I have already a solution but I don't know if this solution is a standard one or if there is another way to do this:
function taglist_wibox_show_hide(box)
local show = timer({ timeout = 0 })
show:connect_signal("timeout", function ()
print("show")
box.visible=true
show:stop() end)
show:start()
local hide = timer({ timeout = 2 })
hide:connect_signal("timeout", function ()
print("hide")
box.visible=false
hide:stop() end)
hide:start()
end
Then I add this shortcut:
awful.key({ modkey, "Control" },"y",function()
taglist_wibox_show_hide(box[mouse.screen])
end),

As far as I know there's no other way. However I think your first timer is not necessary.
function taglist_wibox_show_hide(box)
print("show")
box.visible=true
local hide = timer({ timeout = 2 })
hide:connect_signal("timeout", function ()
print("hide")
box.visible=false
hide:stop() end)
hide:start()
end
Should work just as well.
Cheers

Related

WoW - Adding event handler for modifier key - kgPanels

I'm working with kgPanels to create a raid marker utility. I have two panels. One panel functions as a button - we'll call it rmButton. When rmButton is pressed it opens up the raid marker utility - rmUtility.
In kgPanels you create a panel on which you can add scripts that go in a number of different handlers. For rmUtility I am using OnLoad and OnEvent.
Right now everything is working as far as placing markers on targets. I would like to add further functionality that would allow placing world markers when either shift button is held. I'm having trouble getting that integrated.
In my OnLoad script:
local btnWidth = 30 -- the width of each button
local btnHeight = 30 -- the height of each button
local leftBorderOffset = 7 -- from the left border of the kgPanel to the first button
local btnOffset = 7 -- pixels between the buttons
local topBorderOffset = -7
self:RegisterEvent ("PLAYER_REGEN_DISABLED")
self:RegisterEvent ("PLAYER_REGEN_ENABLED")
self:Show()
self.buttons = {}
local hideFunc = function(s) s.parent:Hide() end
for n=1,6 do
local btn = CreateFrame("Button",nil,self,"SecureActionButtonTemplate")
btn:SetSize(btnWidth, btnHeight) -- replace this
btn:SetPoint("TOP",0,topBorderOffset - ((n-1) * (btnHeight + btnOffset)))
btn:SetAttribute("type","macro")
btn:RegisterForClicks("AnyUp")
btn.parent = self
btn:SetScript("PostClick",hideFunc)
btn:RegisterEvent ("MODIFIER_STATE_CHANGED")
if (event == "MODIFIER_STATE_CHANGED") then
if n == 6 then
btn:SetAttribute("macrotext","/cwm all")
else
btn:SetAttribute("macrotext",("/wm %d"):format(n))
end
else
if n == 6 then
btn:SetAttribute("macrotext","/tm 0")
else
btn:SetAttribute("macrotext",("/tm %d"):format(n))
end
end
self.buttons[n] = btn
end
self.buttons[1]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Square.tga")
self.buttons[2]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Triangle.tga")
self.buttons[3]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Diamond.tga")
self.buttons[4]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Cross.tga")
self.buttons[5]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Star.tga")
self.buttons[6]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Clear.tga")
In my OnEvent script:
if event == "PLAYER_REGEN_DISABLED" then
self:Hide()
elseif event == "PLAYER_REGEN_ENABLED" then
self:Hide()
end
When this panel loads it makes six buttons - five with raid markers, and one that clears the markers. When a button is pressed the panel will hide, and the panel will automatically hide when I enter combat.
As mentioned, I need the panel to accept a 'shift' modifier key to place the world marker.
Thanks.
Did you try something like
btn:SetAttribute("shift-macrotext1",("/wm %d"):format(n))
https://wow.gamepedia.com/SecureActionButtonTemplate#Modified_attributes
Unless you mean you want to use Shift to place a world marker? Instead of using it as a modifier for your secure action button? I'm not aware of any modifier keys like shift, ctrl, alt being able to activate an action button.

Corona SDK - TextField Gets Left On Screen

I have a working textfield in corona...I instantiated it using:
local nameTextField = native.newTextField (centerX, roundedRect.y + roundedRect.height*1.7, 300, 80)
nameTextField:addEventListener( "userInput", textListener )
I then made sure to add this to the scene's self.view in the create method:
function scene:create( event )
local sceneGroup = self.view
sceneGroup:insert(nameTextField)
end
The whole scene is shown using a showoverlay method.
composer.showOverlay( "renameoverlay", options )
When I hide the scene using hide overlay:
composer.hideOverlay( "fade", 400 )
Even after hiding the whole scene using the above code, the nameTextField still gets left on the screen.
This doesn't happen inside my other scenes.
What could be causing this????
How do I solve this???
First, native.newTextField()'s can be added to display.newGroup()'s. The will move with groups, but they still sit on top of the display hierarchy. Scene's that use fade or crossFade can't hide the text fields because they are not being moved.
Since it looks like your overlay is using "fade", you will need to hide the text fields when you call showOverlay and show them when you're done with the overlay.
Scope matters too. I can't tell what part of your code you're creating the new text field, but it has to be visible to any place you are referencing it.
It seems that native objects can't be added to dispaly groups , you need to remove the native object when you hide the scene, try this:
add scene:hide(event)
function scene:hide(event)
if nameTextField then
nameTextField :removeSelf()
nameTextField = nil
end
end
scene:addEventListener("hide", scene)
Hope this helps you!
I am fairly sure it is because of access issue for the local variable.
Change this
local nameTextField = native.newTextField (centerX, roundedRect.y + roundedRect.height*1.7, 300, 80)
to this
nameTextField = native.newTextField (centerX, roundedRect.y + roundedRect.height*1.7, 300, 80)
or this
function scene:create( event )
local sceneGroup = self.view
sceneGroup:insert(nameTextField)
end
to this
function scene:create( event )
sceneGroup = self.view
sceneGroup:insert(nameTextField)
end

how to go to back to a scene in corona sdk after moving to the next scene?

i need some help,
im making an app in corona sdk which contains 4 scenes, main, list, tab1, tab2, the main scene takes you to the list scene by a button and the List takes you to tab1 and tab1 takes you to tab2, what im trying to do is make tab2 go back to the scene List by pressing a button, and when i press on the button nothing happens!!
local button1 = widget.newButton
{
left= 250,
top= 650,
defaultFile = "red1.png",
label = "select chapter",
font = "Arial",
fontSize = 34,
onEvent = handleButtonEvent,
onPress = function() storyboard.gotoScene( "list" ); end,
selected = true
}
You appear to be using a function to handle the event of the botton with "onEvent = handleButtonEvent"
You should instead use that function to do the transition:
-- Function to handle the press of the button
local function handleButtonEvent(event)
if ( "ended" == event.phase) then
storyboard.gotoScene("list")
end
end
and
-- Creation of the button
local button1 = widget.newButton
{
-- All your variables here
onEvent = handleButtonEvent,
}
and you might even be looking for something like this; this function will instead take the user back to the previous scene.
-- Function to handle the press of the button
local function handleButtonEvent(event)
if ( "ended" == event.phase) then
storyboard.gotoScene(storyboard.getPrevious())
end
end

widget.newSwitch() On-Off Switch doesn't work when "moved"

On-Off Switch - widget.newSwitch() doesn't work when I "move" the switch, it works only when I press.
I've tried setting "onEvent" but looks like it's completely ignored as nothing happens.
local widget = require( "widget" )
-- Handle press events for the checkbox
local function onSwitchPress( event )
local switch = event.target
print( "Switch with ID '"..switch.id.."' is on: "..tostring(switch.isOn) )
end
-- Create the widget
local onOffSwitch = widget.newSwitch
{
left = 250,
top = 200,
style = "onOff",
id = "onOffSwitch",
onPress = onSwitchPress
}
The On-Off switch widget has two states: onPress and onRelease.
OnPress is called when we touch the switch. OnRelease is called when we release the switch. There is no event like onMove. This is why you cannot tap the move event.
See the link for more details.

jQuery UI Range Slider event conditions

I need to use a Range Slider to set a time range (8-23) but I need some base conditions on it (I basically need the minimum range to be 1h):
When the two pickers are on the same position the right piker goes "+1"
On right limit (23) the values have to be "22,23)
Here is the code as I tested so far: JSFiddle URL
This works only before the right limit of the slider, when I have "23,23" or "22,23" my getSlide check function does not work properly and I don't understand how to fix it..
Any help?
Thanks!
I solved myself coding all conditions only in slide event:
...
slide: function (event, ui) {
val1 = ui.values[0];
val2 = ui.values[1];
if(val2-val1 < 1 || val1 > 22){
return false;
}
$("#start").text(ui.values[0]);
$("#stop").text(ui.values[1]);
},
...
The strange behaviour with the previous version is still not explained, but it works.

Resources