Esempio n. 1
0
 def addfavtoconf(self, actor):
     """ get desktop entry info """
     entry = 'Desktop Entry'
     filelist = []
     self.fileitem = self.addfavs.get_filename()
     filelist.append(checkconfig.checksetting(self.fileitem, entry, 'Name'))
     filelist.append(checkconfig.checksetting(self.fileitem, entry, 'Exec'))
     filelist.append(checkconfig.checksetting(self.fileitem, entry, 'Icon'))
     filelist.append(checkconfig.checksetting(self.fileitem, entry,
                                              'Comment'))
     tmpcount = 0
     for items in self.favlist:
         if not items[1]:
             logops.write(LOGFILE, ('PIRUM: adding file to config ' +
                                    filelist[1] + '\n'))
             checkconfig.changesetting(CONFIG, 'dock',
                                       str(tmpcount) +'fav', filelist[1])
             checkconfig.changesetting(CONFIG, 'dock',
                                       str(tmpcount) +'icon', filelist[2])
             self.addfavs.hide()
             self.show()
             return actor
         tmpcount = tmpcount + 1
     self.addfavs.hide()
     return actor
Esempio n. 2
0
def checkconfig(inputpath):
    """ create a default config if not available """
    conf = ConfigParser.RawConfigParser()
    conf.read(inputpath)
    if not conf.has_section('dock'):
        count = 0
        logops.write(LOGFILE, 'CHECKCONFIG: adding dock')
        conffile = open(inputpath, "w")
        conf.add_section('dock')
        while count < 20:
            conf.set('dock', str(count) + 'fav', '')
            conf.set('dock', str(count) + 'icon', '')
            count = count + 1
        conf.write(conffile)
        conffile.close()
    if not conf.has_section('options'):
        conffile = open(inputpath, "w")
        logops.write(LOGFILE, 'CHECKCONFIG: adding options')
        conf.add_section('options')
        conf.set('options', 'autostart', '')
        conf.set('options', 'appposition', 'centre')
        conf.set('options', 'showhotlabel', 'True')
        conf.write(conffile)
        conffile.close()
        return
Esempio n. 3
0
def changesetting(inputpath, settingid, setting, value):
    """ set values for settings """
    logops.write(LOGFILE, 'CHECKCONFIG: writing new value for ' + setting)
    conf = ConfigParser.RawConfigParser()
    conf.read(inputpath)
    conf.set(settingid, setting, value)
    conffile = open(inputpath, "w")
    conf.write(conffile)
    conffile.close()
    return
Esempio n. 4
0
def checksetting(inputpath, settingid, setting):
    """ try to identify the default icon theme path """
    conf = ConfigParser.RawConfigParser()
    conf.read(inputpath)
    try:
        name = conf.get(settingid, setting)
    except ConfigParser.NoOptionError as err:
        logops.write(LOGFILE, 'CHECKCONFIG: option not found ' + setting)
        logops.write(LOGFILE, str(err))
        return None
    return name
Esempio n. 5
0
def killprocess(pid):
    """ kill process by pid """
    try:
        proc = psutil.Process(pid)
    except psutil.NoSuchProcess:
        # PID already closed
        proc = None
    if proc:
        logops.write(LOGFILE, 'PROCMAN: Killing ' + str(proc.name()))
        temp = ["/usr/bin/killall", "-g", proc.name()]
        startprocess(temp)
        return True
    return False
Esempio n. 6
0
 def run(self, *args):
     """ configure and show the main window """
     #format windows
     windowlist = [self.mainwindow, self.topdock, self.hotwin]
     # make windows undecorated and set options
     for windows in windowlist:
         windows.set_decorated(False)
         windows.set_decorated(False)
         windows.set_skip_taskbar_hint(True)
         windows.set_skip_pager_hint(True)
         windows.set_keep_above(True)
     self.hotwin.move(0, 0)
     self.hotwin.set_position(Gtk.Align.START)
     if args:
         # only run autostart on initial run
         if args[0] == 'START':
             # write the start of the log
             logops.write(LOGFILE, ('\n================================' +
                                    '===\nSTARTUP: pirum-shell is loading' +
                                    '...\n' + time.asctime() +
                                    '\nWriting to log file: ' + LOGFILE +
                                    '\n================================' +
                                    '===\n'))
             # run autostart commands
             if self.autostart:
                 self.autostart = self.autostart.split("    ")
                 for items in self.autostart:
                     # execute autorun programs as hidden shell commands
                     tmpexec = items.split()
                     if tmpexec:
                         logops.write(LOGFILE, 'PIRUM: executing aut' +
                                      'ostart\n   Command: ' + items + '\n')
                         tmppid = procman.startprocess(tmpexec)
                     if tmppid:
                         self.autostartpids.append(tmppid)
     # Check config files and load favourites.
     self.updatefavdock()
     self.updateopenwindows()
     # set visual options.
     self.initialloading()
     self.hotwin.show()
     self.mainwindow.hide()
     self.topdock.hide()
     return
