~dholbach/ubuntu/lucid/qemulator/fix-257233

« back to all changes in this revision

Viewing changes to usr/local/lib/qemulator/qml_filehandlers.py

  • Committer: Bazaar Package Importer
  • Author(s): Francesco Namuri
  • Date: 2007-06-20 16:11:22 UTC
  • Revision ID: james.westby@ubuntu.com-20070620161122-zzcdsje7in6qsrwm
Tags: upstream-0.5
ImportĀ upstreamĀ versionĀ 0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# coding=utf-8
 
3
 
 
4
##    Qemulator - a qemu gui written in python and GTK/Glade.
 
5
##    Copyright (C) 2006  rainer haage
 
6
##
 
7
##    This program is free software; you can redistribute it and/or
 
8
##    modify it under the terms of the GNU General Public License
 
9
##    as published by the Free Software Foundation; either version 2
 
10
##    of the License, or (at your option) any later version.
 
11
##    
 
12
##    This program is distributed in the hope that it will be useful,
 
13
##    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
##    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
##    GNU General Public License for more details.
 
16
##    
 
17
##    You should have received a copy of the GNU General Public License
 
18
##    along with this program; if not, write to the Free Software
 
19
##    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
20
from os import path
 
21
import os
 
22
import sys
 
23
import pickle
 
24
import time
 
25
import threading
 
26
from threading import Thread
 
27
import locale
 
28
import gettext
 
29
import gtk
 
30
import gtk.glade
 
31
 
 
32
import qemulator
 
33
 
 
34
import Run_Defaultapp
 
35
 
 
36
encoding = locale.getpreferredencoding()
 
37
utf8conv = lambda x : unicode(x, encoding).encode('utf8')
 
38
 
 
39
current_path = os.path.realpath(__file__)
 
40
basedir = os.path.dirname(os.path.realpath(__file__))
 
41
if not os.path.exists(os.path.join(basedir, "main.py")):
 
42
    if os.path.exists(os.path.join(os.getcwd(), "main.py")):
 
43
        basedir = os.getcwd()
 
44
sys.path.insert(0, basedir)   
 
45
 
 
46
basedir = basedir.replace ( '/bin', '' ) 
 
47
basedir = basedir.replace ( '/lib/qemulator', '' ) 
 
48
sys.path.append(basedir)   
 
49
bindir = basedir + "/bin"
 
50
libdir = basedir + "/lib/qemulator"
 
51
sharedir = basedir + "/share/qemulator"
 
52
pixmapdir = basedir + "/share/pixmaps/qemulator"
 
53
homedir = os.path.expanduser('~/.qemulator')
 
54
configdir = homedir + "/config"
 
55
 
 
56
APP = 'Qemulator'
 
57
#DIR = 'locale'
 
58
DIR = basedir + '/share/locale'
 
59
#print "DIR: " + DIR
 
60
locale.setlocale(locale.LC_ALL, '')
 
61
gettext.bindtextdomain(APP, DIR)
 
62
gettext.textdomain(APP)
 
63
_ = gettext.gettext
 
64
 
 
65
gtk.glade.bindtextdomain(APP, DIR)
 
66
gtk.glade.textdomain(APP)
 
67
 
 
68
class Statefiles:
 
69
    def __init__(self, bootimage, settings):
 
70
        self.statefiles_dir = homedir + "/statefiles"
 
71
        self.bootimage = bootimage
 
72
        self.translated_name = self.bootimage.replace ( '/', '_' )
 
73
        self.settings = settings
 
74
        
 
75
    def load_statefiles(self):
 
76
        self.storedstates = []
 
77
        if os.path.exists(self.statefiles_dir):
 
78
            thisjobdir = self.statefiles_dir + "/" + self.translated_name
 
79
            if os.path.exists(thisjobdir):
 
80
                for file in os.listdir(thisjobdir):
 
81
                    #print "file: " + str(file)
 
82
                    self.storedstates.append(str(file))
 
83
        self.storedstates.sort()
 
84
        return self.storedstates 
 
85
    
 
86
    def delete_statefile(self, filename):
 
87
        thisjobdir = self.statefiles_dir + "/" + self.translated_name
 
88
        abs_path = path.abspath(thisjobdir + "/" + filename)
 
89
        if os.path.isfile(abs_path):
 
90
            os.remove(abs_path)
 
91
            time.sleep(0.3)        
 
92
        
 
93
        print "state deleted: " + str(abs_path) 
 
94
        
 
95
    def statefiles_displaynames(self, data): 
 
96
        outdata = []
 
97
        for item in data:
 
98
            oitem = str(item.replace ( '_', ' ' ))
 
99
            outdata.append(oitem)
 
100
        return outdata            
 
101
 
 
102
class Screenshots:
 
103
    def __init__(self, bootimage, settings):
 
104
        self.screenshot_dir = homedir + "/screenshots"
 
105
        self.bootimage = bootimage
 
106
        self.translated_name = self.bootimage.replace ( '/', '_' )
 
107
        self.settings = settings
 
108
        
 
109
    def load_screenshots(self):
 
110
        self.storedshots = []
 
111
        if os.path.exists(self.screenshot_dir):
 
112
            thisjobdir = self.screenshot_dir + "/" + self.translated_name
 
113
            if os.path.exists(thisjobdir):
 
114
                for file in os.listdir(thisjobdir):
 
115
                    #print "file: " + str(file)
 
116
                    self.storedshots.append(str(file))
 
117
        self.storedshots.sort()
 
118
        return self.storedshots
 
119
    
 
120
    def delete_screenshot(self, filename):
 
