Python gi.repository.Gtk.TextView() Examples

The following are 30 code examples of gi.repository.Gtk.TextView(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gi.repository.Gtk , or try the search function .
Example #1
Source File: mail.py    From king-phisher with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def __init__(self, *args, **kwargs):
		self.label = Gtk.Label(label='Send')
		"""The :py:class:`Gtk.Label` representing this tabs name."""
		super(MailSenderSendTab, self).__init__(*args, **kwargs)
		self.textview = self.gobjects['textview_mail_sender_progress']
		"""The :py:class:`Gtk.TextView` object that renders text status messages."""
		self.textview.modify_font(Pango.FontDescription(self.config['text_font']))
		self.textbuffer = self.textview.get_buffer()
		"""The :py:class:`Gtk.TextBuffer` instance associated with :py:attr:`~.MailSenderSendTab.textview`."""
		self.textbuffer_iter = self.textbuffer.get_start_iter()
		self.progressbar = self.gobjects['progressbar_mail_sender']
		"""The :py:class:`Gtk.ProgressBar` instance which is used to display progress of sending messages."""
		self.pause_button = self.gobjects['togglebutton_mail_sender_pause']
		self.sender_thread = None
		"""The :py:class:`.MailSenderThread` instance that is being used to send messages."""
		self.application.connect('exit', self.signal_kpc_exit)
		self.application.connect('exit-confirm', self.signal_kpc_exit_confirm)
		self.textview.connect('populate-popup', self.signal_textview_populate_popup) 
Example #2
Source File: widgets.py    From zim-desktop-wiki with GNU General Public License v2.0 6 votes vote down vote up
def ScrolledTextView(text=None, monospace=False, **kwarg):
	'''Initializes a C{Gtk.TextView} with sane defaults for displaying a
	piece of multiline text and wraps it in a scrolled window

	@param text: initial text to show in the textview
	@param monospace: when C{True} the font will be set to monospaced
	and line wrapping disabled, use this to display log files etc.
	@param kwarg: arguments passed on to L{ScrolledWindow}
	@returns: a 2-tuple of the scrolled window and the textview
	'''
	textview = Gtk.TextView()
	textview.set_editable(False)
	textview.set_left_margin(5)
	textview.set_right_margin(5)
	if monospace:
		font = Pango.FontDescription('Monospace')
		textview.modify_font(font)
	else:
		textview.set_wrap_mode(Gtk.WrapMode.WORD)

	if text:
		textview.get_buffer().set_text(text)
	window = ScrolledWindow(textview, **kwarg)
	return window, textview 
Example #3
Source File: gnomecast.py    From gnomecast with GNU General Public License v3.0 6 votes vote down vote up
def error_callback(self, msg):
    def f():
      dialogWindow = Gtk.MessageDialog(self.win,
                            Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
                            Gtk.MessageType.INFO,
                            Gtk.ButtonsType.OK,
                            '\nGnomecast encountered an error converting your file.')
      dialogWindow.set_title('Transcoding Error')
      dialogWindow.set_default_size(1, 400)
      
      dialogBox = dialogWindow.get_content_area()
      buffer1 = Gtk.TextBuffer()
      buffer1.set_text(msg)
      text_view = Gtk.TextView(buffer=buffer1)
      text_view.set_editable(False)
      scrolled_window = Gtk.ScrolledWindow()
      scrolled_window.set_border_width(5)
      # we scroll only if needed
      scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
      scrolled_window.add(text_view)
      dialogBox.pack_end(scrolled_window, True, True, 0)
      dialogWindow.show_all()
      response = dialogWindow.run()
      dialogWindow.destroy()
    GLib.idle_add(f) 
Example #4
Source File: GUIElements.py    From FlatCAM with MIT License 6 votes vote down vote up
def __init__(self):
        # Gtk.ScrolledWindow.__init__(self)
        # FlatCAMApp.App.log.debug('Gtk.ScrolledWindow.__init__(self)')
        super(FCTextArea, self).__init__()
        FlatCAMApp.App.log.debug('super(FCTextArea, self).__init__()')
        self.set_size_request(250, 100)
        FlatCAMApp.App.log.debug('self.set_size_request(250, 100)')
        textview = Gtk.TextView()
        #print textview
        #FlatCAMApp.App.log.debug('self.textview = Gtk.TextView()')
        #self.textbuffer = self.textview.get_buffer()
        #FlatCAMApp.App.log.debug('self.textbuffer = self.textview.get_buffer()')
        #self.textbuffer.set_text("(Nothing here!)")
        #FlatCAMApp.App.log.debug('self.textbuffer.set_text("(Nothing here!)")')
        #self.add(self.textview)
        #FlatCAMApp.App.log.debug('self.add(self.textview)')
        #self.show() 
Example #5
Source File: RemarkableWindow.py    From Remarkable with MIT License 6 votes vote down vote up
def on_menuitem_custom_activate(self, widget):
        self.custom_window = Gtk.Window()
        self.custom_window.set_default_size(640, 480)
        self.custom_window.set_position(Gtk.WindowPosition.CENTER)
        self.custom_window.set_title("Custom CSS")

        self.custom_vbox = Gtk.VBox()
        self.custom_scroller = Gtk.ScrolledWindow()
        self.custom_button = Gtk.Button("Apply")
        self.custom_vbox.pack_end(self.custom_button, False, False, 0)
        self.custom_text_view = Gtk.TextView()
        self.custom_text_buffer = Gtk.TextBuffer()
        self.custom_text_buffer.set_text(self.custom_css)
        self.custom_text_view.set_buffer(self.custom_text_buffer)
        self.custom_scroller.add(self.custom_text_view)
        self.custom_vbox.pack_start(self.custom_scroller, True, True, 0)
        self.custom_window.add(self.custom_vbox)
        self.custom_window.show_all()
        self.custom_button.connect("clicked", self.apply_custom_css, self.custom_window, self.custom_text_buffer) 
Example #6
Source File: indicator.py    From yandex-disk-indicator with GNU General Public License v3.0 6 votes vote down vote up
def showOutput(self, widget):           # Request for daemon output
            widget.set_sensitive(False)                         # Disable menu item


            def displayOutput(outText, widget):
                # # # NOTE: it is called not from main thread, so it have to add action in main loop queue
                def do_display(outText, widget):
                    # global APPLOGO
                    statusWindow = Gtk.Dialog(_('Yandex.Disk daemon output message'))
                    statusWindow.set_icon(APPLOGO)
                    statusWindow.set_border_width(6)
                    statusWindow.add_button(_('Close'), Gtk.ResponseType.CLOSE)
                    textBox = Gtk.TextView()                            # Create text-box to display daemon output
                    # Set output buffer with daemon output in user language
                    textBox.get_buffer().set_text(outText)
                    textBox.set_editable(False)
                    # Put it inside the dialogue content area
                    statusWindow.get_content_area().pack_start(textBox, True, True, 6)
                    statusWindow.show_all();  statusWindow.run();   statusWindow.destroy()
                    widget.set_sensitive(True)                          # Enable menu item
                idle_add(do_display, outText, widget)

            self.daemon.output(lambda t: displayOutput(t, widget)) 
Example #7
Source File: engineOutputPanel.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def load(self, gmwidg):
        # Specify whether the panel should have a horizontal layout:
        horizontal = True

        if horizontal:
            self.box = Gtk.HBox()
        else:
            self.box = Gtk.VBox()
        __widget__ = self.box

        # Use two engine output widgets for each player color:
        self.output_white = EngineOutput(True)
        self.output_black = EngineOutput(False)
        if horizontal:
            self.output_separator = Gtk.VSeparator()
        else:
            self.output_separator = Gtk.HSeparator()

        self.output_noengines = Gtk.TextView()
        self.output_noengines.get_buffer().set_text(_(
            "No chess engines (computer players) are participating in this game."))
        self.output_noengines.set_editable(False)
        self.output_noengines.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)

        __widget__.pack_start(self.output_noengines, True, True, 0)
        __widget__.show_all()

        self.boardview = gmwidg.board.view

        self.model_cids = [
            self.boardview.model.connect_after("game_changed", self.game_changed),
            self.boardview.model.connect_after("players_changed", self.players_changed),
            self.boardview.model.connect_after("game_started", self.game_started),
            self.boardview.model.connect_after("game_terminated", self.on_game_terminated),
        ]
        return __widget__ 
