source: internals/2011/cmce/trunk/gui/run.py @ 5005

Last change on this file since 5005 was 5005, checked in by goncalo.pinheira, 9 years ago

CMCE: added current version

File size: 2.9 KB
Line 
1#!/usr/bin/python
2import sys, os
3from PyQt4 import QtGui
4from PyQt4.QtCore import QObject, QString, SIGNAL
5from main import  Ui_MainWindow
6from gui_library.input  import choice, force_choice
7from gui_library.output import error
8import uck
9
10def check_iso(filename):
11    if not filename:
12        error(myapp, "Please select a ISO image")
13        return False
14    if not os.path.exists(filename):
15       error(myapp, "Could not open the selected ISO image")
16       return False
17    return True
18
19def choose_languages():
20    language_packs= force_choice(False, True, uck.available_language_packs(), "Choose which languages you want your system to support", multi_choice=True)
21    boot_languages= force_choice(False, True, uck.available_boot_languages(), "Choose which languages you want your system to support while initializing", multi_choice=True)
22    default_boot_language= force_choice(False, True, boot_languages, "Choose the default (system initialization) language")
23    if not (language_packs and boot_languages and default_boot_language):
24        return None
25    else:
26        return (language_packs, boot_languages, default_boot_language)
27
28def start_customization():
29    iso_file= get_iso()
30    cust_dir= os.path.expanduser("~/tmp")   #MUST be absolute path
31    if not check_iso(iso_file):
32         return
33    args= {"remaster_dir":cust_dir, "source_iso":iso_file}
34    if change_language():
35        lp, bl, dbl= choose_languages()
36        args.update({"language_packs":lp, "livecd_locales":bl, "livecd_locale": dbl})
37    if  run_graphic_customization():
38        args.update({"run_graphical_customization":True})
39
40    print "CUSTOMIZATION STARTED WITH ARGS:", args
41    c_process= uck.run_customization(**args)
42    #while True:
43    #    a,b= [pipe.readline() for pipe in (c_process.stdout, c_process.stderr)]
44    #    if not (a or b):
45    #        break
46    #    print (a if a else b),
47    print "RETURN CODE: ", c_process.wait()
48
49
50#------GUI FUNCTIONS-------------------------------------------------
51
52
53def browse_iso():
54    filename= QtGui.QFileDialog().getOpenFileName(None, "Select ISO", "", "ISO image (*.iso)")
55    if filename:
56        myapp.pathEdit.setText(filename)
57
58def get_iso():
59    return myapp.pathEdit.text()
60
61def set_progress(fraction):
62    assert 0<=fraction<=1
63    myapp.progressBar.setValue( int(100*fraction) )
64
65def change_language():
66    return myapp.languageCheck.isChecked()
67
68def run_graphic_customization():
69    return myapp.graphicalCheck.isChecked()
70
71class MyMainWindow(Ui_MainWindow, QtGui.QMainWindow):
72    def __init__(self):
73        QtGui.QMainWindow.__init__(self)
74        self.setupUi(self)
75        self.setupSignals()
76
77    def setupSignals(self):
78        QObject.connect(self.browseButton, SIGNAL("clicked()"), browse_iso)
79        QObject.connect(self.startButton, SIGNAL("clicked()"), start_customization)
80
81
82
83if __name__ == "__main__":
84    app = QtGui.QApplication(sys.argv)
85    myapp = MyMainWindow()
86    myapp.show()
87    sys.exit(app.exec_())
88
89
Note: See TracBrowser for help on using the repository browser.