def reset_tests(self, code_dict): self.__view_tests = code_dict.copy() if self.__current_test: test_code = self.__view_tests.get(self.__current_test) if not test_code: test_code = DEFAULT_CODE self.test_init_code.setText(pyqstr(test_code))
def test_view_select_activated(self, view_name): view_name = qstrpy(view_name) self.__store_current_code() self.__current_test = view_name test_code = self.__view_tests.get(view_name) if not test_code: test_code = DEFAULT_CODE self.test_init_code.setText(pyqstr(test_code))
def activate_test_tab(self): test_cases = sorted(test.name for test in self.__tests.test_list) self.__resetCombobox(self.test_select_combobox, test_cases) self.__current_test = qstrpy(self.test_select_combobox.currentText()) statement_names = sorted(s.name for s in self.slosl_model().statements) self.__resetCombobox(self.test_view_select_combobox, statement_names) test_code = self.__tests.getTestCode(self.__current_test) self.test_init_code.setText(pyqstr(test_code))
def language_name_activated(self, language): if self._selected_language: self._code_dict[self._selected_language] = qstrpy( self.init_code.text() ) language = qstrpy(language).lower() self._selected_language = language try: code = pyqstr( self._code_dict[language] ) except KeyError: self.init_code.clear() else: self.init_code.setText(code)
def collect_values(self, model_attribute, values): "Call *before* setModel()" try: field, label = self.field_dict[model_attribute] except KeyError: field, label = self.code_field_dict[model_attribute] if not isinstance(field, QComboBox): raise ValueError, "Only QComboBox fields are supported." field.clear() for value in values: field.insertItem(pyqstr(value))
def copy_from_model(self): model = self.__model for attribute, value in model: try: field = getattr(self, attribute) except AttributeError: continue if isinstance(field, QCheckBox): field.setChecked( bool(value) ) elif isinstance(field, QButton): field.setDown( bool(value) ) elif isinstance(field, QLineEdit) or isinstance(field, QTextEdit): if isinstance(value, (list, tuple)): value = '\n'.join(v for v in value if v) field.setText(pyqstr(value)) else: raise TypeError, "unsupported field type for name '%s': %s" % (attribute, type(field))
def build_qterm(node, term_type='infix'): return pyqstr( build_term(node, term_type) )
def copy_slosl_from_model(self, model=None): self.__current_foreach_entry = None if model is None: model = self.__model def build_term(node, term_type='infix'): if hasattr(node, 'serialize'): return unicode( node.serialize(term_type) ) else: return u'' def build_qterm(node, term_type='infix'): return pyqstr( build_term(node, term_type) ) def build_assign(t): name = unicode(t[0]) if t[1]: return u"%s=%s" % (name, build_term(t[1])) else: return name self.slosl_view_name.setText(pyqstr(model.name)) self.slosl_attribute_select.setText(pyqstr( '\n'.join(imap(build_assign, model.selects)) )) self.slosl_from.setText( ', '.join(imap(str, model.parents)) ) self.slosl_with.setText(pyqstr( u', '.join(imap(build_assign, model.withs)) )) ranked = model.ranked self.slosl_rank_function.setCurrentText(ranked.function) self.slosl_rank_function_activated() params = ranked.parameters if len(params): self.slosl_rank_count.setText(params[0] and build_qterm(params[0]) or '1') self.slosl_rank_expression.setText(params[1] and build_qterm(params[1]) or '') if len(params) > 2 and params[2]: compare = build_qterm(params[2]) else: compare = '' self.slosl_rank_compare.setText(compare) else: self.slosl_rank_count.setText('1') self.slosl_rank_expression.setText('') self.slosl_rank_compare.setText('') for attribute in ('where', 'having'): value = getattr(model, attribute) if value: expression = build_qterm(value) else: expression = '' getattr(self, 'slosl_%s' % attribute).setText(expression) foreach_list = self.slosl_foreach_list foreach_list.clear() foreachs = model.foreachs for variable_name, variable_declaration in foreachs: QListViewItem(foreach_list, variable_name, build_qterm(variable_declaration, 'slosl_foreach_list')) self.slosl_foreach_values.clear() self.slosl_foreach_varname.clear() self.slosl_copy_buckets_checkbox.setChecked(model.bucket) self.slosl_disable_having(model.bucket or len(foreachs) == 0)
def setModel(self, dialog_model): self._model = dialog_model self.activate_fields() self._code_dict.clear() self._selected_language = None for attrname, (field, label) in self.field_dict.iteritems(): try: value = getattr(dialog_model, attrname) except AttributeError: continue if isinstance(field, QComboBox): field.setCurrentText(value) elif isinstance(field, QListBox): field.clear() for line in sorted(value): field.insertItem(pyqstr(line)) else: field.setText(value) for queue_type in ('to', 'from'): try: field = getattr(self, "%s_queue" % queue_type) state = getattr(dialog_model, "%s_state" % queue_type) selected = getattr(dialog_model, "%s_queue" % queue_type, None) queues = getattr(state, queue_type == 'to' and 'input_queues' or 'output_queues') except AttributeError: continue field.clear() for i, queue in enumerate(sorted(queues)): field.insertItem(pyqstr(queue)) if selected: field.setCurrentText(selected) if hasattr(self, 'class_name'): self.class_name.setCurrentItem(-1) if hasattr(self, 'language_name'): self.language_name.setCurrentItem(-1) if hasattr(self, 'init_code'): self.init_code.clear() if hasattr(dialog_model, 'codes'): field = self.language_name lower_values = set(qstrpy(s).lower() for s in field) for code in dialog_model.codes: language = code.language if language and language not in lower_values: field.insertItem(pyqstr(language.capitalize())) codes = dialog_model.codes self._code_dict.update( (c.language, c.code) for c in codes if c.language ) for code in codes: if code.class_name: self.class_name.setCurrentText(pyqstr(code.class_name)) break if codes: code = codes[0] for language in self.language_name: if qstrpy(language).lower() == code.language: self._selected_language = code.language self.language_name.setCurrentText(language) self.init_code.setText(pyqstr(code.code or '')) break
def _append_to_list(self, listbox, line): qline = pyqstr(line) for i in range(listbox.count()): if qline == listbox.text(i): return listbox.insertItem(qline)
def reset_tests(self, gui_data): self.__tests = gui_data if self.__current_test: test_code = gui_data.getTestCode(self.__current_test) if test_code: self.test_init_code.setText(pyqstr(test_code))
def test_select_activated(self, test_name): test_name = qstrpy(test_name) self.__store_current_code() self.__current_test = test_name test_code = self.__tests.getTestCode(self.__current_test) self.test_init_code.setText(pyqstr(test_code))