Example #8
Source File: results.py    From runsqlrun with MIT License 5 votes vote down vote up
def _initiate_textview(self, data):
        is_jsonlike, data = self._data2str(data)
        if is_jsonlike:
            widget = BaseEditor(self.win.app, 'json')
        else:
            widget = Gtk.TextView()
        widget.get_buffer().set_text(data)
        return widget 
Example #9
Source File: comments_dialog.py    From bokken with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, title='Add comment'):
        super(CommentsDialog,self).__init__(title, None, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, (Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT, Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT))

        # the cancel button
        self.butt_cancel = self.action_area.get_children()[1]
        self.butt_cancel.connect("clicked", lambda x: self.destroy())

        # Positions
        self.resize(400, 200)
        self.set_position(Gtk.WindowPosition.CENTER)
        ui.gtk3.common.set_bokken_icon(self)

        # Log TextView
        #################################################################
        self.input_text = Gtk.TextView(buffer=None)
        self.input_text.set_wrap_mode(Gtk.WrapMode.NONE)
        self.input_text.set_left_margin(10)
        self.input_buffer = self.input_text.get_buffer()

        self.scrolled_window = Gtk.ScrolledWindow()
        self.scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        self.scrolled_window.is_visible = True

        # Add Textview to Scrolled Window
        self.scrolled_window.add_with_viewport(self.input_text)

        #self.vbox.pack_start(self.input_text, True, True, 0)
        self.vbox.pack_start(self.scrolled_window, True, True, 0)
        self.show_all() 
