SEARCH

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

You are not logged in.

#26 2015-03-14 10:10:41

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky Switcher (Pipe Menu)

Offline

Help fund CrunchBang, donate to the project!

#27 2015-03-14 10:48:54

woodape
#! CrunchBanger
From: Cape Town, South Africa
Registered: 2014-03-27
Posts: 113

Re: Conky Switcher (Pipe Menu)

   if len(sys.argv) == 1:

Last edited by woodape (2015-03-14 10:57:43)

Offline

#28 2015-03-14 12:18:29

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky Switcher (Pipe Menu)

Offline

#29 2015-03-14 13:49:48

woodape
#! CrunchBanger
From: Cape Town, South Africa
Registered: 2014-03-27
Posts: 113

Re: Conky Switcher (Pipe Menu)

So here's everything under one roof. I've taken out the sub-menus and added in the single-click feature with the 'Kill / Load' prefix as suggested by @smacz.

So first, make the conky_restore script executable and call it from openbox autostart:

#!/bin/bash
while read config ; do
    conky -q -c "$config" &
    sleep 1s
done < "$HOME/.conky/session.log"
exit 0

Then here is the full "bl-conky-switcher-pipemenu.py"

#!/usr/bin/env python
#
#  A conky config switcher openbox pipe menu
#  by Wesley Werner (kbmonkey)
#
#  Builds a menu from .conky files found under ~/.conky.
#  Clicking a menu item will restart conky with the -c option.
#  
#  HISTORY
#  2015-03-01
#       First version: basic switching
#
#  2015-03-13
#       + Support for multiple conkys
#       + Persist across sessions
#       (Thanks to woodape and detinith for these features!)
#  2015-03-14
#       + Added 'Kill / Load' to indicate which conky groups are open or closed
#  TODO
#  + Highlight the current config in the openbox menu
#
#  -----------------------------------------------------------------
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program. If not, see http://www.gnu.org/licenses/.
import os
import sys
import subprocess
from xml.sax.saxutils import escape

THISFILE = sys.argv[0]
USERHOME = os.path.expanduser('~')
CONFIGSHOME = os.path.join(USERHOME, '.conky')
CONFIGFILES = None

def grabConfigFiles(parentPath):
    """
    Gets a list of all .conky files under the given path.
    Returns: list(str)
    """

    for root, dirs, files in os.walk(parentPath):
        for file in files:
            if file.endswith(".conkyrc"):
                 yield os.path.join(root, file)

def buildConkyMenuItem(configPath):
    """
    Build an openbox menu item tag from the given config file path.
    Returns str
    """    

    file = open(os.path.join(CONFIGSHOME,'session.log'),"r")
    lines = file.readlines()
    file.close()
    killit = 0
    for line in lines:
        if os.path.dirname(line) == str(configPath):
            killit = 1
            break
    if killit == 1 :
        status = 'Kill '
    else:
        status = 'Load '

    menuFormat = """
        <item label="%(label)s">' 
            <action name="Execute">
                <command>
                    %(thisexecutable)s "%(configpath)s"
                </command>
            </action>
        </item>
    """

    nameWithoutExt = os.path.splitext(os.path.basename(configPath))[0]
    return menuFormat % { 
        'thisexecutable': escape(THISFILE),
        'label': status + escape(nameWithoutExt), 
        'configpath': escape(configPath)}

def addHelpMenuItem():
    """
    Inserts a Help menu item.
    """
    
    return '<separator label="La la" /><item label="Help"></item>'
    
    
