Esempio n. 1
0
    def on_query_tooltip(self, view: Gtk.TextView, x: int, y: int,
                         keyboard: bool, tooltip: Gtk.Tooltip) -> bool:
        """
        Manage tooltip query event.

        :param view: The text view.
        :param x: The x position.
        :param y: The y position.
        :param keyboard: True if event comes from keyboard.
        :param tooltip: The queried tooltip.
        :return: True to prevent other handlers from being called.
        """
        position: Gtk.TextIter
        if keyboard:
            buff = view.get_buffer()
            position = buff.get_iter_at_mark(buff.get_insert())
        else:
            buffPos = view.window_to_buffer_coords(Gtk.TextWindowType.TEXT, x,
                                                   y)
            _, position = view.get_iter_at_location(*buffPos)
        line = position.get_line()
        offset = position.get_line_offset()
        error = self.__store.search((line, offset))
        if error is not None:
            tooltip.set_markup(
                GrammalecteAutoCorrector.__TOOLTIP.format(
                    error.description, *tuple(error.context)))
            return True
        else:
            return False
Esempio n. 2
0
    def on_mouse_clicked(self, view: Gtk.TextView,
                         event: Gdk.EventButton) -> bool:
        """
        Manage the mouse clicked event.

        :param view: The text view.
        :param event: The button event.
        :return: True to prevent other handlers from being called.
        """
        if event.button == 3:
            coords = view.window_to_buffer_coords(Gtk.TextWindowType.TEXT,
                                                  int(event.x), int(event.y))
            _, self.__menu_position = view.get_iter_at_location(*coords)
        return False
Esempio n. 3
0
    def target_view_setter(self, view: Gtk.TextView):
        if self._target_editable_connect_id:
            self._target_view.disconnect(self._target_editable_connect_id)

        self._target_editable_connect_id = view.connect(
            'notify::editable', lambda *args: self.queue_draw())
        self._target_view = view
        self.queue_draw()
Esempio n. 4
0
    def target_view_setter(self, view: Gtk.TextView):
        if self._target_editable_connect_id:
            self._target_view.disconnect(self._target_editable_connect_id)

        self._target_editable_connect_id = view.connect(
            'notify::editable', lambda *args: self.queue_draw())
        self._target_view = view
        self.queue_draw()
Esempio n. 5
0
    def on_buffer_changed(self, view: Gtk.TextView, *_) -> None:
        """
        Called when the buffer was changed.

        :param view: The text view.
        """
        self.__buffer_data.terminate()
        self.__buffer_data = _BufferData(view.get_buffer(),
                                         self.on_content_changed)
        self.__ask_request()
Esempio n. 6
0
    def on_popup_menu(self, view: Gtk.TextView) -> bool:
        """
        Manage the popup menu event.

        :param view: The text view.
        :return: True to prevent other handlers from being called.
        """
        buff = view.get_buffer()
        self.__menu_position = buff.get_iter_at_mark(buff.get_insert())
        return False
Esempio n. 7
0
    def disconnect(self, view: Gtk.TextView) -> None:
        """
        Disconnect the corrector from the view.

        :param view: The view to disconnect from auto-analyzer.
        """
        self.__tick_count = GrammalecteAutoCorrector.__TICK_OFF
        self.__config.disconnect(self.__eventConfigCleared)
        self.__config.disconnect(self.__eventConfigUpdated)
        view.disconnect(self.__eventBufferId)
        view.disconnect(self.__eventPopulatePopup)
        view.disconnect(self.__eventPopupMenu)
        view.disconnect(self.__eventMouseClicked)
        view.disconnect(self.__eventTooltipId)
        self.__analyzer.disconnect(self.__eventAnalFinishId)
        self.__analyzer.disconnect(self.__eventAnalStartId)

        self.__buffer_data.terminate()
        self.__cur_buffer = None
