def show_console(self): if not self.window: console = PythonConsole(namespace = { '__builtins__' : __builtins__, 'Lomo' : Lomo, 'Eina' : Eina, 'app' : self.app, 'core' : self.app.get_lomo()}, destroy_cb = self.destroy_console) console.set_size_request(600, 400) v = { 'Eina' : _(u"Eina namespace") , 'Lomo' : _(u"Lomo namespace") , 'app' : _(u"EinaApplication instance"), 'core' : _(u"LomoPlayer instance") } for (k,v) in v.iteritems(): console.eval('print "You can access %s via \'%s\'"' % (v, k)) self.window = Gtk.Window() self.window.set_title(_(u'Eina Python Console')) self.window.add(console) self.window.connect('destroy', self.destroy_console) self.window.show_all() else: self.window.show_all() self.window.grab_focus() self.action.set_active(True)
class PythonConsolePlugin(GObject.Object, Gedit.WindowActivatable, PeasGtk.Configurable): __gtype_name__ = "PythonConsolePlugin" window = GObject.property(type=Gedit.Window) def __init__(self): GObject.Object.__init__(self) def do_activate(self): self._console = PythonConsole(namespace = {'__builtins__' : __builtins__, 'gedit' : Gedit, 'window' : self.window}) self._console.eval('print "You can access the main window through ' \ '\'window\' :\\n%s" % window', False) bottom = self.window.get_bottom_panel() image = Gtk.Image() image.set_from_icon_name(PYTHON_ICON, Gtk.IconSize.MENU) bottom.add_item(self._console, "GeditPythonConsolePanel", _('Python Console'), image) def do_deactivate(self): self._console.stop() bottom = self.window.get_bottom_panel() bottom.remove_item(self._console) def do_update_state(self): pass def do_create_configure_widget(self): config_widget = PythonConsoleConfigWidget(self.plugin_info.get_data_dir()) return config_widget.configure_widget()
def activate(self, window): console = PythonConsole(namespace={"__builtins__": __builtins__, "gedit": gedit, "window": window}) console.eval('print "You can access the main window through ' "'window' :\\n%s\" % window", False) bottom = window.get_bottom_panel() image = gtk.Image() image.set_from_icon_name(PYTHON_ICON, gtk.ICON_SIZE_MENU) bottom.add_item(console, _("Python Console"), image) window.set_data("PythonConsolePluginInfo", console)
class MainWindow(GladeWindow): glade_file = os.path.join("gui", "pybotlearn.glade") def __init__(self): super(MainWindow, self).__init__() self.canvas = Canvas() self.canvas.connect("key-press-event", self.on_key) self.robot = self.canvas.robot execution.robot = self.robot self.canvas_sw.add(self.canvas) self.console = PythonConsole(execution.namespace) self.main_paned.pack2(self.console) self.show_all() self.canvas.get_hadjustment().connect("value-changed", self.on_scroll) self.canvas.get_vadjustment().connect("value-changed", self.on_scroll) def on_up(self, *args): self.console.eval("move_up()", True) def on_down(self, *args): self.console.eval("move_down()", True) def on_right(self, *args): self.console.eval("move_right()", True) def on_left(self, *args): self.console.eval("move_left()", True) def on_key(self, sender, event): if event.keyval == gtk.keysyms.Up: self.on_up() return True elif event.keyval == gtk.keysyms.Down: self.on_down() return True elif event.keyval == gtk.keysyms.Left: self.on_left() return True elif event.keyval == gtk.keysyms.Right: self.on_right() return True def on_say(self, button): text = self.say_textview.get_buffer() text = text.get_text(text.get_start_iter(), text.get_end_iter()) self.console.eval("say(%s)" % repr(text), True) def on_scroll(self, *args): scroll_x = self.canvas.get_hadjustment() scroll_y = self.canvas.get_vadjustment() robot_x = self.robot.get_pixel_x() robot_y = self.robot.get_pixel_y() self.hruler.set_range(scroll_x.value, scroll_x.value + scroll_x.page_size, robot_x, self.canvas.width) self.vruler.set_range(scroll_y.value, scroll_y.value + scroll_y.page_size, robot_y, self.canvas.height)
def do_activate(self): self._console = PythonConsole(namespace = {'__builtins__' : __builtins__, 'gedit' : Gedit, 'window' : self.window}) self._console.eval('print "You can access the main window through ' \ '\'window\' :\\n%s" % window', False) bottom = self.window.get_bottom_panel() image = Gtk.Image() image.set_from_icon_name(PYTHON_ICON, Gtk.IconSize.MENU) bottom.add_item(self._console, "GeditPythonConsolePanel", _('Python Console'), image)
def activate(self, window): console = PythonConsole(namespace = {'__builtins__' : __builtins__, 'gedit' : gedit, 'window' : window}) console.eval('print "You can access the main window through ' \ '\'window\' :\\n%s" % window', False) bottom = window.get_bottom_panel() image = gtk.Image() image.set_from_icon_name('gnome-mime-text-x-python', gtk.ICON_SIZE_MENU) bottom.add_item(console, _('Python Console'), image) window.set_data('PythonConsolePluginInfo', console)
def __init__(self, parent=None): QMainWindow.__init__(self, parent) self.ui = Ui_ScriptEditor() self.ui.setupUi(self) #self.ui.actionExit.triggered.connect(self.exit) self.splitter = QSplitter(Qt.Vertical, self) self.setCentralWidget(self.splitter) self.edit_tab = QTabWidget(self.splitter) self.console_tab = QTabWidget(self.splitter) self.py_console = PythonConsole(self.console_tab) self.console_tab.addTab(self.py_console, "&Python console") self.js_console = QtQmlConsole(self.console_tab) self.console_tab.addTab(self.js_console, "&QtQml console") self.editors = [] self.on_actionNewPython_triggered()
def __init__(self): window = gtk.Window() window.set_title ("Hello World") #Register the self.destroy function to the 'destroy' event of window. window.connect_after('destroy', self.destroy) window.set_resizable(False) #split the window self.box=gtk.VBox(False,2) window.add (self.box) self.createPygameWindow() #interpreter pc=PythonConsole() #the user can use the self.send(x) function with "send(x)" pc.set_size_request(config.WINX,config.InterpreterY) self.box.pack_start(pc,False,False,0) tools.interpreter=pc window.show_all()
def show_console(self, action): if not self.window: console = PythonConsole(namespace = {'__builtins__' : __builtins__, 'Totem' : Totem, 'totem_object' : self.totem}, destroy_cb = self.destroy_console) console.set_size_request(600, 400) console.eval('print "%s" %% totem_object' % _(u"You can access the Totem.Object through " \ "\'totem_object\' :\\n%s"), False) self.window = Gtk.Window() self.window.set_title(_(u'Totem Python Console')) self.window.add(console) self.window.connect('destroy', self.destroy_console) self.window.show_all() else: self.window.show_all() self.window.grab_focus()
def _show_console (self, _action): if not self.window: console = PythonConsole (namespace = { '__builtins__' : __builtins__, 'Xplayer' : Xplayer, 'xplayer_object' : self.xplayer }, destroy_cb = self._destroy_console) console.set_size_request (600, 400) # pylint: disable-msg=E1101 console.eval ('print "%s" %% xplayer_object' % _(u"You can access "\ "the Xplayer.Object through \'xplayer_object\' :\\n%s"), False) self.window = Gtk.Window () self.window.set_title (_(u'Xplayer Python Console')) self.window.add (console) self.window.connect ('destroy', self._destroy_console) self.window.show_all () else: self.window.show_all () self.window.grab_focus ()
def console_cb(self, action, window): if not self.console_window: self.console_window = gtk.Window() console = PythonConsole(namespace = {'__builtins__' : __builtins__, 'eom' : eom, 'window' : window}) console.set_size_request(600, 400) console.eval('print "You can access the main window through ' \ '\'window\' :\\n%s" % window', False) self.console_window.set_title('Python Console') self.console_window.add(console) self.console_window.connect('delete-event', self.on_delete_cb) self.console_window.show_all() self.console_window.set_transient_for(window) self.console_window.set_destroy_with_parent(True) else: self.console_window.show_all() self.console_window.grab_focus()
def _show_console (self, parameter, _action): # pylint: disable=W0613 if not self.window: console = PythonConsole (namespace = { '__builtins__' : __builtins__, 'Totem' : Totem, 'totem_object' : self.totem }, destroy_cb = self._destroy_console) console.set_size_request (600, 400) # pylint: disable=E1101 console.eval ('print("%s" %% totem_object)' % _("You can access "\ "the Totem.Object through “totem_object” :\\n%s"), False) self.window = Gtk.Window () self.window.set_title (_('Totem Python Console')) self.window.add (console) self.window.connect ('destroy', self._destroy_console) self.window.show_all () else: self.window.show_all () self.window.grab_focus ()
def show_console(self, action, idol_object): if not self.window: console = PythonConsole(namespace = {'__builtins__' : __builtins__, 'idol' : idol, 'idol_object' : idol_object}, destroy_cb = self.destroy_console) console.set_size_request(600, 400) console.eval('print "%s" %% idol_object' % _("You can access the idol object through " \ "\'idol_object\' :\\n%s"), False) self.window = gtk.Window() self.window.set_title(_('Idol Python Console')) self.window.add(console) self.window.connect('destroy', self.destroy_console) self.window.show_all() else: self.window.show_all() self.window.grab_focus()
def __init__(self): super(MainWindow, self).__init__() self.canvas = Canvas() self.canvas.connect("key-press-event", self.on_key) self.robot = self.canvas.robot execution.robot = self.robot self.canvas_sw.add(self.canvas) self.console = PythonConsole(execution.namespace) self.main_paned.pack2(self.console) self.show_all() self.canvas.get_hadjustment().connect("value-changed", self.on_scroll) self.canvas.get_vadjustment().connect("value-changed", self.on_scroll)
def _show_console (self, parameter, _action): # pylint: disable-msg=W0613 if not self.window: console = PythonConsole (namespace = { '__builtins__' : __builtins__, 'Totem' : Totem, 'totem_object' : self.totem }, destroy_cb = self._destroy_console) console.set_size_request (600, 400) # pylint: disable-msg=E1101 console.eval ('print("%s" %% totem_object)' % _("You can access "\ "the Totem.Object through \'totem_object\' :\\n%s"), False) self.window = Gtk.Window () self.window.set_title (_('Totem Python Console')) self.window.add (console) self.window.connect ('destroy', self._destroy_console) self.window.show_all () else: self.window.show_all () self.window.grab_focus ()
def _show_console(self, _action): if not self.window: console = PythonConsole(namespace={ '__builtins__': __builtins__, 'Xplayer': Xplayer, 'xplayer_object': self.xplayer }, destroy_cb=self._destroy_console) console.set_size_request(600, 400) # pylint: disable-msg=E1101 console.eval ('print "%s" %% xplayer_object' % _(u"You can access "\ "the Xplayer.Object through \'xplayer_object\' :\\n%s"), False) self.window = Gtk.Window() self.window.set_title(_(u'Xplayer Python Console')) self.window.add(console) self.window.connect('destroy', self._destroy_console) self.window.show_all() else: self.window.show_all() self.window.grab_focus()
def show_console(self, action, totem_object): if not self.window: console = PythonConsole(namespace={ '__builtins__': __builtins__, 'totem': totem, 'totem_object': totem_object }, destroy_cb=self.destroy_console) console.set_size_request(600, 400) console.eval('print "%s" %% totem_object' % _("You can access the totem object through " \ "\'totem_object\' :\\n%s"), False) self.window = gtk.Window() self.window.set_title(_('Totem Python Console')) self.window.add(console) self.window.connect('destroy', self.destroy_console) self.window.show_all() else: self.window.show_all() self.window.grab_focus()
class EditorMainWindow(QMainWindow): def __init__(self, parent=None): QMainWindow.__init__(self, parent) self.ui = Ui_ScriptEditor() self.ui.setupUi(self) #self.ui.actionExit.triggered.connect(self.exit) self.splitter = QSplitter(Qt.Vertical, self) self.setCentralWidget(self.splitter) self.edit_tab = QTabWidget(self.splitter) self.console_tab = QTabWidget(self.splitter) self.py_console = PythonConsole(self.console_tab) self.console_tab.addTab(self.py_console, "&Python console") self.js_console = QtQmlConsole(self.console_tab) self.console_tab.addTab(self.js_console, "&QtQml console") self.editors = [] self.on_actionNewPython_triggered() @pyqtSlot() def closeEvent(self, event): while(self.editors.__len__()): edit = self.edit_tab.currentWidget() if edit: if(edit.isModified()): saveBox = SaveDialog("You have unsaved script. Save it now?") prompt = saveBox.exec_() if(prompt == QMessageBox.Save): event.ignore() self.save(True) elif(prompt == QMessageBox.Cancel): event.ignore() return elif(prompt == QMessageBox.Discard): event.accept() i = self.edit_tab.indexOf(edit) self.edit_tab.removeTab(i) self.editors.remove(edit) event.accept() @pyqtSlot() def on_actionExit_triggered(self): while(self.editors.__len__()): edit = self.edit_tab.currentWidget() if edit: if(edit.isModified()): saveBox = SaveDialog("You have unsaved script. Save it now?") prompt = saveBox.exec_() if(prompt == QMessageBox.Save): self.save(True) elif(prompt == QMessageBox.Cancel): return elif(prompt == QMessageBox.Discard): pass i = self.edit_tab.indexOf(edit) self.edit_tab.removeTab(i) self.editors.remove(edit) self.close() @pyqtSlot() def on_actionNewPython_triggered(self): pyedit = PythonEditorWidget(self.edit_tab) pyedit.setPlainText(template_py) self.edit_tab.addTab(pyedit, "Python") self.edit_tab.setCurrentWidget(pyedit) self.editors.append(pyedit) self.py_console.attach() self.console_tab.setCurrentIndex(0) pyedit.setFocus() pyedit.view.setFocus() @pyqtSlot() def on_actionNewQtQml_triggered(self): jsedit = QtQmlEditorWidget(self.edit_tab) self.edit_tab.addTab(jsedit, "QtQml") self.edit_tab.setCurrentWidget(jsedit) self.editors.append(jsedit) self.js_console.attach() self.console_tab.setCurrentIndex(1) @pyqtSlot() def on_actionClose_triggered(self): edit = self.edit_tab.currentWidget() if edit: if(edit.isModified()): saveBox = SaveDialog("Do you want to save this Script?") prompt = saveBox.exec_() if(prompt == QMessageBox.Save): self.save(True) elif(prompt == QMessageBox.Cancel): return elif(prompt == QMessageBox.Discard): pass i = self.edit_tab.indexOf(edit) self.edit_tab.removeTab(i) self.editors.remove(edit) @pyqtSlot() def on_actionClear_triggered(self): #edit = self.edit_tab.currentWidget() #edit.setPlainText(template_py) self.py_console.clear() @pyqtSlot() def on_actionSave_As_triggered(self): self.save() @pyqtSlot() def on_actionSave_triggered(self): self.save(True) #Path of the script file in each tab will be stored in tabToolTip def save(self, Update = False): edit = self.edit_tab.currentWidget() contents = str(edit.toPlainText()) if((Update == False) or (self.edit_tab.tabText(self.edit_tab.currentIndex()) == "Python") ): #Save in its first invocation and Save As will enter filename = QFileDialog.getSaveFileName(self, "Save File", "", "*.spy") fil = open(filename , 'w') if(filename and self.edit_tab.tabText(self.edit_tab.currentIndex()) == "Python"): #Script hasn't been saved before and user specifies a valid filename self.edit_tab.setTabToolTip(self.edit_tab.currentIndex(), filename+'.spy') self.edit_tab.setTabText(self.edit_tab.currentIndex(), os.path.basename(str(filename+'.spy'))) else: #filename = self.edit_tab.tabText(self.edit_tab.currentIndex()) filename = self.edit_tab.tabToolTip(self.edit_tab.currentIndex()) fil = open( filename , 'w') fil.write(contents) fil.close() edit.setModified(False) @pyqtSlot() def on_actionOpen_triggered(self): filename = QFileDialog.getOpenFileName(self,"Open File","","*.spy") try: fil = open(filename , 'r') except IOError: return code = fil.read() edit = self.edit_tab.currentWidget() self.edit_tab.setTabText(self.edit_tab.currentIndex(), os.path.basename(str(filename))) self.edit_tab.setTabToolTip(self.edit_tab.currentIndex(), filename) edit.setPlainText(code) fil.close() @pyqtSlot() def on_actionRun_triggered(self): self.run() @pyqtSlot() def on_actionRunConsole_triggered(self): self.run(True) def run(self, console=False): edit = self.edit_tab.currentWidget() code = str(edit.toPlainText()) if isinstance(edit, PythonEditorWidget): self.py_console.attach() self.console_tab.setCurrentIndex(0) if console: namespace = self.py_console.namespace else: namespace = {} try: exec code in namespace except Exception as e: traceback.print_exc() try: Scripter.activeWindow.redraw = True Scripter.activeWindow.update() except: pass else: self.js_console.attach() self.console_tab.setCurrentIndex(1) if console: self.js_console.inter.execute(code) else: self.js_console.inter.execute_code(code)