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)

OK, I want to try this new script.  Which post has it?  It's getting confusing?

Does it still require separate directories for each conky?I have to show this again.
pipemenu
Now you are getting into "sub-menus" to do what a simple click might be able to do.


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

Be excellent to each other!

#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)

Sector11 wrote:

OK, I want to try this new script.  Which post has it?  It's getting confusing?

It is getting confusing, there are multiple contributors and perhaps ideas about what the code should be. Maybe it belongs on github instead?

To get it running though, grab the code in the main post by kbmonkey, then follow my post that has "First we'll import a new library at the top of the code:" Replace the 'menuFormat' variable with the one in my post, then find the line

   if len(sys.argv) == 1:

in kbmonkey's code. It should be around line 98. Replace this line to the bottom with the code I posted and you should be good to go.

Sector11 wrote:

Does it still require separate directories for each conky?

Yes, this allows for groups of conkies to be executed together.

woodape wrote:

With the code as is you only need 5 conky directories. Also, what if you had a pair of conkies you always launched together? Without the directory structure that means 'right click -> conky switcher -> conky1 -> Add' , then 'right click -> conky switcher -> conky2 -> Add'. With the directory structure, it is just 'right click -> conky switcher -> group1 -> Add'.

Sector11 wrote:

Now you are getting into "sub-menus" to do what a simple click might be able to do.

A simple click would certainly be able to do both of these functions, but like I said:

woodape wrote:

I wonder though if the single click action would take away functionally that might be wanted in the future. Right now with each conky group as a menu, further items/menus could be added to each conky group menu later down the line. For instance a menu like "Add to Group" which lists all the available groups and then when one is clicked, symbolic-links to all the conkies in the current group are created in the group selected.

However, if for aesthetic reasons you just want the one click action, it could be done easily, but maybe we should wait until the highlighting thing gets sorted? Or else the highlighting can be forgone in favor of @smacz's suggestion of changing the item names conditional on which ones are running. This could be implemented by some conditional logic based on the session.log file.

Edit: Also for persistent conkies across sessions save the following code, make it executable, and source it in your Openbox autostart file:

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

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)

Well, if I have to pick and choose code from multiple posts  - I'll sit back and watch.  It's getting way to complicated for me.

No offence but the idea that each conky needs to be in it's own directory seem silly to me when it's not necessary. {opinion}

There are two ways a script can work:

  1. one click to kill a conky - another click to start the same conky

  2. one click to kill the conky and restart it

I love the idea of the pipemenu
- and @smacz's suggestion of changing the item names conditional on which ones are running sounds perfect

My autostart file now calls up a script that starts 13 conkys

  • 3 on desktop #4 - only seen on desktop #4

  • 2 on desktop #2 - only seen on desktop #2

  • 8 on desktop #1

    • 4 in windows - only seen on desktop #1 - read and closed

    • 2 only seen on desktop #1

    • 2 seen on all desktops

At anytime during the day if I call that script (OB Menu item) it kills all conkys and sets them up again.
I can also kill each individually and restart them individually. but it's a messy OB Menu section

{/lurk mode}


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

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)

Tried out the modified code. I see that you are basing your Kill/Load prefix determination off of the conkys that are indicated to be running in the session.log file. Very nice. That functionality seems to be working excellently!

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

In the code under the 'grabConfigFiles' function,  I see that you require conky files to use a ".conkyrc" extension. Without changing my files, they do not show up in either obmenu as options or terminal output as .xml menu code. Changing them to the extension specified by the code (.conky --> .conkyrc) does cause them all to show up. In the first post @kbmonkey specified that in order to start 'er up:

kbmonkey wrote:

Simply drop any new conky configs into ~/.conky. Use a ".conky" file name extension - the use of directories is encouraged.

Changing the code to make it use ".conky" extensions rather than ".conkyrc" extensions works exactly as expected with files ending in ".conky". Or on the flip side, changing the filenames to .conkyrc is kind of a cute homage to the old setup. Either way, they just have to match in order for the code to work, and work it does!

