当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 1 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : awesome 在写入了几个wiki上的widget之后上面的状态条消失,
帖子发表于 : 2011-03-08 14:38 
头像

注册: 2010-03-16 12:34
帖子: 107
送出感谢: 0 次
接收感谢: 0 次
看了awesome的wiki,向rc。lua里添加了几个widget,-k 选项检查ok。 结果重新运行awesome之后,最上面的状态条消失了,
会不会是我没有安装 配置文件里require的“wicked”的缘故? 请高手指教。
(如果是wicked没有安装的缘故?那ubuntu的源里有吗?)
下面是我的 配置文件。 我只贴我修改的部分,其他的是默认的,就不浪费大家眼睛了。
代码:

-- load wicked for widgets
-- to see more about widget, you can "man wicked" after you installed wicket
require("wicked")

-- ---------------- Auto startup simple way  --------------
-- start network
awful.util.spawn_with_shell("conky")
awful.util.spawn_with_shell("nm-applet")
awful.util.spawn_with_shell("stardict")
-- If you want to run your apps only once and not every time awesome is restarted, create this simple script:
-- #! /bin/bash
-- # Run program unless it's already running.
-- if [ -z "`ps -Af | grep -o -w ".*$1" | grep -v grep | grep -v run-once`" ]; then
--   $@
--   fi
-- run_once in your $PATH and make it executable. then autostart
-- your apps like this:
--awful.util.spawn_with_shell("run_once firefox")
--
-- Alternatively you can use the following to avoid an external script (this also ignore commands running as other users than yourself):
-- function run_once(prg)
--     if not prg then
--         do return nil end
--     end
--     awful.util.spawn_with_shell("pgrep -f -u $USER -x " .. prg .. " || (" .. prg .. ")")
-- end
--
-- run_once("amarok")

-- Or this slightly more advanced version which permits to use command line options and to specify on which screen to launch your programs. It also allows for the case when the name of the process is different from the name of the command used to launch it (e.g. with wicd-client).
function run_once(prg,arg_string,pname,screen)
    if not prg then
        do return nil end
    end

    if not pname then
       pname = prg
    end

    if not arg_string then
        awful.util.spawn_with_shell("pgrep -f -u $USER -x '" .. pname .. "' || (" .. prg .. ")",screen)
    else
        awful.util.spawn_with_shell("pgrep -f -u $USER -x '" .. pname .. "' || (" .. prg .. " " .. arg_string .. ")",screen)
    end
end

-- run_once("xscreensaver","-no-splash")
-- run_once("empathy",nil,nil,2)
-- run_once("wicd-client",nil,"/usr/bin/python2 -O /usr/share/wicd/gtk/wicd-client.py")




-- Table of layouts to cover with awful.layout.inc, order matters.
layouts =
{
    awful.layout.suit.floating,
    awful.layout.suit.tile,
    awful.layout.suit.tile.left,
    awful.layout.suit.tile.bottom,
    awful.layout.suit.tile.top,
    awful.layout.suit.fair,
    awful.layout.suit.fair.horizontal,
    awful.layout.suit.spiral,
    awful.layout.suit.spiral.dwindle,
    awful.layout.suit.max,
    awful.layout.suit.max.fullscreen,
    awful.layout.suit.magnifier
}
-- }}}


-- ---------------------   widget  -----------------------
-- how to creat a widget :
-- invoke fun widget() to Create a widget , set value to invoke wicked.register() . then creat a wibox to put widget in this wibox.
-- EXAMPLE:
-- memwidget = widget({
--     type = 'textbox'
--     name = 'memwidget'
-- })
-- wicked.register(memwidget, wicked.widgets.mem,
--     ' <span color="white">memory:</span> $1 ($2mb/$3mb)')
-- mystatebar = wibox( {position = "bottom", fg = beautiful.fg_normal, bg = beautiful.bg_normal} )
-- mystatebar.widgets = {
--     memwidget,
-- }
--     -- if you only have one screen
-- mystatebar.screen = 1