Esempio n. 7
0
 def execute(self, actor, event):
     """ Execute commands in a subprocess """
     tmppid = None
     if event:
         if Gdk.ModifierType.BUTTON1_MASK == event.get_state():
             tmpcount = 0
             for items in self.favlist:
                 if actor == items[0]:
                     # find existing process
                     if isinstance(items[3], int):
                         tmppid = self.activatepid(items[3])
                         if tmppid:
                             logops.write(LOGFILE, ('PIRUM: found running ' +
                                                    'pid\n     Command: ' +
                                                    str(items[1]) +
                                                    '\n     PID: ' +
                                                    str(items[3]) + '\n'))
                             self.hide()
                             return True
                 tmpcount = tmpcount + 1
             tmpcount = 0
             for items in self.favlist:
                 if actor == items[0]:
                     # Switch to active windows
                     if self.changewindow(items[0], event):
                         logops.write(LOGFILE,
                                      ('PIRUM: activate existing window\n  ' +
                                       '   ' + items[0].get_tooltip_text()))
                         self.hide()
                         return True
                     tmpexec = (items[1]).split()
                     if not tmpexec:
                         tmpexec = [].append(items[1])
                     tmppid = procman.startprocess(tmpexec)
                     if tmppid:
                         logops.write(LOGFILE,
                                      ('PIRUM: executing favourite\n' +
                                       '     CMD: ' + str(items[1]) +
                                       '\n     PID: ' + str(tmppid[0]) +
                                       '\n'))
                         self.setpid(tmppid[0], tmpcount)
                         self.hide()
                         return True
                 tmpcount = tmpcount + 1
     if actor == "enter" or actor == self.gobutton:
         logops.write(LOGFILE, ('PIRUM: executing from runentry\n     ' +
                                self.runentry.get_text() + '\n'))
         runcmd = str.split(self.runentry.get_text())
         tmppid = procman.startprocess(runcmd)
         self.runentry.set_text("")
     if tmppid:
         self.hide()
     return
Esempio n. 8
0
 def activewindows(self, search, actor):
     """ sort through open windows to activate """
     found = False
     foundwin = []
     tmpcount = 0
     overlaycount = None
     self.getwindowlist()
     for items in self.open:
         if items[1] == actor:
             overlaycount = tmpcount
             window = self.openwindows[overlaycount]
             tmpname = window.get_name()
             tmppid = str(window.get_pid())
             logops.write(LOGFILE, ('PIRUM: activating window\n     NAME: ' +
                                    tmpname + '\n     PID:  ' + tmppid +
                                    '\n'))
             window.activate(int(time.time()))
             return True
         else:
             tmpcount = tmpcount + 1
     # identify windows by title
     for windows in self.windowlist:
         tmpxid = windows.get_xid()
         tmppid = windows.get_pid()
         currentwindow = Wnck.Window.get(tmpxid)
         name = currentwindow.get_name().lower()
         pid = currentwindow.get_pid()
         # Activate windows with the same name from the overlay
         if search == name and tmppid == pid:
             foundwin.append(currentwindow)
             while Gtk.events_pending():
                 Gtk.main_iteration()
             #windows.activate(int(time.time()))
             found = True
     # search for split text in windows
     if not found:
         # if you can't find the exact window activate all matches
         for windows in self.windowlist:
             tmpxid = windows.get_xid()
             tmppid = windows.get_pid()
             currentwindow = Wnck.Window.get(tmpxid)
             name = currentwindow.get_name().lower()
             pid = currentwindow.get_pid()
             # Activate windows with the same name from the overlay
             if search == name.split()[0]:
                 foundwin.append(currentwindow)
                 while Gtk.events_pending():
                     Gtk.main_iteration()
                 found = True
     if foundwin:
         logops.write(LOGFILE, ('PIRUM: activating window group'))
         for windows in foundwin:
             tmpname = windows.get_name()
             tmppid = str(windows.get_pid())
             logops.write(LOGFILE, ('     NAME: ' + tmpname +
                                    '\n     PID:  ' + tmppid + '\n'))
             windows.activate(int(time.time()))
         return True
     # Error, Window not activated.
     return False
