SEARCH

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

You are not logged in.

#1 2012-03-14 01:04:38

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

interactive conky

this thread is to separate out the questions and setups for interactive conky from the general conky based questions and setups which should go in the monster thread

you will need:

xdotool, the repos can have an old copy, my version is
NOTE recent ubuntu and ubuntu derivatives should have an up to date copy

xdotool version 2.20110530.1

here are the deb files i used to get xdotool up and running
http://crunchbanglinux.org/forums/post/183389/#p183389

These xdo debs are needed for amd64 architecture.
xdotool_2.20110530.1-1_x86_64.deb
libxdo2_2.20110530.1-1_x86_64.deb

you can get those here
http://code.google.com/p/semicomplete/d … nloadCount

also xwininfo is not one of #! default packages
so you will need to install that too - this is part of a package called "x11-utils"

so that xdotool and xwininfo can get the right information
you need to add this line to your conkyrc

own_window_title clicky 

unless otherwise specified in the lua script

Last edited by mrpeachy (2014-01-22 22:43:57)

Offline

Be excellent to each other!

#2 2012-03-14 02:59:17

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

so here is a test script exploring the mouse over ability

--[[click with mouse over lua by mrpeachy - thanks to barrybarrykelly for the xdotool method and gmonti for finding the deb files for the xdotool
in conkyrc, in addition to regular settings:

own_window_title clicky
lua_load ~/lua/clicky.lua
lua_draw_hook_pre main
TEXT

3/13/12
]]

require 'cairo'

click_start=1-- this starts the clickfunction
buttons={}--this table ini9tially holds the values from the buttons

function conky_main()
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
--#################################################################################################
localx,localy,localnowx,localnowy=clickfunction()--this line activates the clickfunction and sets the click coordinates
--#################################################################################################
--SET DEFAULTS ##########################################################
--set defaults do not localise these defaults if you use a seperate display script
default_font="mono"--font must be in quotes
default_font_size=10
default_color=0xffffff--white
default_alpha=1--fully opaque
default_image_width=50
default_image_height=50
--#################################################################################################
--button setup - this section for an on/off button 
local button_name="cpu"
local blx=100.5--bottom left x coordinate of click area, the .5 makes the 1 pixel box line sharp
local bly=100.5--bottom left x coordinate of click area
local height=20--height of click area
local width=30--width of click area

--setup cpu section position, when setting up cpu function everything is relative to these points
local cpu_blx=blx+width+2
local cpu_bly=100.5
local overlap=width
--##############################################################
--calculate if click was inside box and set actions#############
--best to keep the button calculations seperate to the actions##
if localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]~=1 then
buttons[tostring(button_name)]=1
elseif localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]==1 then
buttons[tostring(button_name)]=0
elseif localx<blx and localx>blx+width and localy<bly and localy>bly-height and buttons[tostring(button_name)]~=1 then
buttons[tostring(button_name)]=0 end
--end of calculations ##########################################

--mouseover
if buttons["coresmo"]==1 or localnowx>=blx and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height then
    if buttons[tostring(button_name)]~=1 then
    cpusection(cpu_blx,cpu_bly,overlap)
    end
end

if localnowx>=blx and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height then
color={0,0,0,1}
fill=1
buttondraw(blx,bly,height,width,color,fill)
end

--##############################################################
--button on off
if buttons[tostring(button_name)]==1 then
color={1,0,0,1}--if button is clicked on it will be drawn red
fill=0
buttondraw(blx,bly,height,width,color,fill)
cpusection(cpu_blx,cpu_bly,overlap)
else
color={1,1,0,1}--if button is clicked on it will be drawn red
fill=0
buttondraw(blx,bly,height,width,color,fill)
end--button on off
out({x=105,y=95,txt="CPU"})
--#########################################################################################################
end-- if updates>5
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
end-- end main function

function cpusection(cpu_blx,cpu_bly,overlap)
--button setup - this section for an on/off button 
local button_name="cores"
local blx=cpu_blx--bottom left x coordinate of click area, the .5 makes the 1 pixel box line sharp
local bly=cpu_bly--bottom left x coordinate of click area
local height=20--height of click area
local width=60--width of click area
--setup cpu section position, when setting up cpu function everything is relative to these points
local cores_blx=blx+width+15
local cores_bly=bly
--##############################################################
--calculate if click was inside box and set actions#############
--best to keep the button calculations seperate to the actions##
if localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]~=1 then
buttons[tostring(button_name)]=1
elseif localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]==1 then
buttons[tostring(button_name)]=0
elseif localx<blx and localx>blx+width and localy<bly and localy>bly-height and buttons[tostring(button_name)]~=1 then
buttons[tostring(button_name)]=0 end
--end of calculations ##########################################
--mouseover
if buttons["processmo"]==1 or localnowx>=blx-overlap and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height then
buttons[tostring(button_name.."mo")]=1
--buttons["cpumo"]=1
--elseif localnowx<blx-overlap or localnowx>blx+width or localnowy>bly or localnowy<bly-height then
--buttons[tostring(button_name.."mo")]=0
else
buttons[tostring(button_name.."mo")]=0
end--mouseover