-- some widgets:
-- {{{ current time }}}
datewidget = widget({
    type = 'textbox',
    name = 'datewidget'
})

wicked.register(datewidget, wicked.widgets.date,
    ' <span color="white">date:</span> %c')
-- {{{mpd}}}
mpdwidget = widget({
    type = 'textbox',
    name = 'mpdwidget'
})
    -- only when the mpd daemon is running.
wicked.register(mpdwidget, wicked.widgets.mpd,
    function(widget, args)
        if args[1]:find("volume:") == nil then
            return ' <span color="white">now playing:</span> '..args[1]
        else
            return ''
        end
    end)
-- {{{ram monitor}}}
memwidget = widget({
    type = 'textbox',
    name = 'memwidget'
})

wicked.register(memwidget, wicked.widgets.mem,
    ' <span color="white">memory:</span> $1 ($2mb/$3mb)')
-- {{{ram bar }}}
membarwidget = widget({
    type = 'progressbar',
    name = 'membarwidget',
    align = 'right'
})

membarwidget:properties_set('mem', {
    width = 40,
    height = 0.65,
    gap = 0,
    border_padding = 1,
    border_width = 1,
    ticks_count = 0,
    ticks_gap = 0,
    vertical = false
})

membarwidget:bar_properties_set('mem', {
    bg = '#222222',
    fg = '#285577',
    fg_center = '#285577',
    fg_end = '#285577',
    fg_off = '#222222',
    reverse = false,
    min_value = 0,
    max_value = 100
})

wicked.register(membarwidget, wicked.widgets.mem, '$1', 1, 'mem')
{{{cpu}}}
cpuwidget = widget({
    type = 'textbox',
    name = 'cpuwidget'
})

wicked.register(cpuwidget, wicked.widgets.cpu,
    ' <span color="white">cpu:</span> $1%')
-- {{{cpu graph}}}
cpugraphwidget = widget({
    type = 'graph',
    name = 'cpugraphwidget',
    align = 'right'
})

cpugraphwidget.height = 0.85
cpugraphwidget.width = 45
cpugraphwidget.bg = '#333333'
cpugraphwidget.border_color = '#0a0a0a'
cpugraphwidget.grow = 'left'

cpugraphwidget:plot_properties_set('cpu', {
    fg = '#aec6d8',
    fg_center = '#285577',
    fg_end = '#285577',
    vertical_gradient = false
})

wicked.register(cpugraphwidget, wicked.widgets.cpu, '$1', 1, 'cpu')
-- {{{ file system }}}
fswidget = widget({
    type = 'textbox',
    name = 'fswidget'
})

wicked.register(fswidget, wicked.widgets.fs,
    ' <span color="white">fs:</span> ${/ used}/${/ size} (${/ usep} used)', 120)
-- {{{network monitor}}}
netwidget = widget({
    type = 'textbox',
    name = 'netwidget'
})

wicked.register(netwidget, wicked.widgets.net,
    ' <span color="white">net</span>: ${eth0 down} / ${eth0 up} [ ${eth0 rx} //  ${eth0 tx} ]',
nil, nil, 3)
-- {{{ battery }}}
settings.batteries = 2

-- label
batterywidget = widget({type = 'textbox',
                        name = 'batterywidget',
                        align = 'right'})
wicked.register(batterywidget, function() return {} end,
                settings.widget_separator ..
                   beautiful.markup.heading('bat') ..
                settings.widget_spacer,
                nil, nil, 500)
table.insert(settings.widgets, {1, batterywidget})

-- function to extract charge percentage
function read_battery_life(number)
   return function(format)
             local fh = io.popen('acpi')
             output = fh:read("*a")
             fh:close()

             count = 0
             for s in string.gmatch(output, "(%d+)%%") do
                if number == count then
                   return {s}
                end
                count = count + 1
             end
          end
end

