Skip to content

Commit

Permalink
Restore Qt backend with fixes (and interface selector)
Browse files Browse the repository at this point in the history
Use it by default everywhere but MATE and GNOME.
Now with Qt5 support and theme icons for stuff.
  • Loading branch information
XRevan86 committed Feb 9, 2016
1 parent 206b201 commit 9069c07
Show file tree
Hide file tree
Showing 8 changed files with 189 additions and 6 deletions.
78 changes: 78 additions & 0 deletions FusionIcon/interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# -*- python -*-
# This file is part of Fusion-icon.

# Fusion-icon 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.
#
# Fusion-icon 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/>.
#
# Author(s): crdlb, nesl247
#
# Copyright 2007 Christopher Williams <[email protected]>

import sys
from util import env
import start

interfaces={
'qt': 'Qt',
'gtk': 'GTK+',
}

def import_interface(interface):
try:
if interface in interfaces:
print(' * Using the ' + interfaces[interface] + ' Interface')
__import__('FusionIcon.interface_' + interface)

else:
print(' *** Error: "' + interface + '" interface is invalid, this should not happen')
raise SystemExit

except ImportError as e:
if [i for i in interfaces if 'interface_' + i in str(e)]:
print(' * Interface not installed')
else:
print(' * ' + str(e))

#doesn't work so remove it from the dict
del interfaces[interface]
if interfaces:
print(' ... Trying another interface')
choose_interface()
else:
print(' *** Error: All interfaces failed, aborting!')
raise SystemExit

def choose_interface(try_first=None):

chosen_interface = None

# handle explicit choice first
if try_first:
if try_first in interfaces:
chosen_interface = try_first
else:
raise SystemExit(' *** Error: No such interface: ' + try_first)
else:

# use qt for gnome; qt for everything else:
if 'gtk' in interfaces and (env.desktop == 'mate' or env.desktop == 'gnome'):
chosen_interface = 'gtk'
elif 'qt' in interfaces:
chosen_interface = 'qt'
elif 'gtk' in interfaces:
chosen_interface = 'gtk'
# interfaces is empty
else:
raise SystemExit(' *** no available interfaces, this should not happen')

import_interface(chosen_interface)
3 changes: 3 additions & 0 deletions FusionIcon/interface_qt/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- python -*-

import main
98 changes: 98 additions & 0 deletions FusionIcon/interface_qt/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# -*- python -*-
# This file is part of Fusion-icon.

# Fusion-icon 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.
#
# Fusion-icon 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/>.

# Author(s): xsacha, XRevan86, raveit65

import sys, os, time
try:
from PyQt5 import QtWidgets, QtGui, QtCore
from PyQt5.QtWidgets import QApplication, QMenu, QActionGroup, QSystemTrayIcon
except ImportError:
from PyQt4 import QtGui, QtCore
from PyQt4.QtGui import QApplication, QMenu, QActionGroup, QSystemTrayIcon
if tuple(map(int, (QtCore.QT_VERSION_STR.split('.')))) < (4, 6, 0):
raise ImportError('Qt 4.6.x or later required')
from FusionIcon.start import wms, apps, options, decorators, init

class Build(QApplication):
def reload_wm(self):
wms.restart()

def toggleWM(self, wm):
if wms.active != wm:
wms.active = wm
wms.start()

def toggleOP(self, option):
options[option].enabled = not options[option].enabled
if wms.active == 'compiz':
wms.start()

def toggleWD(self, decorator):
decorators.active = decorator

def __init__(self, parent=None):
QtCore.QObject.__init__(self, parent)
if not QSystemTrayIcon.isSystemTrayAvailable():
raise SystemExit('Notification area is not available.')
self.Tray = QSystemTrayIcon(QtGui.QIcon.fromTheme('fusion-icon'))
self.Tray.setToolTip('Compiz Icon')
self.Tray.managerMenu = QMenu()
self.Tray.optionsMenu = QMenu()
self.Tray.decoratorMenu = QMenu()
self.groupManager = QActionGroup(self.Tray.managerMenu)
self.groupDecorator = QActionGroup(self.Tray.decoratorMenu)