if localnowx>=blx and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height then
color={0,0,0,1}
fill=1
buttondraw(blx,bly,height,width,color,fill)
--so that cpu isnt drawn twice
    if buttons[tostring(button_name)]~=1 then
    coressection(cores_blx,cores_bly)
    end
end
--##############################################################
--button on off
if buttons[tostring(button_name)]==1 then
color={1,0,0,1}--if button is clicked on it will be drawn red
fill=0
buttondraw(blx,bly,height,width,color,fill)
coressection(cores_blx,cores_bly)
else
color={0,1,1,1}
fill=0
buttondraw(blx,bly,height,width,color,fill)
end--button on off
out({x=blx+5,y=bly-5,txt="CPU%:"..conky_parse("${cpu}")})
--##############################################################
--##############################################################
--##############################################################
--##############################################################
--##############################################################
--button controlling processes section
--button setup - this section for an on/off button 
local button_name="process"
local blx=blx--bottom left x coordinate of click area, the .5 makes the 1 pixel box line sharp
local bly=bly+height+2--bottom left x coordinate of click area
local height=20--height of click area
local width=60--width of click area
--setup cpu section position, when setting up cpu function everything is relative to these points
local process_blx=blx+width+15
local process_bly=bly
--##############################################################
--calculate if click was inside box and set actions#############
--best to keep the button calculations seperate to the actions##
if localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]~=1 then
buttons[tostring(button_name)]=1
elseif localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]==1 then
buttons[tostring(button_name)]=0
elseif localx<blx and localx>blx+width and localy<bly and localy>bly-height and buttons[tostring(button_name)]~=1 then
buttons[tostring(button_name)]=0 end
--end of calculations ##########################################
--mouseover
if localnowx>=blx and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height-height then
buttons[tostring(button_name.."mo")]=1
elseif localnowx<blx or localnowx>blx+width or localnowy>bly or localnowy<bly-height-height then
buttons[tostring(button_name.."mo")]=0
end--mouseover

if localnowx>=blx and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height then
color={0,0,0,1}
fill=1
buttondraw(blx,bly,height,width,color,fill)
--so that cpu isnt drawn twice
    if buttons[tostring(button_name)]~=1 then
    processsection(cores_blx,cores_bly)
    end
end
--##############################################################
--button on off
if buttons[tostring(button_name)]==1 then
color={1,0,0,1}--if button is clicked on it will be drawn red
fill=0
buttondraw(blx,bly,height,width,color,fill)
processsection(cores_blx,cores_bly)
else
color={0,1,1,1}
fill=0
buttondraw(blx,bly,height,width,color,fill)
end--button on off
out({x=blx+5,y=bly-5,txt="PRO#:"..conky_parse("${processes}")})
end--cpu section

function coressection(blx,bly)
out({x=blx,y=bly-5,txt="CPU1:"..conky_parse("${cpu cpu1}").."%"})
out({x=blx,y=bly+15,txt="CPU2:"..conky_parse("${cpu cpu2}").."%"})
out({x=blx,y=bly+35,txt="CPU3:"..conky_parse("${cpu cpu3}").."%"})
--out({c=0x00ff00,x=255,y=155,txt="CPU:"..conky_parse("${cpu cpu4}").."%"})
end--coressection

function processsection(blx,bly)
out({x=blx+100,y=bly-5,txt="PROC1:"..conky_parse("${top name 1}")})
out({x=blx+100,y=bly+15,txt="PROC2:"..conky_parse("${top name 2}")})
out({x=blx+100,y=bly+35,txt="PROC3:"..conky_parse("${top name 3}")})
--out({c=0x00ff00,x=255,y=155,txt="CPU:"..conky_parse("${cpu cpu4}").."%"})
end--coressection

--button drawing function
function buttondraw(blx,bly,height,width,color,fill)
cairo_set_line_width (cr,1)
cairo_set_source_rgba (cr,color[1],color[2],color[3],color[4])
cairo_rectangle (cr,blx,bly,width,-height)
if fill==0 then
cairo_stroke (cr)
elseif fill==1 then
cairo_fill (cr)
end
end--of buttondraw function
function xout(txj)--c,a,f,fs,x,y,txt,j ##################################################
c=nil
c=(txj.c or default_color)
a=nil
a=(txj.a or default_alpha)
f=nil
f=(txj.f or default_font)
fs=nil
fs=(txj.fs or default_font_size)
x=nil
x=(txj.x or 0)
y=nil
y=(txj.y or 0)
txt=nil
txt=(txj.txt or "set txt")
j=nil
j=(txj.j or "l")
    local function col(c,a)
    return ( (c/0x10000) % 0x100)/255,( (c/0x100) % 0x100)/255,(c % 0x100)/255,a
    end--local function
