SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1126 2014-12-16 06:12:33

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 360

Re: interactive conky

Nope. Not working. sad

First I tried it like this:

button1=do_button({settings,settings,settings})
if button1==0 then
--do stuff when button is off
elseif button1==1 then
--do stuff if button is on
end

It started ok, but when you put the cursor on the corner button, all the other buttons started to slowly flicker, about 1/2 second off, 1/2 second on.

So I did it like this:

if tonumber(conky_parse('${updates}')) < 2 then
conky0_started = false
conky1_started = false
conky2_started = false
conky3_started = false
conky4_started = false
conky5_started = false
conky6_started = false
end

--setup buttons here
function button_settings()

	button0=do_button({btype=1,bname="conkybutton0",blx_off=0,bly_off=24,bw_off=45,bh_off=20,text=0,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={""},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={""}})
	if ((button0 == 0) and (conky0_started == true)) then
	elseif ((button0 == 1) and (conky0_started == false)) then

	button1=do_button({btype=1,bname="conkybutton1",blx_off=50,bly_off=24,bw_off=55,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"TINT2"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"TINT2"}})
	if ((button1 == 0) and (conky1_started == true)) then
	os.execute("pkill -f '.*/home/bernardo/.config/tint2/tint2rc'")--do stuff when button is off
	conky1_started = false
	elseif ((button1 == 1) and (conky1_started == false)) then
	os.execute("tint2 -c '/home/bernardo/.config/tint2/tint2rc' &")--do stuff if button is on
	conky1_started = true
	end

	button2=do_button({btype=2,bname="conkybutton2",blx_off=110,bly_off=24,bw_off=70,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"SYSTEM"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"SYSTEM"}})
	if ((button2 == 0) and (conky2_started == true)) then
	os.execute("pkill -f '.*/home/bernardo/.conky/system.conky'")--do stuff when button is off
	conky2_started = false
	elseif ((button2 == 1) and (conky2_started == false)) then
	os.execute("conky -c '/home/bernardo/.conky/system.conky' &")--do stuff if button is on
	conky2_started = true
	end

	button3=do_button			({btype=2,bname="conkybutton3",blx_off=185,bly_off=24,bw_off=60,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"CLOCK"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"CLOCK"}})
	if ((button3 == 0) and (conky3_started == true)) then
	os.execute("pkill -f '.*/home/bernardo/.conky/tintclock.conky'")--do stuff when button is off
	conky3_started = false
	elseif ((button3 == 1) and (conky3_started == false)) then
	os.execute("conky -c '/home/bernardo/.conky/tintclock.conky' &")--do stuff if button is on
	conky3_started = true
	end

	button4=do_button	({btype=2,bname="conkybutton4",blx_off=250,bly_off=24,bw_off=90,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"CALENDAR"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"CALENDAR"}})
	if ((button4 == 0) and (conky4_started == true)) then
	os.execute("pkill -f '.*/home/bernardo/.conky/calendar.conky'")--do stuff when button is off
	conky4_started = false
	elseif ((button4 == 1) and (conky4_started == false)) then
	os.execute("conky -c '/home/bernardo/.conky/calendar.conky' &")--do stuff if button is on
	conky4_started = true
	end

	button5=do_button({btype=2,bname="conkybutton5",blx_off=345,bly_off=24,bw_off=70,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"MARKET"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"MARKET"}})
	if ((button5 == 0) and (conky5_started == true)) then
	os.execute("pkill -f '.*/home/bernardo/.conky/dolar.conky'")--do stuff when button is off
	conky5_started = false
	elseif ((button5 == 1) and (conky5_started == false)) then
	os.execute("conky -c '/home/bernardo/.conky/dolar.conky' &")--do stuff if button is on
	conky5_started = true
	end

	button6=do_button		({btype=2,bname="conkybutton6",blx_off=420,bly_off=24,bw_off=70,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"BDATES"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"BDATES"}})
	if ((button6 == 0) and (conky6_started == true)) then
	os.execute("pkill -f '.*/home/bernardo/.conky/dates.conky'")--do stuff when button is off
	conky6_started = false
	elseif ((button6 == 1) and (conky6_started == false)) then
	os.execute("conky -c '/home/bernardo/.conky/dates.conky' &")--do stuff if button is on
	conky6_started = true
	end
	conky0_started = true
	end
	
end--function button_settings

and it's even worse: it flickers once, and it's gone.

Sorry Arclance to be this dumb. Can you give me a hand? sad

Online

Help fund CrunchBang, donate to the project!

#1127 2014-12-17 00:32:21

arclance
#! Die Hard
Registered: 2012-03-29
Posts: 922

Re: interactive conky

You don't need to do the conky0_started stuff for the invisible button since it is not controlling any programs.
It will only run once the way you have it now because of that.