Esempio n. 8
0
    def __init__(self, view: Gtk.TextView, config: GrammalecteConfig,
                 analyzer: GrammalecteAnalyzer) -> None:
        """
        Initialize the corrector.

        :param view: The view to connect to analyzer.
        :param config: The configuration associated to the view.
        :param analyzer: The error analyzer.
        """
        self.__config: GrammalecteConfig = config
        self.__analyzer: GrammalecteAnalyzer = analyzer
        self.__requested: bool = False
        self.__cur_buffer: Optional[Gtk.TextBuffer] = None
        self.__store: GrammalecteErrorStore = GrammalecteErrorStore()
        self.__menu_position: Gtk.TextIter = view.get_buffer().get_start_iter()
        self.__tick_count: int = 1

        self.__buffer_data: _BufferData = _BufferData(view.get_buffer(),
                                                      self.on_content_changed)

        self.__eventAnalStartId = self.__analyzer.connect(
            "analyze-started", self.on_analyze_started)
        self.__eventAnalFinishId = self.__analyzer.connect(
            "analyze-finished", self.on_analyze_finished)
        self.__eventTooltipId = view.connect("query-tooltip",
                                             self.on_query_tooltip)
        self.__eventMouseClicked = view.connect("button-press-event",
                                                self.on_mouse_clicked)
        self.__eventPopupMenu = view.connect("popup-menu", self.on_popup_menu)
        self.__eventPopulatePopup = view.connect("populate-popup",
                                                 self.on_populate_popup)
        self.__eventBufferId = view.connect("notify::buffer",
                                            self.on_buffer_changed)
        self.__eventConfigUpdated = self.__config.connect(
            "updated", self.on_conf_updated)
        self.__eventConfigCleared = self.__config.connect(
            "cleared", self.on_conf_cleared)

        view.set_property("has_tooltip", True)
        self.__ask_request()
        GObject.timeout_add(GrammalecteAutoCorrector.__TICK_DURATION,
                            self.__add_request)
Esempio n. 9
0
        def start_playback(wdg):
            # Create GStreamer instance
            self.gst = GStreamer()
            self.gst.set_playback('gapless')
            self.gst.player.connect('about-to-finish', self.song_nearly_ended)
            self.gst.stop()

            self.current_song = False
            self.current_album = False

            # Prepare buttons
            self.btn_playpause = wdg[0][7]
            self.btn_previous = wdg[0][5]
            self.btn_next = wdg[0][8]
            self.btn_stop = wdg[0][6]

            self.btn_previous.connect('clicked', self.previous_pressed)
            self.btn_stop.connect('clicked', self.stop_pressed)
            self.btn_playpause.connect('clicked', self.play_pressed)
            self.btn_next.connect('clicked', self.next_pressed)

            self.btn_player = wdg[0][9]
            self.headerbar = wdg[0][0]

            # Create the player box and popover
            gtkpla = join(self.functions.datadir, 'glade', 'playerbar.ui')
            win = gtk_builder()
            win.set_translation_domain('bluemindo')
            win.add_from_file(gtkpla)
            basebox = win.get_object('playerbox')
            wdg[0][0].add(basebox)

            self.player_event = win.get_object('player_event')
            self.player_event.set_size_request(32, 32)
            self.player_button_img = win.get_object('image_cover')
            self.player_event.connect('button-press-event', self.show_player)
            default = join(self.functions.datadir, 'image', 'logo_head_big.png')
            cover_px = Pixbuf.new_from_file_at_scale(default, 20, 20, True)
            self.player_button_img.set_from_pixbuf(cover_px)
            self.player_event.set_sensitive(False)

            self.player_scalab = win.get_object('label_scale')
            self.player_scalab.set_markup('<span size="small">00:00</span>')
            self.player_sca = win.get_object('scale')
            self.player_sca.connect('change-value', self.on_change_value)
            self.player_sca.set_sensitive(False)

            # Create the player popover
            gtkpla = join(self.functions.datadir, 'glade', 'playerpopover.ui')
            win = gtk_builder()
            win.add_from_file(gtkpla)
            hbox = win.get_object('box-player')

            self.player_img = win.get_object('image')
            self.player_pop = Popover.new(self.player_event)
            self.player_pop.set_size_request(200, 200)
            self.player_pop.add(hbox)

            self.lyrics_button = wdg[1].get_object('tool-lyrics')
            self.lyrics_pop = Popover.new(self.lyrics_button)
            self.lyrics_pop.set_size_request(400, 600)
            box = Box(1, 0)
            self.lyrics_swin = ScrolledWindow()
            lyrics_tview = TextView()
            lyrics_tview.set_editable(False)
            self.lyrics_buffer = TextBuffer()
            lyrics_tview.set_buffer(self.lyrics_buffer)
            self.lyrics_swin.add(lyrics_tview)
            box.add(self.lyrics_swin)
            self.lyrics_wait = Spinner()
            self.lyrics_wait.props.active = True
            box.add(self.lyrics_wait)
            self.lyrics_pop.add(box)

            def show_lyrics(widget):
                if self.current_song:
                    title = self.current_song.title
                    artist = self.current_song.artist
                    album = self.current_song.album
                    filename = self.current_song.filename

                    sn = self.functions.get_hash(title, artist)
                    lyrics_file = join(self.userconf.datadir, '%s.lyrics' % sn)

                    lyrics = self.lyrics_downloader.get_lyrics(title,
                                                               artist,
                                                               True)

                    self.lyrics_pop.show_all()

                    if lyrics is not None:
                        self.lyrics_wait.hide()
                        self.lyrics_swin.show()
                        self.lyrics_buffer.set_text(lyrics)
                    else:
                        self.lyrics_swin.hide()
                        self.lyrics_wait.show()
                        self.lyrics_buffer.set_text('')

            self.lyrics_button.connect('clicked', show_lyrics)
            self.lyrics_button.set_sensitive(False)