Esempio n. 9
0
 def updateopenwindows(self):
     """ Update the list of open windows on the overlay """
     winlist = self.getwindowlist()
     if not winlist:
         logops.write(LOGFILE, 'PIRUM: no change')
         return False
     count = 0
     # blank before filling dock
     for items in self.open:
         items[0].set_tooltip_text("")
         items[2].set_text("")
         items[0].set_visible(False)
         items[1].set_visible(False)
         items[2].set_visible(False)
     # fill dock with open windows
     for windows in self.openwindows:
         if not count == 28:
             text = windows.get_name()
             pixbuf = windows.get_icon()
             if pixbuf.get_height() > 32 or pixbuf.get_width() > 32:
                 scaled = pixbuf.scale_simple(32, 32,
                                              GdkPixbuf.InterpType.HYPER)
             else:
                 scaled = pixbuf
             self.open[count][0].set_from_pixbuf(scaled)
             self.open[count][1].connect("button-release-event",
                                         self.changewindow)
             self.open[count][1].set_tooltip_text(text)
             self.open[count][2].set_line_wrap(True)
             self.open[count][2].set_text(text)
             self.open[count][0].set_visible(True)
             self.open[count][1].set_visible(True)
             self.open[count][2].set_visible(True)
             self.overflowlabel.set_text('')
             count = count + 1
         if count == 28:
             self.overflowlabel.set_text('WARNING: Out of room to display' +
                                         ' open windows')
     return True
Esempio n. 10
0
def startprocess(proclist):
    """ start process returning the pid """
    pid = None
    try:
        pid = subprocess.Popen(proclist, preexec_fn=os.setpgrp).pid
    except OSError as err:
        #no file found
        logops.write(LOGFILE, 'PROCMAN: No File Found')
        logops.write(LOGFILE, str(err))
        return False
    except TypeError as err:
        #malformed entry
        logops.write(LOGFILE, 'PROCMAN: Bad file name')
        logops.write(LOGFILE, str(err))
        return False
    #process.wait()
    tmpproc = getprocesses()
    for proc in tmpproc:
        ###debug###print(str(pid) + ' - ' + str(proc))
        if proc[0] == pid:
            return proc
    return False