Also, IIRC @johnraff stated that anything that could be migrated into the `~/.config/` directory should be, so would this be a chance to push `~/.conky/` to `~/.config/conky/`? Since we're not using the default `~/.conkyrc` functionality, I don't believe that it would really matter either way.

Lastly, with the Kill/Load prefix implemented, is there really any call to have the running conkys highlighted?
(I'm invoking Betteridge's Law of Headlines here)

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)

Wow this is amazing... everyone seems to dig this pipemenu smile

The Load/Kill toggling is much nicer than the sub-menus, kudos @woodape for adding all of that! It is working well here. (Noted the rename to .conkyrc - thumbs up)

It got a bit confusing for a moment because I think we all had a different idea of how we organise our conky configs. This new mechanism of Loading configs satisfies both use-cases (single or combined running configs). Wonderful!

I am excited to go through the code and learn what has changed, still out of town and doubt I will get a moment today, but looking forward to it! I will update the OP with this code above, and for learning sake: mapping string formats by key-value pairs is available for Python 2 and up smile

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  O:)

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)

@kbmonkey By all means! I love playing end user. Truth is, #! was my "Look how cool this Linux thing is" go-to distro, and in my day job, I have to anticipate my client's problems before they can stumble onto them, so this is just playtime for me...

51785756.jpg

And I don't think I can make a good farting noise on a forum, but I would if I could in regards to my pygobject project.

I can think of one sticking point for this current incarnation though. Any conky not started by this program will not be logged into the `session.log` file. That will then not show up on the menu as a running conky, and the menu will then give you a prompt to RUN that conky instead of kill it. I demo'd this out, and it will let you run it again, and then after running it via the menu a second time, it will then (and only then) give you an option to kill it. Selecting the option to kill it at that point only kills the second instance. The instance started previously (I had started it via the command line) was not killed with that command. See #1 below

At this moment I envision one of two ways of dealing with this.
1) The kill/load command is based off of /proc and the pid (instead of session.log -- which would be way messier) and can (automagically) see if a similar (if not the exact same command) is already running and report that when obmenu fires up. OR:
2) Based on session.log (but can detect if/when `conky -c *` is run and store to session.log? Sorry, I totally had a grasp on an alternative but it slipped my mind. I blame it on the Jameson. Umm...a command logger maybe? That seems like it'd be needlessly dangerous though.)

Either way, I need it to "see" what I see. If I start `bl-left` via the script and `cb-right` via command line I can't have it prompting me to start `cb-right` again. I "see" them both on my desktop...why wouldn't my menu see that too? I need to be able to kill `cb-right` at that point.

EDIT: I have not tried this (nor can I) with multiple monitors.

#1) Caveat: I had started the command in the conky's directory, so my command looked like:

 conky -qc ./bl-left.conky

So of course looking for a process containing `/home/smacz42/.conky/bl-left/bl-left.conky` was not found (by the script) to be killed. Nevertheless, there was a duplicate instance of that same exact conky that the script did not recognize needed to be killed. I would consider that a bug.

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)

smacz wrote:

In the code under the 'grabConfigFiles' function,  I see that you require conky files to use a ".conkyrc" extension.

Yes, the default extension for a conky file is .conkyrc, so i figured it would be a better suffix.

smacz wrote:

lso, IIRC @johnraff stated that anything that could be migrated into the `~/.config/` directory should be, so would this be a chance to push `~/.conky/` to `~/.config/conky/`? Since we're not using the default `~/.conkyrc` functionality, I don't believe that it would really matter either way.

I've updated this in my version below. It seems like a good idea to me. I prefer as few folders in my home directory as possible.

kbmonkey wrote:

kudos @woodape for adding all of that!

No problem, I've got some more below wink

kbmonkey wrote:

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

I know! I'm loving the idea, it'd be nice to get it into BL.