cairo_select_font_face (cr, f, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fs)
local text=string.gsub(txt," ","_")
extents=cairo_text_extents_t:create()
cairo_text_extents(cr,text,extents)
local wx=extents.width
cairo_set_source_rgba (cr,col(c,a))
if j=="l" then
cairo_move_to (cr,x,y)
adx=wx
elseif j=="c" then
cairo_move_to (cr,x-(wx/2),y)
adx=wx/2
elseif j=="r" then
cairo_move_to (cr,x-wx,y)
adx=0
end
cairo_show_text (cr,txt)
cairo_stroke (cr)
nextx=nil
nextx=adx+x
return nextx
end--function xout ###################################################################
function out(tx)--####################################################################
c=nil
c=(tx.c or default_color)
a=nil
a=(tx.a or default_alpha)
f=nil
f=(tx.f or default_font)
fs=nil
fs=(tx.fs or default_font_size)
x=nil
x=(tx.x or 0)
y=nil
y=(tx.y or 0)
txt=nil
txt=(tx.txt or "set txt")
local function col(c,a)
return ( (c/0x10000) % 0x100)/255,( (c/0x100) % 0x100)/255,(c % 0x100)/255,a
end--local function
cairo_select_font_face (cr, f, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fs)
cairo_set_source_rgba (cr,col(c,a))
cairo_move_to (cr,x,y)
cairo_show_text (cr,txt)
cairo_stroke (cr)
end--function out ###################################################################
function image(im)--#################################################################
x=nil
x=(im.x or 0)
y=nil
y=(im.y or 0)
w=nil
w=(im.w or default_image_width)
h=nil
h=(im.h or default_image_height)
file=nil
file=tostring(im.file)
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(w)==0 then 
width=imlib_image_get_width() 
else
width=tonumber(w)
end
if tonumber(h)==0 then 
height=imlib_image_get_height() 
else
height=tonumber(h)
end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), width, height)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(x, y)
imlib_free_image()
show=nil
end--function image ##################################################################
--clickfunction, this runs xdotool and xwininfo and reads the coordinates of clicks
function clickfunction()
--start click logging and calculations ##########################################
if click_start==1 then
xdot=conky_parse("${if_running xdotool}1${else}0${endif}")
if tonumber(xdot)==1 then
os.execute("killall xdotool && echo 'xdo killed' &")
end
os.execute("xdotool search --name 'clicky' behave %@ mouse-click getmouselocation >> /tmp/xdo &")
local f = io.popen("xwininfo -name 'clicky' | grep 'Absolute'")
geometry = f:read("*a")
f:close()
local geometry=string.gsub(geometry,"[\n]","")
s,f,abstlx=string.find(geometry,"X%p%s*(%d*)")
s,f,abstly=string.find(geometry,"Y%p%s*(%d*)")
click_start=nil
end--if click_start=1 ######################################
--click calculations #################################
local f=io.open("/tmp/xdo")
click=f:read()
f:close()
if click~=nil then
local f = io.open("/tmp/xdo","w")
f:write("")
f:close() 
end--if click=nil
if click==nil then click="x:0 y:0 " end
--print (click)
local s,f,mousex=string.find(click,"x%p(%d*)%s")
local s,f,mousey=string.find(click,"y%p(%d*)%s")
localx=tonumber(mousex)-abstlx
localy=tonumber(mousey)-abstly
--get now location
os.execute("xdotool getmouselocation > /tmp/xdonow ")
local f=io.open("/tmp/xdonow")
mousenow=f:read()
f:close()
local s,f,mousenowx=string.find(mousenow,"x%p(%d*)%s")
local s,f,mousenowy=string.find(mousenow,"y%p(%d*)%s")
localnowx=tonumber(mousenowx)-abstlx
localnowy=tonumber(mousenowy)-abstly
--END CLICK CALCULATIONS #################################
return localx,localy,localnowx,localnowy
end--function

needs some cleaning up, can see some inconsistencies which are a simple result of messy script writing (what works is more important than how it looks when im starting out!)
took a while to figure out the interactions to allow the mouse to move from one button to the next without shutting off the first

Last edited by mrpeachy (2012-03-14 03:44:26)

Offline

#3 2012-03-14 03:57:38

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

Re: interactive conky

WOW! Squeaky clean thread - not even dust in the corners yet.

Lookin good there mrpeachy... lookin real good!
031583179684861.jpg

Why do I get the feeling that the cpu in the first box to the left of CPU1 is CPU0  big_smile
But I had to try modifying it ... and it didn't even break.  big_smile

