Exemplo n.º 1
0
    def userNewFile(self, widget, data=None):
        tab_box = gtk.HBox(False, 0)
        tab_box.show()

        new_file_label = gtk.Label("Untitled")
        tab_box.pack_start(new_file_label, False, False, 5)
        new_file_label.show()

        close_button = gtk.Button("X")
        tab_box.pack_start(close_button, False, False, 5)
        close_button.show()

        scrolledwindow = gtk.ScrolledWindow()
        scrolledwindow.show()

        lang = SyntaxLoader("python")
        buff = CodeBuffer(lang=lang)
        textview = gtk.TextView(buff)
        textview.connect("key-press-event", self.markFileAsModified)
        textview.filepath = ""  #so we don't get an error when we try to save
        scrolledwindow.add(textview)
        textview.show()

        self.file_notebook.append_page(scrolledwindow, tab_box)
        close_button.connect("clicked", self.removePage, scrolledwindow)
Exemplo n.º 2
0
    def __init__(self):
        _path = path.dirname(sys.modules[self.__module__].__file__)

        _conf_filename = '%s/config' %_path
        _conf_dict = {
            'Menu': {'Layer': 'gimp-layer*'},
            'Templates': {'Get first layer': 'layer = image.layers[0]'}
            }
        if not(path.isfile(_conf_filename)):
            self._create_conf_file(_conf_filename, _conf_dict)
        self.config = ConfigParser()
        self.config.read(_conf_filename) 
        self._check_conf(_conf_filename, _conf_dict)       

        self.ui = gtk.Builder()
        self.ui.set_translation_domain('GEB')
        self.ui.add_from_file('%s/batch_ex.ui' %_path)
        self.ui.connect_signals(self)
        self.status = self.ui.get_object('status')

        #Check Gimp version and updade syntax file, if needed
        self._check_syntax('%s/python-fu.xml' %_path)

        add_syntax_path(_path)
        buff = CodeBuffer(lang=SyntaxLoader("python-fu"))
        self.ui.get_object('code').set_buffer(buff)
        buff.connect('changed', self.code_changed)

        self.base = shelve.open('%s/batch_base' %_path)
        self._get_macro_list()
        self._ckey = ""
        self.browse_dlg = None

        # Menu
        self._create_menu()

        # colors
        self.red_color = pango.AttrList()
        self.red_color.insert(pango.AttrForeground(65535, 0, 0, 0, -1))
        self.red_color.insert(pango.AttrWeight(pango.WEIGHT_HEAVY, 0, -1))
        self.green_color = pango.AttrList()
        self.green_color.insert(pango.AttrForeground(0, 65535, 0, 0, -1))        
        self.green_color.insert(pango.AttrWeight(pango.WEIGHT_HEAVY, 0, -1))
        self.blue_color = pango.AttrList()
        self.blue_color.insert(pango.AttrForeground(0, 0, 65535, 0, -1)) 
        self.blue_color.insert(pango.AttrWeight(pango.WEIGHT_HEAVY, 0, -1))

        # Log
        self._log = self.ui.get_object('log').get_buffer()
        self._log.create_tag('alert', foreground='red', weight=700)
        self._log.create_tag('ok', foreground='black')
        self._log.create_tag('done', foreground='blue', weight=700)

        self._set_status(ST_NEW)
        self.format_changed(self.ui.get_object('format_combo'))
        self._add_log(_('GEB started!'), 'done')
Exemplo n.º 3
0
    def __init__(self, render_callback, src, settings):
        """Takes the following parameters:
          * render_callback: callback function to execute with "apply" button
          * src: source code that should be pre-inserted into the LaTeX input"""

        self.render_callback = render_callback
        self.src = src if src else ""
        self.settings = settings

        # init the syntax highlighting buffer
        lang = SyntaxLoader("latex")
        self.syntax_buffer = CodeBuffer(lang=lang)

        self.setup_ui()