Example #10
Source File: search_dialog.py    From bokken with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, main, title='Search results'):
        super(SearchDialog,self).__init__(title, main.window, Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, (Gtk.STOCK_OK,Gtk.ResponseType.ACCEPT))

        # the cancel button
        self.butt_cancel = self.action_area.get_children()[0]
        self.butt_cancel.connect("clicked", lambda x: self.destroy())

        # Positions
        self.resize(400, 400)
        self.set_position(Gtk.WindowPosition.CENTER)
        ui.gtk3.common.set_bokken_icon(self)

        # Log TextView
        #################################################################
        self.output_text = Gtk.TextView(buffer=None)
        self.output_text.set_wrap_mode(Gtk.WrapMode.NONE)
        self.output_text.set_editable(False)
        self.output_buffer = self.output_text.get_buffer()

        self.scrolled_window = Gtk.ScrolledWindow()
        self.scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.ALWAYS)
        self.scrolled_window.is_visible = True

        # Add Textview to Scrolled Window
        self.scrolled_window.add_with_viewport(self.output_text)

        #self.vbox.pack_start(self.output_text, True, True, 0)
        self.vbox.pack_start(self.scrolled_window, True, True, 0)
        self.show_all() 
Example #11
Source File: gtk.py    From bups with MIT License 5 votes vote down vote up
def __init__(self, manager, parent=None):
		Gtk.Window.__init__(self, title=_("Backup"))
		self.set_border_width(10)
		self.set_icon_name("drive-harddisk")
		self.set_position(Gtk.WindowPosition.CENTER)

		if parent is not None:
			self.set_transient_for(parent)

		vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
		self.add(vbox)

		self.label = Gtk.Label(_("Ready."), xalign=0)
		self.label.set_justify(Gtk.Justification.LEFT)
		vbox.pack_start(self.label, False, False, 0)

		self.progressbar = Gtk.ProgressBar()
		vbox.pack_start(self.progressbar, False, False, 0)

		self.textview = Gtk.TextView()
		#self.textview.modify_bg(Gtk.StateType.NORMAL, Gdk.Color(0, 0, 0))
		#self.textview.modify_text(Gtk.StateType.NORMAL, Gdk.Color(255, 255, 255))
		fontdesc = Pango.FontDescription("monospace")
		self.textview.modify_font(fontdesc)
		self.textview.set_editable(False)
		sw = Gtk.ScrolledWindow()
		sw.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
		sw.set_min_content_height(200)
		sw.add(self.textview)
		exp = Gtk.Expander()
		exp.set_label(_("Details"))
		exp.add(sw)
		vbox.pack_start(exp, True, True, 0)

		hbox = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL, spacing=50)
		vbox.add(hbox)
		self.close_button = Gtk.Button(_("Close"))
		self.close_button.connect("clicked", self.on_close_clicked)
		hbox.pack_end(self.close_button, False, False, 0)

		self.manager = manager 
Example #12
Source File: FlatCAMApp.py    From FlatCAM with MIT License 5 votes vote down vote up
def on_fileopengerber(self, param):
        """
        Callback for menu item File->Open Gerber. Defines a function that is then passed
        to ``self.file_chooser_action()``. It requests the creation of a FlatCAMGerber object
        and updates the progress bar throughout the process.

        :param param: Ignore
        :return: None
        """

        # This works here.
        # t = Gtk.TextView()
        # print t

        self.file_chooser_action(lambda ao, filename: self.open_gerber(filename)) 
Example #13
Source File: FlatCAMApp.py    From FlatCAM with MIT License 5 votes vote down vote up
def file_chooser_action(self, on_success):
        """
        Opens the file chooser and runs on_success on a separate thread
        upon completion of valid file choice.

        :param on_success: A function to run upon completion of a valid file
            selection. Takes 2 parameters: The app instance and the filename.
            Note that it is run on a separate thread, therefore it must take the
            appropriate precautions  when accessing shared resources.
        :type on_success: func
        :return: None
        """
        dialog = Gtk.FileChooserDialog("Please choose a file", self.ui,
                                       Gtk.FileChooserAction.OPEN,
                                       (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                        Gtk.STOCK_OPEN, Gtk.ResponseType.OK))
        response = dialog.run()

        # Works here
        # t = Gtk.TextView()
        # print t

        if response == Gtk.ResponseType.OK:
            filename = dialog.get_filename()
            dialog.destroy()
            # Send to worker.
            self.worker.add_task(on_success, [self, filename])
        elif response == Gtk.ResponseType.CANCEL:
            self.info("Open cancelled.")
            dialog.destroy()

        # Works here
        # t = Gtk.TextView()
        # print t 
Example #14
Source File: kano_dialog.py    From kano-toolset with GNU General Public License v2.0 5 votes vote down vote up
def __add_scrolled_window(self):
        text = Gtk.TextView()
        text.get_buffer().set_text(self.scrolled_text)
        text.set_wrap_mode(Gtk.WrapMode.WORD)
        text.set_editable(False)

        scrolledwindow = ScrolledWindow()
        scrolledwindow.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
        scrolledwindow.add_with_viewport(text)
        scrolledwindow.set_size_request(400, 200)
        scrolledwindow.apply_styling_to_widget(wide=False)

        return scrolledwindow 
Example #15
Source File: InfoPanel.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def onFingeringFinished(self, fm, finger, playername):
            if not isinstance(self.get_child(), Gtk.Label) or \
                    finger.getName().lower() != playername.lower():
                return
            self.fm.disconnect(self.handle_id)

            label = Gtk.Label()
            label.set_markup("<b>%s</b>" % playername)
            widget = Gtk.Frame()
            widget.set_label_widget(label)
            widget.set_shadow_type(Gtk.ShadowType.NONE)

            alignment = Gtk.Alignment.new(0, 0, 1, 1)
            alignment.set_padding(3, 0, 12, 0)
            widget.add(alignment)

            text_view = Gtk.TextView()
            text_view.set_editable(False)
            text_view.set_cursor_visible(False)
            text_view.props.wrap_mode = Gtk.WrapMode.WORD

            tb_iter = text_view.get_buffer().get_end_iter()
            for i, note in enumerate(finger.getNotes()):
                if note:
                    insert_formatted(text_view, tb_iter, "%s\n" % note)
            text_view.show_all()
            scroll_win = Gtk.ScrolledWindow()
            scroll_win.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
            scroll_win.add(text_view)
            alignment.add(scroll_win)

            self.remove(self.get_child())
            self.add(widget)
            widget.show_all() 
Example #16
Source File: NewsPanel.py    From pychess with GNU General Public License v3.0 5 votes vote down vote up
def onNewsItem(self, nm, news):
        weekday, month, day, title, details = news

        dtitle = "%s, %s %s: %s" % (weekday, month, day, title)
        label = Gtk.Label(label=dtitle)
        label.props.width_request = 300
        label.props.xalign = 0
        label.set_ellipsize(Pango.EllipsizeMode.END)
        expander = Gtk.Expander()
        expander.set_label_widget(label)
        expander.set_tooltip_text(title)
        textview = Gtk.TextView()
        textview.set_wrap_mode(Gtk.WrapMode.WORD)
        textview.set_editable(False)
        textview.set_cursor_visible(False)
        textview.props.pixels_above_lines = 4
        textview.props.pixels_below_lines = 4
        textview.props.right_margin = 2
        textview.props.left_margin = 6

        tb_iter = textview.get_buffer().get_end_iter()
        insert_formatted(textview, tb_iter, details)

        alignment = Gtk.Alignment()
        alignment.set_padding(3, 6, 12, 0)
        alignment.props.xscale = 1
        alignment.add(textview)

        expander.add(alignment)
        expander.show_all()
        self.widgets["newsVBox"].pack_start(expander, False, False, 0) 
