/usr/share/pyshared/SCRIBES/InstanceManager.py is in scribes 0.4~r543-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | class Manager(object):
def __init__(self):
from DBusService import DBusService
DBusService(self)
self.__init_attributes()
from SaveProcessInitializer.Manager import Manager
Manager()
from sys import setcheckinterval
setcheckinterval(-1)
from gobject import timeout_add
timeout_add(30000, self.__init_psyco, priority=9999)
self.__init_i18n()
timeout_add(300000, self.__init_garbage_collector, priority=9999)
def __init_attributes(self):
from collections import deque
self.__editor_instances = deque([])
from gtk import WindowGroup
self.__wingroup = WindowGroup()
self.__busy = False
self.__interval = 0
self.__shortcut_list = []
return
########################################################################
#
# Public APIs
#
########################################################################
def register_editor(self, instance):
self.__wingroup.add_window(instance.window)
self.__editor_instances.append(instance)
return False
def unregister_editor(self, instance):
try:
self.__wingroup.remove_window(instance.window)
self.__editor_instances.remove(instance)
except ValueError:
print "===================================================="
print "Module: InstanceManager.py"
print "Class: Manager"
print "Method: unregister_editor"
print "Exception Type: ValueError"
print "Error: Instance not found", instance
print "===================================================="
finally:
# Quit when there are no editor instances.
if not self.__editor_instances: self.__quit()
return
def save_processor_is_ready(self):
from Utils import get_save_processor
processor = get_save_processor()
return processor.is_ready() if processor else False
def get_save_processor(self):
from Utils import get_save_processor
return get_save_processor()
def open_files(self, uris=None, encoding="utf-8"):
try:
if not uris: raise ValueError
has_uri = lambda x: x in self.get_uris()
has_not_uri = lambda x: not (x in self.get_uris())
open_file = lambda x: self.__open_file(x, encoding)
# Focus respective window if file is already open.
[self.focus_file(uri) for uri in uris if has_uri(uri)]
# Open new file if it's not already open.
[open_file(uri) for uri in uris if has_not_uri(uri)]
except ValueError:
self.__new_editor()
return False
def close_files(self, uris):
if not uris: return False
[self.__close_file(uri) for uri in uris]
return False
def close_all_windows(self):
from copy import copy
[instance.close() for instance in copy(self.__editor_instances)]
return False
def focus_file(self, uri):
found_instance = [editor for editor in self.__editor_instances if editor.uri == uri]
if not found_instance: return False
editor = found_instance[0]
self.__focus(editor)
return False
def focus_by_id(self, id_):
instance = [instance for instance in self.__editor_instances if instance.id_ == id_]
editor = instance[0]
self.__focus(editor)
return False
def get_uris(self):
if not self.__editor_instances: return []
return [editor.uri for editor in self.__editor_instances if editor.uri]
def get_editor_instances(self):
return self.__editor_instances
def add_shortcut(self, shortcut):
return self.__shortcut_list.append(shortcut)
def remove_shortcut(self, shortcut):
return self.__shortcut_list.remove(shortcut)
def get_shortcuts(self):
return self.__shortcut_list
def response(self):
if self.__busy: return False
self.__busy = True
from Utils import response
response()
self.__busy = False
return False
def set_vm_interval(self, response=True):
#FIXME: This function is deprecated!
return False
def __open_file(self, uri, encoding="utf-8"):
if not uri: return False
instances = self.__editor_instances
empty_windows = [x for x in instances if not x.contains_document]
empty_windows[0].load_file(uri, encoding) if empty_windows else self.__new_editor(uri, encoding)
return False
def __close_file(self, uri):
from copy import copy
[editor.close() for editor in copy(self.__editor_instances) if editor.uri == uri]
return False
def __new_editor(self, uri=None, encoding="utf-8"):
from Editor import Editor
Editor(self, uri, encoding)
return False
def __focus(self, editor):
editor.response()
if editor.window.get_data("minimized"): editor.window.deiconify()
coordinates = None if editor.window.get_data("maximized") else editor.window.get_position()
editor.response()
editor.window.hide()
editor.response()
if coordinates: editor.window.move(coordinates[0], coordinates[1])
editor.response()
editor.window.present()
editor.refresh()
return False
def __init_garbage_collector(self):
from gc import collect
collect()
return True
def __init_psyco(self):
try:
from psyco import background
background()
except ImportError:
pass
return False
def __init_i18n(self):
from Globals import data_path
from os import path
locale_folder = path.join(data_path, "locale")
# Initialize glade first.
try:
from locale import setlocale, LC_ALL, Error, bindtextdomain
bindtextdomain("scribes", locale_folder)
setlocale(LC_ALL, "")
except Error:
pass
from gtk import glade
glade.bindtextdomain("scribes", locale_folder)
glade.textdomain("scribes")
from gettext import textdomain, bindtextdomain
from gettext import install, bind_textdomain_codeset
bindtextdomain("scribes", locale_folder)
bind_textdomain_codeset("scribes", "UTF-8")
textdomain("scribes")
install("scribes", locale_folder, unicode=1)
return
def __remove_swap_area(self):
from glob import glob
from Globals import home_folder, metadata_folder, tmp_folder
from os.path import join
# files = glob(join(home_folder, ".Scribes*scribes"))
files = glob(join(tmp_folder, ".Scribes*scribes"))
from shutil import rmtree
[rmtree(file_, True) for file_ in files]
files = glob(join(metadata_folder, "__db*"))
from shutil import rmtree
[rmtree(file_, True) for file_ in files]
return
def __quit(self):
self.__remove_swap_area()
raise SystemExit
return
|