smacz wrote:

I can think of one sticking point for this current incarnation though. Any conky not started by this program will not be logged into the `session.log` file. That will then not show up on the menu as a running conky, and the menu will then give you a prompt to RUN that conky instead of kill it.

Eish, yea I ran into the same sticking point. Some people have large conky setups already in play, e.g. the layout Sector11 discussed before, and it would be a pain for them to have to launch all of those from this script to get the functionality. I think the way to go is probably to get the script to detect any running instances of conky and offer to kill them, but only offer to load the ones in '~/.config/conky/*'. Also, as Sector11 has said, it is a pain to have to make directories for conkies that are just one file...

...so I've added a bit more to the script... There is now a toggle for 'Load / Kill' mode and 'Replace' mode, the ability to kill running conkies that weren't started with this script ( or rather, any conky not listed in 'session.log'), and it now recognizes individual conkies in the '~/.config/conky/' directory in the same way as directories. So any conkies in a subdirectory of '~/.config/conky/' will be launched as a group, while any individual *.conkyrc files in '~/.config/conky/' are launched individually.

The script doesn't consider anything not in '~/.config/conky/*' as something to be managed, so if a conky is started outside of this script and outside of this directory, I think the only option that should be provided is to kill it. With the script below, even if the config file is under '~/.config/conky/*', if it is started outside of the script (not in 'session.log') it will ask if you want to kill it, but still ask if you want to load it. Confusing - yes. I think there needs to be a distinction between scripts that are 'managed' and 'unmanaged' though. One way to do this would be to treat all conkies not launched with the script as not related to ones that are 'managed', even if they are one in the same *.config file.

The toggle for 'Load / Kill' mode and 'Replace' mode puts a '0' or a '1', respectively, at the end of the 'session.log' file to detect which mode is active.

This requires a change to the "bl-conky-switcher-pipemenu-resume.sh" file:

#!/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

And here is the now very long "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 CONFIGSHOME.
#  Clicking a menu item will restart conky with the -q -c options.
#  
#  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
#  2015-03-15
#       + Added Toggle for 'Load / Kill' mode and 'Replace' mode
#       + Added support for single conkies in CONFIGSHOME
#       + Added ability to kill open conkies not managed in 'session.log'
#  TODO
#       ?
#  -----------------------------------------------------------------
#  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, '.config','conky')
CONFIGFILES = None
LOGFILE = os.path.join(CONFIGSHOME,'session.log')

def openConky():
    command='ps -C conky -o cmd'
    psconky=subprocess.Popen(command.split(),stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    output=psconky.communicate()[0]
    openconfigs=[]
    for line in output.split('\n'):
        if line == 'CMD':
            pass
        elif line == '':
            pass
        else:
            line0=line.split('/',1)
            openconfigs.append('/'+line0[1])

    openconfigs.sort()
    return openconfigs

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 buildSpecialItems():
    """
    Build a menu for the special items, e.g. Killall, and Load/Replace toggle
    """
    if TOGGLE == "0\n" :
        status = 'Toggle Replace'
        tchar = "0"
    else:
        status = 'Toggle Load / Kill'
        tchar = "1"

    itemFormat = """
        <separator/>
        <item label="Kill All">
            <action name = "Execute">
                <execute>
                    sh -c 'killall conky'
                </execute>
            </action>
            <action name = "Execute">
                <execute>
                    sh -c 'echo "%(toggle)s" > %(sessionlog)s'
                </execute>
            </action>
        </item>
        <item label="%(label)s">
            <action name = "Execute">
                <command> 
                    %(thisexecutable)s "toggle" 
                </command>
            </action>
        </item>
    """

    return itemFormat % { 
        'thisexecutable': escape(THISFILE),
        'label': status, 
        'sessionlog': LOGFILE,
        'toggle': tchar}

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

    if unmanaged == 1:
        status = 'Kill '
    else:
        if TOGGLE == "0\n":
            file = open(LOGFILE,"r")
            lines = file.readlines()
            file.close()
            killit = 0

            if os.path.isfile(configPath):
                for line in lines:
                    if str(line) == str(configPath+'\n'):
                        killit = 1
                        break
            else:
                for line in lines:
                    if os.path.dirname(line) == str(configPath):
                        killit = 1
                        break

            if killit == 1 :
                status = 'Kill '
            else:
                status = 'Load '
        else:
            status = ''

    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 os.path.isfile(LOGFILE):
        file = open(LOGFILE,"r")
        TOGGLE = file.readlines()[-1]
        file.close()
    else:
        file = open(LOGFILE,"w")
        file.write('0\n')
        file.close()
        TOGGLE = '0\n'

    OPENCONFIGS = openConky()
    file = open(LOGFILE,"r")
    LOGLINES = file.readlines()
    file.close()

    if not os.path.exists(CONFIGSHOME):
        print('<openbox_pipe_menu><item label="Place your .conky files under '+CONFIGSHOME+' 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:
            if  os.path.dirname(file) == CONFIGSHOME:
                CONFIGDIRS.append(file)
            else:
                CONFIGDIRS.append(os.path.dirname(file))


        CONFIGDIRS = list(set(CONFIGDIRS))
        CONFIGDIRS.sort()
        print('<openbox_pipe_menu>')
        for configdir in CONFIGDIRS:
            print(buildConkyMenuItem(configdir,0))

        addseparator = 0
        for configdir in OPENCONFIGS:
            if str(configdir+'\n') not in LOGLINES:
                    addseparator = 1
        if addseparator == 1:
            print('<separator/>')

        for configdir in OPENCONFIGS:
            if str(configdir+'\n') not in LOGLINES:
                    print(buildConkyMenuItem(configdir,1))
        print(buildSpecialItems())
        print('</openbox_pipe_menu>')

    else:
        if sys.argv[1] == "toggle":
            configFiles = list(grabConfigFiles(sys.argv[1]))
            file = open(LOGFILE,"w")
            for line in LOGLINES:
                if line == "0\n":
                    file.write("1\n")
                elif line == "1\n":
                    file.write("0\n")
                else:
                    file.write(line)
            file.close()

        else:

            if os.path.isfile(sys.argv[1]):
                configFiles=[]
                configFiles.append(sys.argv[1])
            else:
                configFiles = list(grabConfigFiles(sys.argv[1]))

            if TOGGLE == "0\n":
                for configFile in configFiles:
                    if configFile in OPENCONFIGS:
                        ckill="conky -q -c " + configFile
                        subprocess.Popen(['pkill', '-xf', ckill ])
                        file = open(LOGFILE,"w")
                        for line in LOGLINES:
                            if line == str(configFile) + "\n":
                                pass
                            elif line == TOGGLE:
                                pass
                            else:
                                file.write(line)
                        file.close()
                        file = open(LOGFILE,"r")
                        LOGLINES = file.readlines()
                        file.close()
                    else:
                        subprocess.Popen(['conky','-q','-c', configFile])
                        file = open(LOGFILE,"w")
                        for line in LOGLINES:
                            if line != TOGGLE:
                                file.write(line)
                        file.write(configFile + "\n")
                	file.close()
                        file = open(LOGFILE,"r")
                        LOGLINES = file.readlines()
                        file.close()
                file = open(LOGFILE,"a")
                file.write(TOGGLE)
                file.close()

            else:
                if os.path.isfile(sys.argv[1]):
                    if str(sys.argv[1] +'\n') not in LOGLINES:
                        ckill="conky -q -c " + sys.argv[1]
                        subprocess.Popen(['pkill', '-xf', ckill ])
                else:
                    subprocess.call(['killall', 'conky'])
                    file = open(LOGFILE,"w")
                    file.close()
                    file = open(LOGFILE,"a")
                    for configFile in configFiles:
                        subprocess.Popen(['conky','-q','-c', configFile])
                        file.write(configFile + "\n")
                    file.write(TOGGLE)
                    file.close()

It's working full on for me, but the code is perhaps not the most elegant. I've been learning a lot of python over these last few days, but this code is more of a concrete-block house than a seaside condo - it works just fine, but it a'int pretty. Maybe some redundancies can be found and corrected?

Here it is in action:

One conky managed, 'Min Weather', and one unmanaged, 'chron', that also happens to be in the Chronograph folder:

First
hetah5vm.png

Second
NdCe1C0m.png

Third
RY24yLum.png

Finally
VWF6ArJm.png

EDIT: Found 2 bugs, fixed them.
EDIT2: Re-fixed the bugs, there were spacing issues when pasting the code

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)

I don't particularly agree with some things happening here;

  • like moving the directory to ~/.config/conky, or

  • the multiple directory aspect.

But:

  • as a member of the BunsenLabs Dev-Team  I'm backing this pipemenu to be added to BumsenLabs.  It is a pretty awesome idea.

  • I've also suggested that the conky-BL zenity script not be a default but added to the bl-welcome script

If that happens, not etched in stone yet, I'll edit the zenity script to use the same 'directory' that Conky Switcher uses and it will add:

  1. ConkySwitcher_Directory/bin

  2. ConkySwitcher_Directory/LUA

  3. ConkySwitcher_Directory/scripts

--- Dev-Team hat off ---
On a personal note I'd like to see the pipemenu use the same conkys that are in the "zenity" script to keep them at least equal that way.
NOTE:  They are not confirmed as defaults yet either - but let's stay on the same page anyway, for testing, developing purposes.   {opinion}


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

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)

Sector11 wrote:

I don't particularly agree with some things happening here;

like moving the directory to ~/.config/conky

Why don't you agree with that?


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
#! forum moderator    BunsenLabs

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)

smacz wrote:

At this moment I envision one of two ways of dealing with this.
1) The kill/load command is based off of /proc and the pid (instead of session.log -- which would be way messier) and can (automagically) see if a similar (if not the exact same command) is already running and report that when obmenu fires up. OR:
2) Based on session.log (but can detect if/when `conky -c *` is run and store to session.log? Sorry, I totally had a grasp on an alternative but it slipped my mind. I blame it on the Jameson. Umm...a command logger maybe? That seems like it'd be needlessly dangerous though.)

Part of the reason I suggested seeing if killing a conky (lets use the ~/.config/conky structure) with:

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

that was started with:

conky -c $HOME/.config/conky/bl-right.conky

or

conky -c $HOME/.config/conky/bl-right.conky &

in the python script.

with a variable maybe?

kp='pkill -xf "conky -c $HOME/.config/conky/$conky'

Since I don't code, I have no idea if it is usable or not, but if it does work it would simplify things.

Please - I beg you - don't take this to conkys outside of whatever directory structure you are using now.  I don't want to wait for the pipemenu to call up 2000+ conkys, if the session log ever recorded my conky daily usage it would be popping up test conkys all over the place.  But then, I simply wouldn't use it if that was the case.

KISS it!


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

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)

Sector11 wrote:

I don't particularly agree with some things happening here;

  • like moving the directory to ~/.config/conky, or

  • the multiple directory aspect.

Fair enough, to each their own. The ~/.config/conky bit is only defined once in the switcher script at the top and once in the restore script toward the bottom, so any user can change this to whatever they'd like. #2 is optional, if you don't want any subdirectories but instead want all your conkies lumped into '/path/of/your/choice/' the above script supports that now too.

Sector11 wrote:

But:

  • as a member of the BunsenLabs Dev-Team  I'm backing this pipemenu to be added to BumsenLabs.  It is a pretty awesome idea.

  • I've also suggested that the conky-BL zenity script not be a default but added to the bl-welcome script

If that happens, not etched in stone yet, I'll edit the zenity script to use the same 'directory' that Conky Switcher uses and it will add:

  1. ConkySwitcher_Directory/bin

  2. ConkySwitcher_Directory/LUA

  3. ConkySwitcher_Directory/scripts

Awesome! I've actually never tried this zenity script, but I totally agree they should be working out of the same directory to not have to double things up.

Sector11 wrote:

--- Dev-Team hat off ---
On a personal note I'd like to see the pipemenu use the same conkys that are in the "zenity" script to keep them at least equal that way.
NOTE:  They are not confirmed as defaults yet either - but let's stay on the same page anyway, for testing, developing purposes.   {opinion}

It could very easily use the same conkys, it just means either relabeling them to be *.conkyrc, or changing the one line of code in the switcher to look for *.conky files (which was in the original version by @kbmonkey actually). Either way is a win smile

Is it too early to push for an 'Appearance' menu on the main BL-obmenu? I've modified this script to do the exact same thing for tint2 config files.

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)

Sector11 wrote:

Part of the reason I suggested seeing if killing a conky (lets use the ~/.config/conky structure) with:

pkill -xf "conky -c $HOME/.config/conky/bl-right.conky"
247                        ckill="conky -q -c " + configFile
248                        subprocess.Popen(['pkill', '-xf', ckill ])
...
270                        ckill="conky -q -c " + sys.argv[1]
271                        subprocess.Popen(['pkill', '-xf', ckill ])

pkill is already implemented in the script to handle any conkies launched outside of the script like

conky -q -c $HOME/.config/conky/bl-right.conky

so long as a full path is given when launching the conky. It wouldn't be so difficult to change it to kill conkies that only have the '-c' tag as well.

Sector11 wrote:

Please - I beg you - don't take this to conkys outside of whatever directory structure you are using now.  I don't want to wait for the pipemenu to call up 2000+ conkys, if the session log ever recorded my conky daily usage it would be popping up test conkys all over the place.  But then, I simply wouldn't use it if that was the case.

KISS it!

Totally agree, that would be a nightmare! The script does recognize running conkys [is it conkys or conkies??] that were started outside of the script, and gives the option to kill these, but it doesn't look anywhere outside of the directory specified by

45 CONFIGSHOME = os.path.join(USERHOME, '.config','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)

johnraff wrote:
Sector11 wrote:

I don't particularly agree with some things happening here;

like moving the directory to ~/.config/conky

Why don't you agree with that?

Opinion: One more sub-directory in a hidden directory for something that is not configuring the OS in anyway.


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

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)

woodape wrote:

Totally agree, that would be a nightmare! The script does recognize running conkys [is it conkys or conkies??] that were started outside of the script, and gives the option to kill these, but it doesn't look anywhere outside of the directory specified by

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

It does look good no denying that.

I would say following all proper protocols it would be conkies ... but I like conkys.  smile

EDIT:  I'll grab it, KFC my conkys, and test it. If I'm going to support it I may as well play with it.

alias kfc='killall conky'   ## Kentucky Fried Conky

·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

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)

Sector11 wrote:
johnraff wrote:
Sector11 wrote:

I don't particularly agree with some things happening here;

like moving the directory to ~/.config/conky

Why don't you agree with that?

Opinion: One more sub-directory in a hidden directory for something that is not configuring the OS in anyway.

Actually nothing in ~/.config is configuring the OS. It's all about user settings, so why not conky too? More and more apps are moving from dropping config files directly in the user's root directory to putting them in .config/ or .config/appname/ As woodape said, it helps keep the user's home a bit tidier.


John
--------------------
( a boring Japan blog , Japan Links, idle twitterings  and GitStuff )
#! forum moderator    BunsenLabs

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)

^ ~/.config is defined by the XDG sepecifications as $XDG_CONFIG_HOME and this is used by most software.
http://standards.freedesktop.org/basedi … atest.html

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)

@ johnraff, HoaS & woodape

OK OK OK, I give up ...  :8   smile   It's just an opinion anyway.

Since 95% of all "my stuff" isn't in /home (20G used: 3.9G) at all, it's on /media/5 (197G Used: 58G)  and I have a LOT of conkys over there I have a tendency to forget people either create one large partition for an install or a small / and a large /home

I've downloaded other peoples conky setup and they all want to go in /home
~/.conky
~/conky
~/Conky
~/XYZ-Conky
etc

The only ones I really leave in ~/home are my version of ~/.conkyrc and Teo's weather scripts so when I test, edit them they will work in his archives.  Other than that conkys are short lived in my ~/home

Like I said: opinion, don't want to rock the boat, and I'm behind this pipemenu 110%, let those that know how to write it ... do it.  Opinions are just that and sometimes mine suck  big_smile

@ woodape - to quote you:

The ~/.config/conky bit is only defined once in the switcher script at the top and once in the restore script toward the bottom, so any user can change this to whatever they'd like.

I have seen some scripts have variables:

xyz="something"

so I change it to:

xyz="mything"

only to run the script and find that there is a "something" here and there hard coded in the script so it missed "mything" and crapped out. (mostly python and lua script where I have seen this)

Any chance of making a variable for: "~/.config/conky" so noobs (like me) only have to change it once if needed?


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

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)

detinith wrote:

Hey guys,

Hi detinith - welcome to the thread...

detinith wrote:

@Sector11:

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

At this line, change it to this:

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

OK ... good stuff.
I'm not a coder so I am about to find out if:

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

will work.  I love breaking things.  ]:D ]:D

detinith wrote:

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

Look out Monsters Inc.  cool

--== OH OH ==--
detinith wrote:

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

Wanna bet? lol

Not even a chance to break things - yet, OK, it's a comment BUT.

21 #       + Added support for single conkies in $HOME/.config/conky

and a hardcoded let's break the CONFIGSHOME variable at line 98:

98                    sh -c 'echo "%(toggle)s" > $HOME/.config/conky/session.log'

and again:

190        print('<openbox_pipe_menu><item label="Place your .conky files under ~/.conky to use this switcher."></item></openbox_pipe_menu>')

Also I see bl-conky-switcher-pipemenu-resume.sh has:

$HOME/.config/conky/session.log

hardcoded.

... hits on what I mentioned before about finding some things that are different than a variable that can be changed by a user.

And this noob has no idea how to change those hardcoded areas to use CONFIGSHOME.

I think if I activate my version with:

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

.. it will probably break. ...

EDIT:  Yup!

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


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

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)

Sector11 wrote:

I'm not a coder so I am about to find out if:

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

will work.  I love breaking things.  ]:D ]:D
...
.. it will probably break. ...
EDIT:  Yup!

Yes this is a particular python-y thing. The 'os.path.join()' function is how python joins together directories so that the code is compatable across different filesystems. This is how it was coded by @kbmonkey and is the proper way to do things in python apparently.
You almost had the right thing, every directory must be a new argument. So just take out the slashes and put '5' in a new argument:

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

Putting in

CONFIGSHOME = '/media/5/'

has unwanted effects, but

CONFIGSHOME = '/media/5'

seems to work - it just isn't proper python.

Sector11 wrote:

Not even a chance to break things - yet, OK, it's a comment BUT.

21 #       + Added support for single conkies in $HOME/.config/conky

and a hardcoded let's break the CONFIGSHOME variable at line 98:

98                    sh -c 'echo "%(toggle)s" > $HOME/.config/conky/session.log'

and again:

190        print('<openbox_pipe_menu><item label="Place your .conky files under ~/.conky to use this switcher."></item></openbox_pipe_menu>')

yikes
Yep you're totally right, these should be changed. I've just updated the code in my last post.

Sector11 wrote:

Also I see bl-conky-switcher-pipemenu-resume.sh has:

$HOME/.config/conky/session.log

hardcoded.

...this is hardly hardcoded. It's the only mention of the file in a script that's all of 8 lines. To add a variable at line 2 that is referenced once at line 8 seems a bit pointless.

It does bring up the fact that there are currently 2 scripts to make this thing work fully. I'm sure another function can be added in "bl-conky-switcher-pipmenu.py" that checks if an argument 'resume' is passed and then loads all conkies in the 'session.log' file. This would eliminate the need for the twofiles and solve the issue of specifying a directory once and only once.

Thus adding

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

to the openbox autostart file to get the resume functionality currently provided by the separate script  "bl-conky-switcher-pipemenu-resume.sh".

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)

woodape wrote:

This is how it was coded by @kbmonkey and is the proper way to do things in python apparently.
You almost had the right thing, every directory must be a new argument. So just take out the slashes and put '5' in a new argument:

WOW!!!  I was that close huh.  Not bad for a non-coding noob.  cool
... but lets do it "the proper way"

woodape wrote:
Sector11 wrote:

Not even a chance to break things - yet

yikes
Yep you're totally right, these should be changed. I've just updated the code in my last post.

lol tongue ... oops!  I meant wink

woodape wrote:

...this is hardly hardcoded. It's the only mention of the file in a script that's all of 8 lines. To add a variable at line 2 that is referenced once at line 8 seems a bit pointless.

Hardcoded is hardcoded be it an 8 line bash scrip or a 3000 line python script.
But I agree super easy to fix here - because this noob knows how - but there are those that might miss it and adding a variable here would mean two edits either way, in the python script and the bash script so it would be a wasted variable line.

woodape wrote:

It does bring up the fact that there are currently 2 scripts to make this thing work fully.
{snip}
Thus adding

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

to the openbox autostart file to get the resume functionality currently provided by the separate script  "bl-conky-switcher-pipemenu-resume.sh".

Now that's smokin along!

Grabbing new code now.... but then have to run ... scrot later.


·  ↓   ↓   ↓   ↓   ↓   ↓  ·
BunsenLabs Forums now Open for Registration
·  ↑   ↑   ↑   ↑   ↑   ↑  · BL ModSquad

Offline

Help fund CrunchBang, donate to the project!

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

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

Re: Conky Switcher (Pipe Menu)

Wow that's a lot of new code wink Couple bugs to report.

FINAL EDIT: See this post for clarification.
#########################################################################
Double checking the following as it is much different than the intended behavior:

EDIT: REVOKED -- behavior still present when invoked with -qc as well as just -c

The "Kill the conky not logged in session.log" ability straight up does not kill the instances in LOAD/KILL mode.

For example:

  1. Terminal: conky -c "path/to/conky1.conkyrc"

  2. Root menu --> LOAD/KILL: Kill "conky1.conkyrc"



In REPLACE mode it acts as a "killall". The entries show up great on the menu, but the functionality is just not there.

For example:

  1. Terminal: conky -c "path/to/conky1.conkyrc"

  2. Root menu --> LOAD/KILL or Terminal: "conky2.conkyrc"

  3. Root menu --> REPLACE: Kill conky1

Just selecting a separate conky in REPLACE mode kills that instance just fine though and starts the selected one.

[/weirdness]
############################################################################################

I'm a fan of the REPLACE mode...and no bugs to report there big_smile , but I feel that the new functionality can be less ambiguous. Any chance you would put a separator tag at the top containing which method we're currently in? It may seem redundant at first, but it is more immediately informative and saves me a second or two to double check that my next click is going to do what I want it to do. I guess I'm used to vim putting the word "INSERT" in caps on the bottom. I know that the script does put the option at the bottom to toggle to the other mode, which will tell me what mode I'm not in, but for the sake of making it friendly, having a title at the top wouldn't hurt.

Keep up the good work guys! Thanks for the time and effort, you better know it's much appreciated!

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