~ubuntu-branches/ubuntu/saucy/mago/saucy

« back to all changes in this revision

Viewing changes to mago/application/main.py

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2011-02-08 13:32:13 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110208133213-m1og7ey0m990chg6
Tags: 0.3+bzr20-0ubuntu1
* debian/rules:
  - updated to debhelper 7
  - use dh_python2 instead of python-central
* debian/pycompat:
  - removed, no longer needed
* debian/control:
  - dropped cdbs and python-central dependencies
* bzr snapshot of the current trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
PACKAGE = "mago"
2
 
 
3
 
"""
4
 
main module contains the definition of the main Application class
5
 
that is used to wrap applications functionality
6
 
"""
7
 
import ldtp, ooldtp
8
 
import os
9
 
from ..cmd import globals
10
 
import gettext
11
 
 
12
 
gettext.install (True)
13
 
gettext.bindtextdomain (PACKAGE, globals.LOCALE_SHARE)
14
 
gettext.textdomain (PACKAGE)
15
 
t = gettext.translation(PACKAGE, globals.LOCALE_SHARE, fallback = True)
16
 
_ = t.gettext
17
 
 
18
 
class Application:
19
 
    """
20
 
    Superclass for the rest of the applications
21
 
 
22
 
    Constants that should be defined in the classes that inherit from this class
23
 
    LAUNCHER: Command to launching the application through ldtp.launchapp
24
 
    LAUNCHER_ARGS: Arguments to pass when launching the application through
25
 
                   ldtp.launchapp.
26
 
    WINDOW: Top application frame pattern using ldtp syntax
27
 
    CLOSE_TYPE: Close object type (one of 'menu' or 'button')
28
 
    CLOSE_NAME: Close object name
29
 
    """
30
 
    CLOSE_TYPE = 'menu'
31
 
    CLOSE_NAME = _('mnuQuit')
32
 
    LAUNCHER_ARGS = []
33
 
    WINDOW     = ''
34
 
    TOP_PANEL = _('frmTopExpandedEdgePanel')
35
 
 
36
 
 
37
 
    def __init__(self, name = None, close_type= None, close_name= None):
38
 
        """
39
 
        @type close_type: string
40
 
        @param close_type: The type of close widget of the application. Types: menu, button.
41
 
        @type close_name: string
42
 
        @param close_name: The name of the close widget of the application. If not mentioned the default will be used ("Quit")
43
 
        """
44
 
        if name:
45
 
            self.name = name
46
 
        else:
47
 
            self.name = self.WINDOW
48
 
 
49
 
        if close_type:
50
 
            self.close_type = close_type
51
 
        else:
52
 
            self.close_type = self.CLOSE_TYPE
53
 
 
54
 
        if close_name:
55
 
            self.close_name = close_name
56
 
        else:
57
 
            self.close_name = self.CLOSE_NAME
58
 
 
59
 
 
60
 
    def set_name(self, name):
61
 
        if name is not None:
62
 
            self.name = name
63
 
 
64
 
    def set_close_type(self, close_type):
65
 
        if close_type is not None:
66
 
            self.close_type = close_type
67
 
 
68
 
    def set_close_name(self, close_name):
69
 
        if close_name is not None:
70
 
            self.close_name = close_name
71
 
 
72
 
    def remap(self):
73
 
        """
74
 
        It reloads the application map for the given ooldtp.context.
75
 
        """
76
 
        ldtp.remap(self.name)
77
 
 
78
 
    def open(self):
79
 
        """
80
 
        Given an application, it tries to open it.
81
 
        """
82
 
        self._enable_a11y(True)
83
 
        ldtp.launchapp(self.LAUNCHER, args=self.LAUNCHER_ARGS)
84
 
        self._enable_a11y(False)
85
 
 
86
 
        ldtp.wait(2)
87
 
        response = ldtp.waittillguiexist(self.name, '', 20)
88
 
 
89
 
        if response == 0:
90
 
            raise ldtp.LdtpExecutionError, "The " + self.name + " window was not found."
91
 
 
92
 
    def is_opened(self):
93
 
        """
94
 
        Returns 1, if the application is opened. 0, otherwise
95
 
        """
96
 
        return ldtp.guiexist(self.name)
97
 
 
98
 
    def close(self):
99
 
        """
100
 
        Given an application, it tries to close it.
101
 
        """
102
 
        app = ooldtp.context(self.name)
103
 
        close_widget = app.getchild(self.close_name)
104
 
 
105
 
        if self.close_type == 'menu':
106
 
            close_widget.selectmenuitem()
107
 
        elif self.close_type == 'button':
108
 
            close_widget.click()
109
 
        else:
110
 
            raise ldtp.LdtpExecutionError, "Wrong close item type."
111
 
        
112
 
        response = ldtp.waittillguinotexist(self.name, '', 20)
113
 
        if response == 0:
114
 
            raise ldtp.LdtpExecutionError, "Mmm, something went wrong when closing the application."
115
 
 
116
 
    def save(self, save_menu=_('mnuSave')):
117
 
        """
118
 
        Given an application, it tries to save the current document.
119
 
        This method gives very basic functionality. Please, override this method in the subclasses for error checking.
120
 
 
121
 
        @type save_menu: string
122
 
        @param save_menu: The name of the Save menu of the application. If not mentioned the default will be used ("Save").
123
 
        """
124
 
        app = ooldtp.context(self.name)
125
 
        actualMenu = app.getchild(save_menu)
126
 
 
127
 
        actualMenu.selectmenuitem()
128
 
 
129
 
    def write_text(self, text, txt_field=''):
130
 
        """
131
 
        Given an application it tries to write text to its current buffer.
132
 
        """
133
 
        app = ooldtp.context(self.name)
134
 
 
135
 
        if txt_field == '':
136
 
            ldtp.enterstring(text)
137
 
        else:
138
 
            app_txt_fields = app.getchild(txt_field, "text")
139
 
            for field in app_txt_fields:
140
 
                field.settextvalue(text)
141
 
 
142
 
    def _enable_a11y(self, enable):
143
 
        os.environ['NO_GAIL'] = str(int(not enable))
144
 
        os.environ['NO_AT_BRIDGE'] = str(int(not enable))