Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for ironhide-indicator... #77

Open
icb410 opened this issue Sep 20, 2011 · 2 comments
Open

Fix for ironhide-indicator... #77

icb410 opened this issue Sep 20, 2011 · 2 comments

Comments

@icb410
Copy link

icb410 commented Sep 20, 2011

Hi,
Just wanted to post this fix for the ironhide-indicator. There was a libnotify() issue that caused a crash as well as some indentation problems and problems with notify_state() function. Also in Config.py, this line should be changed:

user_relative_desktop_file_directory = '/'

to

user_relative_desktop_file_directory = '/.local/share/applications/'

so that the default "examples.desktop" in the home directory doesn't cause an initial crash, and so that when apps are configured to start with optirun always, they will.

Thanks for all the great coding!

#!/usr/bin/python
# -*- coding: utf-8 -*-
### BEGIN LICENSE
#
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <davy.renaud@laposte.net> wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return Davy Renaud (glyptostroboides)
# ----------------------------------------------------------------------------
#

#    This file is part of ironhide-ui.
#
#    ironhide-ui 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
#    (at your option) any later version.
#
#    ironhide-ui 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 ironhide-ui.  If not, see <http://www.gnu.org/licenses/>.
#
### END LICENSE

#UI MODULE
import pygtk
pygtk.require('2.0')
import gtk
import gobject
import appindicator
import pynotify

#SYSTEM MODULE
import os
import subprocess

###ORIGINAL CLASS
import app.Config
from app.AppSettings import Applications_settings, IconSet
from app.DesktopFile import DesktopFile, DesktopFileSet

class IronhideIndicator():
#TODO There must be a better way to get the icon than
    def notify_state(self,title,msg,icon_name):    #Altered by icb410
        self.notification= pynotify.Notification(title, msg, IconSet().get_uri(icon_name,48))  #fixed tab indentation to space
        self.notification.set_urgency(pynotify.URGENCY_CRITICAL)
            #self.notification.set_timeout(pynotify.EXPIRES_NEVER) ######   NICE TO SHOW A MESSAGE SIMPLY
        #FIXME The notification is to slow and this doesn't work
            #self.notification.set_timeout(1000)
        self.notification.show()

###INITIALIZATION OF INDICATOR AND MENU
    def __init__(self):
        #TODO Choose the best category for the indicator : appindicator.CATEGORY_APPLICATION_STATUS or appindicator.CATEGORY_SYSTEM_SERVICES
        self.ind = appindicator.Indicator ("ironhide-indicator", "ironhide-indicator", appindicator.CATEGORY_HARDWARE)
        self.ind.set_status (appindicator.STATUS_ACTIVE)
        self.ind.set_icon_theme_path(app.Config.icon_file_directory)
        #TODO The icons style and accesibility must be enhanced : see icons/test directory
        self.ind.set_icon(app.Config.icon_file_directory + "ironhide-indicator.svg",'Ironhide is unactive')
        self.ind.set_attention_icon (app.Config.icon_file_directory + "ironhide-indicator-active.svg",'Ironhide is active')
        self.card_state=False
        self.build_menu()
        self.menu.show()
        self.ind.set_menu(self.menu)
        pynotify.init("ironhide_indicator")  #Added to avoid crash by icb410
    def quit(self, widget, data=None):
        gtk.main_quit()

    def build_menu(self):
        self.menu = gtk.Menu()
        self.switch = gtk.CheckMenuItem()
        self.initial_state_checker()
        self.switch.set_sensitive(False)
        self.menu.append(self.switch)

        self.build_menu_separator()

        self.prefered_app_submenu = gtk.MenuItem("Preferred Apps")
        self.update_menu()
        self.prefered_app_submenu.connect('activate', self.update_menu)
        self.menu.append(self.prefered_app_submenu)

        item2 = gtk.MenuItem("Configure Apps")
        item2.connect("activate", self.app_configure)
        self.menu.append(item2)

    #TODO An UI to configure Ironhide would be nice

         #item3 = gtk.MenuItem("Configure Ironhide")
        #item3.show()
        #self.menu.append(item3)

        self.build_menu_separator()

        quit = gtk.ImageMenuItem(gtk.STOCK_QUIT)
        quit.connect("activate", self.quit)
        self.menu.append(quit)

        self.menu.show_all()

    def build_menu_separator(self):
        separator = gtk.SeparatorMenuItem()
        separator.show()
        self.menu.append(separator)