Esempio n. 10
0
    def _setSentenceRelated(self) -> None:
        """
        Sets up the sentence editing widgets related.
        Also initialize both text buffers.

        :return:
        """

        box: Box = Box()

        self._main_box.pack_start(box, False, True, 0)

        box.set_orientation(Orientation.VERTICAL)

        setMargin(box, 5)

        toolbar: Toolbar = Toolbar()

        box.pack_start(toolbar, False, True, 0)

        toolbar.set_halign(Align.END)
        setMargin(toolbar, 5)

        lbl: Label = Label()
        lbl.set_markup('<i><b>Front</b></i>')

        box.pack_start(lbl, False, True, 0)

        lbl.set_halign(Align.START)
        setMargin(lbl, 5)

        scrl_wnd: ScrolledWindow = ScrolledWindow()
        scrl_wnd.set_hexpand(True)
        scrl_wnd.set_vexpand(True)

        textview: TextView = TextView()
        scrl_wnd.add(textview)

        box.pack_start(scrl_wnd, False, True, 0)

        self._textbuffer_front = textview.get_buffer()

        lbl2: Label = Label()
        lbl2.set_halign(Align.START)
        lbl2.set_markup('<i><b>Back</b></i>')

        box.pack_start(lbl2, False, True, 0)
        setMargin(lbl2, 5)

        scrl_wnd2: ScrolledWindow = ScrolledWindow()
        scrl_wnd2.set_hexpand(True)
        scrl_wnd2.set_vexpand(True)

        textview2: TextView = TextView()
        scrl_wnd2.add(textview2)

        box.pack_end(scrl_wnd2, False, True, 0)

        self._textbuffer_back = textview2.get_buffer()

        # this depends on the text buffer to be initialized
        self._setToolbarColorButton(toolbar)

        toolbar.insert(SeparatorToolItem(), 3)

        self._setToolbarUnderlineButton(toolbar)
        self._setToolbarBoldButton(toolbar)
        self._setToolbarItalicButton(toolbar)

        toolbar.insert(SeparatorToolItem(), 7)

        self._setToolbarTagRemoverButton(toolbar)