-- display one vertical progressbar per battery
for battery=0, settings.batteries-1 do
   batterygraphwidget = widget({ type = 'progressbar',
                                 name = 'batterygraphwidget',
                                 align = 'right' })
   batterygraphwidget.height = 0.85
   batterygraphwidget.width = 8
   batterygraphwidget.bg = '#333333'
   batterygraphwidget.border_color = '#0a0a0a'
   batterygraphwidget.vertical = true
   batterygraphwidget:bar_properties_set('battery',
                                         { fg = '#aec6d8',
                                           fg_center = '#285577',
                                           fg_end = '#285577',
                                           fg_off = '#222222',
                                           vertical_gradient = true,
                                           horizontal_gradient = false,
                                           ticks_count = 0,
                                           ticks_gap = 0 })

   wicked.register(batterygraphwidget, read_battery_life(battery), '$1', 1, 'battery')
   table.insert(settings.widgets, {1, batterygraphwidget})

   spacewidget = widget({type = 'textbox',
                           name = 'spacewidget',
                           align = 'right'})
   wicked.register(spacewidget, function() return {} end,
                   settings.widget_spacer,
                   nil, nil, 500)
   table.insert(settings.widgets, {1, spacewidget})
end

-- {{{ volume }}}
-- the following example displays the volume from alsa (gotten by running the `amixer` command and parsing the output), every 4 seconds. (note: requires alsa-utils)
volumewidget = widget({
    type = 'textbox',
    name = 'volumewidget'
})

function amixer_volume(format)
   local f = io.popen('amixer get pcm')
   local l = f:lines()
   local v = ''

   for line in l do
       if line:find('front left:') ~= nil then
            pend = line:find('%]', 0, true)
            pstart = line:find('[', 0, true)
            v = line:sub(pstart+1, pend)
       end
   end

   f:close()

   return {v}
end


wicked.register(volumewidget, amixer_volume, "<span color='white'>volume</span>: $1", 4)
-- you can use the following to run any external script you might have written that collects data and outputs it:
mywidget = widget({
    type = 'textbox',
    name = 'mywidget'
})
 
function run_script()
    local filedescriptor = io.popen('my_nifty_script.py')
    local value = filedescriptor:read()
    filedescriptor:close()

    return {value}
end
 
-- runs 'my_nifty_script.py' every 10 seconds and puts its output into the widget
wicked.register(mywidget, run_script, "$1", 10)

-- -----awesome suspended  ---------------
-- 因为awesome在继续运行之前会等待lua脚本借书,因此运行一个缓慢的脚本很可能会让你的整个awesome反应迟钝。你可以用一个后台线程或者是临时文件来避免这个问题。通过下面的方法来运行一个缓慢的脚本可以避免阻塞awesome:
mywidget = widget({
    type = 'textbox',
    name = 'mywidget'
})

function run_slow_script (widget, args)
   -- read the temporary file left by the script
   local filedescriptor = io.open('/tmp/script-temp-file')
   local value = nil

   if filedescriptor ~= nil then
      value = filedescriptor:read()
   end

   filedescriptor:close()

   if value == nil then
      return {''}
   else
      return {value}
   end
end

-- runs 'my_slow_script.py' every 10 seconds and puts its output into the widget
wicked.register(mywidget, run_slow_script, "$1", 10)

-- register a timer to run every 9 seconds
awful.hooks.timer.register(9, mywidget_timer)

-- use the timer to fill the temporary file
function mywidget_timer ()
   os.execute('my_slow_script.py > /tmp/script-temp-file &')
end

-- suspend wicked ---------
-- 如果你很在意电池的使用时间,那么你可能更希望wicked在你的电脑处于电池供电状态的时候不要一直运行命令。你可以通过绑定命 令"wicked.suspend()"来临时停止所有wicked的更新。你可以使用"wicked.activate()"来重新激活被挂起的 wicked。
--  你可以在hal脚本之类的地方使用awesome-cliend来自动调用这些命令。你可以像这么调用:
-- #!/bin/bash
-- echo "wicked.suspend()" | awesome-client
-- 把suspend在hal脚本的适当的地方换成activate就可以自动唤醒挂起的wicked了。


_________________
My Blog: http://stardiviner.tumblr.com/


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 1 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 1 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译