#FUNCTION TO GET THE MENU FROM THE CONFIG FILE
    def update_menu(self, widget=None):    
        self.pref_menu=gtk.Menu()
        subitem = gtk.MenuItem("Glxgears")
        subitem.connect("activate", self.call_app, ['optirun', 'glxgears'])
        subitem.show()
        self.pref_menu.append(subitem)
        file_set.get_configured_from_cfg()
        for file_name in file_set.configured_set:
            [Name, File_name, Categorie, Icon_name]  = DesktopFile(file_name).get_app_info()
            subitem = gtk.MenuItem(label=Name)
            #TODO : Discuss about style : is an icon needed for this simple shortcut
            #subitem = gtk.ImageMenuItem()
            #subitem.set_image(gtk.image_new_from_pixbuf(IconSet().get_pixbuf(Icon_name,icon_size=gtk.ICON_SIZE_MENU)))
            #subitem.set_label(Name)
            subitem.connect("activate", self.call_app, DesktopFile(file_name).get_exec_list())
            subitem.show()
            self.pref_menu.append(subitem)
        self.pref_menu.show()
        self.prefered_app_submenu.set_submenu(self.pref_menu)


    def initial_state_checker(self):
        if self.attention_state_condition(): self.set_attention_state(notify=False)
        else : self.set_active_state(notify=False)

    def state_checker(self):
        if self.attention_state_condition():
            if self.card_state == False : self.set_attention_state()
        elif self.card_state == True: self.set_active_state()    
        return True

    def attention_state_condition(self):
        stdout_handle = os.popen("cat /etc/default/ironhide |grep VGL_DISPLAY |cut -f2 -d:", "r")
        vgl_display = stdout_handle.read().rstrip("\n")
        vgl_display = "/tmp/.X%s-lock" % vgl_display
        if  os.path.exists(vgl_display): return True
        else: return False

    def set_attention_state(self, notify=True):
        self.ind.set_status(appindicator.STATUS_ATTENTION)
        self.card_state = True
        if notify == True: self.notify_state("Discrete card : ON", "Discrete graphic card is powered on", "ironhide-indicator-active")
        self.switch.set_label("Discrete card : ON")
        self.switch.set_active(True)

    def set_active_state(self, notify=True):
        self.ind.set_status(appindicator.STATUS_ACTIVE)
        self.card_state = False
        if notify == True: self.notify_state("Discrete card : OFF", "Discrete graphic card is powered off", "ironhide-indicator")
        self.switch.set_label("Discrete card : OFF")
        self.switch.set_active(False)

    def app_configure(self,widget):
        Applications_settings(file_set=file_set)

    def call_app(self, widget, app_exec):
    #FIXME There is a problem when closing the launched app and when the indicator has been closed: the indicator is still running : What a daemon!!
        subprocess.Popen(app_exec,shell=False)

    def about_box(self, widget, data=None):
        dialog = gtk.MessageDialog(None, type=gtk.MESSAGE_INFO,buttons=gtk.BUTTONS_NONE,message_format="Preferences/About")
        dialog.format_secondary_text("This is Optimus by mrs_sheep. \n It is based on ironhide by MrMEEE. \n The configuration can (by now) only be set thorugh the config file!")
        dialog.add_button(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)
        dialog.run()
        dialog.destroy()


    def main(self):
        self.state_checker()
        #FIXME It would be nice to avoid this loop : Maybe by using a signal emitted by the system
        #gtk.timeout_add(1000,self.state_checker)
        gobject.timeout_add_seconds(2, self.state_checker)
        gtk.main()

if __name__ == "__main__":

    file_set=DesktopFileSet()
    indicator = IronhideIndicator()
    indicator.main()
@rockorequin
Copy link

Applying those two changes against 1.0-1~oneiricubuntu1 fixes it for me, thanks! I now get a dialog when I choose Configure Apps, and a notification when the nvidia driver is loaded or unloaded - and no crash reports.

MrMEEE?

@PetrDlouhy
Copy link

This bug is still present in packages in PPA. Are there any obstacles to fix it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants