Author Topic: (SOLVED) Yad startup script for ceni  (Read 8325 times)

misko_2083

  • Posts: 61
    • View Profile
Re: Yad startup script for ceni
« Reply #45 on: July 28, 2015, 01:13:41 AM »
@ misko_2083

Thanks for that!  I will look more into making the script a cosmetic makeover
I see you've managed to make Yad script working the way you want.
In the meantime I made vsido-start.py Not as fancy as YAD though.  :P Some python and gtk3+.

Code: [Select]
#!/usr/bin/env python3
#vsido-start.py
from gi.repository import Gtk
from subprocess import Popen
from gi.repository.GdkPixbuf import Pixbuf

icon="/usr/local/bin/images/vsidologo.png"

class LabelWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="VSIDO Message Center")

        self.set_default_size(-1, 450)


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


        self.create_label()
        self.create_buttons()


    def create_label(self):
        label = Gtk.Label()
        label.set_markup("Welcome to VSIDO. Due to changes from Debian, systemd and udev, it is not possible to see every Network Interface that systemd/udev now creates"
                          "\n\n"
                          "It is recommended that you run Ceni to establish your network before you begin. Ceni is a Curses user interface for configuring network interfaces with ifupdown developed by Kel Modderman and used for setting up networks on several distros. You can also select and use the WICD GUI that has more robust WIFI connectivity options"
                          "\n\n"
                          "Simply select your Network Interface and then Accept-Enter and finally Yes to exit Ceni.  Your network is then ready to go and connectivity to the Internet established")
        label.set_line_wrap(True)
        label.set_size_request(450, -1)


        table = Gtk.Table(1, 1, False)
        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):

        button1 = Gtk.Button(label="Run Ceni")
        button1.connect("clicked", self.on_open_clicked)
        self.grid.attach(button1, 1, 2, 1, 1)

        button2 = Gtk.Button(label="Run Wicd")
        button2.connect("clicked", self.on_click_me_clicked)
        self.grid.attach_next_to(button2, button1, Gtk.PositionType.RIGHT, 1, 1)

        button3 = Gtk.Button(label="_Close", use_underline=True)
        button3.connect("clicked", self.on_close_clicked)
        self.grid.attach(button3,  1, 3, 3, 1)

    def on_click_me_clicked(self, button):
        Popen('/bin/bash -c "wicd-gtk -n &>/dev/null &"', shell=True, stdin=None, stdout=None, stderr=None, close_fds=True)
        Gtk.main_quit()
    def on_open_clicked(self, button):
        Popen('/bin/bash -c "xfce4-terminal -e ceni &>/dev/null &"', shell=True, stdin=None, stdout=None, stderr=None, close_fds=True)
        Gtk.main_quit()
    def on_close_clicked(self, button):
        print("Closing VSIDO Message Center")
        Gtk.main_quit()

window = LabelWindow()     
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.show_all()
Gtk.main()
It looks like this:

VastOne

  •      v-ger
  • Posts: 3841
    • View Profile
    • VSIDO Community
Re: (SOLVED) Yad startup script for ceni
« Reply #46 on: July 28, 2015, 03:58:41 AM »
Wow, very nice work misko_2083!

Any reason as to why python would be a better choice? 

Thank you
VSIDO      VSIDO Twitter     VSIDO FB     VSIDO Google+   

I dev VSIDO

misko_2083

  • Posts: 61
    • View Profile
Re: (SOLVED) Yad startup script for ceni
« Reply #47 on: July 30, 2015, 12:16:06 PM »
Wow, very nice work misko_2083!

Any reason as to why python would be a better choice? 

Thank you
It's all the same.
For example this is the equivalent of hakerdefo's script:
Code: [Select]
#!/usr/bin/env python3
#vsido-start.py
from gi.repository import Gtk, Gdk
import os
import sys
import subprocess
from subprocess import Popen
from gi.repository.GdkPixbuf import Pixbuf


icon="/usr/local/bin/images/vsidoorb_blk.png"

# Which
def which(program):
    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file
    return None

class VsidoStartWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="VSIDO Message Center")

        self.set_default_size(-1, 450)


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


        self.create_label()
        self.create_buttons()


    def create_label(self):
        label = Gtk.Label()
        label.set_markup("Welcome to VSIDO. Due to changes from Debian, systemd and udev, it is not possible to see every Network Interface that systemd/udev now creates"
                          "\n\n"
                          "It is recommended that you run Ceni to establish your network before you begin. Ceni is a Curses user interface for configuring network interfaces with ifupdown developed by Kel Modderman and used for setting up networks on several distros. You can also select and use the WICD GUI that has more robust WIFI connectivity options"
                          "\n\n"
                          "Simply select your Network Interface and then Accept-Enter and finally Yes to exit Ceni.  Your network is then ready to go and connectivity to the Internet established")
        label.set_line_wrap(True)
        label.set_size_request(450, -1)


        table = Gtk.Table(1, 1, False)
        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):

        button1 = Gtk.Button(label="Run Ceni")
        button1.connect("clicked", self.on_open_clicked)
        self.grid.attach(button1, 1, 2, 1, 1)

        button2 = Gtk.Button(label="Run Wicd")
        button2.connect("clicked", self.on_click_me_clicked)
        self.grid.attach_next_to(button2, button1, Gtk.PositionType.RIGHT, 1, 1)

        button3 = Gtk.Button(label="_Close", use_underline=True)
        button3.connect("clicked", self.on_close_clicked)
        self.grid.attach(button3,  1, 3, 3, 1)

    def on_click_me_clicked(self, button):
        checking = which("wicd-gtk")
        if checking == None:
           print("wicd-gtk not found")
           dialog = Gtk.MessageDialog(None, 0, Gtk.MessageType.INFO,
              Gtk.ButtonsType.OK, "VSIDO Message Center")
           dialog.format_secondary_text(
              "'wicd-gtk' can not be found.\nNothing to execute.")
           dialog.set_name('VsidoStart')
           dialog.run()
           dialog.destroy()
        else:
           cmd = "sudo systemctl status wicd | grep -c dead"
           wicdd = os.popen(cmd)
           wicdd = wicdd.readline()

   
           cmd = "sudo systemctl is-enabled wicd | grep -c disabled"
           wicdb = os.popen(cmd)
           wicdb = wicdb.readline()

           if int(wicdd) == 1:
              dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.QUESTION,
                 Gtk.ButtonsType.YES_NO, "VSIDO Message Center", title="VSIDO Message Center")
              dialog.format_secondary_text(
               "You have decided to use Wicd. Wicd service is not running. \nDo you want to start Wicd service?")
              response = dialog.run()

              if response == Gtk.ResponseType.YES:
                os.system('sudo systemctl start wicd')
                dialog.destroy()
              elif response == Gtk.ResponseType.NO:
                dialog.destroy()

           if int(wicdb) == 1:
              dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.QUESTION,
                 Gtk.ButtonsType.YES_NO, "VSIDO Message Center")
              dialog.format_secondary_text(
                 "Wicd service is disabled from autostarting.\nDo you want to enable Wicd autostart?")
              response_disable = dialog.run()
              if response_disable == Gtk.ResponseType.YES:
                 os.system('sudo systemctl enable wicd')
                 dialog.destroy()
              elif response_disable == Gtk.ResponseType.NO:
                 print("wicd not enabled")
              dialog.destroy()
           Popen('/bin/bash -c "wicd-gtk -n &>/dev/null &"', shell=True, stdin=None, stdout=None, stderr=None, close_fds=True)
           Gtk.main_quit()
    def on_open_clicked(self, button):
        #check if ceni exists
        checking = which("ceni")
        if checking == None:
           print("ceni not found")
           dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.INFO,
              Gtk.ButtonsType.OK, "VSIDO Message Center")
           dialog.format_secondary_text(
              "'ceni' can not be found.\nNothing to execute.")
           dialog.set_name('VsidoStart')
           dialog.run()
           dialog.destroy()
        else:
           cmd = "sudo systemctl status wicd | grep -c dead"
           wicdd = os.popen(cmd)
           wicdd = wicdd.readline()

   
           cmd = "sudo systemctl is-enabled wicd | grep -c disabled"
           wicdb = os.popen(cmd)
           wicdb = wicdb.readline()

           if int(wicdd) < 1:
              dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.QUESTION,
                 Gtk.ButtonsType.YES_NO, "VSIDO Message Center", title="VSIDO Message Center")
              dialog.format_secondary_text(
               "You have decided to use Ceni. Wicd is no longer needed. Stop Wicd?")
              response = dialog.run()

              if response == Gtk.ResponseType.YES:
                os.system('sudo systemctl stop wicd')
                dialog.destroy()
              elif response == Gtk.ResponseType.NO:
                dialog.destroy()

           if int(wicdb) < 1:
              dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.QUESTION,
                 Gtk.ButtonsType.YES_NO, "VSIDO Message Center")
              dialog.format_secondary_text(
                 "You have decided to use Ceni. Wicd is no longer needed. Disable Wicd?")
              response_disable = dialog.run()
              if response_disable == Gtk.ResponseType.YES:
                 os.system('sudo systemctl disable wicd')
              elif response_disable == Gtk.ResponseType.NO:
                dialog.destroy()

           Popen('/bin/bash -c "xfce4-terminal -e ceni &>/dev/null &"', shell=True, stdin=None, stdout=None, stderr=None, close_fds=True)
           Gtk.main_quit()
    def on_close_clicked(self, button):
        print("Closing VSIDO Message Center")
        Gtk.main_quit()

window = VsidoStartWindow()     
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('VsidoStart')
style_provider = Gtk.CssProvider()
css = """
#VsidoStart {
    background: black;
    background-repeat: no-repeat;
    background-position: 0px 0px;
    color: #FFF;
    font: 20px sans-serif;

}
.button {
    font: 15px sans-serif;
    background: teal;
    -webkit-transition: color 1s;
    transition: color 1s;
    border: 1px solid #000;
    color: white;
    padding-top: 10px;
    padding-right: 20px;
    padding-bottom: 10px;
    padding-left: 20px;
}
.button:hover{
    background-color: #E3E1B8;
    font: 15px sans-serif;
    border: 1px solid #000;
    color: navy;
}
.dialog {
    background-repeat: no-repeat;
    background-position: 0px 0px;
    color: #FFF;
}
"""

style_provider.load_from_data(css.encode())

Gtk.StyleContext.add_provider_for_screen(
    Gdk.Screen.get_default(),
    style_provider,     
    Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION
)
window.show_all()
Gtk.main()
I assume he intended to run it with sudo. Same problem here, it starts Wicd GTK interface with elevated privileges.
Just played a little with css here. Python and Css are a great combo.

Edit.............................................................
Perhaps it's better to stick with yad. I'd like to help but who knows wheater I will have the time.
I have a few other things on my mind. We are making a control center and Ubuntu 14.04.3 will be out in a few days so I'll be busy next month as we prepareing a new release.
Cheers :)