for wm in wms.ordered_list:
actionWM = self.groupManager.addAction(self.Tray.managerMenu.addAction(wms[wm].label, lambda val=wm : self.toggleWM(val)))
actionWM.setCheckable(True)
if wms.active == wm:
actionWM.setChecked(True)

for option in options:
actionOP = self.Tray.optionsMenu.addAction(options[option].label, lambda val=option: self.toggleOP(val))
actionOP.setCheckable(True)
if not options[option].sensitive:
actionOP.setEnabled(False)
actionOP.setChecked(options[option].enabled)

for decorator in decorators:
actionWD = self.groupDecorator.addAction(self.Tray.decoratorMenu.addAction(decorators[decorator].label, lambda val=decorator: self.toggleWD(val)))
actionWD.setCheckable(True)
if decorators.active == decorator:
actionWD.setChecked(True)

self.Tray.menu = QMenu()

if 'ccsm' in apps:
self.Tray.menu.addAction(QtGui.QIcon.fromTheme('preferences-system'), apps['ccsm'].label, lambda: run(['ccsm']))
if 'emerald theme manager' in apps:
self.Tray.menu.addAction(QtGui.QIcon.fromTheme('emerald-theme-manager', QtGui.QIcon('/usr/share/pixmaps/emerald-theme-manager-icon.png')), \
apps['emerald theme manager'].label, lambda: run(apps['emerald theme manager'].command))
if 'ccsm' in apps or 'emerald theme manager' in apps:
self.Tray.menu.addSeparator()

self.Tray.menu.addAction(QtGui.QIcon.fromTheme('view-refresh'), 'Reload Window Manager', self.reload_wm)
self.Tray.menu.addAction(QtGui.QIcon.fromTheme('view-restore'), 'Select Window Manager').setMenu(self.Tray.managerMenu)
self.Tray.menu.addAction(QtGui.QIcon.fromTheme('document-properties'), 'Compiz Options').setMenu(self.Tray.optionsMenu)
self.Tray.menu.addAction(QtGui.QIcon.fromTheme('view-fullscreen'), 'Select Window Decorator').setMenu(self.Tray.decoratorMenu)
self.Tray.menu.addSeparator()
self.Tray.menu.addAction(QtGui.QIcon.fromTheme('application-exit'), 'Quit', self.quit)
self.Tray.setContextMenu(self.Tray.menu)
self.Tray.show()
init()

Build(sys.argv).exec_()
5 changes: 4 additions & 1 deletion FusionIcon/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,11 @@

interface_group = OptionGroup(parser, 'Interface Options')

interface_group.add_option('-i', '--interface', dest='interface',
help='Try a certain interface first')

interface_group.add_option('-u', '--no-interface', action='store_true', dest='no_interface',
help='Do not use graphics interface')
help='Do not use any interface')

parser.add_option_group(interface_group)

Expand Down
2 changes: 2 additions & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ FusionIcon/__init__.py
FusionIcon/data.py
FusionIcon/interface.py
FusionIcon/parser.py
FusionIcon/interface_qt/__init__.py
FusionIcon/interface_qt/main.py
FusionIcon/interface_gtk/__init__.py
FusionIcon/interface_gtk/main.py.in
FusionIcon/util.py
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PREFIX = '/usr'
DESTDIR = '/'
interfaces = 'gtk'
interfaces = 'qt gtk'

all:
@python setup.py build
Expand Down
6 changes: 2 additions & 4 deletions fusion-icon
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,5 @@ if options.no_interface:
init()

else:
try:
import FusionIcon.interface_gtk
except ImportError as e:
print(' * GTK+ interface is missing required library ', e)
from FusionIcon.interface import choose_interface
choose_interface(try_first=options.interface)
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def run(self):
packages = ['FusionIcon']

available_interfaces = {
'qt': 'FusionIcon.interface_qt',
'gtk': 'FusionIcon.interface_gtk',
}

Expand Down

0 comments on commit 9069c07

Please sign in to comment.