This should do what you want.

if tonumber(conky_parse('${updates}')) < 2 then
conky1_started = false
conky2_started = false
conky3_started = false
conky4_started = false
conky5_started = false
conky6_started = false
end

--setup buttons here
function button_settings()

	button0=do_button({btype=1,bname="conkybutton0",blx_off=0,bly_off=24,bw_off=45,bh_off=20,text=0,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={""},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={""}})
	if (button0 == 1) then -- Only Do something When Button is on
	
		button1=do_button({btype=1,bname="conkybutton1",blx_off=50,bly_off=24,bw_off=55,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"TINT2"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"TINT2"}})
		if ((button1 == 0) and (conky1_started == true)) then
			os.execute("pkill -f '.*/home/bernardo/.config/tint2/tint2rc'")--do stuff when button is off
			conky1_started = false
		elseif ((button1 == 1) and (conky1_started == false)) then
			os.execute("tint2 -c '/home/bernardo/.config/tint2/tint2rc' &")--do stuff if button is on
			conky1_started = true
		end

		button2=do_button({btype=2,bname="conkybutton2",blx_off=110,bly_off=24,bw_off=70,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"SYSTEM"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"SYSTEM"}})
		if ((button2 == 0) and (conky2_started == true)) then
			os.execute("pkill -f '.*/home/bernardo/.conky/system.conky'")--do stuff when button is off
			conky2_started = false
		elseif ((button2 == 1) and (conky2_started == false)) then
			os.execute("conky -c '/home/bernardo/.conky/system.conky' &")--do stuff if button is on
			conky2_started = true
		end

		button3=do_button			({btype=2,bname="conkybutton3",blx_off=185,bly_off=24,bw_off=60,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"CLOCK"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"CLOCK"}})
		if ((button3 == 0) and (conky3_started == true)) then
			os.execute("pkill -f '.*/home/bernardo/.conky/tintclock.conky'")--do stuff when button is off
			conky3_started = false
		elseif ((button3 == 1) and (conky3_started == false)) then
			os.execute("conky -c '/home/bernardo/.conky/tintclock.conky' &")--do stuff if button is on
			conky3_started = true
		end

		button4=do_button	({btype=2,bname="conkybutton4",blx_off=250,bly_off=24,bw_off=90,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"CALENDAR"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"CALENDAR"}})
		if ((button4 == 0) and (conky4_started == true)) then
			os.execute("pkill -f '.*/home/bernardo/.conky/calendar.conky'")--do stuff when button is off
			conky4_started = false
		elseif ((button4 == 1) and (conky4_started == false)) then
			os.execute("conky -c '/home/bernardo/.conky/calendar.conky' &")--do stuff if button is on
			conky4_started = true
		end

		button5=do_button({btype=2,bname="conkybutton5",blx_off=345,bly_off=24,bw_off=70,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"MARKET"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"MARKET"}})
		if ((button5 == 0) and (conky5_started == true)) then
			os.execute("pkill -f '.*/home/bernardo/.conky/dolar.conky'")--do stuff when button is off
			conky5_started = false
		elseif ((button5 == 1) and (conky5_started == false)) then
			os.execute("conky -c '/home/bernardo/.conky/dolar.conky' &")--do stuff if button is on
			conky5_started = true
		end

		button6=do_button		({btype=2,bname="conkybutton6",blx_off=420,bly_off=24,bw_off=70,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"BDATES"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"BDATES"}})
		if ((button6 == 0) and (conky6_started == true)) then
			os.execute("pkill -f '.*/home/bernardo/.conky/dates.conky'")--do stuff when button is off
			conky6_started = false
		elseif ((button6 == 1) and (conky6_started == false)) then
			os.execute("conky -c '/home/bernardo/.conky/dates.conky' &")--do stuff if button is on
			conky6_started = true
		end

	end
	
end--function button_settings

I removed the if "button0==0" part of the if statement since you don't need it if you do nothing in that case.
You can add it back if that changes in the future.

Offline

#1128 2014-12-17 01:16:19

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 360

Re: interactive conky

I tried the code you just posted. It keeps flickering... sad

Online

#1129 2014-12-17 17:45:43

arclance
#! Die Hard
Registered: 2012-03-29
Posts: 922

Re: interactive conky

^ I don't know then it might have something to do with the button script you are using with your code.

Offline

#1130 2014-12-18 23:13:54

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 360

Re: interactive conky

Ok, thank you Arclance for everything.
I'll keep on reading the Lua book, see if I can figure something out.

Online

#1131 2014-12-19 01:49:34

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 360

Re: interactive conky

Ok, here's an update.
Being that I don't really know what I'm doing, I decided to go for broke, and pretty much start all over again... after backing up the file.
So I stripped the script, leaving only the invisible button, and one function button with no other function than to just show up on screen.
BTW: this IS the buttons.lua script.

Here's the whole script, then:

--[[buttons by mrpeachy - thanks to barrybarrykelly for the xdotool method, gmonti for finding the deb files for the xdotool and arclance for xdotool error catching
see here for instructions: http://crunchbanglinux.org/forums/post/245759/#p245759
]]

conky_name="interactiveconkyrc"
click_data_file ="/tmp/xdo"



--setup buttons here
function button_settings()

	button2=do_button({btype=1,bname="conkybutton2",blx_off=0,bly_off=24,bw_off=45,bh_off=30,text=0,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={""},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={""}})

 

	button1=do_button({btype=1,bname="conkybutton1",blx_off=50,bly_off=24,bw_off=55,bh_off=16,draw=1,dtype_off=3,docr_off=8,docr_on=8,dfcr_off=8,dfcr_on=8,text=1,dfcol_off=0x00000F,dfcol_on=0x00000F,dolw_off=2,dolw_on=2,  fcol_off={0xFFFFFF},fcol_on={0xFFFFFF},docol_off=0x7FFF00,txt_off={"TINT2"},font_off={"Sans"},fs_off={14},fs_on={14},fxadj_off={5},fyadj_off={-3,0},txt_on={"TINT2"}})

	
end--function button_settings

require 'cairo'
require 'imlib2'
function conky_start_xdo(rc_info)--######################################################
click_data_file=rc_info or click_data_file
os.execute("pkill -f 'xdotool search --sync --classname conky behave %@ mouse-click getmouselocation'")
os.execute("xdotool search --sync --classname 'conky' behave %@ mouse-click getmouselocation 2> /dev/null >> "..click_data_file.." &")
rc_info=nil
end--of function ########################################################################

function conky_stop_xdo()--##############################################################
os.execute("pkill -f 'xdotool search --sync --classname conky behave %@ mouse-click getmouselocation'")
end--of function ########################################################################

buttons={}--#############################################################################
click_table={}--#########################################################################
start=1
function conky_get_mouse(rc_info)--######################################################
if conky_window == nil then return end
local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
cr = cairo_create(cs)
--#######################################################################################
if rc_info~=nil then
rc_info=loadstring("return" .. rc_info)()
end
--start click logging and calculations ##################################################
--#######################################################################################
if start==1 then
current_update=tonumber(conky_parse("${updates}"))
start=0
end
local updates=tonumber(conky_parse("${updates}"))
if updates==(current_update or 0)+5 then
local click_data_file=rc_info[2] or click_data_file
local conky_name=rc_info[1] or conky_name
print ("own_window_title="..conky_name)
local f=io.popen("xwininfo -all -int -tree -name '"..conky_name.."'")
windata = f:read("*a")
f:close()
local windata=string.lower(windata)
local s,f,x=string.find(windata,"absolute%supper%pleft%sx%p%s*(%p*%d*)")
local s,f,y=string.find(windata,"absolute%supper%pleft%sy%p%s*(%p*%d*)")
local s,f,p=string.find(windata,"parent%swindow%sid%p%s(%d*)%s")
local s,f,w=string.find(windata,"xwininfo%p%swindow%sid%p%s(%d*)%s")
xwin={x,y,p,w,click_data_file}--don't blank with nil
print (xwin[1],xwin[2],xwin[3],xwin[4],xwin[5])
elseif updates<(current_update or 0)+5 then
local click_data_file=rc_info[2] or click_data_file
xwin={0,0,0,0,click_data_file}
end--if updates== #######################################################################
--click calculations ####################################################################
--get now location and window id ########################################################
local f = io.popen("xdotool getmouselocation 2> /dev/null")
mousenow=(f:read())
f:close()
local mousenow=string.lower(mousenow or "x:0 y:0 window:0 ")
local s,f,mousenowx=string.find(mousenow,"x%p(%d*)%s")
local s,f,mousenowy=string.find(mousenow,"y%p(%d*)%s")
local s,f,xwinid=string.find(mousenow,"window%p(%d*)")
local localnowx=(tonumber(mousenowx) or 0)-xwin[1]
local localnowy=(tonumber(mousenowy) or 0)-xwin[2]
--read file if windowid matches
if tonumber(xwin[3])==tonumber(xwinid) or tonumber(xwin[4])==tonumber(xwinid) then
	local f = io.open(xwin[5])
        click = f:read()
        f:close()
	--get click location
	if click==nil then click="x:0 y:0 window:0 " else print (click) end
	local s,f,mousex=string.find(click,"x%p(%d*)%s")
	local s,f,mousey=string.find(click,"y%p(%d*)%s")
	local localx=(tonumber(mousex) or 0)-xwin[1]
	local localy=(tonumber(mousey) or 0)-xwin[2]
	click_table[1]=localx
	click_table[2]=localy
	click_table[3]=localnowx
	click_table[4]=localnowy
	click=nil
	--blank file
	local f = io.open(xwin[5],"w")
	f:write("")
	f:close() 
