4
## Qemulator - a qemu gui written in python and GTK/Glade.
5
## Copyright (C) 2006 rainer haage
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.
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.
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.
26
from threading import Thread
36
encoding = locale.getpreferredencoding()
37
utf8conv = lambda x : unicode(x, encoding).encode('utf8')
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")):
44
sys.path.insert(0, basedir)
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"
58
DIR = basedir + '/share/locale'
60
locale.setlocale(locale.LC_ALL, '')
61
gettext.bindtextdomain(APP, DIR)
62
gettext.textdomain(APP)
65
gtk.glade.bindtextdomain(APP, DIR)
66
gtk.glade.textdomain(APP)
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
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
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):
93
print "state deleted: " + str(abs_path)
95
def statefiles_displaynames(self, data):
98
oitem = str(item.replace ( '_', ' ' ))
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
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
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):
126
#print "screenshot deleted: " + str(abs_path)
128
def screenshots_displaynames(self, data):
130
#data = self.storedstates
132
oitem = str(item.replace ( '.ppm', '' ))
133
oitem = str(oitem.replace ( '_', ' ' ))
134
outdata.append(oitem)
137
def run_imageviewer(self, imagefile):
139
screenshot_path = self.screenshot_dir + "/" + self.translated_name + "/" + imagefile
141
viewer = self.settings["helperapps_imageviewer"]
143
command = viewer + " " + screenshot_path
145
runit = RunExternalApp(command)
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)
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
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
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):
185
print "capture deleted: " + str(abs_path)
187
def captures_displaynames(self, data):
190
oitem = str(item.replace ( '.wav', '' ))
191
oitem = str(oitem.replace ( '_', ' ' ))
193
outdata.append(oitem)
196
def run_audioplayer(self, audiofile):
198
capture_path = self.capture_dir + "/" + self.translated_name + "/" + audiofile
199
viewer = self.settings["helperapps_audioplayer"]
201
command = viewer + " " + capture_path
203
runit = RunExternalApp(command)
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)
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)
224
runit = os.popen(self.command, 'r')
227
print "command done!"
229
def run_command(command):
231
child_stdin, child_stdout, child_stderr = os.popen3(command)
233
errormesg = child_stderr.readlines()
234
resultmesg = child_stdout.readlines()
236
#self.general_error = True
237
print "Error: " + str(errormesg)
238
returnmesg = errormesg
242
returnmesg = resultmesg
244
returnmesg = "no command given!"
b'\\ No newline at end of file'