2 from PyQt4.QtCore import *
3 from PyQt4.QtGui import *
5 from sface.config import config
6 from sface.screens.sfascreen import SfaScreen
8 from sfa.util.version import version_core
9 from sface.version import version_dict
11 from sface.sficreate import CreateWindow
15 "Sface : %s (%s)" % (version_dict()['code_tag'], version_dict()['code_url']),
16 "with (local) SFA libs : %s (%s)" % (version_core()['code_tag'],version_core()['code_url']),
18 'registry': "usual port for registry: 12345",
19 'slicemgr': ["usual port for slice manager: 12347","usual port for aggregate: 12346"],
22 class ConfigWidget(QWidget):
23 def __init__(self, parent):
24 QWidget.__init__(self, parent)
25 # init can be called several times for when the config dir is changed
29 def store_local (self, name, value):
30 setattr (self, 'widget_'+name, value)
31 def retrieve_local (self, name):
32 return getattr (self, 'widget_'+name, None)
35 # if already inited we just need to set the values
37 for (field,msg) in config.field_labels():
38 edit = self.retrieve_local(field)
39 if isinstance (edit,QCheckBox):
40 if config.is_true(config.get(field)): edit.setCheckState (Qt.Checked)
41 else: edit.setCheckState (Qt.Unchecked)
43 edit.setText (config.get(field) or "")
46 # otherwise we need to build the whole thing up
47 glayout = QGridLayout()
49 for (field,msg) in config.field_labels():
51 if static_labels.has_key(field):
52 labels=static_labels[field]
53 if not isinstance(labels,list): labels = [ labels, ]
55 glayout.addWidget(QLabel(label),row,1)
57 # edit : text or checkbox
58 default=config.field_default(field)
59 if isinstance(default,bool):
61 self.store_local (field, edit)
62 if config.is_true(config.get(field)):
63 edit.setCheckState(Qt.Checked)
65 edit=QLineEdit(config.get(field) or "", self)
66 self.store_local (field, edit)
67 edit.setAttribute(Qt.WA_MacShowFocusRect, 0)
68 setattr(self,field,edit)
70 glayout.addWidget(QLabel(msg+":",self), row, 0)
71 glayout.addWidget(edit, row, 1)
75 hlayout = QHBoxLayout()
76 def bottom_button (action,label,align):
77 button=QPushButton(label, self)
78 button.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
79 hlayout.addWidget(button,0,align)
80 hlayout.addSpacing(10)
81 self.connect(button, SIGNAL('clicked()'), getattr(self,action))
83 bottom_button ('load','Load Config Dir',Qt.AlignLeft)
85 # the config dir edit dialog
86 confdir=QLineEdit (config.get_dirname(),self)
87 self.store_local('config_dirname',confdir)
88 confdir.setAttribute(Qt.WA_MacShowFocusRect, 0)
89 confdir.setSizePolicy(QSizePolicy.Expanding,QSizePolicy.Maximum)
90 confdir.setStyleSheet("QLineEdit { width: 200px; }")
91 self.connect(confdir,SIGNAL ('returnPressed()'), self.load)
92 hlayout.addWidget (confdir,0,Qt.AlignLeft)
93 hlayout.addSpacing(10)
96 bottom_button ('createSlice', 'Create New Slice', Qt.AlignRight),
97 bottom_button ('apply','Apply Only',Qt.AlignRight),
98 bottom_button ('save','Apply && Save',Qt.AlignRight)
100 layout = QVBoxLayout()
101 layout.addLayout(glayout)
102 layout.addLayout(hlayout)
104 self.setLayout(layout)
107 def createSlice(self):
108 dlg = CreateWindow(parent=self)
110 if (dlg.sliceWasCreated):
111 self.slice.setText(dlg.getHrn())
115 for field in config.fields():
116 widget=getattr(self,field)
117 if isinstance(widget,QCheckBox):
118 if widget.checkState() == Qt.Checked:
119 config.set(field, True)
121 config.set(field, False)
123 config.set(field, str(widget.text()))
125 self.parent().setStatus("<font color='green'>Settings loaded for current session</font>", timeout=5000)
126 config.display("after apply")
128 self.parent().signalAll('configurationChanged')
134 self.parent().setStatus("<font color='green'>Configuration saved in %s !</font>"%config.config_file(), timeout=5000)
136 # switch to another config dir
138 # obtain new dor somehow
140 edit=self.retrieve_local('config_dirname')
141 newdir=str(edit.text())
143 print 'installing',newdir
144 config.set_dirname (newdir)
146 self.parent().signalAll('configurationChanged')
149 class ConfigScreen(SfaScreen):
150 def __init__(self, parent):
151 SfaScreen.__init__(self, parent)
153 widget = ConfigWidget(self)
154 self.init(widget, "Configure", "Configure the OneLab SFA crawler")