Example #17
Source File: logging_console.py    From RAFCON with Eclipse Public License 1.0 5 votes vote down vote up
def __init__(self):
        View.__init__(self)

        self._lock = threading.Lock()

        self.text_view = Gtk.TextView()
        self.text_view.set_property('editable', False)

        self.filtered_buffer = self.create_text_buffer()

        self.text_view.set_buffer(self.filtered_buffer)

        self.text_view.set_border_window_size(Gtk.TextWindowType.LEFT, 10)
        self.text_view.set_border_window_size(Gtk.TextWindowType.RIGHT, 10)
        self.text_view.set_border_window_size(Gtk.TextWindowType.TOP, 10)
        self.text_view.set_border_window_size(Gtk.TextWindowType.BOTTOM, 10)

        self._enables = {}
        self._auto_scroll_handler_id = None

        scrollable = Gtk.ScrolledWindow()
        scrollable.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        scrollable.set_name('console_scroller')
        scrollable.add(self.text_view)
        self.text_view.show()

        self['scrollable'] = scrollable
        self.top = 'scrollable'
        self.quit_flag = False

        self.logging_priority = global_gui_config.get_config_value("LOGGING_CONSOLE_GTK_PRIORITY", GLib.PRIORITY_LOW)

        self._stored_line_number = None
        self._stored_line_offset = None
        self._stored_text_of_line = None
        self._stored_relative_lines = None 
Example #18
Source File: text_view.py    From Apostrophe with GNU General Public License v3.0 5 votes vote down vote up
def update_vertical_margin(self, top_margin=0, hb_size=0):
        if self.focus_mode:
            height = self.get_allocation().height + top_margin + hb_size
            # The height/6 may seem strange. It's a workaround for a GTK bug
            # If a top-margin is larger than a certain amount of the TextView height,
            # jumps may occur when pressing enter.
            self.set_top_margin(height / 2 + top_margin - height/6)
            self.set_bottom_margin(height / 2)
        else:
            self.props.top_margin = 80 + top_margin
            self.props.bottom_margin = 64 
Example #19
Source File: widgets.py    From zim-desktop-wiki with GNU General Public License v2.0 5 votes vote down vote up
def ScrolledWindow(widget, hpolicy=Gtk.PolicyType.AUTOMATIC, vpolicy=Gtk.PolicyType.AUTOMATIC, shadow=Gtk.ShadowType.IN):
	'''Wrap C{widget} in a C{Gtk.ScrolledWindow} and return the resulting
	widget
	@param widget: any Gtk widget
	@param hpolicy: the horizontal scrollbar policy
	@param vpolicy: the vertical scrollbar policy
	@param shadow: the shadow type
	@returns: a C{Gtk.ScrolledWindow}
	'''
	window = Gtk.ScrolledWindow()
	window.set_policy(hpolicy, vpolicy)
	window.set_shadow_type(shadow)

	if isinstance(widget, (Gtk.TextView, Gtk.TreeView, Gtk.Layout)):
		# Known native-scrolling widgets
		window.add(widget)
	else:
		window.add_with_viewport(widget)

	if hpolicy == Gtk.PolicyType.NEVER:
		hsize = -1 # do not set
	else:
		hsize = 24

	if vpolicy == Gtk.PolicyType.NEVER:
		vsize = -1 # do not set
	else:
		vsize = 24

	window.set_size_request(hsize, vsize)
		# scrolled widgets have at least this size...
		# by setting this minimum widgets can not "disappear" when
		# HPaned or VPaned bar is pulled all the way
	return window 
Example #20
Source File: DateCalculator.py    From addons-source with GNU General Public License v2.0 5 votes vote down vote up
def __add_text_view(self, name):
        """
        Add a text view to the interface.
        """
        label = Gtk.Label(halign=Gtk.Align.START)
        label.set_markup('<b>%s</b>' % name)
        self.top.pack_start(label, False, False, 6)
        swin = Gtk.ScrolledWindow()
        swin.set_shadow_type(Gtk.ShadowType.IN)
        tview = Gtk.TextView()
        swin.add(tview)
        self.top.pack_start(swin, True, True, 6)
        return tview.get_buffer() 