if __name__ == "__main__":
    
    if not os.path.exists(CONFIGSHOME):
        print('<openbox_pipe_menu><item label="Place your .conky files under ~/.conky to use this switcher."></item></openbox_pipe_menu>')
        sys.exit(0)

    if len(sys.argv) == 1:
        CONFIGFILES = list(grabConfigFiles(CONFIGSHOME))
        CONFIGDIRS = []
        for file in CONFIGFILES:
            CONFIGDIRS.append(os.path.dirname(file))
        CONFIGDIRS = list(set(CONFIGDIRS))
        CONFIGDIRS.sort()
        print('<openbox_pipe_menu>')
        for configdir in CONFIGDIRS:
            print(buildConkyMenuItem(configdir))
        print("""
        <separator/>
        <item label="Kill All">
            <action name = "Execute">
                <execute>sh -c 'killall conky ;amp;amp echo "" > $HOME/.conky/session.log'</execute>
            </action>
        </item>
        """)
        print('</openbox_pipe_menu>')
    else:
        configFiles = list(grabConfigFiles(sys.argv[1]))
        file = open(os.path.join(CONFIGSHOME,'session.log'),"r")
        lines = file.readlines()
        file.close()
        for configFile in configFiles:
            killit = 0
            for line in lines:
                if line == str(configFile) + "\n":
                    killit = 1
                    break

            if killit == 1:
                ckill="conky -q -c " + configFile
                subprocess.Popen(['pkill', '-xf', ckill ])
                file = open(os.path.join(CONFIGSHOME,'session.log'),"w")
                for line in lines:
                    if line != str(configFile) + "\n":
                        file.write(line)
                file.close()
                file = open(os.path.join(CONFIGSHOME,'session.log'),"r")
                lines = file.readlines()
                file.close()
            else:
                subprocess.Popen(['conky','-q','-c', configFile])
                file = open(os.path.join(CONFIGSHOME,'session.log'),"a")
                file.write(configFile + "\n")
                file.close()

Check it out!

Last edited by woodape (2015-03-14 14:43:58)

Offline

#30 2015-03-15 05:28:40

smacz
#! Junkie
Registered: 2014-12-09
Posts: 250

Re: Conky Switcher (Pipe Menu)

for root, dirs, files in os.walk(parentPath):
        for file in files:
            if file.endswith(".conkyrc"):
                 yield os.path.join(root, file)

Offline

#31 2015-03-15 05:55:55

kbmonkey
#! Die Hard
From: South Africa
Registered: 2011-01-14
Posts: 879
Website

Re: Conky Switcher (Pipe Menu)

Offline

#32 2015-03-15 06:05:43

smacz
#! Junkie
Registered: 2014-12-09
Posts: 250

Re: Conky Switcher (Pipe Menu)

Yep. Much love. I was working on my own pygobject implementation of this kind of thing for about a week leading up to your post. I scrapped it as soon as I saw what you started. Any chance we can get this up on github anytime soon? If no one has any objections, I'm sure the repos would benefit (with the powers' that be approval of course) from including this.

Offline

#33 2015-03-15 06:39:15

kbmonkey
#! Die Hard
From: South Africa
Registered: 2011-01-14
Posts: 879
Website

Re: Conky Switcher (Pipe Menu)

Updated the original post with the latest from woodape (Load/Kill menus).

I am enjoying how the scope and ideas for this is changing so rapidly, this is fun smile

@smacz thanks for your input. How far did you get with your pygobject implementation? I can fork the BunsenLab repository and include this pipemenu, but even so a pull request will only be feasible after a week (or a few) of running with this to see how it performs in terms of user experience and usability (ahem bugs).

Edit: No - the Load/Kill toggling in the menus replace the disabled menu items (with batteries included IMO)

Oh my hat I wish I had a whole day to play around with this - will be back in a day or two  angel

Last edited by kbmonkey (2015-03-15 06:40:49)

Offline

#34 2015-03-15 07:37:18

smacz
#! Junkie
Registered: 2014-12-09
Posts: 250

Re: Conky Switcher (Pipe Menu)

 conky -qc ./bl-left.conky

Last edited by smacz (2015-03-15 08:21:30)

Offline

#35 2015-03-15 12:42:31

woodape
#! CrunchBanger
From: Cape Town, South Africa
Registered: 2014-03-27
Posts: 113

Re: Conky Switcher (Pipe Menu)

#!/bin/bash
while read config ; do
	if [ "$config" != "0" ] && [ "$config" != "1" ] ; then
		conky -q -c "$config" &
		sleep 3s
	fi
done < "$HOME/.config/conky/session.log"
exit 0

Last edited by woodape (2015-03-16 18:23:16)

Offline

