Linux Lite 8.0 RC1 has been released - Click here


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Control Center Ideas
#1

I'll start with an idea to use a little python script to display a tray icon instead of the xfce panel plugin. This way it will run not only in xfce but on cinnamon, mate and other.
I've created 2 applications and one desktop file for this.
The first application will launch a tray icon and right click menu. I've added a few right-click menu items: about dialog, Start Control Center, Settings and Quit.

/usr/share/litecc/litecc-tray-icon.py
Code:
#!/usr/bin/env python3
import subprocess
from gi.repository import Gtk
from gi.repository.GdkPixbuf import Pixbuf
import os
licon = "/usr/share/pixmaps/lite-controlcenter.png"

class LiteCCTray():
   
    def __init__(self):
        self.tray = Gtk.StatusIcon()
        self.tray.set_from_file(licon)
        self.tray.connect('popup-menu', self.on_right_click)
        self.tray.connect('activate', self.on_left_click)
        self.tray.set_tooltip_text('Linux Lite Control Center')


    def on_right_click(self, icon, button, time):

        self.menu = Gtk.Menu()

        about = Gtk.MenuItem()
        about.set_label("About")
        run = Gtk.MenuItem()
        run.set_label("Start Control Center")
        settings = Gtk.MenuItem()
        settings.set_label("Settings")
        quit = Gtk.MenuItem()
        quit.set_label("Quit")

        about.connect("activate", self.show_about_dialog)
        run.connect("activate", self.run_lite_cc)
        settings.connect("activate", self.settings_lite_cc)
        quit.connect("activate", Gtk.main_quit)

        self.menu.append(about)
        self.menu.append(run)
        self.menu.append(settings)
        self.menu.append(quit)

        self.menu.show_all()

        def pos(menu, icon):
                return (Gtk.StatusIcon.position_menu(menu, icon))

        self.menu.popup(None, None, pos, self.tray, button, time)
       
    #open lite cc
    def on_left_click(self, event):
        subprocess.Popen(['python3', '/usr/share/litecc/litecenter.py'])

    def run_lite_cc(self, event):
        subprocess.Popen(['python3', '/usr/share/litecc/litecenter.py'])

    def settings_lite_cc(self, event):
        subprocess.Popen(['python3', '/usr/share/litecc/litecc-tray.py'])

    def show_about_dialog(self, widget):
        about_dialog = Gtk.AboutDialog()
        about_dialog.set_destroy_with_parent (True)
        about_dialog.set_program_name("Linux Lite Control Center Tray Icon")
        about_dialog.set_website('http://linuxliteos.com')
        about_dialog.set_website_label('linuxliteos.com')
        about_dialog.set_icon(Pixbuf.new_from_file(licon))
        about_dialog.set_logo(Pixbuf.new_from_file(licon))
        about_dialog.set_copyright('Copyright 2015')
        about_dialog.set_comments((u'Tool for Launching Liunx Lite Control Center'))
        about_dialog.set_license('''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 2 of the License, or
(at your option) 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. ''')
        about_dialog.set_authors([u'Milos Pavlovic <[email protected]>'])
        about_dialog.run()
        about_dialog.destroy()

if __name__ == '__main__':
    LiteCCTray()
    Gtk.main()
Left click will open the control center.

The second application launches a gtk3 widnow which is used to set tray icon autostart. This window is launched from a tray icon's right click menu -> Settings
/usr/share/litecc/litecc-tray.py
Code:
#!/usr/bin/env python3
#litecc tray settings, Misko
from gi.repository import Gtk
import os
import sys
from subprocess import Popen
from gi.repository.GdkPixbuf import Pixbuf

#Temporary window icon don't forget to change!
icon="/usr/share/pixmaps/lite-controlcenter.png"
autostart_path = os.path.expanduser('~/.config/autostart/litecc-tray-icon.desktop')

class LiteccTrayWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="Linux Lite Control Center Settings")

        self.set_default_size(-1, 200)
        self.set_border_width(10)

        self.grid = Gtk.Grid()
        self.add(self.grid)


        self.create_label()
        self.create_buttons()

    def create_label(self):
        label = Gtk.Label()
        label.set_markup("Linux Lite Control Center settings")
        label.set_line_wrap(True)
        label.set_size_request(200, -1)


        table = Gtk.Table(1, 1, False)
        table.set_border_width(10)
        table.attach(label, 0, 1, 0, 1, Gtk.AttachOptions.SHRINK | Gtk.AttachOptions.FILL)
        self.grid.attach(table, 1, 0, 2, 1)

    def create_buttons(self):
        label1 = Gtk.Label("Tray Icon Autostart  ", xalign=1)


        self.grid.attach(label1, 1, 1, 1, 1)


        button1 = Gtk.Switch()
        button1.connect("notify::active", self.on_switch_activateda)
        button1.set_name('button')
        if not os.path.exists(autostart_path):
           button1.set_active(False)
        else:
           button1.set_active(True)
        self.grid.attach_next_to(button1, label1, Gtk.PositionType.RIGHT, 1, 1)



        buttonc = Gtk.Button(label="_Close", use_underline=True)
        buttonc.set_border_width(8)
        buttonc.connect("clicked", self.on_close_clicked)
        self.grid.attach(buttonc,  2, 7, 1, 1)



    def on_switch_activateda(self, switch, gparam):
        state = ""
        if switch.get_active():
            try:
                os.symlink( '/usr/share/applications/litecc-tray-icon.desktop', autostart_path)
                state = "on"
            except OSError as e:
                print(e)
                pass
        else:
            try:
                os.unlink(autostart_path)
                state = "off"
            except OSError as e:
                print(e)
                pass

        print("Lite CC Tray Icon Autostart is set", state)



    def on_close_clicked(self, button):
        print("Closing Lite CC Settings")
        Gtk.main_quit()

window = LiteccTrayWindow()     
window.connect("delete-event", Gtk.main_quit)
window.set_resizable(False)
window.set_position(Gtk.WindowPosition.CENTER)
window.set_icon(Pixbuf.new_from_file("{0}".format(icon)))
window.set_name('DesktopIcons')
window.show_all()
Gtk.main()

The last part is a desktop file in /usr/share/applications which is going to be symlinked in order to autostart the tray icon
/usr/share/applications/litecc-tray-icon.desktop
Code:
[Desktop Entry]
Encoding=UTF-8
Version=0.1
Type=Application
Name=Linux Lite Control Center Tray Icon
Comment=Linux Lite Control Center Tray Icon
Exec=/usr/share/litecc/litecc-tray-icon.py
Icon=lite-controlcenter
OnlyShowIn=XFCE;
StartupNotify=false
Terminal=false
Hidden=false
I've noticed that Hidden=true in the desktop file prevents it from starting.

P.S. Don't forget to make scripts and desktop file executable.

Here is how this looks:
[Image: qAFaCNb.png]
Reply
#2

That's some nice code there Milos. What do you think of this shaggy?

Download your free copy of Linux Lite today.

Jerry Bezencon
Linux Lite Creator

"Do not correct a fool, or he will hate you; correct a wise man and he will appreciate you."

[Image: X5qGkCg.png]

[Image: 0op1GNe.png] [Image: LgJ2mtP.png] [Image: vLZcFUE.png] [Image: lrUHro3.jpg]
Reply
#3

I like this, what I still am on the ropes about tho is the icon lol. That aside, it looks great and I dig the idea. With one question tho, are we going to test other wm's and kinda track how well this works (maybe some kinda list we can keep lol) because if there is a list of known wm's we kinda track, can also adjust the desktop/wm info part of the control center to make sure its displaying proper. (all unoffically ofc jerry lol) Otherwise I love this.