Exemplo n.º 4
0
    def userOpenFile(self, widget, data=None):
        chooser = gtk.FileChooserDialog(
            title=None,
            action=gtk.FILE_CHOOSER_ACTION_OPEN,
            buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL, gtk.STOCK_OPEN,
                     gtk.RESPONSE_OK))
        chooser.show()

        response = chooser.run()
        if response == gtk.RESPONSE_OK:
            #read file
            filepath = chooser.get_filename()
            fo = open(filepath, "r")
            text = fo.read()
            fo.close()

            #put text into textview
            #create (and pack some stuff into) box for page's label
            tab_box = gtk.HBox(False, 0)
            tab_box.show()

            file_label = gtk.Label(os.path.basename(filepath))
            tab_box.pack_start(file_label, False, False, 5)
            file_label.show()

            close_button = gtk.Button("X")
            tab_box.pack_start(close_button, False, False, 5)
            close_button.show()

            scrolledwindow = gtk.ScrolledWindow()
            scrolledwindow.show()

            lang = SyntaxLoader("python")
            buff = CodeBuffer(lang=lang)
            textview = gtk.TextView(buff)
            textview.connect("key-press-event", self.markFileAsModified)
            textview.filepath = filepath  #storing so we can save file later
            scrolledwindow.add(textview)
            textview.show()

            textv_buffer = textview.get_buffer()
            textv_buffer.set_text(text)

            self.file_notebook.append_page(scrolledwindow, tab_box)
            close_button.connect("clicked", self.removePage, scrolledwindow)
        chooser.destroy()
Exemplo n.º 5
0
    def __create_text_with_line_number(self):
        scrolled_window = gtk.ScrolledWindow()
        scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scrolled_window.set_shadow_type(gtk.SHADOW_IN)
        
        from gtkcodebuffer import CodeBuffer, SyntaxLoader
        lang = SyntaxLoader("pl0")
        buffer = CodeBuffer(lang=lang)
        
        text_view = gtk.TextView(buffer)
        fontdesc = pango.FontDescription('Monospace 11')
        text_view.modify_font(fontdesc)
        scrolled_window.add(text_view)

        #text_view.set_editable(False)
        #text_view.set_cursor_visible(False)
        text_view.set_border_window_size(gtk.TEXT_WINDOW_LEFT, 20)
        text_view.connect("expose_event", self.line_numbers_expose)
        
        return scrolled_window, buffer
Exemplo n.º 6
0
 def _create_source_view(self):
     ''' Creacion de las pestanas que mostraran el codigo fuente de las paginas
     TODO: Obtener el html a traves del webview y no con urllib '''
     ''' obtenemos la url que esta mostrando la pestana actual '''
     url = self.tabs[self.notebook.get_current_page()][0].url_bar.get_text()
     ''' Pedimos la pagina con urllib '''
     response = urllib2.urlopen(url)
     page = response.read()
     soup = BeautifulSoup(page)
     ''' La ponemos bonita con bs4'''
     html = soup.prettify()
     ''' Ahora hacemos uso de la libreria pygtkcodebuffer para mostrar el 
     codigo que acabamos de obtener 
     Primero establecemos el lenguaje que estamos usando para colorear el codigo '''
     lang = SyntaxLoader("html")
     ''' Creamos el buffer '''
     buff = CodeBuffer(lang=lang)
     ''' Lo metemos dentro de una ventana con scroll '''
     scr = gtk.ScrolledWindow()
     scr.add(gtk.TextView(buff))
     ''' Y lo mostramos '''
     buff.set_text(html)
     return url, scr
Exemplo n.º 7
0
def setCodeText(codeView, str):
    lang = SyntaxLoader("c")
    buff = CodeBuffer(lang=lang)
    codeView.set_buffer(buff)
    buff.set_text(str)
    addTags(codeView)