Example #21
Source File: ImportGramplet.py    From addons-source with GNU General Public License v2.0 5 votes vote down vote up
def init(self):
        """
        Constructs the GUI, consisting of a text area, and
        an Import and Clear buttons.
        """
        from gi.repository import Gtk
        # GUI setup:
        self.set_tooltip(_("Enter text to import and then click\n"
                           "the Import button at bottom"))
        # create
        self.import_text = Gtk.TextView()
        self.import_text.set_wrap_mode(Gtk.WrapMode.NONE)
        self.import_text.set_editable(True)
        import_button = Gtk.Button()
        clear_button = Gtk.Button()
        # layout
        scrolled_window = Gtk.ScrolledWindow()
        scrolled_window.add(self.import_text)
        buttonbox = Gtk.HButtonBox()
        buttonbox.set_layout(Gtk.ButtonBoxStyle.SPREAD)
        buttonbox.pack_start(clear_button, False, False, 0)
        buttonbox.pack_start(import_button, False, False, 0)
        vbox = Gtk.VBox()
        vbox.pack_start(scrolled_window, True, True, 0)
        vbox.pack_start(buttonbox, False, False, 0)
        scrolled_window = self.gui.get_container_widget()
        for widget in scrolled_window.get_children():
            widget.destroy()
        scrolled_window.add_with_viewport(vbox)
        scrolled_window.get_children()[0].set_shadow_type(Gtk.ShadowType.NONE)
        # bindings
        actiongroup = Gtk.ActionGroup('GrampletImportActions')
        actiongroup.add_actions([
            ('import', None, _("_Import"), '<Alt>i', None, self.run),
            ('clear', Gtk.STOCK_CLEAR, None, None, None, self.clear)])
        import_button.set_related_action(actiongroup.get_action('import'))
        clear_button.set_related_action(actiongroup.get_action('clear'))
        # show
        vbox.show_all() 
Example #22
Source File: gtk.py    From encompass with GNU General Public License v3.0 5 votes vote down vote up
def create_about_tab(self):
        from gi.repository import Pango
        page = Gtk.VBox()
        page.show()
        tv = Gtk.TextView()
        tv.set_editable(False)
        tv.set_cursor_visible(False)
        tv.modify_font(Pango.FontDescription(MONOSPACE_FONT))
        scroll = Gtk.ScrolledWindow()
        scroll.add(tv)
        page.pack_start(scroll, True, True, 0)
        self.info = tv.get_buffer()
        self.add_tab(page, 'Wall') 
Example #23
Source File: asktext.py    From textext with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def set_monospace_font(text_view):
    """
    Set the font to monospace in the text view
    :param text_view: A GTK TextView
    """
    try:
        import pango

        font_desc = pango.FontDescription('monospace 11')
        if font_desc:
            text_view.modify_font(font_desc)
    except ImportError:
        pass 
Example #24
Source File: extras.py    From king-phisher with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def __init__(self, *args, **kwargs):
		Gtk.Frame.__init__(self, *args, **kwargs)
		self.get_style_context().add_class('multilineentry')
		textview = Gtk.TextView()
		self.add(textview) 
Example #25
Source File: internationalizer.py    From zim-desktop-wiki with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self):
	#~ def __init__(self, dir):
		GObject.GObject.__init__(self)
		self.set_title('Internationalizer')
		self.set_default_size(500, 500)
		#~ self.dir = dir

		vbox = Gtk.VBox()
		self.add(vbox)

		self.status_label = Gtk.Label()
		vbox.pack_start(self.status_label, False)

		hbox = Gtk.HBox()
		vbox.add(hbox)
		scrollwindow = Gtk.ScrolledWindow()
		hbox.add(scrollwindow)

		self.textview = Gtk.TextView()
		self.textview.set_left_margin(12)
		self.textview.set_right_margin(5)
		scrollwindow.add(self.textview)

		bbox = Gtk.HButtonBox()
		vbox.pack_start(bbox, False)

		savebutton = Gtk.Button(stock='gtk-save')
		savebutton.connect_object('clicked', self.__class__.save_file, self)
		bbox.add(savebutton)

		reloadbutton = Gtk.Button(stock='gtk-refresh')
		reloadbutton.connect_object('clicked', self.__class__.reload_file, self)
		bbox.add(reloadbutton)

		nextbutton = Gtk.Button(stock='gtk-forward')
		nextbutton.connect_object('clicked', self.__class__.next_tag, self)
		bbox.add(nextbutton)

		applybutton = Gtk.Button(stock='gtk-apply')
		applybutton.connect_object('clicked', self.__class__.apply_mark, self)
		bbox.add(applybutton) 