Last edited by Sector11 (2012-03-14 03:58:04)


To #! or not to #!?  That is the question! | #! Forum Moderator
#! Conky = 16 Threads & the Conky Archives | Conky PitStop | OTHCG'er
StartPage -  protect your privacy | IcyBlack | LinuxBBQ

Offline

#4 2012-03-14 04:03:48

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

Sector11 wrote:

WOW! Squeaky clean thread - not even dust in the corners yet.

Lookin good there mrpeachy... lookin real good!
031583179684861.jpg

Why do I get the feeling that the cpu in the first box to the left of CPU1 is CPU0  big_smile
But I had to try modifying it ... and it didn't even break.  big_smile

im very disappointed sector11... lol (at the lack of breakage)

the first cpu number

CPU%: X

is the output of ${cpu} which is the average usage (which i think is the same as ${cpu cpu0}), then you mouse over or click to see the individual cores

or am i missing your point?

Why do I get the feeling that the cpu in the first box to the left of CPU1 is CPU0

Last edited by mrpeachy (2012-03-14 04:05:34)

Offline

#5 2012-03-14 12:42:25

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

Re: interactive conky

mrpeachy wrote:

im very disappointed sector11... lol (at the lack of breakage)

or am i missing your point?

Why do I get the feeling that the cpu in the first box to the left of CPU1 is CPU0

No you got my point.  I added a cpu0 because I didn't see it on the list and I have 3.  Besides, I want to see if it would break  lol

Have to look at thew code closer to if I can add something myself ... now don't go cheating and telling me how, it might not break.  tongue


To #! or not to #!?  That is the question! | #! Forum Moderator
#! Conky = 16 Threads & the Conky Archives | Conky PitStop | OTHCG'er
StartPage -  protect your privacy | IcyBlack | LinuxBBQ

Offline

#6 2012-03-14 14:35:13

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

Re: interactive conky

You did this on purpose I can tell.  You said - I'll confuse Sector11.  I wanted to add a button and have it work.

The have it work part doesn't look so hard BUT adding a button???  Where?

out({x=15,y=24,txt="GO:"})
   --#########################################################################################################
   end-- if updates>5
   cairo_destroy(cr)
   cairo_surface_destroy(cs)
   cr=nil
   end-- end main function

   function cpusection(cpu_blx,cpu_bly,overlap)
   --button setup - this section for an on/off button
   local button_name="cores"
   local blx=cpu_blx--bottom left x coordinate of click area, the .5 makes the 1 pixel box line sharp
   local bly=cpu_bly--bottom left x coordinate of click area
   local height=20--height of click area
   local width=60--width of click area
   --setup cpu section position, when setting up cpu function everything is relative to these points
   local cores_blx=blx+width+15
   local cores_bly=bly
   --##############################################################
   --calculate if click was inside box and set actions#############
   --best to keep the button calculations seperate to the actions##
   if localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]~=1 then
   buttons[tostring(button_name)]=1
   elseif localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]==1 then
   buttons[tostring(button_name)]=0
   elseif localx<blx and localx>blx+width and localy<bly and localy>bly-height and buttons[tostring(button_name)]~=1 then
   buttons[tostring(button_name)]=0 end
   --end of calculations ##########################################
   --mouseover
   if buttons["processmo"]==1 or localnowx>=blx-overlap and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height then
   buttons[tostring(button_name.."mo")]=1
   --buttons["cpumo"]=1
   --elseif localnowx<blx-overlap or localnowx>blx+width or localnowy>bly or localnowy<bly-height then
   --buttons[tostring(button_name.."mo")]=0
   else
   buttons[tostring(button_name.."mo")]=0
   end--mouseover

   if localnowx>=blx and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height then
   color={0,0,0,1}
   fill=1
   buttondraw(blx,bly,height,width,color,fill)
   --so that cpu isnt drawn twice
       if buttons[tostring(button_name)]~=1 then
       coressection(cores_blx,cores_bly)
       end
   end
   --##############################################################
   --button on off
   if buttons[tostring(button_name)]==1 then
   color={1,0,0,1}--if button is clicked on it will be drawn red
   fill=0
   buttondraw(blx,bly,height,width,color,fill)
   coressection(cores_blx,cores_bly)
   else
   color={0,1,1,1}
   fill=0
   buttondraw(blx,bly,height,width,color,fill)
   end--button on off
   out({x=blx+5,y=bly-5,txt="CPU%:"..conky_parse("${cpu}")})
   --##############################################################
   --##############################################################
   --##############################################################
   --##############################################################
   --##############################################################
   --button controlling processes section
   --button setup - this section for an on/off button
   local button_name="process"
   local blx=blx--bottom left x coordinate of click area, the .5 makes the 1 pixel box line sharp
   local bly=bly+height+2--bottom left x coordinate of click area
   local height=20--height of click area
   local width=60--width of click area
   --setup cpu section position, when setting up cpu function everything is relative to these points
   local process_blx=blx+width+15
   local process_bly=bly
   --##############################################################
   --calculate if click was inside box and set actions#############
   --best to keep the button calculations seperate to the actions##
   if localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]~=1 then
   buttons[tostring(button_name)]=1
   elseif localx>=blx and localx<=blx+width and localy<=bly and localy>=bly-height and buttons[tostring(button_name)]==1 then
   buttons[tostring(button_name)]=0
   elseif localx<blx and localx>blx+width and localy<bly and localy>bly-height and buttons[tostring(button_name)]~=1 then
   buttons[tostring(button_name)]=0 end
   --end of calculations ##########################################
   --mouseover ###
   if localnowx>=blx and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height-height then
   buttons[tostring(button_name.."mo")]=1
   elseif localnowx<blx or localnowx>blx+width or localnowy>bly or localnowy<bly-height-height then
   buttons[tostring(button_name.."mo")]=0
   end--mouseover ###

   if localnowx>=blx and localnowx<=blx+width and localnowy<=bly and localnowy>=bly-height then
   color={0,0,0,1}
   fill=1
   buttondraw(blx,bly,height,width,color,fill)
   --so that cpu isnt drawn twice
       if buttons[tostring(button_name)]~=1 then
       processsection(cores_blx,cores_bly)
       end
   end
   --##############################################################
   --button on off
   if buttons[tostring(button_name)]==1 then
   color={1,0,0,1} --if button is clicked on it will be drawn red
   fill=0
   buttondraw(blx,bly,height,width,color,fill)
   processsection(cores_blx,cores_bly) --HUH???
   else
   color={0,1,1,1}
   fill=0
   buttondraw(blx,bly,height,width,color,fill)
   end --button on off
   out({x=blx+5,y=bly-5,txt="Pro#:"..conky_parse("${processes}")})
   end --cpu section