#36 2015-03-15 14:59:25

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky Switcher (Pipe Menu)

Offline

#37 2015-03-15 15:32:54

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: Conky Switcher (Pipe Menu)

Offline

#38 2015-03-15 15:36:46

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky Switcher (Pipe Menu)

pkill -xf "conky -c $HOME/.config/conky/bl-right.conky"

Offline

#39 2015-03-15 15:48:34

woodape
#! CrunchBanger
From: Cape Town, South Africa
Registered: 2014-03-27
Posts: 113

Re: Conky Switcher (Pipe Menu)

Offline

#40 2015-03-15 16:07:16

woodape
#! CrunchBanger
From: Cape Town, South Africa
Registered: 2014-03-27
Posts: 113

Re: Conky Switcher (Pipe Menu)

pkill -xf "conky -c $HOME/.config/conky/bl-right.conky"

Offline

#41 2015-03-15 16:08:35

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky Switcher (Pipe Menu)

Offline

#42 2015-03-15 16:56:17

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky Switcher (Pipe Menu)

45 CONFIGSHOME = os.path.join(USERHOME, '.config','conky')

Offline

#43 2015-03-16 03:43:53

johnraff
nullglob
From: Nagoya, Japan
Registered: 2009-01-07
Posts: 4,148
Website

Re: Conky Switcher (Pipe Menu)

Offline

#44 2015-03-16 07:29:45

Head_on_a_Stick
CatMod
From: A world of pure imagination
Registered: 2014-01-21
Posts: 4,797

Re: Conky Switcher (Pipe Menu)

Offline

#45 2015-03-16 13:31:08

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky Switcher (Pipe Menu)

xyz="something"

Offline

#46 2015-03-16 14:10:25

detinith
New Member
From: South Florida
Registered: 2014-11-06
Posts: 9

Re: Conky Switcher (Pipe Menu)

Hey guys, I've finally been able to read up on this thread @woodape keeps telling me about. After reading through the thread and updating my understanding of the program a bit, I think I can help contribute now haha.

@Sector11:

45 CONFIGSHOME = os.path.join(USERHOME, '.config','conky')

At this line, change it to this:

45 CONFIGSHOME = os.path.join(USERHOME, '.conky')

You will get your own functionality. There are no hardcoded mentions of "~/.config/conky" present, it all refers to that variable CONFIGSHOME. Changing it should be fine.

I'm also rephrasing a lot of the code to be more "python", as well as restructuring some parts to be less redundant (there are a couple locations I've seen so far). And for all of you who would also like to contribute, I'll have a fully commented script either later tonight or tomorrow to post here. This wall of code will need to be mapped out!

One such change is incorporating those preferences of @Sector11 and @kbMonkey, namely making two new variables initialized at the beginning of the script that will allow custom conky config extensions and directory to be changed once and apply throughout the code rather than find/replacing everything.

Hopefully this will become a monster, then a tame monster.


The only thing like me is me. - Rocket

Offline

#47 2015-03-16 16:47:12

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky Switcher (Pipe Menu)

45 CONFIGSHOME = os.path.join(USERHOME, '.config','conky')

Last edited by Sector11 (2015-03-16 17:01:28)

Offline

#48 2015-03-16 18:20:48

woodape
#! CrunchBanger
From: Cape Town, South Africa
Registered: 2014-03-27
Posts: 113

Re: Conky Switcher (Pipe Menu)

45 CONFIGSHOME = os.path.join(/media/5, 'BL-conky')

Last edited by woodape (2015-03-16 18:24:29)

Offline

#49 2015-03-16 19:00:46

Sector11
#!'er to BL'er
From: SR11 Cockpit
Registered: 2010-05-05
Posts: 15,667
Website

Re: Conky Switcher (Pipe Menu)

"bl-conky-switcher-pipmenu.py resume" 

Offline

Be excellent to each other!

#50 2015-03-17 05:13:19

smacz
#! Junkie
Registered: 2014-12-09
Posts: 250

Re: Conky Switcher (Pipe Menu)

Last edited by smacz (2015-03-18 08:34:17)

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.
Server: acrobat

Debian Logo