Example #26
Source File: FlatCAMApp.py    From FlatCAM with MIT License 4 votes vote down vote up
def open_gerber(self, filename):
        """
        Opens a Gerber file, parses it and creates a new object for
        it in the program. Thread-safe.

        :param filename: Gerber file filename
        :type filename: str
        :return: None
        """

        # Fails here
        # t = Gtk.TextView()
        # print t

        GLib.idle_add(lambda: self.set_progress_bar(0.1, "Opening Gerber ..."))

        # How the object should be initialized
        def obj_init(gerber_obj, app_obj):
            assert isinstance(gerber_obj, FlatCAMGerber)

            # Opening the file happens here
            GLib.idle_add(lambda: app_obj.set_progress_bar(0.2, "Parsing ..."))
            gerber_obj.parse_file(filename)

            # Further parsing
            GLib.idle_add(lambda: app_obj.set_progress_bar(0.5, "Creating Geometry ..."))
            GLib.idle_add(lambda: app_obj.set_progress_bar(0.6, "Plotting ..."))

        # Object name
        name = filename.split('/')[-1].split('\\')[-1]

        self.new_object("gerber", name, obj_init)

        # New object creation and file processing
        # try:
        #     self.new_object("gerber", name, obj_init)
        # except:
        #     e = sys.exc_info()
        #     print "ERROR:", e[0]
        #     traceback.print_exc()
        #     self.message_dialog("Failed to create Gerber Object",
        #                         "Attempting to create a FlatCAM Gerber Object from " +
        #                         "Gerber file failed during processing:\n" +
        #                         str(e[0]) + " " + str(e[1]), kind="error")
        #     GLib.timeout_add_seconds(1, lambda: self.set_progress_bar(0.0, "Idle"))
        #     self.collection.delete_active()
        #     return

        # Register recent file
        self.register_recent("gerber", filename)

        # GUI feedback
        self.info("Opened: " + filename)
        GLib.idle_add(lambda: self.set_progress_bar(1.0, "Done!"))
        GLib.timeout_add_seconds(1, lambda: self.set_progress_bar(0.0, "Idle")) 
Example #27
Source File: gnomecast.py    From gnomecast with GNU General Public License v3.0 4 votes vote down vote up
def show_file_info(self, b=None):
    print('show_file_info')
    fmd = self.get_fmd()
    msg = '\n' + fmd.details()
    if self.cast:
      msg += '\nDevice: %s (%s)' % (self.cast.device.model_name, self.cast.device.manufacturer) 
    msg += '\nChromecast: v%s' % (__version__)
    dialogWindow = Gtk.MessageDialog(self.win,
                          Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
                          Gtk.MessageType.INFO,
                          Gtk.ButtonsType.OK,
                          msg)
    dialogWindow.set_title('File Info')
    dialogWindow.set_default_size(1, 400)
    
    if self.cast:
      title = 'Error playing %s' % os.path.basename(self.fn)
      body = '''
[Please describe what happened here...]

[Please link to the download here...]

```
[If possible, please run `ffprobe -i <fn>` and paste the output here...]
```

------------------------------------------------------------

%s

%s

```%s```''' % (msg, fmd, fmd._important_ffmpeg)
      url = 'https://github.com/keredson/gnomecast/issues/new?title=%s&body=%s' % (urllib.parse.quote(title), urllib.parse.quote(body))
      dialogWindow.add_action_widget(Gtk.LinkButton(url, label="Report File Doesn't Play"), 10)
      

    dialogBox = dialogWindow.get_content_area()
    buffer1 = Gtk.TextBuffer()
    buffer1.set_text(fmd._ffmpeg_output)
    text_view = Gtk.TextView(buffer=buffer1)
    text_view.set_editable(False)
    scrolled_window = Gtk.ScrolledWindow()
    scrolled_window.set_border_width(5)
    # we scroll only if needed
    scrolled_window.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
    scrolled_window.add(text_view)
    dialogBox.pack_end(scrolled_window, True, True, 0)

    dialogWindow.show_all()
    response = dialogWindow.run()
    dialogWindow.destroy() 
Example #28
Source File: utils.py    From tartube with GNU General Public License v3.0 4 votes vote down vote up
def add_links_to_textview_from_clipboard(app_obj, textbuffer, mark_start=None,
mark_end=None, drag_drop_text=None):

    """Called by mainwin.AddVideoDialogue.__init__(),
    .on_window_drag_data_received() and .clipboard_timer_callback().

    Function to add valid URLs from the clipboard to a Gtk.TextView, ignoring
    anything that is not a valid URL, and ignoring duplicate URLs.

    If some text is supplied as an argument, uses that text rather than the
    clipboard text

    Args:

        app_obj (mainapp.TartubeApp): The main application

        textbuffer (Gtk.TextBuffer): The textbuffer to which valis URLs should
            be added (unless they are duplicates)

        mark_start, mark_end (Gtk.TextMark): The marks at the start/end of the
            buffer (using marks rather than iters prevents Gtk errors)

        drag_drop_text (str): If specified, use this text and ignore the
            clipboard

    """

    if drag_drop_text is None:

        # Get text from the system clipboard
        clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
        cliptext = clipboard.wait_for_text()

    else:

        # Ignore the clipboard, and use the specified text
        cliptext = drag_drop_text

    # Pass the text on to the next function, first converting it into a list
    if cliptext is not None:
        add_links_to_textview(
            app_obj,
            cliptext.split('\n'),
            textbuffer,
            mark_start,
            mark_end,
        ) 