Esempio n. 11
0
 def updatefavdock(self):
     """ Read config and fill favourites list """
     checkconfig.checkconfig(CONFIG)
     self.conf.read(CONFIG)
     try:
         self.autostart = self.conf.get('options', 'autostart')
     except ConfigParser.NoOptionError as err:
         logops.write(LOGFILE, 'CONFIG: Missing autostart option')
         logops.write(LOGFILE, str(err))
         self.autostart = None
     try:
         self.appposition = self.conf.get('options', 'appposition')
     except ConfigParser.NoOptionError as err:
         logops.write(LOGFILE, 'CONFIG: Missing appposition option')
         logops.write(LOGFILE, str(err))
         self.appposition = 'Centre'
     try:
         self.showhotlabel = self.conf.get('options', 'showhotlabel')
     except ConfigParser.NoOptionError as err:
         logops.write(LOGFILE, 'CONFIG: Missing showhotlabel option')
         logops.write(LOGFILE, str(err))
         self.showhotlabel = 'False'
     self.cmd0 = self.conf.get('dock', '0fav')
     self.cmd1 = self.conf.get('dock', '1fav')
     self.cmd2 = self.conf.get('dock', '2fav')
     self.cmd3 = self.conf.get('dock', '3fav')
     self.cmd4 = self.conf.get('dock', '4fav')
     self.cmd5 = self.conf.get('dock', '5fav')
     self.cmd6 = self.conf.get('dock', '6fav')
     self.cmd7 = self.conf.get('dock', '7fav')
     self.cmd8 = self.conf.get('dock', '8fav')
     self.cmd9 = self.conf.get('dock', '9fav')
     self.cmd10 = self.conf.get('dock', '10fav')
     self.cmd11 = self.conf.get('dock', '11fav')
     self.cmd12 = self.conf.get('dock', '12fav')
     self.cmd13 = self.conf.get('dock', '13fav')
     self.cmd14 = self.conf.get('dock', '14fav')
     self.cmd15 = self.conf.get('dock', '15fav')
     self.cmd16 = self.conf.get('dock', '16fav')
     self.cmd17 = self.conf.get('dock', '17fav')
     self.cmd18 = self.conf.get('dock', '18fav')
     self.cmd19 = self.conf.get('dock', '19fav')
     self.favlist = [[self.fav0, self.cmd0, self.image0, self.fpid0],
                     [self.fav1, self.cmd1, self.image1, self.fpid1],
                     [self.fav2, self.cmd2, self.image2, self.fpid2],
                     [self.fav3, self.cmd3, self.image3, self.fpid3],
                     [self.fav4, self.cmd4, self.image4, self.fpid4],
                     [self.fav5, self.cmd5, self.image5, self.fpid5],
                     [self.fav6, self.cmd6, self.image6, self.fpid6],
                     [self.fav7, self.cmd7, self.image7, self.fpid7],
                     [self.fav8, self.cmd8, self.image8, self.fpid8],
                     [self.fav9, self.cmd9, self.image9, self.fpid9],
                     [self.fav10, self.cmd10, self.image10, self.fpid10],
                     [self.fav11, self.cmd11, self.image11, self.fpid11],
                     [self.fav12, self.cmd12, self.image12, self.fpid12],
                     [self.fav13, self.cmd13, self.image13, self.fpid13],
                     [self.fav14, self.cmd14, self.image14, self.fpid14],
                     [self.fav15, self.cmd15, self.image15, self.fpid15],
                     [self.fav16, self.cmd16, self.image16, self.fpid16],
                     [self.fav17, self.cmd17, self.image17, self.fpid17],
                     [self.fav18, self.cmd18, self.image18, self.fpid18],
                     [self.fav19, self.cmd19, self.image19, self.fpid19]]
     tmpcount = 0
     for items in self.favlist:
         if not items[1] == "":
             tmpimage = Gtk.Image()
             tmpimage.set_from_file(self.conf.get('dock', (str(tmpcount) +
                                                           'icon')))
             pixbuf = tmpimage.get_pixbuf()
             try:
                 if pixbuf.get_height() > 48 or pixbuf.get_width() > 48:
                     scaled = pixbuf.scale_simple(48, 48,
                                                  GdkPixbuf.InterpType.HYPER)
                 else:
                     scaled = pixbuf
             except AttributeError:
                 tmpimage.set_from_file('/usr/share/icons/gnome/48x48/' +
                                        'status/dialog-question.png')
                 scaled = tmpimage.get_pixbuf()
             items[0].set_visible(True)
             items[0].set_tooltip_text(items[1])
             items[0].connect("button-release-event", self.execute)
             items[2].set_from_pixbuf(scaled)
         else:
             items[0].set_visible(False)
             items[0].set_tooltip_text("")
         tmpcount = tmpcount + 1
     tmpcount = 0
     self.delfavbutton.set_visible(False)
     for items in self.favlist:
         if not items[1]:
             tmpcount = tmpcount + 1
         if items[1]:
             # Allow delete if there are any shortcuts
             self.delfavbutton.set_visible(True)
     # only allow add it there is room to fit it
     if tmpcount == 0:
         self.addfavbutton.set_visible(False)
     else:
         self.addfavbutton.set_visible(True)
     return
Esempio n. 12
0
                                          str(tmpcount) +'icon', filelist[2])
                self.addfavs.hide()
                self.show()
                return actor
            tmpcount = tmpcount + 1
        self.addfavs.hide()
        return actor

    def delmode(self, actor):
        """ allow live deleting of favourites """
        return actor

    def choosefavs(self, actor):
        """ file chooser to pick favourites by *.desktop file """
        if actor == self.addfavbutton:
            self.hide()
            self.addfavs.present()
        return

    def cancelchoose(self, actor):
        """ close the filechooser """
        if actor == self.addfavcancel:
            self.addfavs.hide()
            self.show()
if __name__ == "__main__":
    PIRUMSHELL()
    logops.write(LOGFILE, ('\n===================================\n' +
                           'SHUTTING DOWN: pirum-shell closing...\n' +
                           time.asctime() + '\n========================' +
                           '===========\n'))