boss.py :  » IDE » PIDA » pida-0.6beta3 » pida » core » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » IDE » PIDA 
PIDA » pida 0.6beta3 » pida » core » boss.py
# -*- coding: utf-8 -*-
"""
    pida.core.boss
    ~~~~~~~~~~~~~~

    Boss is the main controller for Pida,
    it manages glueing together the rest

    :license: GPL2 or later
    :copyright: 2005-2008 by The PIDA Project
"""

import os
import gtk
import sys

from pida.core.environment import (is_firstrun,firstrun_filename,is_safe_mode
    workspace_name)
from .options import OptionsManager
from pida.core.servicemanager import ServiceManager
from pida.ui.icons import IconRegister
from pida.ui.window import PidaWindow
from pida.ui.splash import SplashScreen

# locale
from pida.core.locale import Locale
locale = Locale('pida')
_ = locale.gettext



class Boss(object):

    def __init__(self):
        self.show_splash()
        self._sm = ServiceManager(self, 
                                  update_progress=self._splash.update_progress)
        self._run_first_time()
        self.window = PidaWindow(self)

    def _run_first_time(self):
        if is_firstrun():
            from pida.utils.firstrun import FirstTimeWindow
            ft = FirstTimeWindow(self._sm.get_available_editors())
            success, editor = ft.run(firstrun_filename)
            self.override_editor = editor
            self.quit_before_started = not success
        else:
            self.override_editor = None
            self.quit_before_started = False

    def start(self):
        if self.quit_before_started:
            return False
        else:
            self._sm.activate_services()
            if self.override_editor is not None:
                self.get_service('editor').set_opt('editor_type',
                    self.override_editor)
            editor_name = self.get_service('editor').opt('editor_type')
            self._sm.activate_editor(editor_name)
            self._icons = IconRegister()
            self.window.start()
            self._sm.start_services()
            self._sm.start_editor()
            return True

    def stop(self, force=False, kill=False):
        """
        Stop pida.
        @force: on True: doesn't ask the user to quite, but a service may ask 
                for actions. Services can't stop the shutdown process
        @kill: on True: kill pida hard, nothing is informed or saved
        """
        if kill:
            gtk.main_quit()
        if force:
            self._sm.stop(force=force)
            gtk.main_quit()
        elif self.window.yesno_dlg(_('Are you sure you want to quit PIDA ?')):
            # in non force mode we only kill ourself if service manager
            # returns True
            if self._sm.stop():
                gtk.main_quit()
        else:
            return False

    def loop_ui(self):
        try:
            gtk.main()
        except KeyboardInterrupt:
            sys.exit(1)

    def get_service(self, servicename):
        return self._sm.get_service(servicename)

    def get_services(self):
        return self._sm.get_services()

    @property
    def editor(self):
        return self._sm.editor

    def get_plugins(self):
        return self._sm.get_plugins()

    def start_plugin(self, name):
        return self._sm.start_plugin(name)

    def stop_plugin(self, name):
        return self._sm.stop_plugin(name)

    def add_action_group_and_ui(self, actiongroup, uidef):
        self.window.add_action_group(actiongroup)
        return self.window.add_uidef(uidef)

    def remove_action_group_and_ui(self, actiongroup, ui_merge_id):
        self.window.remove_uidef(ui_merge_id)
        self.window.remove_action_group(actiongroup)

    def cmd(self, servicename, commandname, **kw):
        return self.get_service(servicename).cmd(commandname, **kw)

    def show_splash(self):
        self._splash = SplashScreen()
        self._splash.show_splash()

    def hide_splash(self):
        self._sm.update_progress = None
        self._splash.hide_splash()
        del self._splash

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.