121
        thisjobdir = self.screenshot_dir + "/" + self.translated_name
 
122
        abs_path = path.abspath(thisjobdir + "/" + filename)
 
123
        if os.path.isfile(abs_path):
 
124
            os.remove(abs_path)
 
125
            time.sleep(0.3)        
 
126
        #print "screenshot deleted: " + str(abs_path)
 
127
        
 
128
    def screenshots_displaynames(self, data): 
 
129
        outdata = []   
 
130
        #data = self.storedstates
 
131
        for item in data:
 
132
            oitem = str(item.replace ( '.ppm', '' ))
 
133
            oitem = str(oitem.replace ( '_', ' ' ))
 
134
            outdata.append(oitem)
 
135
        return outdata   
 
136
    
 
137
    def run_imageviewer(self, imagefile):       
 
138
        if imagefile != "":
 
139
            screenshot_path = self.screenshot_dir + "/" + self.translated_name + "/" + imagefile
 
140
            
 
141
            viewer = self.settings["helperapps_imageviewer"]
 
142
            if viewer != '':
 
143
                command = viewer + " " + screenshot_path
 
144
                returnval = False
 
145
                runit = RunExternalApp(command)
 
146
                runit.start()
 
147
                #return returnval 
 
148
            else:                
 
149
                runit = Run_Defaultapp
 
150
                rundefault = runit.open(screenshot_path)
 
151
                if rundefault != True:
 
152
                    dialogtitle = _('Error!')
 
153
                    dialogtext = _('Default application for this filetype could not be detected!\n\
 
154
Please select a custom application in main settings.')
 
155
                    dialog_markup = "<b>" + dialogtext + "</b>"
 
156
                    errordialog = qemulator.Dialog("error", dialog_markup, dialogtitle)                    
 
157
                
 
158
             
 
159
    
 
160
class Wavecaptures:
 
161
    def __init__(self, bootimage, settings):
 
162
        self.capture_dir = homedir + "/capture"
 
163
        self.bootimage = bootimage
 
164
        self.translated_name = self.bootimage.replace ( '/', '_' )
 
165
        self.settings = settings
 
166
        
 
167
    def load_captures(self):
 
168
        self.storedcapts = []
 
169
        if os.path.exists(self.capture_dir):
 
170
            thisjobdir = self.capture_dir + "/" + self.translated_name
 
171
            if os.path.exists(thisjobdir):
 
172
                for file in os.listdir(thisjobdir):
 
173
                    #print "file: " + str(file)
 
174
                    self.storedcapts.append(str(file))
 
175
        self.storedcapts.sort()
 
176
        return self.storedcapts    
 
177
    
 
178
    def delete_capture(self, filename):
 
179
        thisjobdir = self.capture_dir + "/" + self.translated_name
 
180
        abs_path = path.abspath(thisjobdir + "/" + filename)
 
181
        if os.path.isfile(abs_path):
 
182
            os.remove(abs_path)
 
183
            time.sleep(0.3)        
 
184
        
 
185
        print "capture deleted: " + str(abs_path)    
 
186
        
 
187
    def captures_displaynames(self, data): 
 
188
        outdata = []
 
189
        for item in data:
 
190
            oitem = str(item.replace ( '.wav', '' ))
 
191
            oitem = str(oitem.replace ( '_', ' ' ))
 
192
            
 
193
            outdata.append(oitem)
 
194
        return outdata  
 
195
    
 
196
    def run_audioplayer(self, audiofile):    
 
197
        if audiofile != "":
 
198
            capture_path = self.capture_dir + "/" + self.translated_name + "/" + audiofile
 
199
            viewer = self.settings["helperapps_audioplayer"]
 
200
            if viewer != '':
 
201
                command = viewer + " " + capture_path
 
202
                returnval = False
 
203
                runit = RunExternalApp(command)
 
204
                runit.start()
 
205
                #return returnval 
 
206
            else:                
 
207
                runit = Run_Defaultapp
 
208
                rundefault = runit.open(capture_path)
 
209
                if rundefault != True:
 
210
                    dialogtitle = _('Error!')
 
211
                    dialogtext = _('Default application for this filetype could not be detected!\n\
 
212
Please select a custom application in main settings.')
 
213
                    dialog_markup = "<b>" + dialogtext + "</b>"
 
214
                    errordialog = qemulator.Dialog("error", dialog_markup, dialogtitle)                    
 
215
                
 
216
                                                         
 
217
        
 
218
class RunExternalApp ( Thread ):
 
219
    def __init__ (self, command):
 
220
        Thread.__init__(self)
 
221
        self.command = command     
 
222
        print "Run App called with command: " + str(self.command)
 
223
    def run(self):
 
224
        runit = os.popen(self.command, 'r')
 
225
        print str(runit)
 
226
        return str(runit)
 
227
        print "command done!"  
 
228
        
 
229
def run_command(command):
 
230
        if command != '':
 
231
            child_stdin, child_stdout, child_stderr = os.popen3(command)
 
232
            child_stdin.close()    
 
233
            errormesg = child_stderr.readlines()
 
234
            resultmesg = child_stdout.readlines()
 
235
            if errormesg != []:
 
236
                #self.general_error = True
 
237
                print "Error: " + str(errormesg)
 
238
                returnmesg = errormesg
 
239
                child_stderr.close()
 
240
                child_stdout.close()
 
241
            else:
 
242
                returnmesg = resultmesg
 
243
        else:
 
244
            returnmesg = "no command given!"
 
245
        return returnmesg                  
 
246
                 
 
247
             
 
 
b'\\ No newline at end of file'