The Truth is out there.
Be sure to check the Manual out and always report Bugs or feature requests.
[Image: psCXIcR.png]
Reply
#4

Thank you Jerry and John. :)
(08-11-2015, 10:42 AM)shaggytwodope link Wrote:  I like this, what I still am on the ropes about tho is the icon lol. That aside, it looks great and I dig the idea. With one question tho, are we going to test other wm's and kinda track how well this works (maybe some kinda list we can keep lol) because if there is a list of known wm's we kinda track, can also adjust the desktop/wm info part of the control center to make sure its displaying proper. (all unoffically ofc jerry lol) Otherwise I love this.
Yes the icon doesn't fit the tray icon theme. Perhaps in the future we could add an option in the Settings, just above the autostart, to select between the light and dark icon. That way it would cover the light and dark gtk themes.
Reply
#5

Keep this off the main branch on github for now. Let's continue to explore the implementation, code and design. Cheers :)

Download your free copy of Linux Lite today.

Jerry Bezencon
Linux Lite Creator

"Do not correct a fool, or he will hate you; correct a wise man and he will appreciate you."

[Image: X5qGkCg.png]

[Image: 0op1GNe.png] [Image: LgJ2mtP.png] [Image: vLZcFUE.png] [Image: lrUHro3.jpg]
Reply
#6

(08-11-2015, 03:59 PM)Jerry link Wrote:  Keep this off the main branch on github for now. Let's continue to explore the implementation, code and design. Cheers :)
This is just an idea. It will stay off the main branch. No problem.
Reply
#7

Ideas:

- Left click only spawns one instance.
- Quitting the tray icon also quits the application OR have another right click in the tray option to quit the application.
- Each right click option has a small icon beside it.

Download your free copy of Linux Lite today.

Jerry Bezencon
Linux Lite Creator

"Do not correct a fool, or he will hate you; correct a wise man and he will appreciate you."

[Image: X5qGkCg.png]

[Image: 0op1GNe.png] [Image: LgJ2mtP.png] [Image: vLZcFUE.png] [Image: lrUHro3.jpg]
Reply
#8

(08-12-2015, 11:21 PM)Jerry link Wrote:  Ideas:

- Left click only spawns one instance.
- Quitting the tray icon also quits the application OR have another right click in the tray option to quit the application.
- Each right click option has a small icon beside it.
Good ideas.
Not having much free time lately to look into.
1. Control center should be launched in another way or we could integrate the tray icon into the control center code.
Just a quick google on single instance.
http://solvedstack.com/questions/python-...of-program
Implementing that would stop spawning multiple instances.
2. Quiting the tray icon quits the application. Solving issuie number 1 will solve that.
3. As for icons I think some other widget has to be used. GtkImageMenuItem. That is something to experiment with.
Reply
#9

OK this is added.
- Left click only spawns one instance.
- Quitting the tray icon also quits the application.
- Each right click option has a small icon beside it.
Code:
#!/usr/bin/env python3
import subprocess
from gi.repository import Gtk
from gi.repository.GdkPixbuf import Pixbuf
import os
import sys
import fcntl
import signal
import ctypes

licon = "/usr/share/pixmaps/lite-controlcenter.png"

fh=0
def run_once():
    global fh
    fh=open(os.path.realpath(__file__),'r')
    try:
        fcntl.flock(fh,fcntl.LOCK_EX|fcntl.LOCK_NB)
    except:
        sys.exit (0)

run_once()


libc = ctypes.CDLL("libc.so.6")
def set_pdeathsig(sig = signal.SIGTERM):
    def callable():
        return libc.prctl(1, sig)
    return callable

