pilas.interprete

Package pilas :: Module interprete |
[hide private]
[frames] | no frames]

# Source Code for Module pilas.interprete

     1  # -*- coding: utf-8 -*-
     2  import sys
     3
     4  try:
     5      from PyQt4 import QtCore, QtGui
     6      from interprete_base import Ui_InterpreteDialog
     7  except:
     8      print "ERROR: No se encuentra pyqt"
     9      Ui_InterpreteDialog = object
    10      pass
    11
    12  import pilas
    13  import utils
    14
    15  try:
    16      sys.path.append(utils.obtener_ruta_al_recurso('../lanas'))
    17      import lanas
    18  except ImportError, e:
    19      print e
    20
    21  import os
    22
    23  if os.environ.has_key('lanas'):
    24      del os.environ['lanas']
    25
    26 -class VentanaInterprete(Ui_InterpreteDialog):
    27
    28 -    def setupUi(self, main):
    29          self.main = main
    30          Ui_InterpreteDialog.setupUi(self, main)
    31          scope = self._insertar_ventana_principal_de_pilas()
    32          self._insertar_consola_interactiva(scope)
    33          pilas.utils.centrar_ventana(main)
    34          pilas.utils.centrar_ventana(main)
    35
    36 -    def _insertar_ventana_principal_de_pilas(self):
    37          pilas.iniciar(usar_motor='qtsugar', ancho=640, alto=400)
    38
    39          mono = pilas.actores.Mono()
    40
    41          ventana = pilas.mundo.motor.ventana
    42          canvas = pilas.mundo.motor.canvas
    43          canvas.setFocusPolicy(QtCore.Qt.ClickFocus)
    44          self.canvas.setFocus()
    45
    46          self.canvas.addWidget(ventana)
    47          self.canvas.setCurrentWidget(ventana)
    48          return {'pilas': pilas, 'mono': mono}
    49
    50 -    def _insertar_consola_interactiva(self, scope):
    51          codigo_inicial = [
    52                  'import pilas',
    53                  '',
    54                  'pilas.iniciar()',
    55                  'mono = pilas.actores.Mono()',
    56                  ]
    57
    58          consola = lanas.interprete.Ventana(self.splitter, scope, "\n".join(codigo_inicial))
    59          self.console.addWidget(consola)
    60          self.console.setCurrentWidget(consola)
    61
    62 -def main(parent=None, do_raise=False):
    63      dialog = QtGui.QDialog(parent)
    64      dialog.setWindowFlags(dialog.windowFlags() | QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowMinMaxButtonsHint)
    65      ui = VentanaInterprete()
    66      ui.setupUi(dialog)
    67
    68      if do_raise:
    69          dialog.show()
    70          dialog.raise_()
    71
    72      dialog.exec_()
    73