Exemplo n.º 8
0
    def __init__(self):
        #Set the Glade file
        self.builder = gtk.Builder()
        self.builder.add_from_file(GLADE_PATH)

        # get top window
        self.window = self.builder.get_object("top_window")

        # status bar stuff
        self.statusbar = self.builder.get_object("statusbar")
        self.statusbar_ctx = self.statusbar.get_context_id("default")

        # set buttons
        self.save_button = self.builder.get_object('save_file_toolbutton')
        self.connect_button = self.builder.get_object('connect_button')

        self.save_button.set_sensitive(False)
        self.connect_button.set_sensitive(True)

        # set control buttons
        self.controls = [
            self.builder.get_object('reset_button'),
            self.builder.get_object('bootloader_button'),
            self.builder.get_object('exec_button'),
            self.builder.get_object('stop_button'),
            self.builder.get_object('zoomin_button'),
            self.builder.get_object('zoomout_button'),
            self.builder.get_object('bestfit_button'),
            self.builder.get_object('refresh_button')
        ]

        self.connected = False
        map(lambda x: x.set_sensitive(False), self.controls)

        # workaround bug in gtkcodebuffer
        gtkcodebuffer.SYNTAX_PATH.append(
            os.path.join(sys.prefix, "local", "share", "pygtkcodebuffer",
                         "syntax"))

        # Configure source viewer
        self.buffer = CodeBuffer(lang=SyntaxLoader("python"))
        self.buffer.connect("changed", self.text_changed)
        tabs = pango.TabArray(1, True)
        tabs.set_tab(0, pango.TAB_LEFT, 8 * 4)  #seems right
        txtview = gtk.TextView(self.buffer)
        txtview.set_tabs(tabs)
        self.builder.get_object("src_scrolledwindow").add(txtview)

        # Configure terminal window
        self.terminal_scroll = self.builder.get_object('vte_scrolledwindow')
        self.terminal = self.builder.get_object('vte_textview')
        self.terminal.modify_base(gtk.STATE_NORMAL,
                                  gtk.gdk.color_parse('black'))
        self.terminal.modify_text(gtk.STATE_NORMAL,
                                  gtk.gdk.color_parse('green'))

        # get drawingarea
        self.pixbuf = None
        self.drawingarea = self.builder.get_object("drawingarea")
        self.da_menu = self.builder.get_object("da_menu")

        # selection coords
        self.sel_ended = False
        self.selection_started = False
        self.x1 = self.y1 = self.x2 = self.y2 = 0

        # set control scales attributes
        self.builder.get_object("contrast_adjust").attr = openmv.ATTR_CONTRAST
        self.builder.get_object(
            "brightness_adjust").attr = openmv.ATTR_BRIGHTNESS
        self.builder.get_object(
            "saturation_adjust").attr = openmv.ATTR_SATURATION
        self.builder.get_object(
            "gainceiling_adjust").attr = openmv.ATTR_GAINCEILING

        #connect signals
        signals = {
            "on_top_window_destroy": self.quit,
            "on_connect_clicked": self.connect_clicked,
            "on_reset_clicked": self.reset_clicked,
            "on_fwupdate_clicked": self.fwupdate_clicked,
            "on_fwpath_clicked": self.fwpath_clicked,
            "on_execute_clicked": self.execute_clicked,
            "on_stop_clicked": self.stop_clicked,
            "on_motion_notify": self.motion_notify,
            "on_button_press": self.button_pressed,
            "on_button_release": self.button_released,
            "on_open_file": self.open_file,
            "on_new_file": self.new_file,
            "on_save_file": self.save_file,
            "on_save_file_as": self.save_file_as,
            "on_save_template_activate": self.save_template,
            "on_save_descriptor_activate": self.save_descriptor,
            "on_ctrl_scale_value_changed": self.on_ctrl_scale_value_changed,
            "on_zoomin_clicked": self.zoomin_clicked,
            "on_zoomout_clicked": self.zoomout_clicked,
            "on_bestfit_clicked": self.bestfit_clicked,
            "on_preferences_clicked": self.preferences_clicked,
            "on_updatefb_clicked": self.updatefb_clicked,
            "on_vte_size_allocate": self.scroll_terminal,
        }
        self.builder.connect_signals(signals)

        # create data directory
        if not os.path.isdir(DATA_DIR):
            os.makedirs(DATA_DIR)

        # create user scripts directory
        if not os.path.isdir(SCRIPTS_DIR):
            os.makedirs(SCRIPTS_DIR)

        # create fresh config if needed
        if not os.path.isfile(CONFIG_PATH):
            try:
                with open(CONFIG_PATH, "w") as f:
                    f.write(DEFAULT_CONFIG)
            except Exception as e:
                print("Failed to create config file %s" % (e))
                sys.exit(1)

        # load config
        self.config = configparser.ConfigParser()
        try:
            self.config.read(CONFIG_PATH)
        except Exception as e:
            print("Failed to open config file %s" % (e))
            sys.exit(1)

        # current file path
        self.file_path = None
        self.fw_file_path = ""
        #        path = self.config.get("main", "last_opened_file")
        #        if os.path.isfile(path):
        #            self._load_file(path)

        # built-in examples menu
        submenu = gtk.Menu()
        menu = self.builder.get_object('example_menu')
        files = sorted(os.listdir(EXAMPLES_DIR))
        for f in files:
            if f.endswith(".py"):
                label = os.path.basename(f)
                mitem = gtk.MenuItem(label)
                mitem.connect("activate", self.open_example, EXAMPLES_DIR)
                submenu.append(mitem)

        menu.set_submenu(submenu)

        # recent files menu
        self.files = []
        files = self.config.get("main", "recent")
        if files:
            self.files = files.split(',')
            self.update_recent_files()