else
	click_table[1]=0
	click_table[2]=0
	click_table[3]=0
	click_table[4]=0
end--window id matching
button_settings()
mousenow=nil
windata=nil
rc_info=nil
f=nil
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
return ""
end-- end getmouse function #############################################################
--#######################################################################################

function do_button(bd)
if bd.btype==nil then
bd=loadstring("return" .. bd)()
end
local localx=click_table[1]	or 0
local localy=click_table[2]	or 0
local localnowx=click_table[3]	or 0
local localnowy=click_table[4]	or 0
local button_name=bd.bname
local st_type=bd.st_type	or 0
local btype=bd.btype		or 1
local on_on_on=bd.on_on_on	or {}
local on_on_off=bd.on_on_off	or {}
local off_on_on=bd.off_on_on	or {}
local off_on_off=bd.off_on_off	or {}
local return_co=bd.return_co	or 0
--#######################################################################################
--#######################################################################################
--initialize button
if buttons[tostring(button_name)]==nil then
	if btype~=4 and st_type==0 then --button is off on start
	buttons[tostring(button_name)]=0
	elseif btype~=4 and st_type==1 then --button is on on start
	buttons[tostring(button_name)]=1
	elseif btype==4 then
	buttons[tostring(button_name)]=1
	end
end
--set mouse point type
if btype==1 or btype==3 or btype==4 then
--on off execute or cycle
localx=localx
localy=localy
elseif btype==2 then
--mouse over
localx=localnowx
localy=localnowy
else
print ("button type not set")
end
--set click area if on or off
if btype~=4 and buttons[tostring(button_name)]==0 then
--button is off
blx=bd.blx_off
bly=bd.bly_off
bw=bd.bw_off
bh=bd.bh_off
elseif btype~=4 and buttons[tostring(button_name)]==1 then
--button is on
blx=bd.blx_on or bd.blx_off
bly=bd.bly_on or bd.bly_off
bw=bd.bw_on or bd.bw_off
bh=bd.bh_on or bd.bh_off
elseif btype==4 then
local blxt=bd.blx_cyc
local blyt=bd.bly_cyc
local bwt=bd.bw_cyc
local bht=bd.bh_cyc
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
blx=blxt[set] or blxt[#blxt]
bly=blyt[set] or blyt[#blyt]
bw=bwt[set] or bwt[#bwt]
bh=bht[set] or bht[#bht]
end
--set mechanism based on button type
if btype==1 then --on off ###############################################################
--if click is inside box and button is not on - turn on
if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh and buttons[tostring(button_name)]~=1 then
buttons[tostring(button_name)]=1
--turn on other buttons as set
	for i=1,#on_on_on do
	buttons[tostring(on_on_on[i])]=1
	end
--turn off other buttons as set
	for i=1,#off_on_on do
	buttons[tostring(off_on_on[i])]=0
	end
--if click is inside box and button is on - turn off
elseif localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh and buttons[tostring(button_name)]==1 then
buttons[tostring(button_name)]=0
--turn off other buttons as set
	for i=1,#off_on_off do
	buttons[tostring(off_on_off[i])]=0
	end
--turn on other buttons as set
	for i=1,#on_on_off do
	buttons[tostring(on_on_off[i])]=1
	end
end
end --if btype==1########################################################################
if btype==2 then --mouse over ###########################################################
--if mouse is inside box
if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh then
buttons[tostring(button_name)]=1
--turn on other buttons as set
	for i=1,#on_on_on do
	buttons[tostring(on_on_on[i])]=1
	end
--turn off other buttons as set
	for i=1,#off_on_on do
	buttons[tostring(off_on_on[i])]=0
	end
--if click is inside box and button is on - turn off
else --mouse is outside
buttons[tostring(button_name)]=0
--turn off other buttons as set
	for i=1,#off_on_off do
	buttons[tostring(off_on_off[i])]=0
	end
--turn on other buttons as set
	for i=1,#on_on_off do
	buttons[tostring(on_on_off[i])]=1
	end
end --if mouse inside
end --if btype==3########################################################################
if btype==3 then --execte ###############################################################
--if mouse click is inside box
if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh then
buttons[tostring(button_name)]=1
--turn on other buttons as set
	for i=1,#on_on_on do
	buttons[tostring(on_on_on[i])]=1
	end
--turn off other buttons as set
	for i=1,#off_on_on do
	buttons[tostring(off_on_on[i])]=0
	end
--if click is inside box and button is on - turn off
else --mouse click is outside
buttons[tostring(button_name)]=0
--turn off other buttons as set
	for i=1,#off_on_off do
	buttons[tostring(off_on_off[i])]=0
	end
--turn on other buttons as set
	for i=1,#on_on_off do
	buttons[tostring(on_on_off[i])]=1
	end
end--if click inside
end --if btype==3########################################################################
if btype==4 then --cycle ################################################################
local cynum=bd.cynum
--if mouse click is inside box
	if localx>=blx and localx<=blx+bw and localy<=bly and localy>=bly-bh then
		if buttons[tostring(button_name)]+1>cynum then
		buttons[tostring(button_name)]=1
		else
		buttons[tostring(button_name)]=buttons[tostring(button_name)]+1
		end
	end--if click inside
end --if btype==4########################################################################
local function rgb_to_r_g_b(col_a)
return ((col_a[1] / 0x10000) % 0x100) / 255., ((col_a[1] / 0x100) % 0x100) / 255., (col_a[1] % 0x100) / 255., col_a[2]
end
--draw ##################################################################################
local draw=bd.draw or 0
if draw==1 then--########################################################################
--set variables if button on or off
if btype~=4 and buttons[tostring(button_name)]==0 then
dtype=bd.dtype_off  or 1
--fill when off
dfblx=bd.dfxadj_off or 0
dfbly=bd.dfyadj_off or 0
dfw=bd.dfw_off      or bw
dfh=bd.dfh_off      or bh
dfcr=bd.dfcr_off    or 0
dfcol=bd.dfcol_off  or 0xffffff
dfal=bd.dfal_off    or 1
--outline when off
doblx=bd.doxadj_off or 0
dobly=bd.doyadj_off or 0
dow=bd.dow_off      or bw
doh=bd.doh_off      or bh
docr=bd.docr_off    or 0
docol=bd.docol_off  or 0xffffff
doal=bd.doal_off    or 1
dolw=bd.dolw_off    or 1
elseif btype~=4 and buttons[tostring(button_name)]==1 then--draw on and button on
dtype=bd.dtype_on  or bd.dtype_off or 1
--fill when on
dfblx=bd.dfxadj_on or 0
dfbly=bd.dfyadj_on or 0
dfw=bd.dfw_on      or bw
dfh=bd.dfh_on      or bh
dfcr=bd.dfcr_on    or 0
dfcol=bd.dfcol_on  or 0xff0000
dfal=bd.dfal_on    or 1
--outline when on
doblx=bd.doxadj_on or 0
dobly=bd.doyadj_on or 0
dow=bd.dow_on      or bw
doh=bd.doh_on      or bh
docr=bd.docr_on    or 0 
docol=bd.docol_on  or 0xff0000
doal=bd.doal_on    or 1
dolw=bd.dolw_on    or 1
--#######################################################################################
elseif btype==4 then --##################################################################
--#######################################################################################
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
--set draw type
dtypet=bd.dtype_cyc or {1}
dtype=dtypet[set] or dtypet[#dtypet]
--fill cycle
local dfblxt=bd.dfxadj_cyc or {0}
local dfblyt=bd.dfyadj_cyc or {0}
local dfwt=bd.dfw_cyc      or {bw}
local dfht=bd.dfh_cyc      or {bh}
local dfcrt=bd.dfcr_cyc    or {0}
local dfcolt=bd.dfcol_cyc  or {0xffffff}
local dfalt=bd.dfal_cyc    or {1}
dfblx=dfblxt[set] or dfblxt[#dfblxt] or 0
dfbly=dfblyt[set] or dfblyt[#dfblyt] or 0
dfw=dfwt[set]     or dfwt[#dfwt]     or bw
dfh=dfht[set]     or dfht[#dfht]     or bh
dfcr=dfcrt[set]   or dfcrt[#dfcrt]   or 0
dfcol=dfcolt[set] or dfcolt[#dfcolt] or 0xffffff
dfal=dfalt[set]   or dfalt[#dfalt]   or 1
--outline cycle
local doblxt=bd.doxadj_off or {0}
local doblyt=bd.doyadj_off or {0}
local dowt=bd.dow_off      or {bw}
local doht=bd.doh_off      or {bh}
local docrt=bd.docr_off    or {0}
local docolt=bd.docol_off  or {0xffffff}
local doalt=bd.doal_off    or {1}
local dolwt=bd.dolw_off    or {1}    
doblx=doblxt[set] or doblxt[#doblxt] or 0
dobly=doblyt[set] or doblyt[#doblyt] or 0
dow=dowt[set]     or dowt[#dowt]     or bw
doh=doht[set]     or doht[#doht]     or bh
docr=docrt[set]   or docrt[#docrt]   or 0
docol=docolt[set] or docolt[#docolt] or 0xff0000
doal=doalt[set]   or doalt[#doalt]   or 1
dolw=dolwt[set]   or dolwt[#dolwt]   or 1
else
print ("error4")
end--check btype and button on off
--#######################################################################################
--draw based on type
if dtype==1 then
--top left mid circle
local xtl=blx+dfblx+dfcr
local ytl=bly+dfbly-(dfh-dfcr)
--top right mid circle
local xtr=xtl+(dfw-(dfcr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dfbly-dfcr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-dfcr)
cairo_line_to (cr,xtr,ytr-dfcr)
cairo_arc(cr,xtr,ytr,dfcr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+dfcr,ybr)
cairo_arc(cr,xbr,ybr,dfcr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+dfcr)
cairo_arc(cr,xbl,ybl,dfcr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-dfcr,ytl)
cairo_arc(cr,xtl,ytl,dfcr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({dfcol,dfal}))
cairo_fill (cr)
elseif dtype==2 then
--top left mid circle
local xtl=blx+doblx+docr
local ytl=bly+dobly-(doh-docr)
--top right mid circle
local xtr=xtl+(dow-(docr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dobly-docr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-docr)
cairo_line_to (cr,xtr,ytr-docr)
cairo_arc(cr,xtr,ytr,docr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+docr,ybr)
cairo_arc(cr,xbr,ybr,docr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+docr)
cairo_arc(cr,xbl,ybl,docr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-docr,ytl)
cairo_arc(cr,xtl,ytl,docr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({docol,doal}))
cairo_set_line_width (cr,dolw)
cairo_stroke (cr)
elseif dtype==3 then
--top left mid circle
local xtl=blx+dfblx+dfcr
local ytl=bly+dfbly-(dfh-dfcr)
--top right mid circle
local xtr=xtl+(dfw-(dfcr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dfbly-dfcr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-dfcr)
cairo_line_to (cr,xtr,ytr-dfcr)
cairo_arc(cr,xtr,ytr,dfcr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+dfcr,ybr)
cairo_arc(cr,xbr,ybr,dfcr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+dfcr)
cairo_arc(cr,xbl,ybl,dfcr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-dfcr,ytl)
cairo_arc(cr,xtl,ytl,dfcr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({dfcol,dfal}))
cairo_fill (cr)
--top left mid circle
local xtl=blx+doblx+docr
local ytl=bly+dobly-(doh-docr)
--top right mid circle
local xtr=xtl+(dow-(docr*2))
local ytr=ytl
--bottom right mid circle
local xbr=xtr
local ybr=bly+dobly-docr
--bottom left mid circle
local xbl=xtl
local ybl=ybr
--the drawing part---------------------------
cairo_move_to (cr,xtl,ytl-docr)
cairo_line_to (cr,xtr,ytr-docr)
cairo_arc(cr,xtr,ytr,docr,((2*math.pi/4)*3),((2*math.pi/4)*4))
cairo_line_to (cr,xbr+docr,ybr)
cairo_arc(cr,xbr,ybr,docr,((2*math.pi/4)*4),((2*math.pi/4)*1))
cairo_line_to (cr,xbl,ybl+docr)
cairo_arc(cr,xbl,ybl,docr,((2*math.pi/4)*1),((2*math.pi/4)*2))
cairo_line_to (cr,xtl-docr,ytl)
cairo_arc(cr,xtl,ytl,docr,((2*math.pi/4)*2),((2*math.pi/4)*3))
cairo_close_path(cr)
cairo_set_source_rgba (cr,rgb_to_r_g_b({docol,doal}))
cairo_set_line_width (cr,dolw)
cairo_stroke (cr)
end
end--if draw=1 ##########################################################################
local image=bd.image or 0
if image==1 then--#######################################################################
if btype~=4 and buttons[tostring(button_name)]==0 then
file=tostring(bd.im_file_off)
if file==nil then print("set image file") end
local show = imlib_load_image(file)
if show == nil then return end
imlib_context_set_image(show)
	if tonumber(bw)==0 then 
	width=imlib_image_get_width() 
	end
	if tonumber(bh)==0 then 
	height=imlib_image_get_height() 
	end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), bw, bh)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(blx, bly-bh)
imlib_free_image()
show=nil
elseif btype~=4 and buttons[tostring(button_name)]==1 then
file=tostring(bd.im_file_on)
if file==nil then print("set image file") end
---------------------------------------------
local show = imlib_load_image(file)
if show == nil then return end
imlib_context_set_image(show)
	if tonumber(bw)==0 then 
	width=imlib_image_get_width() 
	end
	if tonumber(bh)==0 then 
	height=imlib_image_get_height() 
	end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), bw, bh)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(blx, bly-bh)
imlib_free_image()
show=nil
elseif btype==4 then
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
local file=bd.im_file_cyc or {}
file=file[set]
if file==nil then print("set image file") end
---------------------------------------------
local show = imlib_load_image(file)
if show == nil then return end
imlib_context_set_image(show)
	if tonumber(bw)==0 then 
	width=imlib_image_get_width() 
	end
	if tonumber(bh)==0 then 
	height=imlib_image_get_height() 
	end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), bw, bh)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(blx, bly-bh)
imlib_free_image()
show=nil
end--btype test
end--if image ###########################################################################
local text=bd.text
if text==1 then --#######################################################################
--set variables if button on or off
if btype~=4 and buttons[tostring(button_name)]==0 then
local txt=bd.txt_off   or {"text"}
local font=bd.font_off or {"mono"}
local fs=bd.fs_off     or {12}
local fx=bd.fxadj_off  or {0}
local fy=bd.fyadj_off  or {0}
local fcol=bd.fcol_off or {0x000000}
local fal=bd.fal_off   or {1}
	for i=1,#txt do
	cairo_select_font_face (cr, font[i] or font[#font], CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size (cr, fs[i] or fs[#fs])
	cairo_set_source_rgba (cr,rgb_to_r_g_b({fcol[i] or fcol[#fcol],fal[i] or fal[#fal]}))
	cairo_move_to (cr,blx+(fx[i] or fx[#fx]),bly+(fy[i] or fy[#fy]))
	cairo_show_text (cr, txt[i] or txt[#txt])
	cairo_stroke (cr)
	end
elseif btype~=4 and buttons[tostring(button_name)]==1 then
local txt=bd.txt_on   or bd.txt_off   or {"text"}
local font=bd.font_on or bd.font_off  or {"mono"}
local fs=bd.fs_on     or bd.fs_off    or {12}
local fx=bd.fxadj_on  or bd.fxadj_off or {0}
local fy=bd.fyadj_on  or bd.fyadj_off or {0}
local fcol=bd.fcol_on or bd.fcol_off  or {0x000000}
local fal=bd.fal_on   or bd.fal_off   or {1}
	for i=1,#txt do
	cairo_select_font_face (cr, font[i] or font[#font], CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size (cr, fs[i] or fs[#fs])
	cairo_set_source_rgba (cr,rgb_to_r_g_b({fcol[i] or fcol[#fcol],fal[i] or fal[#fal]}))
	cairo_move_to (cr,blx+(fx[i] or fx[#fx]),bly+(fy[i] or fy[#fy]))
	cairo_show_text (cr, txt[i] or txt[#txt])
	cairo_stroke (cr)
	end
elseif btype==4 then
--text for cycle trype button
--into tables round 1
local cynum=bd.cynum
local set=tonumber(buttons[tostring(button_name)])
local txtt=bd.txt_cyc   or {{"text"}}
local fontt=bd.font_cyc or {{"mono"}}
local fst=bd.fs_cyc     or {{12}}
local fxt=bd.fxadj_cyc  or {{0}}
local fyt=bd.fyadj_cyc  or {{0}}
local fcolt=bd.fcol_cyc or {{0x000000}}
local falt=bd.fal_cyc   or {{1}}
--into tables round 2
local txt=txtt[set]    or txtt[#txtt]
local font=fontt[set]  or fontt[#fontt]
local fs=fst[set]      or fst[#fst]
local fx=fxt[set]      or fxt[#fxt]
local fy=fyt[set]      or fyt[#fyt]
local fcol=fcolt[set]  or fcolt[#fcolt]
local fal=falt[set]    or falt[#falt]
	for i=1,#txt do
	cairo_select_font_face (cr, font[i] or font[#font], CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
	cairo_set_font_size (cr, fs[i] or fs[#fs])
	cairo_set_source_rgba (cr,rgb_to_r_g_b({fcol[i] or fcol[#fcol],fal[i] or fal[#fal]}))
	cairo_move_to (cr,blx+(fx[i] or fx[#fx]),bly+(fy[i] or fy[#fy]))
	cairo_show_text (cr, txt[i] or txt[#txt])
	cairo_stroke (cr)
	end
else
print ("error with text")
end--if buttons[]==0
end--if text==1 #########################################################################
--#######################################################################################
if return_co==0 then
return tonumber(buttons[tostring(button_name)])
elseif return_co==1 then
return tonumber(buttons[tostring(button_name)]),localnowx,localnowy
end--return settings
end-- end button calculations function ##################################################
--#######################################################################################

function conky_rc_button(bd)--function to setup button in conkyrc
if conky_window == nil then return end
local cs = cairo_xlib_surface_create(conky_window.display, conky_window.drawable, conky_window.visual, conky_window.width, conky_window.height)
cr = cairo_create(cs)
local updates=tonumber(conky_parse('${updates}'))
if updates>5 then
--#######################################################################################
send=do_button(bd)
--#######################################################################################
end--if updates>3
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
return send or 0
end-- end main function

I've even changed the button number to 2, just in case the program had a problem with a button "0".
So, I started it, and... it worked. No functions, of course, but the button did show up on screen, and there was no flickering whatsoever.

So I then added the " if button2 == 1 then" line, and ended the function... and the flickering came back

So, somehow, it's the if-then branch that's causing the flickering. Don't ask me why (I'm not that good...yet), but the fact is that, when I add it, all hell breaks lose.

Now, on the tutorial on page 13, MrPeachy talks about some "off_on_on, off_on_off, etc." functions, for a button to control other buttons but offers no further explanation about them. Maybe those are the functions I should be using? In any case, what would be the right way to use those functions?

Online

#1132 2014-12-20 01:39:49

arclance
#! Die Hard
Registered: 2012-03-29
Posts: 922

Re: interactive conky

I don't know.
This must be a quirk of MrPeachys button script which I don't use as is so I don't know anything about it.

Offline

#1133 2014-12-20 03:26:28

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 360

Re: interactive conky

Don't worry about it. Thank you for trying.
I will figure it out... eventually.  tongue

Online

#1134 2014-12-20 04:24:26

tknomanzr
Member
From: Heavener, OK
Registered: 2014-12-09
Posts: 48

Re: interactive conky

local on_on_on=bd.on_on_on	or {}
local on_on_off=bd.on_on_off	or {}
local off_on_on=bd.off_on_on	or {}
local off_on_off=bd.off_on_off	or {}

those are locally declared variable to this function:

function do_button(bd)

As far as the code, I would suspect the draw function if you are getting flickering, like it is redrawing the whole window instead of just the buttons. You may need to check that function and start outputting variables to see if you are getting expected output. Sorry I can't be much more help. I am not very familiar with lua and am mostly just trying to translate from languages and concepts I do know.

Offline

#1135 2014-12-20 06:18:56

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 360

Re: interactive conky

Yeah, I could figure the on_on_off part already. It has nothing to do with the buttons showing or not. It's actually for the displayed information to be turned on or off.
As of now, I'm reading on MrPeachy's lua how-to. I will report back as soon as I can find a solution. smile

Online

#1136 2014-12-20 15:12:50

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 12,832
Website

Re: interactive conky

^ just so you know I have been looking for an interactive conky here using the button lua script - that works.  I've found a few that don't work ... but I know someplace in the conky catacombs here there is one that does.

When I find it ....

Offline

#1137 2014-12-20 21:33:05

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 360

Re: interactive conky

Sector11 wrote:

When I find it ....

Well, if somebody CAN find it, it's you.
So, I will be waiting... tongue

Online

#1138 2014-12-20 22:31:26

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 12,832
Website

Re: interactive conky

Can't find it here ... BUT I found it online here.  I'll have to download it and try it again  big_smile

Go figure .. I was looking for something else and there it was!

Offline

#1139 2014-12-20 23:33:05

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 360

Re: interactive conky

Hmmm... a few days ago I saw a video of a conky with a gazillion buttons. I would KILL to find it again, and to get my hands on its lua script.
I'd also love to get Falldown's interactive weather conky's lua script, but, as far as I know, he has never posted it... sad

Online

#1140 Yesterday 01:07:15

Sector11
77345 ¡#
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 12,832
Website

Re: interactive conky

You Tube:
One by falldown and on the right - a few more.

Then there is this: Interactive Weather v9000 and of course the video  The problem is the tar.gz is no more.  sad

Offline

#1141 Yesterday 01:18:48

Inodoro Pereyra
#! Junkie
From: Buenos Aires, Argentina
Registered: 2013-07-01
Posts: 360

Re: interactive conky

Sector11 wrote:

You Tube:
One by falldown and on the right - a few more.

I saw that one. The one I'm talking about was just rows upon rows of plain, square buttons with rounded corners. Nothing fancy. I even saw videos of it, but now I can't find it. sad

Ohhh, I would KILL to get my hands on Falldown's V9000 lua script...

Online

#1142 Yesterday 01:22:35

arclance
#! Die Hard
Registered: 2012-03-29
Posts: 922

Re: interactive conky

My weather script has nested buttons that work correctly.
The button code in mine is only based on an early version of MrPeachys button code and does not use his actual button script though.
The script is quite large so it could be hard to figure out on your own since it was not written to be as user friendly as MrPeachys was.

Last edited by arclance (Yesterday 01:24:40)

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo