Beispiel #1
0
 def __init__(self):
     # we define a scrollable window with automatic behavior for scrolling bars
     self.text_window = gtk.ScrolledWindow()
     self.text_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
     self.text_area = gtk.TextView()
     # set text area as editable in order to let it be cleaned by selecting and deleting
     # then we set wrap mode for text
     self.text_area.set_editable(True)
     self.text_area.set_wrap_mode(gtk.WRAP_WORD)
     self.text_buffer = self.text_area.get_buffer()
     self.text_window.add(self.text_area)
     # here we set default values for background and text of console window
     self.text_area.modify_base(gtk.STATE_NORMAL,
                                gtk.gdk.color_parse("dark grey"))
     self.text_area.modify_text(gtk.STATE_NORMAL,
                                gtk.gdk.color_parse("red"))
     # then we define some text tag for defining colors for system messages and stdout
     self.tag_table = self.text_buffer.get_tag_table()
     self.stdout_tag = gtk.TextTag("stdout")
     self.stdout_tag.set_property("foreground", "black")
     self.stdout_tag.set_property("style", "normal")
     #self.stdout_tag.set_property("weight", 600)
     #self.stdout_tag.set_property("size-points", 9)
     self.tag_table.add(self.stdout_tag)
     self.system_message_tag = gtk.TextTag("system")
     self.system_message_tag.set_property("foreground", "white")
     self.system_message_tag.set_property("style", "normal")
     self.tag_table.add(self.system_message_tag)
     self.text_area.modify_font(pango.FontDescription("monospace italic 9"))
Beispiel #2
0
def show_diff_blob(title, result):
    d = gtk.Dialog(title=title, buttons=(gtk.STOCK_OK, gtk.RESPONSE_OK))
    b = gtk.TextBuffer()

    tags = b.get_tag_table()
    for color in ["red", "blue", "green", "grey"]:
        tag = gtk.TextTag(color)
        tag.set_property("foreground", color)
        tags.add(tag)
    tag = gtk.TextTag("bold")
    tag.set_property("weight", pango.WEIGHT_BOLD)
    tags.add(tag)

    lines = result.split(os.linesep)
    for line in lines:
        if line.startswith("-"):
            tags = ("red", "bold")
        elif line.startswith("+"):
            tags = ("blue", "bold")
        else:
            tags = ()
        b.insert_with_tags_by_name(b.get_end_iter(), line + os.linesep, *tags)
    v = gtk.TextView(b)
    fontdesc = pango.FontDescription("Courier 11")
    v.modify_font(fontdesc)
    v.set_editable(False)
    v.show()
    s = gtk.ScrolledWindow()
    s.add(v)
    s.show()
    d.vbox.pack_start(s, 1, 1, 1)
    d.set_size_request(600, 400)
    d.run()
    d.destroy()
Beispiel #3
0
 def _create_widgets(self):
     self.hbox = HIGHBox()
     self.lbl_diff = HIGSectionLabel("<b>%s</b>" % _("Diff Result"))
     self.scrolled = gtk.ScrolledWindow()
     self.txt_diff_result = gtk.TextView()
     self.txg_tag = gtk.TextTag("diff_style")
     self.txg_added = gtk.TextTag('added style')
     self.txg_removed = gtk.TextTag('removed style')
Beispiel #4
0
    def __init__(self, parent=None):
        gtk.Window.__init__(self)
        try:
            self.set_screen(parent.get_screen())
        except AttributeError:
            self.connect('destroy', lambda *w: gtk.main_quit())

        self.set_title(self.__class__.__name__)
        self.set_default_size(500, 250)
        self.set_icon_from_file(ICON_IMAGE)
        self.set_geometry_hints(min_width=100, min_height=100)
        rootbox = gtk.VBox()
        self.add(rootbox)
        #region TextView
        textview = gtk.TextView()
        textbuffer = textview.get_buffer()
        textbuffer.set_text(text)
        textview.set_wrap_mode(gtk.WRAP_WORD)
        #endregion
        line_count = textbuffer.get_line_count()
        char_count = textbuffer.get_char_count()

        iter = textbuffer.get_iter_at_line(2)
        textbuffer.place_cursor(iter)

        table = textbuffer.get_tag_table()
        tag_red = gtk.TextTag(name="red")
        tag_red.set_property("foreground", "red")
        table.add(tag_red)

        tag_blue = gtk.TextTag(name="blue")
        tag_blue.set_property("foreground", "blue")
        table.add(tag_blue)

        tag_green = gtk.TextTag(name="green")
        tag_green.set_property("foreground", "green")
        table.add(tag_green)

        size = table.get_size()

        start, end = textbuffer.get_bounds()
        textbuffer.apply_tag(tag_red, start, end)

        Label_text = "Table contains: " + str(size) + " Tags"
        rootbox.pack_start(textview)
        status_bar = gtk.InfoBar()
        rootbox.pack_start(status_bar, False, False)
        status_bar.set_message_type(gtk.MESSAGE_INFO)
        status_bar.get_content_area().pack_start(gtk.Label(Label_text), False,
                                                 False)
        tagtable = textbuffer.props.tag_table

        def foreach_func(tag, data):
            print tag.props.name

        tagtable.foreach(foreach_func, None)

        self.show_all()
Beispiel #5
0
 def prepare_tags(self):
     # TODO: load styling from configuration
     tag = gtk.TextTag(name='RemoteInput')
     tag.set_property('foreground', 'Black')
     self.get_buffer().get_tag_table().add(tag)
     tag = gtk.TextTag(name='LocalOutput')
     tag.set_property('foreground' ,'Blue')
     self.get_buffer().get_tag_table().add(tag)
     self.get_buffer().get_tag_table().foreach(temp_print)
Beispiel #6
0
def setConsoleTags(console):
	b = console.get_buffer()
	tag = gtk.TextTag("red_foreground")
	tag.set_property("foreground", "red")
	table = b.get_tag_table()
	table.add(tag)
	tag = gtk.TextTag("white_foreground")
	tag.set_property("foreground", "white")
	table = b.get_tag_table()
	table.add(tag)
Beispiel #7
0
 def init_tags(self):
     tag_table = self.get_property("tag_table")
     error_tag = gtk.TextTag("error")
     error_tag.set_property("underline-set", True)
     error_tag.set_property("underline", pango.UNDERLINE_ERROR)
     warning_tag = gtk.TextTag("warning")
     warning_tag.set_property("underline-set", True)
     warning_tag.set_property("underline", pango.UNDERLINE_SINGLE)
     tag_table.add(error_tag)
     tag_table.add(warning_tag)
Beispiel #8
0
def addTags(codeView):
    buff = codeView.get_buffer()
    tag = gtk.TextTag(name="conflict")
    tag.set_property("background-gdk",
                     gtk.gdk.Color(red=65535, green=32000, blue=32000))
    buff.get_tag_table().add(tag)

    tag = gtk.TextTag(name="current")
    tag.set_property("background-gdk",
                     gtk.gdk.Color(red=32000, green=65535, blue=32000))
    buff.get_tag_table().add(tag)
Beispiel #9
0
 def setup_tags(self):
     self.markup_tag = gtk.TextTag('markup')
     self.markup_tag.set_property('editable', False)
     self.markup_tag.set_property('scale', pango.SCALE_SMALL)
     self.markup_tag.set_property('rise', 15)
     self.markup_tag.set_property('foreground', '#f00')
     self.ignore_tag = gtk.TextTag('ignore')
     self.ignore_tag.set_property('invisible', True)
     self.ignore_tag.set_property('editable', False)
     self.tb.get_tag_table().add(self.markup_tag)
     self.tb.get_tag_table().add(self.ignore_tag)
Beispiel #10
0
 def set_url_color(self, color):
     url_color = gtk.gdk.color_parse(color)
     self.tag_table = self.buffer.get_tag_table()
     if not self.tag_url:
         self.tag_url = gtk.TextTag("url")
         self.tag_table.add(self.tag_url)
         self.tag_url.set_property("underline", pango.UNDERLINE_SINGLE)
         self.tag_mid = gtk.TextTag("mid")
         self.tag_table.add(self.tag_mid)
         self.tag_mid.set_property("underline", pango.UNDERLINE_SINGLE)
     self.tag_url.set_property("foreground-gdk", url_color)
     self.tag_mid.set_property("foreground-gdk", url_color)
    def __init__(self):
        gtk.HBox.__init__(self, False, 4)
        self.set_border_width(4)

        self.table = gtk.TextTagTable()
        self.tag_offset = gtk.TextTag('hex-o-view')  # offset view
        self.tag_hex = gtk.TextTag('hex-x-view')  # hex view
        self.tag_ascii = gtk.TextTag('hex-a-view')  # ascii view
        self.tag_sec_sel = gtk.TextTag(
            'hex-s-selection')  # secondary selection

        self.table.add(self.tag_offset)
        self.table.add(self.tag_hex)
        self.table.add(self.tag_ascii)
        self.table.add(self.tag_sec_sel)

        self._bpl = 16
        self._font = "Monospace 10"
        self._payload = ""
        self._base_addr = 0
        self.scroll_mark = None
        self.editable = False

        self.vadj = gtk.Adjustment()
        self.vscroll = gtk.VScrollbar(self.vadj)

        self.offset_text = OffsetText(self)
        self.hex_text = HexText(self)
        self.ascii_text = AsciiText(self)

        self.offset_text.set_scroll_adjustments(None, self.vadj)
        self.hex_text.set_scroll_adjustments(None, self.vadj)
        self.ascii_text.set_scroll_adjustments(None, self.vadj)

        self.hex_text.buffer.connect('mark-set', self.__on_hex_change)
        self.ascii_text.buffer.connect('mark-set', self.__on_ascii_change)

        self.offset_text.connect('scroll-event', self.__on_scroll_event)
        self.hex_text.connect('scroll-event', self.__on_scroll_event)
        self.ascii_text.connect('scroll-event', self.__on_scroll_event)

        def scroll(widget):
            widget.set_size_request(-1, 128)
            frame = gtk.Frame()
            frame.set_shadow_type(gtk.SHADOW_IN)
            frame.add(widget)
            return frame

        self.pack_start(scroll(self.offset_text), False, False)
        self.pack_start(scroll(self.hex_text), False, False)
        self.pack_start(scroll(self.ascii_text), False, False)
        self.pack_end(self.vscroll, False, False)
Beispiel #12
0
    def __init__(self):
        super(ConsolePanel, self).__init__()

        self._history = [
            '',
        ] * ConsolePanel.MAX_HISTORY
        self._history_i = 0

        s_window = gtk.ScrolledWindow()
        s_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        s_window.show()

        t_table = gtk.TextTagTable()

        tag_out = gtk.TextTag("output")
        tag_out.set_property("foreground", "blue")
        tag_out.set_property("font", "monospace 10")
        tag_out.set_property("editable", False)
        t_table.add(tag_out)

        tag_in = gtk.TextTag("input")
        tag_in.set_property("foreground", "black")
        tag_in.set_property("font", "monospace 10")
        t_table.add(tag_in)

        self.tag_table = t_table

        self._buffer = gtk.TextBuffer(t_table)
        self._view = gtk.TextView(buffer=self._buffer)
        self._view.connect("key_press_event", self.actionKeyPress)
        self._view.show()
        s_window.add(self._view)
        self.add(s_window)
        evalButton = gtk.Button("Evaluate")
        evalButton.connect("clicked", self.evaluateAction, "evaluate")
        #evalButton.show()
        self.pack_start(evalButton, False, False, 0)
        self._evalButton = evalButton
        console_info = gtk.Label('')
        self._console_info = console_info
        self.update_consoleinfo()
        console_info.show()
        self.pack_start(console_info, False, False, 0)
        self.append("> ", "input")

        location = self._buffer.get_end_iter()
        self._start_mark = self._buffer.create_mark("beginCode",
                                                    location,
                                                    left_gravity=True)

        self._firstEnter = False
Beispiel #13
0
    def __init__(self, main_win):
        self.FILENAME = os.path.join(get_wdir(), "server_logs.dat")
        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect("delete_event", self.delete_event)
        self.window.connect("destroy", self.destroy)
        self.window.set_title(_("Server Logs Viewer"))
        self.window.set_position(gtk.WIN_POS_CENTER)
        if main_win != None:
            self.window.set_modal(True)
            self.window.set_transient_for(main_win)
        vbox = gtk.VBox(False, 0)
        vbox.set_border_width(2)
        label = gtk.Label("\n<b>" + _("Server Logs") + "</b>\n")
        label.set_use_markup(True)
        vbox.pack_start(label, False, True, 0)
        self.buffer = gtk.TextBuffer()
        scrolledwin = gtk.ScrolledWindow()
        scrolledwin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        scrolledwin.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        scrolledwin.set_border_width(4)
        self.view = gtk.TextView(self.buffer)
        self.view.set_wrap_mode(gtk.WRAP_WORD)
        self.view.set_justification(gtk.JUSTIFY_LEFT)
        self.view.set_cursor_visible(False)
        self.view.set_editable(False)
        self.view.set_indent(2)
        scrolledwin.add(self.view)

        blue_color = gtk.gdk.color_parse("blue")
        red_color = gtk.gdk.color_parse("red")
        black_color = gtk.gdk.color_parse("black")
        self.tag_table = self.buffer.get_tag_table()
        self.blue_tag = gtk.TextTag("blue")
        self.red_tag = gtk.TextTag("red")
        self.time_tag = gtk.TextTag("time")
        self.tag_table.add(self.blue_tag)
        self.tag_table.add(self.red_tag)
        self.tag_table.add(self.time_tag)
        self.blue_tag.set_property("foreground-gdk", blue_color)
        self.red_tag.set_property("foreground-gdk", red_color)
        self.time_tag.set_property("foreground-gdk", black_color)

        vbox.pack_start(scrolledwin, True, True, 0)
        self.button = gtk.Button(None, gtk.STOCK_OK)
        self.button.set_border_width(4)
        self.button.connect("clicked", self.destroy)
        vbox.pack_start(self.button, False, True, 0)
        self.window.add(vbox)
        self.window.set_default_size(550, 500)
        self.window.show_all()
        self.load_logs()
Beispiel #14
0
    def __init__(self, main_window):
        self.main_window = main_window
        self.app = main_window.get_app()

        self.outfile = Stream(self.output_text)
        self.errfile = Stream(lambda t: self.output_text(t, "error"))

        self.error_tag = gtk.TextTag()
        self.error_tag.set_property("foreground", "red")
        self.error_tag.set_property("weight", pango.WEIGHT_BOLD)

        self.info_tag = gtk.TextTag()
        self.info_tag.set_property("foreground", "blue")
        self.info_tag.set_property("weight", pango.WEIGHT_BOLD)
Beispiel #15
0
    def __init__(self):
        gtk.VBox.__init__(self, False, 2)
        self.set_border_width(4)

        self.not_selected_lbl = gtk.Label('')
        self.not_selected_lbl.set_markup(
            _('<span size=\'large\'><b>'
              'No plugin selected.</b></span>'))

        self.tagtable = gtk.TextTagTable()

        self.bold = gtk.TextTag('bold')
        self.bold.set_property('right-margin', 15)
        self.bold.set_property('weight', pango.WEIGHT_BOLD)
        self.tagtable.add(self.bold)

        self.par = gtk.TextTag('par')
        self.par.set_property('left-margin', 15)
        self.par.set_property('right-margin', 15)
        self.par.set_property('justification', gtk.JUSTIFY_FILL)
        self.tagtable.add(self.par)

        self.link = gtk.TextTag('link')
        self.link.set_property('foreground', '#0000FF')
        self.link.set_property('right-margin', 15)
        self.link.set_property('underline', pango.UNDERLINE_SINGLE)
        self.link.connect('event', self.__on_link)
        self.tagtable.add(self.link)

        self.buff = gtk.TextBuffer(self.tagtable)
        self.text = gtk.TextView(self.buff)
        self.text.modify_font(pango.FontDescription('Monospace 9'))
        self.text.set_editable(False)
        self.text.set_wrap_mode(gtk.WRAP_WORD_CHAR)

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

        self.pack_start(self.not_selected_lbl)
        self.pack_end(self.sw)

        self.current_plugin = None

        self.show()
        self.not_selected_lbl.show()

        self.connect('realize', self.__on_realize)
Beispiel #16
0
 def set_sign_color(self, color):
     sign_color = gtk.gdk.color_parse(color)
     self.tag_table = self.buffer.get_tag_table()
     if not self.sign_tag:
         self.sign_tag = gtk.TextTag("sign")
         self.tag_table.add(self.sign_tag)
     self.sign_tag.set_property("foreground-gdk", sign_color)
Beispiel #17
0
    def __init__(self,
                 p_doc=None,
                 p_offset1=None,
                 p_offset2=None,
                 p_offset3=None,
                 p_blocks=None,
                 p_type=None,
                 p_handler_ids=None):
        # Args
        self.__doc = p_doc
        self.__offset1 = p_offset1  # deleted after installed
        self.__offset2 = p_offset2  # deleted after installed
        self.__offset3 = p_offset3  # deleted after installed
        self.__blocks = p_blocks if p_blocks != None else []
        self.__type = p_type
        self.__mark1 = None
        self.__mark2 = None
        self.__mark3 = None
        self.__tag = gtk.TextTag()
        self.__tag.set_property("invisible-set", True)
        self.__anchor = None
        self.__handler_ids = p_handler_ids if p_handler_ids != None else []
        self.__pendings = []  # deleted after installed

        self.__installed = False

        def function():
            assert (not self.__installed)
            return (self.__offset1, self.__offset2, self.__offset3)

        self.get_initial_offsets = function  # deleted after installed
        del function
Beispiel #18
0
 def get_tag(self, ttype, tb):
     tag = None
     if ttype in self.tags:
         tag = self.tags[ttype]
     else:
         style = self.style.style_for_token(ttype)
         tag = gtk.TextTag()
         if 'bgcolor' in style and not style['bgcolor'] is None:
             tag.set_property('background', '#%s' % style['bgcolor'])
         if 'bold' in style and style['bold']:
             tag.set_property('weight', pango.WEIGHT_BOLD)
         if 'border' in style and not style['border'] is None:
             #TODO
             pass
         if 'color' in style and not style['color'] is None:
             tag.set_property('foreground', '#%s' % style['color'])
         if 'italic' in style and style['italic']:
             tag.set_property('style', pango.STYLE_ITALIC)
         if 'mono' in style and not style['mono'] is None:
             tag.set_property('family', 'Monospace')
             tag.set_property('family-set', True)
         if 'roman' in style and not style['roman'] is None:
             #TODO
             pass
         if 'sans' in style and not style['sans'] is None:
             tag.set_property('family', 'Sans')
             tag.set_property('family-set', True)
         if 'underline' in style and style['underline']:
             tag.set_property('underline', 'single')
         self.tags[ttype] = tag
         tb.get_tag_table().add(tag)
     return tag
Beispiel #19
0
 def __init__(self, master, mode, dims, font, editable):
     self.this = gtk.ScrolledWindow()
     self.this.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
     self.txtw = gtk.TextView()
     self.this.add(self.txtw)
     self.master = master
     self.txtw.set_wrap_mode(mode)
     if font:
         self.tag = gtk.TextTag()
         self.tag.set_property('font', font)
         bf = self.txtw.get_buffer()
         bf.get_tag_table().add(self.tag)
         print "IT'sa:", bf.get_start_iter(), type(bf.get_start_iter())
         bf.apply_tag(self.tag, bf.get_start_iter(), bf.get_end_iter())
     else:
         self.tag = None
     if dims != (0, 0):
         pl = self.txtw.create_pango_layout('g').get_pixel_extents()
     if dims[0] == 0: gx = -1
     else: gx = pl[1][2] * dims[0]
     if dims[1] == 0: gy = -1
     else:
         gy = (pl[1][3] + self.txtw.get_pixels_above_lines() +
               self.txtw.get_pixels_below_lines()) * dims[1]
     self.this.set_size_request(gx, gy)
     self.set_editable(editable)
Beispiel #20
0
    def __init__(self, pipe, log_view):
        self.__pipe = pipe
        self.__log_view = log_view

        tag_table = log_view.buffer.get_tag_table()
        self.__tag = gtk.TextTag()

        self.__good_tag = gobject.new(gtk.TextTag,
            weight                  = pango.WEIGHT_BOLD,
            foreground              = "darkgreen",
            paragraph_background    = "lightgreen")

        self.__bad_tag = gobject.new(gtk.TextTag,
            weight                  = pango.WEIGHT_BOLD,
            foreground              = "darkred",
            paragraph_background    = "pink")

        # for warnings, etc.
        self.__ugly_tag = gobject.new(gtk.TextTag,
            #weight                  = pango.WEIGHT_BOLD,
            foreground              = "red")

        tag_table.add(self.__tag)
        tag_table.add(self.__good_tag)
        tag_table.add(self.__bad_tag)
        tag_table.add(self.__ugly_tag)

        pipe_util.start_reader(pipe)
        self.__reader_task = gobject.timeout_add(20, self.__reader_tick)
Beispiel #21
0
 def create(descs):
     table = gtk.TextTagTable()
     for name, properties in descs.items():
         tag = gtk.TextTag(name); table.add(tag)
         for property, value in properties.items():
             tag.set_property(property, value)
     return table
Beispiel #22
0
 def editor_open(self, *args):
     step = 1000
     fcd = FileChooserDialog(self, action='open')
     fcd.run()
     if not self.path:
         return
     self.editor_path = self.path
     self.fcd_dir = os.path.dirname(self.path)
     self.path = ''
     text = open(self.editor_path).read()
     self.path = ''
     t_table = gtk.TextTagTable()
     tag = gtk.TextTag('output')
     t_table.add(tag)
     self.editor_buffer = gtk.TextBuffer(t_table)
     self.textview_edit.set_buffer(self.editor_buffer)
     self.assert_quit = True
     size=len(text)
     if size < step:
         self.editor_buffer.set_text(text)
     else:
         self.editor_buffer.set_text(text[:step])
         while gtk.events_pending():
             gtk.main_iteration_do(False)
         i = step
         while i < size-step:
             self.editor_buffer.insert(self.editor_buffer.get_end_iter(), text[i:i+step])
             i += step
             while gtk.events_pending():
                 gtk.main_iteration_do(False)
         self.editor_buffer.insert(self.editor_buffer.get_end_iter(), text[i:])
Beispiel #23
0
    def open(self, filename, container=None):
        self.type = "gtk"
        self.has_data = True
        self.tag_table = gtk.TextTagTable()

        sheet = self.get_style_sheet()

        for name in sheet.get_paragraph_style_names():
            tag = gtk.TextTag(name)

            style = sheet.get_paragraph_style(name)
            font = style.get_font()
            if font.get_type_face() == FONT_SERIF:
                tag.set_property("family", "Serif")
            elif font.get_type_face() == FONT_SANS_SERIF:
                tag.set_property("family", "Sans")
            elif font.get_type_face() == FONT_MONOSPACE:
                tag.set_property("family", "MonoSpace")

            tag.set_property("size-points", float(font.get_size()))
            if font.get_bold():
                tag.set_property("weight", pango.WEIGHT_BOLD)
            if style.get_alignment() == PARA_ALIGN_RIGHT:
                tag.set_property("justification", gtk.JUSTIFY_RIGHT)
            elif style.get_alignment() == PARA_ALIGN_LEFT:
                tag.set_property("justification", gtk.JUSTIFY_LEFT)
            elif style.get_alignment() == PARA_ALIGN_CENTER:
                tag.set_property("justification", gtk.JUSTIFY_CENTER)
            else:
                tag.set_property("justification", gtk.JUSTIFY_FILL)

            if font.get_italic():
                tag.set_property("style", pango.STYLE_ITALIC)

            if style.get_first_indent():
                tag.set_property("indent", pixels(style.get_first_indent()))
                #tag.set_property("tabs", [pixels(abs(style.get_first_indent()))])

            tag.set_property("left-margin", pixels(style.get_left_margin()))
            tag.set_property("right-margin", pixels(style.get_right_margin()))
            tag.set_property("pixels-above-lines", pixels(style.get_top_margin()))
            tag.set_property("pixels-below-lines", pixels(style.get_bottom_margin()))
            tag.set_property("wrap-mode", gtk.WRAP_WORD)

            new_tabs = style.get_tabs()

            tab_array = pango.TabArray(len(new_tabs)+1,True)
            index = 0
            for tab in map(pixels, new_tabs):
                tab_array.set_tab(index, pango.TAB_LEFT, tab)
                index += 1
            tag.set_property("tabs", tab_array)

            self.tag_table.add(tag)
        self.buffer = gtk.TextBuffer(self.tag_table)
        if container:
            return DocumentManager(_('Quick View'), self, container)
        else:
            DisplayBuf(_('Quick View'), self)
            return
Beispiel #24
0
    def put_tag(self, aa, props, pre="", post=""):

        para2 = aa[1].replace("\n", " ")
        para2 = self.singlespace(para2)
        para2 = self.htmlentity(para2)

        para2 = pre + para2 + post

        # Too much space looks bad
        if not isvalue.search(para2) and \
            not isvalue.search(self.old_para):
            #print "Duplicate empty tag", para2
            return

        self.old_para = para2

        xtag = gtk.TextTag()
        for aa in props:
            #print "setting prop", aa[0], aa[1]
            try:
                xtag.set_property(aa[0], aa[1])
            except:
                # If cannot set, assume new data (like link)
                #print "set data", aa[0], aa[1]
                xtag.set_data(aa[0], aa[1])

        self.mw.add_text_xtag(para2, xtag, False)
Beispiel #25
0
    def __init__(self, session, on_send_message, on_cycle_history,
                 on_drag_data_received):
        '''constructor'''
        TextBox.__init__(self, session.config, on_drag_data_received)
        self.on_send_message = on_send_message
        self.on_cycle_history = on_cycle_history
        self._tag = None
        self._textbox.connect('key-press-event', self._on_key_press_event)
        self._buffer.connect('changed', self.on_changed_event)
        self.session = session

        self.changed = False
        self.parse_timeout = None
        self.invisible_tag = gtk.TextTag()
        self.invisible_tag.set_property('invisible', True)
        self._buffer.get_tag_table().add(self.invisible_tag)

        self.spell_checker = None

        if self.config.b_enable_spell_check:
            try:
                import gtkspell
                spell_lang = self.config.get_or_set("spell_lang", "en")
                self.spell_checker = gtkspell.Spell(self._textbox, spell_lang)
            except Exception, e:
                log.warning("Could not load spell-check: %s" % e)
Beispiel #26
0
 def buffer_initialize(self):
     """
     Initialize the GtkTextBuffer associated with the GtkTextView. If you
     have associated a new GtkTextBuffer with the GtkTextView call this
     method.
     """
     self._buffer = self._view.get_buffer()
     self._buffer.connect('insert-text', self._before_text_insert)
     self._buffer.connect_after('insert-text', self._after_text_insert)
     self._buffer.connect_after('delete-range', self._range_delete)
     self._buffer.connect_after('mark-set', self._mark_set)
     start = self._buffer.get_bounds()[0]
     self._marks = {'insert-start' : SpellChecker._Mark(self._buffer,
                        '{}-insert-start'.format(self._prefix), start),
                    'insert-end' : SpellChecker._Mark(self._buffer,
                        '{}-insert-end'.format(self._prefix), start),
                    'click' : SpellChecker._Mark(self._buffer,
                        '{}-click'.format(self._prefix), start)}
     self._table = self._buffer.get_tag_table()
     if not self._table.lookup(self._misspelled.get_property("name")): self._table.add(self._misspelled)
     self.ignored_tags = []
     def tag_added(tag, *args):
         if hasattr(tag, 'spell_check') and not getattr(tag, 'spell_check'):
             self.ignored_tags.append(tag)
     def tag_removed(tag, *args):
         if tag in self.ignored_tags:
             self.ignored_tags.remove(tag)
     self._table.connect('tag-added', tag_added)
     self._table.connect('tag-removed', tag_removed)
     self._table.foreach(tag_added, None)
     self.no_spell_check = self._table.lookup('no-spell-check')
     if not self.no_spell_check:
         self.no_spell_check = gtk.TextTag('no-spell-check')
         self._table.add(self.no_spell_check)
     self.recheck()
Beispiel #27
0
    def __init__(self, pipe, log_view):
        self.__log_view = log_view

        tag_table = log_view.buffer.get_tag_table()
        self.__tag = gtk.TextTag()

        self.__good_tag = gobject.new(gtk.TextTag,
                                      weight=pango.WEIGHT_BOLD,
                                      foreground="darkgreen",
                                      paragraph_background="lightgreen")

        self.__bad_tag = gobject.new(gtk.TextTag,
                                     weight=pango.WEIGHT_BOLD,
                                     foreground="darkred",
                                     paragraph_background="pink")

        # for warnings, etc.
        self.__ugly_tag = gobject.new(
            gtk.TextTag,
            #weight                  = pango.WEIGHT_BOLD,
            foreground="red")

        tag_table.add(self.__tag)
        tag_table.add(self.__good_tag)
        tag_table.add(self.__bad_tag)
        tag_table.add(self.__ugly_tag)

        self.__watch_id = gobject.io_add_watch(
            pipe,
            gobject.IO_IN | gobject.IO_PRI | gobject.IO_ERR | gobject.IO_HUP,
            self.__on_output)