When I do a "function " search I find: function cpusection but I don't find "function processsection" or anything similar but I see it all mixed up in the cpu section.

I see a "--setup cpu section position" but no "--setup process section position"

BRAIN FREEZE! 548741179754635.jpg


To #! or not to #!?  That is the question! | #! Forum Moderator
#! Conky = 16 Threads & the Conky Archives | Conky PitStop | OTHCG'er
StartPage -  protect your privacy | IcyBlack | LinuxBBQ

Offline

#7 2012-03-14 19:23:58

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

that is a drawback of the interaction
its not configured easily
im thinking about how to make it more "modular" but given the number of different permutations you could have (or want) for the time being these kinds of setups need to be on the bespoke side

i think i have an idea that could be based on setup tables... just enter info into the tables, do a bit of copying and pasting and you have your own setup, but thats a little ways away

the other thing is, as mentioned above

needs some cleaning up, can see some inconsistencies which are a simple result of messy script writing (what works is more important than how it looks when im starting out!)

real world has taken precedence today however...

Offline

#8 2012-03-14 20:54:20

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

Re: interactive conky

mrpeachy wrote:

that is a drawback of the interaction

needs some cleaning up, can see some inconsistencies which are a simple result of messy script writing (what works is more important than how it looks when im starting out!)

real world has taken precedence today however...

1. I realize it's in super-alpha but had to ask/mention it.
2. in my excitement I didn't see what you quoted.
3. Yea me too, after being out for 5 hours I just got home.

LOOK: (checking- yes interactive conky thread)
bc0f96179811192.jpg 5f76b0179811195.jpg
Second one for anyone that wants it.

Last edited by Sector11 (2012-03-14 20:54:52)


To #! or not to #!?  That is the question! | #! Forum Moderator
#! Conky = 16 Threads & the Conky Archives | Conky PitStop | OTHCG'er
StartPage -  protect your privacy | IcyBlack | LinuxBBQ

Offline

#9 2012-03-15 19:01:02

falldown
#! Samurai
Registered: 2011-09-01
Posts: 1,726

Re: interactive conky

The S-11 tux is cool as sh#! big_smile

Now I need to get my hands on the interactive launcher.. I have a few concepts that I want to throw at it.

Offline

#10 2012-03-16 03:10:15

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

here is the launcher script

--[[launcher icons

call in conkyrc in a similar manner to this above TEXT in addition to regular conky settings

lua_load ~/pathto/filename.lua
lua_draw_hook_pre draw_main

in the conkyrc you also need to add this setting

own_window_title clicky

or you can set your own window title then edit towards the bottom of the script
so that any instances of clicky are replaced with the title you set
avoid spaces in title name

]]