Example #29
Source File: export_common.py    From oomox with GNU General Public License v3.0 4 votes vote down vote up
def __init__(
            self, transient_for,
            headline=_("Export Theme"),
            width=150,
            height=80
    ):
        Gtk.Dialog.__init__(self, headline, transient_for, 0)
        self.set_default_size(width, height)

        self.label = CenterLabel()

        self.spinner = Gtk.Spinner()

        # Scrollable log window:
        self.log = Gtk.TextView()
        self.log.set_editable(False)
        # self.log.set_cursor_visible(False)
        self.log.override_font(
            # @TODO: make log size configurable?
            Pango.font_description_from_string("monospace 8")
        )
        self.log.set_wrap_mode(Gtk.WrapMode.CHAR)
        #
        self.scrolled_window = Gtk.ScrolledWindow(expand=True)
        self.scrolled_window.set_margin_bottom(5)
        self.scrolled_window.add(self.log)
        #
        adj = self.scrolled_window.get_vadjustment()
        adj.connect(
            'changed',
            lambda adj: adj.set_value(adj.get_upper() - adj.get_page_size())
        )

        self.options_box = Gtk.Box(
            orientation=Gtk.Orientation.VERTICAL, spacing=5
        )
        self.options_box.set_margin_top(5)
        self.options_box.set_margin_bottom(15)

        self.apply_button = Gtk.Button(label=_("_Apply Options and Export"), use_underline=True)
        self.apply_button.connect("clicked", lambda x: self.do_export())

        self.error_box = Gtk.Box(
            orientation=Gtk.Orientation.VERTICAL, spacing=5
        )
        self.error_box.set_margin_bottom(10)

        self.box = self.get_content_area()
        self.box.set_margin_left(5)
        self.box.set_margin_right(5)
        self.box.set_spacing(5)
        self.top_area = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
        self.box.add(self.top_area)
        self.top_area.add(self.label)

        self.show_all()
        self.box.add(self.spinner)
        self.box.add(self.scrolled_window) 
Example #30
Source File: annotationPanel.py    From pychess with GNU General Public License v3.0 4 votes vote down vote up
def menu_edit_comment(self, widget=None, board=None, index=0):
        """
        The method will create/update or delete a comment.
        The popup window will receive an additional button if there is an existing comment.
        """
        creation = True
        if not board.children:
            board.children.append("")
        elif not isinstance(board.children[index], str):
            board.children.insert(index, "")
        else:
            creation = False

        buttons_list = () if creation else (Gtk.STOCK_CLEAR, Gtk.ResponseType.REJECT)
        buttons_list = buttons_list + (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                       Gtk.STOCK_OK, Gtk.ResponseType.ACCEPT)

        dialog = Gtk.Dialog(_("Add comment") if creation else _("Edit comment"),
                            mainwindow(),
                            Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT,
                            buttons_list)

        textedit = Gtk.TextView()
        textedit.set_editable(True)
        textedit.set_cursor_visible(True)
        textedit.set_wrap_mode(Gtk.WrapMode.WORD)
        textedit.set_accepts_tab(False)

        textbuffer = textedit.get_buffer()
        textbuffer.set_text(board.children[index])

        sw = Gtk.ScrolledWindow()
        sw.set_policy(Gtk.PolicyType.AUTOMATIC, Gtk.PolicyType.AUTOMATIC)
        sw.add(textedit)

        dialog.get_content_area().pack_start(sw, True, True, 0)
        dialog.resize(300, 200)
        dialog.show_all()

        response = dialog.run()
        dialog.destroy()
        if response == Gtk.ResponseType.DELETE_EVENT:  # Escape key implies Cancel
            response = Gtk.ResponseType.CANCEL

        (iter_first, iter_last) = textbuffer.get_bounds()
        comment = '' if response == Gtk.ResponseType.REJECT else textbuffer.get_text(iter_first, iter_last, False)
        if response != Gtk.ResponseType.CANCEL and board.children[index] != comment:
            if len(comment) == 0:
                del board.children[index]
            else:
                board.children[index] = comment
            self.gamemodel.needsSave = True
            self.update()