class LiteCCTray():
   
    def __init__(self):
        self.tray = Gtk.StatusIcon()
        self.tray.set_from_file(licon)
        self.tray.connect('popup-menu', self.on_right_click)
        self.tray.connect('activate', self.on_left_click)
        self.tray.set_tooltip_text('Linux Lite Control Center')


    def on_right_click(self, icon, button, time):

        self.menu = Gtk.Menu()
       
        img = Gtk.Image()
        img.set_from_file('/usr/share/pixmaps/leafpad.png')
        about = Gtk.ImageMenuItem()
        about.set_label("About")
        about.set_image(img)
        about.set_always_show_image(True)

        img = Gtk.Image()
        img.set_from_file('/usr/share/pixmaps/lite-controlcenter.png')
        run = Gtk.ImageMenuItem()
        run.set_label("Start Control Center")
        run.set_image(img)
        run.set_always_show_image(True)

        img = Gtk.Image()
        img.set_from_file('/usr/share/pixmaps/htop.png')
        settings = Gtk.ImageMenuItem()
        settings.set_label("Settings")
        settings.set_image(img)
        settings.set_always_show_image(True)

        img = Gtk.Image()
        img.set_from_file('/usr/share/pixmaps/language-selector.png')

        separator = Gtk.SeparatorMenuItem()

        quit = Gtk.ImageMenuItem()
        quit.set_label("Quit")
        quit.set_image(img)
        quit.set_always_show_image(True)

        about.connect("activate", self.show_about_dialog)
        run.connect("activate", self.run_lite_cc)
        settings.connect("activate", self.settings_lite_cc)
        quit.connect("activate", Gtk.main_quit)

        self.menu.append(about)
        self.menu.append(run)
        self.menu.append(settings)
        self.menu.append(separator)
        self.menu.append(quit)

        self.menu.show_all()

        def pos(menu, icon):
                return (Gtk.StatusIcon.position_menu(menu, icon))

        self.menu.popup(None, None, pos, self.tray, button, time)
       
    #open lite cc
    def on_left_click(self, event):
        subprocess.Popen(['python3', '/usr/share/litecc/litecenter.py'], preexec_fn = set_pdeathsig(signal.SIGTERM))

    def run_lite_cc(self, event):
        subprocess.Popen(['python3', '/usr/share/litecc/litecenter.py'], preexec_fn = set_pdeathsig(signal.SIGTERM))

    def settings_lite_cc(self, event):
        subprocess.Popen(['python3', '/usr/share/litecc/litecc-tray.py'], preexec_fn = set_pdeathsig(signal.SIGTERM))

    def show_about_dialog(self, widget):
        about_dialog = Gtk.AboutDialog()
        about_dialog.set_destroy_with_parent (True)
        about_dialog.set_program_name("Linux Lite Control Center Tray Icon")
        about_dialog.set_website('http://linuxliteos.com')
        about_dialog.set_website_label('linuxliteos.com')
        about_dialog.set_icon(Pixbuf.new_from_file(licon))
        about_dialog.set_logo(Pixbuf.new_from_file(licon))
        about_dialog.set_copyright('Copyright 2015')
        about_dialog.set_comments((u'Tool for Launching Liunx Lite Control Center'))
        about_dialog.set_license('''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 2 of the License, or
(at your option) 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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA. ''')
        about_dialog.set_authors([u'Milos Pavlovic <[email protected]>'])
        about_dialog.run()
        about_dialog.destroy()


if __name__ == '__main__':
    LiteCCTray()
    Gtk.main()

Just used some icons from /usr/share/pixmaps
They are not that small :)
Anyway we can always change that later.

Hm, I wonder if it's a good idea to implement shaggy's tray update icon into control center icon.
We would have one icon instead of two. ;)
Something to think about once Shaggy finishes update tool.
Reply
#10

what py file is that for?

Download your free copy of Linux Lite today.

Jerry Bezencon
Linux Lite Creator

"Do not correct a fool, or he will hate you; correct a wise man and he will appreciate you."

[Image: X5qGkCg.png]

[Image: 0op1GNe.png] [Image: LgJ2mtP.png] [Image: vLZcFUE.png] [Image: lrUHro3.jpg]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)