Exemplo n.º 9
0
  def __init__(self,assembly,entity):
    super(PropertyWindow,self).__init__()

    self.set_size_request(500, 400)
    self.set_position(gtk.WIN_POS_CENTER)

    # Remove this property window from the static store
    self.connect("destroy", self.on_destroy)

    # Store data structures
    self.assembly = assembly
    self.entity = entity

    self.set_title(str(self.entity))

    #########################################

    vpaned = gtk.VPaned()

    vbox = gtk.VBox(False, 8)

    sw = gtk.ScrolledWindow()
    sw.set_shadow_type(gtk.SHADOW_ETCHED_IN)
    sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

    vbox.pack_start(sw, True, True, 0)

    store = self.create_model()

    treeView = gtk.TreeView(store)
    treeView.connect("row-activated", self.on_activated)
    treeView.set_rules_hint(True)
    sw.add(treeView)

    self.create_columns(treeView)

    ###################################################

    ###################################################

    if assembly.rule_src.has_key(self.entity.name):
      rule_name = self.entity.name

      # Create the syntax hilighter and code buffer
      lang = SyntaxLoader("cpp")
      buff = CodeBuffer(lang=lang)

      hbox = gtk.HBox(False, 8)
      scr = gtk.ScrolledWindow()
      scr.add(gtk.TextView(buff))
      scr.set_shadow_type(gtk.SHADOW_ETCHED_IN)
      scr.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)	      

      # Get the source file path, and start line
      src_path = assembly.rule_src[rule_name][0]
      src_line_start = int(assembly.rule_src[rule_name][1])-1

      # Open the source file
      src_file = open(src_path,'r')
      src_file_lines = src_file.readlines()
      src_line_end = len(src_file_lines)
      
      # Find the line on which the next rule is defined
      for line in range(src_line_start+1,len(src_file_lines)):
	if src_file_lines[line].find("::") != -1:
	  src_line_end = line;
	  break

      # Display the source code of just this rule
      srccode = "".join(src_file_lines[src_line_start:src_line_end])

      buff.set_text(srccode)
      hbox.pack_start(scr, True, True, 0)
      vbox.pack_start(hbox, True, True, 0)

    ##################################################

    self.statusbar = gtk.Statusbar()
    vbox.pack_start(self.statusbar, False, False, 0)

    self.add(vbox)
    self.show_all()
Exemplo n.º 10
0
#!/usr/bin/python
import gtk
from gtkcodebuffer import CodeBuffer, SyntaxLoader, add_syntax_path

#
# This example shows how to use the CodeBuffer.
#   Note: You need to have PyGTKCodeBuffer installed!

txt = """fsd sdfsd sdfsd is fsdfdf"""

lang = SyntaxLoader("pascal")
buff = CodeBuffer(lang=lang)

win = gtk.Window(gtk.WINDOW_TOPLEVEL)
scr = gtk.ScrolledWindow()
win.add(scr)
scr.add(gtk.TextView(buff))

win.set_default_size(300, 200)
win.show_all()
win.connect("destroy", lambda w: gtk.main_quit())

buff.set_text(txt)

gtk.main()
Exemplo n.º 11
0
'''
Created on Jul 6, 2009

@author: shivkumar
'''
import gtk
import os
from ns3.rapidnet.rapidnet_config import *
from gtkcodebuffer import CodeBuffer, SyntaxLoader

lang = SyntaxLoader("cpp")


class SimulateMenu(gtk.MenuItem):
    def __init__(self, menubar):
        gtk.MenuItem.__init__(self, 'Protocols')
        self.menubar = menubar
        self.rootmenu = gtk.Menu()
        self.set_submenu(self.rootmenu)
        self.SetupMenuTree('traces', self.rootmenu)

    def SetupMenuTree(self, folder, menu):
        if 'events.log' in os.listdir(folder):
            return
        subfolders = os.listdir(folder)
        subfolders.sort()
        for entry in subfolders:
            abs_entry = os.path.join(folder, entry)
            if os.path.isdir(abs_entry) and entry != '.svn':
                submenu = gtk.Menu()
                print 'Found', abs_entry
Exemplo n.º 12
0
also this [link] type


## TODO and Unsupported Markup

TODO! I've overloaded some of the styles/colours in the XML file,
e.g. URLs are datatypes (like emphasis).

Currently does not handle:

*   Horizontal Rules/Lines

"""


lang = SyntaxLoader("markdown")
buff = CodeBuffer(lang=lang)

win = gtk.Window(gtk.WINDOW_TOPLEVEL)
scr = gtk.ScrolledWindow()
win.add(scr)
scr.add(gtk.TextView(buff))
        
win.set_default_size(300,200)
win.show_all()
win.connect("destroy", lambda w: gtk.main_quit())
        
buff.set_text(txt)
        
gtk.main()        
Exemplo n.º 13
0
#!/usr/bin/python
import gtk
from gtkcodebuffer import CodeBuffer, SyntaxLoader, add_syntax_path

#
# This example shows how to use the CodeBuffer. 
#   Note: You need to have PyGTKCodeBuffer installed!

txt = """<?xml version="1.0"?>
<!-- a <comment> -->
<DocumentRoot attribute="value">
    Some &gt;text&lt;...
    <ns:tag>content</ns:tag>
</DocumentRoot> """

lang = SyntaxLoader("xml")
buff = CodeBuffer(lang=lang)

win = gtk.Window(gtk.WINDOW_TOPLEVEL)
scr = gtk.ScrolledWindow()
win.add(scr)
scr.add(gtk.TextView(buff))
        
win.set_default_size(300,200)
win.show_all()
win.connect("destroy", lambda w: gtk.main_quit())
        
buff.set_text(txt)
        
gtk.main()        
Exemplo n.º 14
0
#!/usr/bin/python
import gtk
import sys

# comment-out if CodeBuffer is installed
sys.path.insert(0, "..")
from gtkcodebuffer import CodeBuffer, SyntaxLoader, add_syntax_path

# comment-out if CodeBuffer is installed
add_syntax_path("../syntax")

lang = SyntaxLoader("python")
buff = CodeBuffer(lang=lang)

win = gtk.Window(gtk.WINDOW_TOPLEVEL)
scr = gtk.ScrolledWindow()
win.add(scr)
scr.add(gtk.TextView(buff))

win.set_default_size(300, 200)
win.show_all()
win.connect("destroy", lambda w: gtk.main_quit())

buff.set_text(open(__file__, 'r').read())

gtk.main()
Exemplo n.º 15
0
 def on_lang_changed(self, widget, lang):
     lspec = SyntaxLoader(lang)
     self.__buffer.reset_language(lspec)