def montre_dialogue_aide(self): titre = make_unicode("À propos de ByTheBooks") message = "ByTheBooks offre une approche multi-étapes pour produire" \ " un schéma structurellement solide à partir de laquelle" \ " écrire des scénarios, guidant l'écrivain de l'idée de" \ " scénario au battement final de l'acte III." QtGui.QMessageBox.about(self, titre, make_unicode(message))
def generate_file_menu(self): menu = self.menuBar().addMenu("Fichier") action = menu.addAction(make_unicode("Nouvelle idée...")) action.triggered.connect(self.montre_dialogue_idee) action = menu.addAction(make_unicode("Nouveau scénario...")) action.triggered.connect(self.montre_dialogue_scenario) action = menu.addAction(make_unicode("Supprimer scénario...")) action.triggered.connect(self.montre_dialogue_suppression_scenario)
def montre_dialogue_suppression_scenario(self): titre = make_unicode("Supprimer scénario") message = make_unicode("Voulez-vous vraiment supprimer le scénario ?") ret = QtGui.QMessageBox.warning(self, titre, message, QtGui.QMessageBox.Ok) if ret == QtGui.QMessageBox.Ok: return
def __init__(self, parent=None): super(DialogueIdee, self).__init__(parent) self.setWindowTitle(make_unicode("Informations idéales")) self.setWindowFlags(QtCore.Qt.Dialog | QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.WindowTitleHint | QtCore.Qt.CustomizeWindowHint) self.titre_edit = QtGui.QLineEdit(self) self.titre_label = QtGui.QLabel("Titre", self) self.type_edit = QtGui.QComboBox(self) self.type_edit.addItem("Battement d'action") self.type_edit.addItem("Blague") self.type_edit.addItem("Cadre") self.type_edit.addItem("Concept") self.type_edit.addItem("Dialogue") self.type_edit.addItem("Expression") self.type_edit.addItem("Location") self.type_edit.addItem("Personnage") self.type_edit.addItem(make_unicode("Scène")) self.type_edit.addItem("Site Internet") self.type_edit.addItem(make_unicode("Thème")) self.type_edit.addItem("Titre") self.type_label = QtGui.QLabel("Type", self) self.date_edit = QtGui.QDateEdit(self) self.date_edit.setDate(QtCore.QDate.currentDate()) self.date_label = QtGui.QLabel(make_unicode("Date de création"), self) self.desc_edit = QtGui.QTextEdit(self) self.desc_label = QtGui.QLabel("Descrition", self) self.grid_layout = QtGui.QGridLayout(self) self.grid_layout.addWidget(self.titre_label, 0, 0) self.grid_layout.addWidget(self.titre_edit, 0, 1) self.grid_layout.addWidget(self.type_label, 1, 0) self.grid_layout.addWidget(self.type_edit, 1, 1) self.grid_layout.addWidget(self.date_label, 2, 0) self.grid_layout.addWidget(self.date_edit, 2, 1) self.grid_layout.addWidget(self.desc_label, 3, 0) self.grid_layout.addWidget(self.desc_edit, 3, 1) button_box = cree_boite_bouton() self.grid_layout.addWidget(button_box, 4, 1) button_box.accepted.connect(self.accept) button_box.rejected.connect(self.reject)
def read_unicode(path, encoding, encoding_errors): """ Return the contents of a file as a unicode string. """ try: f = open(path, 'rb') return make_unicode(f.read(), encoding, encoding_errors) finally: f.close()
def __render_tag(info, state): """ Render an individual tag by making the appropriate replacement within the current context (if any). """ new_contexts, context_match = get_tag_context(info['tag_key'], state) replacement = '' if context_match or context_match == 0: replacement = context_match elif info['tag_key'] == '.': replacement = state.context() else: replacement = '' # Call all callables / methods / lambdas / functions if replacement and callable(replacement): replacement = make_unicode(replacement()) state.push_tags(state.default_tags) replacement = __render(template=replacement, state=state) state.pop_tags() for i in xrange(new_contexts): state.context.pop() if state.escape(): return html_escape(replacement) return replacement
def __init__(self, parent=None): super(MainWindow, self).__init__(parent) self.projet = Projet() self.outline_text_area = [] self.generate_file_menu() self.generate_help_menu() widget = QtGui.QWidget() self.vlayout = QtGui.QVBoxLayout(widget) scroll = QtGui.QScrollArea() scroll.setWidget(widget) scroll.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) scroll.setWidgetResizable(True) for point in outline_points: widget_point = PlotPointWidget(point.title, point.desc, self) self.outline_text_area.append(widget_point) self.vlayout.addWidget(widget_point) self.setCentralWidget(scroll) dock = QtGui.QDockWidget(make_unicode("Progès"), self) self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dock) # Dock pour les idées. self.idee_table = TableIdee() dock = QtGui.QDockWidget(make_unicode("Idées"), self) dock.setWidget(self.idee_table) self.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock) # Dock pour les scénarios. self.scenario_table = TableScenario() dock = QtGui.QDockWidget(make_unicode("Scénarios"), self) dock.setWidget(self.scenario_table) self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, dock)
def render(template, context, partials={}, state=None): """ Renders a given mustache template, with sane defaults. """ # Create a new state by default state = state or State() # Add context to the state dict if isinstance(context, Context): state.context = context else: state.context = Context(context) # Add any partials to the state dict if partials: state.partials.push(partials) # Render the rendered template return __render(make_unicode(template), state)
def passe_mot(self): mot = str(self.line_edit.text()) if len(mot) is 0: return donnees_entrees = convertie_mot(mot) #print donnees_entrees self.reseau_neuronal.avance(donnees_entrees) #print "Résultat:", self.reseau_neuronal.sorties langue_possible = defini_langue(self.reseau_neuronal.sorties) texte = "Langue possible: %s, confidence: %f." texte = texte % (langue_possible['langue'], langue_possible['confidence']) self.guess_label.setText(make_unicode(texte)) self.update()
def read_unicode(path, encoding, encoding_errors): """ Return the contents of a file as a unicode string. """ with open(path, 'rb') as f: return make_unicode(f.read(), encoding, encoding_errors)
def __init__(self, parent=None): super(DialogueScenario, self).__init__(parent) self.setWindowTitle(make_unicode("Information scénaristique")) self.setWindowFlags(QtCore.Qt.Dialog | QtCore.Qt.WindowStaysOnTopHint | QtCore.Qt.WindowTitleHint | QtCore.Qt.CustomizeWindowHint) self.name_edit = QtGui.QLineEdit(self) self.name_label = QtGui.QLabel("Name", self) self.author_edit = QtGui.QLineEdit(self) self.author_label = QtGui.QLabel("Auteur", self) self.date_edit = QtGui.QDateEdit(self) self.date_edit.setDate(QtCore.QDate.currentDate()) self.date_label = QtGui.QLabel(make_unicode("Date de création"), self) self.genre_edit = QtGui.QComboBox(self) self.genre_edit.addItem("Action") self.genre_edit.addItem("Adolescent") self.genre_edit.addItem("Animation") self.genre_edit.addItem("Aventure") self.genre_edit.addItem(make_unicode("Comédie")) self.genre_edit.addItem(make_unicode("Crime/Détective")) self.genre_edit.addItem("Documentaire") self.genre_edit.addItem("Drame") self.genre_edit.addItem(make_unicode("Dramédie")) self.genre_edit.addItem("Horreur") self.genre_edit.addItem("Manga") self.genre_edit.addItem("Science-Fiction") self.genre_edit.addItem("Suspense") self.genre_edit.addItem("Thriller") self.genre_label = QtGui.QLabel("Genre", self) self.source_edit = QtGui.QComboBox(self) self.source_edit.addItem("Article - Journal") self.source_edit.addItem("Article - Magazine") self.source_edit.addItem("Contacte Personnel") self.source_edit.addItem("Histoire Vraie") self.source_edit.addItem(make_unicode("Idée Originale")) self.source_edit.addItem("Livre/Histoire") self.source_edit.addItem("Remake") self.source_edit.addItem("Site Internet") self.source_label = QtGui.QLabel("Source", self) self.grid_layout = QtGui.QGridLayout(self) self.grid_layout.addWidget(self.name_label, 0, 0) self.grid_layout.addWidget(self.name_edit, 0, 1) self.grid_layout.addWidget(self.author_label, 1, 0) self.grid_layout.addWidget(self.author_edit, 1, 1) self.grid_layout.addWidget(self.date_label, 2, 0) self.grid_layout.addWidget(self.date_edit, 2, 1) self.grid_layout.addWidget(self.genre_label, 3, 0) self.grid_layout.addWidget(self.genre_edit, 3, 1) self.grid_layout.addWidget(self.source_label, 4, 0) self.grid_layout.addWidget(self.source_edit, 4, 1) button_box = cree_boite_bouton() self.grid_layout.addWidget(button_box, 5, 1) button_box.accepted.connect(self.accept) button_box.rejected.connect(self.reject)
def generate_help_menu(self): menu = self.menuBar().addMenu("Aide") action = menu.addAction(make_unicode("À propos de ByTheBooks...")) action.triggered.connect(self.montre_dialogue_aide)
def __render(template, state, index=0): """ Given a /template/ string, a parser /state/, and a starting offset (/index/), return the rendered version of the template. """ # Find a Match match = state.tag_re.search(template, index) if not match: return template[index:] info = get_match_info(template, match, state) _pre = template[index : info['tag_start']] # template before the tag _tag = template[info['tag_start'] : info['tag_end']] # tag _continue = info['tag_end'] # the index at which to continue # Comment if info['tag_type'] == '!': # Comments are removed from output repl = "" # Delimiter change elif info['tag_type'] == '=': # Delimiters are changed; the tag is rendered as "" delimiters = re.split(r'\s*', info['tag_key']) new_tags = state.tags(_copy=True) new_tags['otag'], new_tags['ctag'] = map(re.escape, delimiters) state.push_tags(new_tags) repl = "" # Plain tag elif info['tag_type'] == '': repl = __render_tag(info, state) # Raw tag (should not be escaped) elif info['tag_type'] == '&': state.escape.push(False) repl = __render_tag(info, state) state.escape.pop() # Partial elif info['tag_type'] == '>': partial_name = info['tag_key'] partial_template = None new_dir = None lead_wsp = re.compile(r'^(.)', re.M) repl = '' try: # Cached partial_template = state.partials()[partial_name] except (KeyError, IndexError): try: # Load the partial template from a file (if it exists) new_dir, filename = split(partial_name) if new_dir: state.partials_dir.push(new_dir) partial_template = load_template(filename, state.abs_partials_dir, state.extension, state.encoding, state.encoding_error) except (IOError): pass if partial_template: # Preserve indentation if info['standalone']: partial_template = lead_wsp.sub(info['lead_wsp']+r'\1', partial_template) # Update state state.partials.push(state.partials()) # XXX wtf is this shit? state.push_tags(state.default_tags) # Render the partial repl = __render(partial_template, state) # Restore state state.partials.pop() state.pop_tags() if new_dir: state.partials_dir.pop() # Section # TODO(peter): add a stop= index to __render so that template_to_inner does # not need to be constructed with [:] indexing, which is extremely # expensive. elif info['tag_type'] in ('#', '^'): otag_info = info ctag_info = section_end_info(template, info['tag_key'], state, _continue) # Don't want to parse beyond the end of the inner section, but # must include information on prior contents so that whitespace # is preserved correctly and inner tags are not marked as standalone. inner_start = otag_info['tag_end'] inner_end = ctag_info['tag_start'] _continue = ctag_info['tag_end'] template_with_inner = template[:inner_end] new_contexts, ctm = get_tag_context(otag_info['tag_key'], state) truthy = otag_info['tag_type'] == '#' #if ctm is not None: if ctm: # If there's a match and it's callable, feed it the inner template if callable(ctm): template_to_inner = template[:inner_start] inner = template[inner_start:inner_end] template_with_inner = template_to_inner + make_unicode(ctm(inner)) # Make the context list an iterable from the ctm if not hasattr(ctm, '__iter__') or isinstance(ctm, dict): ctx_list = [ctm] else: ctx_list = ctm # If there's no match, there are no new contexts else: ctx_list = [False] # If there are new contexts and the section is truthy, or if # there are no new contexts and the section is falsy, render # the contents repl_stack = [] for ctx in ctx_list: if (truthy and ctx) or (not truthy and not ctx): state.context.push(ctx) repl_stack.append( __render(template_with_inner, state, inner_start)) else: break repl = ''.join(repl_stack) for i in xrange(new_contexts): state.context.pop() else: raise Exception("found unpaired end of section tag!") return u''.join(( _pre, make_unicode(repl), __render(template, state, _continue)))
Options: -h, --help Montre cet écran. --version Montre la version du logiciel. --entrainement Démarre l'entrainement du réseau neuronal. """ import sys from docopt import docopt from PyQt4 import QtGui from main_window import MainWindow from utils import make_unicode reload(sys) sys.setdefaultencoding('utf-8') if __name__ == '__main__': arguments = docopt(__doc__, version='Gengo 0.1') app = QtGui.QApplication(sys.argv) w = MainWindow() w.setWindowTitle(make_unicode("言語")) w.show() if arguments["--entrainement"] is True: w.entraine_reseau() sys.exit(app.exec_())