Beispiel #28
0
def Text(vparser, token, tentry):
    global mainview
    emit(vparser.strx)

    xtag = gtk.TextTag()

    # Decorate textag according to machine state
    if Textstate.bold: xtag.set_property("weight", pango.WEIGHT_BOLD)
    if Textstate.italic: xtag.set_property("style", pango.STYLE_ITALIC)
    if Textstate.itbold: xtag.set_property("foreground", "red")
    if Textstate.large: xtag.set_property("scale", pango.SCALE_LARGE)
    if Textstate.xlarge: xtag.set_property("scale", pango.SCALE_X_LARGE)
    if Textstate.xxlarge: xtag.set_property("scale", pango.SCALE_XX_LARGE)
    if Textstate.small: xtag.set_property("scale", pango.SCALE_SMALL)
    if Textstate.ul: xtag.set_property("underline", pango.UNDERLINE_SINGLE)
    if Textstate.red: xtag.set_property("foreground", "red")
    if Textstate.green: xtag.set_property("foreground", "green")
    if Textstate.blue: xtag.set_property("foreground", "blue")
    if Textstate.strike: xtag.set_property("strikethrough", True)
    if Textstate.center: xtag.set_property("justification", gtk.JUSTIFY_CENTER)
    if Textstate.wrap: xtag.set_property("wrap_mode", gtk.WRAP_WORD)

    cnt = 0
    ind = 48
    while True:
        if Textstate.indent > cnt:
            xtag.set_property("indent", ind)
            ind += 32
            cnt += 1
        else:
            break

    mainview.add_text_xtag(vparser.strx, xtag)
Beispiel #29
0
    def __init__(self, window):
        super(_CommentsDialog, self).__init__(_('Comments'), window, 0,
            (gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE))

        self.set_resizable(True)
        self.set_default_response(gtk.RESPONSE_CLOSE)
        self.set_default_size(600, 550)
        self.set_border_width(4)

        tag = gtk.TextTag()
        tag.set_property('editable', False)
        tag.set_property('editable-set', True)
        tag.set_property('family', 'Monospace')
        tag.set_property('family-set', True)
        tag.set_property('scale', 0.9)
        tag.set_property('scale-set', True)
        tag_table = gtk.TextTagTable()
        tag_table.add(tag)

        self._tag = tag
        self._tag_table = tag_table
        self._notebook = None
        self._window = window
        self._comments = []

        self._window.filehandler.file_available += self._on_file_available
        self._window.filehandler.file_opened += self._update_comments
        self._window.filehandler.file_closed += self._update_comments
        self._update_comments()
        self.show_all()
Beispiel #30
0
 def __init__(self, scrolling='hv', **kwds):
     gtk_sw = gtk.ScrolledWindow()
     gtk_sw.show()
     gtk_tv = gtk.TextView()
     gtk_tv.show()
     gtk_sw.add(gtk_tv)
     gtk_tb = gtk.TextBuffer()
     self._gtk_textbuffer = gtk_tb
     gtk_tv.set_buffer(self._gtk_textbuffer)
     tag = gtk.TextTag()
     tabs = pango.TabArray(1, True)
     tabs.set_tab(0, pango.TAB_LEFT, 28)
     tag.set_property('tabs', tabs)
     tag.set_property('tabs-set', True)
     self._gtk_tag = tag
     gtk_tb.get_tag_table().add(tag)
     GTextEditor.__init__(self,
                          _gtk_outer=gtk_sw,
                          _gtk_inner=gtk_tv,
                          _gtk_focus=gtk_tv,
                          **kwds)
     self.set_hscrolling('h' in scrolling)
     self.set_vscrolling('v' in scrolling)
     if 'h' not in scrolling:
         gtk_tv.set_wrap_mode(gtk.WRAP_WORD)
     self._gtk_apply_tag()