require 'cairo'
require 'imlib2'
start=1
buttons={}
buttons[1]=0
text_table={}
--------------------------------------------------------------------------------
function conky_main()
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
--#########################################################################################################
--get click coordinates
localx,localy=clickfunction()--dont edit
--##############################################
print (localx,localy)
--SETTINGS #####################################

icons={--enter locations of files enter command,icon_path
"/home/mcdowall/files/launcher/firefox.png",
"/home/mcdowall/files/launcher/gedit.png",
"/home/mcdowall/files/launcher/terminal.png",
"/home/mcdowall/files/launcher/gimp.png",
}
execute={
"firefox &",
"gedit &",
"gnome-terminal &",
"gimp &",
}

--set button top left corner coordinates and width/heioght
local main_tlx=20.5
local main_tly=20.5
local main_height=40
local main_width=40
--need to set the top left corner of the top button in the list
local list_height=40
local list_width=40
local list_start_deg=90
local list_deg_gap=30
local list_radius=80
--END OF SETTINGS ########################################
local number_in_list=#icons
--########################################################
--calculate if click was inside box
if localx>=main_tlx and localx<=main_tlx+main_width and localy>=main_tly and localy<=main_tly+main_height and buttons[1]~=1 then
buttons[1]=1
elseif localx>=main_tlx and localx<=main_tlx+main_width and localy>=main_tly and localy<=main_tly+main_height and buttons[1]==1 then
buttons[1]=0
elseif localx>main_tlx and localx>main_tlx+main_width and localy<main_tly and localy>main_tly+main_height and buttons[1]~=1 then
buttons[1]=0
end
if buttons[1]==1 then
image({x=main_tlx,y=main_tly,w=main_width,h=main_height,file="/home/mcdowall/files/launcher/off.png"})
elseif buttons[1]==0 then
image({x=main_tlx,y=main_tly,w=main_width,h=main_height,file="/home/mcdowall/files/launcher/on.png"})
end
cairo_set_source_rgba (cr,1,1,1,1)
--[[draw the box for positioning purposes, you can comment out the draw commands later
cairo_set_line_width (cr,1)
cairo_rectangle (cr,main_tlx,main_tly,main_width,main_height)
cairo_stroke (cr)--]]
--------------------------------------------------------------------------------------
--if the main button is clicked then all this stuff will happen
if buttons[1]==1 then 
        for i=1,number_in_list do --use a for loop to generate all the buttons with a single code chunk
        --calculate icon positions################################
        local point=(math.pi/180)*(list_start_deg+(list_deg_gap*(i-1)))
        local list_tlx=main_tlx+list_radius*(math.sin(point))
        local list_tly=main_tly-list_radius*(math.cos(point))
        --########################################################
        --calculate if click is inside buttons
        if localx>=list_tlx and localx<=list_tlx+list_width and localy>=list_tly and localy<=list_tly+list_height and buttons[tostring("button1_"..i)]~=1 then
        buttons[tostring("button1_"..i)]=1
        elseif localx>=list_tlx and localx<=list_tlx+list_width and localy>=list_tly and localy<=list_tly+list_height and buttons[tostring("button1_"..i)]==1 then
        buttons[tostring("button1_"..i)]=0
        end
        if buttons[tostring("button1_"..i)]==1 then
        os.execute(execute[i])
        n=i
            for i=1,number_in_list do
                buttons[tostring("button1_"..i)]=0
            end
            buttons[1]=0
        end
        image({x=list_tlx,y=list_tly,w=list_width,h=list_height,file=icons[i]})
        cairo_set_source_rgba (cr,1,1,1,1)
        --[[draw the box for positioning purposes, you can comment out the draw commands later
        cairo_set_line_width (cr,1)
        cairo_rectangle (cr,list_tlx,list_tly+((list_gap+height)*(i-1)),list_width,list_height)
        cairo_stroke (cr)--]]
    end--for loop
end--if main button=1

--#########################################################################################################
end-- if updates>5
cairo_destroy(cr)
cairo_surface_destroy(cs)
cr=nil
end--end main function

function string:split(delimiter)
local result = { }
local from = 1
local delim_from, delim_to = string.find( self, delimiter, from )
while delim_from do
table.insert( result, string.sub( self, from , delim_from-1 ) )
from = delim_to + 1
delim_from, delim_to = string.find( self, delimiter, from )
end
table.insert( result, string.sub( self, from ) )
return result
end--of function

function out(tx)--####################################################################
c=nil
c=(tx.c or default_color)
a=nil
a=(tx.a or default_alpha)
f=nil
f=(tx.f or default_font)
fs=nil
fs=(tx.fs or default_font_size)
x=nil
x=(tx.x or 0)
y=nil
y=(tx.y or 0)
txt=nil
txt=(tx.txt or "set txt")
local function col(c,a)
return ( (c/0x10000) % 0x100)/255,( (c/0x100) % 0x100)/255,(c % 0x100)/255,a
end--local function
cairo_select_font_face (cr, f, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
cairo_set_font_size (cr, fs)
cairo_set_source_rgba (cr,col(c,a))
cairo_move_to (cr,x,y)
cairo_show_text (cr,txt)
cairo_stroke (cr)
end--function out ###################################################################

function image(im)--#################################################################
x=nil
x=(im.x or 0)
y=nil
y=(im.y or 0)
w=nil
w=(im.w or default_image_width)
h=nil
h=(im.h or default_image_height)
file=nil
file=tostring(im.file)
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(w)==0 then 
width=imlib_image_get_width() 
else
width=tonumber(w)
end
if tonumber(h)==0 then 
height=imlib_image_get_height() 
else
height=tonumber(h)
end
imlib_context_set_image(show)
local scaled=imlib_create_cropped_scaled_image(0, 0, imlib_image_get_width(), imlib_image_get_height(), width, height)
imlib_free_image()
imlib_context_set_image(scaled)
imlib_render_image_on_drawable(x, y)
imlib_free_image()
show=nil
end--function image ##################################################################

function clickfunction()
--start click logging and calculations ##########################################
if start==1 then
xdot=conky_parse("${if_running xdotool}1${else}0${endif}")
    if tonumber(xdot)==1 then
    os.execute("/usr/bin/killall xdotool && echo 'xdo killed' &")
    end
os.execute("xdotool search --name clicky behave %@ mouse-click getmouselocation >> /tmp/xdo &")
start=nil--]]
local f = io.popen("xwininfo -name 'clicky' | grep 'Absolute'")
geometry = f:read("*a")
f:close()
geometry=string.gsub(geometry,"[\n]","")
s,f,abstlx=string.find(geometry,"X%p%s*(%d*)")
s,f,abstly=string.find(geometry,"Y%p%s*(%d*)")
end--if start=1 ######################################
--click calculations #################################
local f=io.open("/tmp/xdo")
click=f:read()
f:close()
    if click~=nil then
    local f = io.open("/tmp/xdo","w")
    f:write("")
    f:close() 
    end--if click=nil
if click==nil then click="x:0 y:0 " end
s,f,mousex=string.find(click,"x%p(%d*)%s")
s,f,mousey=string.find(click,"y%p(%d*)%s")
mousex=tonumber(mousex)
mousey=tonumber(mousey)
localx=mousex-abstlx
localy=mousey-abstly
--END CLICK CALCULATIONS #################################
return localx,localy
end--function

one difference here is that i have moved to storing the click outcomes in tables which gives me the ability to generate multiple buttons through a for loop with just one chunk of code

im using this code in the for loop

        local point=(math.pi/180)*(list_start_deg+(list_deg_gap*(i-1)))
        local list_tlx=main_tlx+list_radius*(math.sin(point))
        local list_tly=main_tly-list_radius*(math.cos(point))

to arrange the icons around the start button in a circle

ive written a bit about working with for loops in the lua how to which might help

basically what i have is the main button is an on/off button which then turnes on the outer buttons that are the execute buttons

Offline

#11 2012-03-16 03:22:22

falldown
#! Samurai
Registered: 2011-09-01
Posts: 1,726

Re: interactive conky

mrpeachy wrote:

basically what i have is the main button is an on/off button which then turnes on the outer buttons that are the execute buttons

That gives me a starting point to build from.. cool!!
I have been visiting the how-to a lot.. big_smile

Thanks for the script.. and post any suggestions that you have.

Offline

#12 2012-03-16 18:48:24

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

some progress

http://youtu.be/gbxyON3g2Dw

buttons are MUCH more configurable and easy to add remove adjust
working on the placement and rearrangements when buttons are clicked on/off

still have to come up with a format i like

Offline

#13 2012-03-16 18:54:31

falldown
#! Samurai
Registered: 2011-09-01
Posts: 1,726

Re: interactive conky

Keep me up on your improvements with the system monitor SirPeachy.!
I'm getting a

Conky: llua_do_call: function conky_main execution failed: attempt to call a nil value

with the system monitor lua.

I added

own_window_title clicky

and its your weather_conkyrc so I'm not sure what I'm overlooking here big_smile

Last edited by falldown (2012-03-16 19:14:24)

Offline

#14 2012-03-16 19:13:03

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

falldown wrote:

Keep me up on your improvements with the system monitor SirPeachy.!
I'm getting a

Conky: llua_do_call: function conky_main execution failed: attempt to call a nil value

with the system monitor lua.

I added

own_window_title clicky

and its your weather_conky so I'm not sure what I'm overlooking here big_smile

hmmm i do tend to recycle scripts, and occasionally things get left over fomr previous incarnations!

ill post the above scritpt in a bit, dont have access to it right now

Offline

#15 2012-03-16 19:21:53

falldown
#! Samurai
Registered: 2011-09-01
Posts: 1,726

Re: interactive conky

mrpeachy wrote:

hmmm i do tend to recycle scripts, and occasionally things get left over fomr previous incarnations!

ill post the above scritpt in a bit, dont have access to it right now

Ok Peachy.. I'm sure that I am just overlooking something here.

note: could you make a list of all the libs and tools that you have associated with conky. Not a big rush on that, but I think it might be useful for all of us followers big_smile

EDIT: Found the issue.. had a random "=]" smiley face out in the far reaches of X.. and sadly enough I probably put it there while posting on a forum. Yes I make silly mistakes like this all the time lol

Last edited by falldown (2012-03-16 19:41:08)

Offline

#16 2012-03-16 19:49:16

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

here is the new version
http://dl.dropbox.com/u/19008369/intera … lua.tar.gz

only things additional to conky required is

xdotool version 2.20110530.1
and
xwininfo

Offline

#17 2012-03-16 19:58:57

falldown
#! Samurai
Registered: 2011-09-01
Posts: 1,726

Re: interactive conky

mrpeachy wrote:

Cool cool.. lots of function notes and examples! looks like it was written just for me!! big_smile

Offline

#18 2012-03-17 18:24:48

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

some steps in the right direction

http://youtu.be/sAqfjj6HqTI

the buttons next to the processes button, M P C T

M is a mode button and switches from list ordered by current cpu to list by cpu time
P shows pid
C shows cpu usage
T shows time

script
http://dl.dropbox.com/u/19008369/intera … lua.tar.gz

Offline

#19 2012-03-17 21:05:59

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

and closer

http://youtu.be/6xvd_flp4qw

been able to achieve a good level of modularity
you copy and paste the button function
make some changes here and there and by doing so can easily add a new display section

still requires editing throughout the script, so would like to consolidate settings to the main function at the top

Offline

#20 2012-03-17 21:15:29

falldown
#! Samurai
Registered: 2011-09-01
Posts: 1,726

Re: interactive conky

Here is a rough look of how the launcher will turn out.. right now its just a non animated png..
167006180275132.jpg
I think it looks like a HUD in a starship  lol

Offline

#21 2012-03-17 21:17:28

VastOne
#! Ranger
From: V-Ger
Registered: 2011-04-26
Posts: 10,163
Website

Re: interactive conky

^That is amazing!  Wow!

What is that panel/launcher you are using bottom center?


VSIDO | Words That Build Or Destroy

We do not run from challenges, they become new innovations within VSIDO!

Offline

#22 2012-03-17 21:18:16

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

falldown wrote:

Here is a rough look of how the launcher will turn out.. right now its just a non animated png..
167006180275132.jpg
I think it looks like a HUD in a starship  lol

wow!, looks very professional
extremely nice work falldown, as ever

@ Vastone
thats falldows version of my conky launcher script big_smile

Last edited by mrpeachy (2012-03-17 21:19:53)

Offline

#23 2012-03-17 21:20:26

falldown
#! Samurai
Registered: 2011-09-01
Posts: 1,726

Re: interactive conky

mrpeachy wrote:

and closer

http://youtu.be/6xvd_flp4qw

been able to achieve a good level of modularity
you copy and paste the button function
make some changes here and there and by doing so can easily add a new display section

still requires editing throughout the script, so would like to consolidate settings to the main function at the top

HOLY COW PEACHY!! Options.. options and a side order of options..... then wash it down with a HUGE glass of options!! big_smile
It's looking really GOOD!

EDIT: I will grab your new script for system monitor.. after you get your consolidating done big_smile

Last edited by falldown (2012-03-17 21:30:15)

Offline

#24 2012-03-17 21:28:54

mrpeachy
20% cooler
From: The Everfree Forest
Registered: 2009-11-08
Posts: 3,460

Re: interactive conky

what i was thinking about with the circle launcher is to have a couple of buttons that would let you turn the circle
so you can access other programs by spinning the circle round

not entirely sure how to do that right now, but its on my to do list smile

Offline

Help fund CrunchBang, donate to the project!

#25 2012-03-17 21:34:21

falldown
#! Samurai
Registered: 2011-09-01
Posts: 1,726

Re: interactive conky

mrpeachy wrote:

what i was thinking about with the circle launcher is to have a couple of buttons that would let you turn the circle
so you can access other programs by spinning the circle round

not entirely sure how to do that right now, but its on my to do list smile

I was thinking that earlier today.. while messing with the start degree and gap. You can only have so many launchers+gap before they start to overlap.
The rotation function sounds like a good solution.

EDT: Peachy you know that if you can mouse-over and click in conky... you might be able to GRAB in conky.
Just a random thought. big_smile

Last edited by falldown (2012-03-17 21:41:49)

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