~ubuntu-branches/ubuntu/saucy/unity-tweak-tool/saucy-proposed

« back to all changes in this revision

Viewing changes to UnityTweakTool/__init__.py

  • Committer: Package Import Robot
  • Author(s): Barneedhar Vigneshwar, Barneedhar Vigneshwar, J Phani Mahesh, Sam Hewitt
  • Date: 2013-04-05 23:05:49 UTC
  • Revision ID: package-import@ubuntu.com-20130405230549-tizel3514r09ke7l
Tags: 0.0.4
[ Barneedhar Vigneshwar ]
* New upstream release (LP: #1165141)
* data/windowmanager.ui
  - Fix missing signal in the auto-raise switch (LP: #1160782)
* UnityTweakTool/section/sphagetti/theme.py
  - Fix KeyError when fetching window themes (LP: #1146122)
* UnityTweakTool/section/unity.py
  - Fix show-desktop switch (LP: #1156266)
  - Fix 'switch between workspace' switch (LP: #1156236)

[ J Phani Mahesh ]
* debian/source_unity-tweak-tool.py  
  - Update Apport hook to file crash bugs against the package by default
* setup.py
  - Install translated pot files
* unity-tweak-tool
  - Fixed and renamed -r parameter to --reset-unity in the wrapper
* UnityTweakTool/__init__.py
  - Prevent multiple instances using dbus
* UnityTweakTool/elements/radio.py
  - Fix AssertionError in __init__() (LP: #1156201)
  - Fix AssertionError due to missing overlay-scrollbar package (LP: #1156337)
* UnityTweakTool/section/sphagetti/compiz.py
  - Fix resetting transparency values (LP: #1099067)
* UnityTweakTool/section/sphagetti/unity.py
  - Fix AttributeError in refresh(): 'NoneType' object has no attribute 'get_boolean' (LP: #1155331)

[Sam Hewitt]
* debian/control
  - Added dependency on python3-cairo (LP: #1156789)
* UnityTweakTool/section/sphagetti/unity.py
  - Fixed unresponsive 'battery-life' switch (LP: #1129262)

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
__all__=['backends','config','elements']
35
35
 
36
36
import os
 
37
import sys
37
38
import logging
 
39
import dbus, dbus.service
38
40
from gi.repository import Gtk
 
41
from dbus.mainloop.glib import DBusGMainLoop
39
42
from UnityTweakTool.config.logging import LOGFILE,LOGFMT,LOGLVL
40
43
 
 
44
DBusGMainLoop(set_as_default=True)
 
45
 
41
46
logger=logging.getLogger('UnityTweakTool')
42
47
logger.setLevel(LOGLVL)
43
48
 
51
56
 
52
57
del _fh, _formatter
53
58
 
54
 
def connectpages():
55
 
    from UnityTweakTool.section.overview import Overview
56
 
    from UnityTweakTool.section.unity import Unity
57
 
    from UnityTweakTool.section.windowmanager import WindowManager
58
 
    from UnityTweakTool.section.system import System
59
 
    from UnityTweakTool.section.appearance import Appearance
60
 
    sections=[Overview(notebook),Unity,WindowManager,Appearance,System]
61
 
    for section in sections:
62
 
        id=notebook.append_page(section.page,None)
63
 
        assert id is not -1
64
 
 
65
 
def connecthandlers(builder):
66
 
    handler={}
67
 
    def show_overview(*args,**kwargs):
68
 
        notebook.set_current_page(0)
69
 
    handler['on_b_overview_clicked']=show_overview
70
 
 
71
 
    appmenu={
72
 
        'unity_launcher'    :(1,0),
73
 
        'unity_dash'        :(1,1),
74
 
        'unity_panel'       :(1,2),
75
 
        'unity_switcher'    :(1,3),
76
 
        'unity_webapps'     :(1,4),
77
 
        'unity_additional'  :(1,5),
78
 
 
79
 
        'compiz_general'    :(2,0),
80
 
        'compiz_workspace'  :(2,1),
81
 
        'compiz_windows_spread' :(2,2),
82
 
        'compiz_windows_snapping':(2,3),
83
 
        'compiz_hotcorners'         :(2,4),
84
 
        'compiz_additional'         :(2,5),
85
 
 
86
 
        'theme_system'      :(3,0),
87
 
        'theme_icon'        :(3,1),
88
 
        'theme_cursor'      :(3,2),
89
 
        'theme_fonts'       :(3,3),
90
 
        'window_controls'   :(3,4),
91
 
 
92
 
        'desktop_icons'     :(4,0),
93
 
        'system_security'   :(4,1),
94
 
        'scrolling'         :(4,2)
95
 
    }
96
 
 
97
 
    def gen_appmenu_handler(loc):
98
 
        def appmenu_handler(*args):
99
 
            notebook.set_current_page(loc[0])
100
 
            notebook.get_nth_page(loc[0]).set_current_page(loc[1])
101
 
        return appmenu_handler
102
 
 
103
 
    for item,location in appmenu.items():
104
 
        handler['on_menuitem_%s_activate'%item]=gen_appmenu_handler(location)
105
 
 
106
 
    handler['on_menuimage_quit_activate']=lambda *args:Gtk.main_quit()
107
 
    from UnityTweakTool.about import About
108
 
    handler['on_menuimage_about_activate']=lambda *args: About()
109
 
    builder.connect_signals(handler)
 
59
 
110
60
##########################################################################
111
 
def init(page=0):
112
 
    print('Initialising...')
113
 
    from UnityTweakTool.config.data import get_data_path
114
 
    global notebook
115
 
    builder=Gtk.Builder()
116
 
    ui=os.path.join(get_data_path(),'unitytweak.ui')
117
 
    builder.add_from_file(ui)
118
 
    notebook=builder.get_object('nb_unitytweak')
119
 
    connectpages()
120
 
    notebook.set_current_page(page)
121
 
    connecthandlers(builder)
122
 
    builder.get_object('unitytweak_main').show_all()
123
 
    builder.get_object('unitytweak_main').connect('delete-event',Gtk.main_quit)
124
 
    Gtk.main()
125
 
 
 
61
 
 
62
class Application(dbus.service.Object):
 
63
    def __init__(self,pageid=-1):
 
64
        DIR=os.path.expanduser('~/.config/unity-tweak-tool/')
 
65
        LOCKFILE=os.path.join(DIR,"pid.lockfile")
 
66
        if not os.path.exists(DIR):
 
67
            os.makedirs(DIR)
 
68
        if os.access(LOCKFILE, os.F_OK):
 
69
            pidfile = open(LOCKFILE, "r")
 
70
            pidfile.seek(0)
 
71
            old_pd = pidfile.readline()
 
72
            pidfile.close()
 
73
            if os.path.exists("/proc/%s" % old_pd):
 
74
                print("""
 
75
        Another instance of Unity Tweak Tool seems to be running with
 
76
        process id %s. Switching to the already existing window.
 
77
                    """ % old_pd)
 
78
                self.call_running_instance(pageid)
 
79
                sys.exit(1)
 
80
            else:
 
81
                os.remove(LOCKFILE)
 
82
 
 
83
        pidfile = open(LOCKFILE, "w")
 
84
        pidfile.write("%s" % os.getpid())
 
85
        pidfile.close()
 
86
 
 
87
        self.register_dbus_session()
 
88
        self.run(pageid)
 
89
 
 
90
    def run(self,pageid):
 
91
        from UnityTweakTool.config.data import get_data_path
 
92
        self.builder=Gtk.Builder()
 
93
        self.builder.set_translation_domain('unity-tweak-tool')
 
94
        self.ui=os.path.join(get_data_path(),'unitytweak.ui')
 
95
        self.builder.add_from_file(self.ui)
 
96
        self.notebook=self.builder.get_object('nb_unitytweak')
 
97
        self.connectpages()
 
98
        self.connecthandlers()
 
99
# from gi.repository import Unity
 
100
#        self.launcher = Unity.LauncherEntry.get_for_desktop_id("unity-tweak-tool.desktop")        
 
101
        self.window=self.builder.get_object('unitytweak_main')
 
102
        self.window.show_all()
 
103
        self.window.connect('delete-event',Gtk.main_quit)
 
104
        if pageid is not None:
 
105
            self.switch_to_page(pageid)
 
106
        Gtk.main()
 
107
 
 
108
    def connectpages(self):
 
109
        from UnityTweakTool.section.overview import Overview
 
110
        from UnityTweakTool.section.unity import Unity
 
111
        from UnityTweakTool.section.windowmanager import WindowManager
 
112
        from UnityTweakTool.section.system import System
 
113
        from UnityTweakTool.section.appearance import Appearance
 
114
        sections=[Overview(self.notebook),Unity,WindowManager,Appearance,System]
 
115
        for section in sections:
 
116
            id=self.notebook.append_page(section.page,None)
 
117
            assert id is not -1
 
118
 
 
119
    def connecthandlers(self):
 
120
        handler={}
 
121
        def show_overview(*args,**kwargs):
 
122
            self.notebook.set_current_page(0)
 
123
        handler['on_b_overview_clicked']=show_overview
 
124
 
 
125
        appmenu={
 
126
            'unity_launcher'    :(1,0),
 
127
            'unity_dash'        :(1,1),
 
128
            'unity_panel'       :(1,2),
 
129
            'unity_switcher'    :(1,3),
 
130
            'unity_webapps'     :(1,4),
 
131
            'unity_additional'  :(1,5),
 
132
 
 
133
            'compiz_general'    :(2,0),
 
134
            'compiz_workspace'  :(2,1),
 
135
            'compiz_windows_spread' :(2,2),
 
136
            'compiz_windows_snapping':(2,3),
 
137
            'compiz_hotcorners'         :(2,4),
 
138
            'compiz_additional'         :(2,5),
 
139
 
 
140
            'theme_system'      :(3,0),
 
141
            'theme_icon'        :(3,1),
 
142
            'theme_cursor'      :(3,2),
 
143
            'theme_fonts'       :(3,3),
 
144
            'window_controls'   :(3,4),
 
145
 
 
146
            'desktop_icons'     :(4,0),
 
147
            'system_security'   :(4,1),
 
148
            'scrolling'         :(4,2)
 
149
        }
 
150
 
 
151
        def gen_appmenu_handler(loc):
 
152
            def appmenu_handler(*args):
 
153
                self.notebook.set_current_page(loc[0])
 
154
                self.notebook.get_nth_page(loc[0]).set_current_page(loc[1])
 
155
            return appmenu_handler
 
156
 
 
157
        for item,location in appmenu.items():
 
158
            handler['on_menuitem_%s_activate'%item]=gen_appmenu_handler(location)
 
159
 
 
160
        handler['on_menuimage_quit_activate']=lambda *args:Gtk.main_quit()
 
161
        from UnityTweakTool.about import About
 
162
        handler['on_menuimage_about_activate']=lambda *args: About()
 
163
        self.builder.connect_signals(handler)
 
164
    
 
165
 
 
166
 
 
167
    def register_dbus_session(self):
 
168
        bus_name = dbus.service.BusName('org.freyja.utt', bus=dbus.SessionBus())
 
169
        dbus.service.Object.__init__(self, bus_name, '/org/freyja/utt')
 
170
 
 
171
    def call_running_instance(self, pageid):
 
172
        bus = dbus.SessionBus()
 
173
        service = bus.get_object('org.freyja.utt', '/org/freyja/utt')
 
174
        service.get_dbus_method('switch_to_page', 'org.freyja.utt')(pageid)
 
175
 
 
176
    @dbus.service.method('org.freyja.utt', in_signature='i')
 
177
    def switch_to_page(self, pageid):
 
178
        if not pageid == -1:
 
179
            self.notebook.set_current_page(pageid)
 
180
        self.window.present()
 
181
 
 
182
def reset_all():
 
183
    import UnityTweakTool.utils.unityreset as unityreset
 
184
    unityreset.UnityReset()