Daniel Brötzmann pushed to branch mainwindow at gajim / gajim
Commits: 7f5ec638 by wurstsalat at 2021-11-07T11:39:00+01:00 Conversation: Use Gtk.TextView on Windows, else Gtk.Label
- - - - - ddee44c7 by wurstsalat at 2021-11-07T12:06:20+01:00 PlainWidget: Typing
- - - - - e7600d06 by wurstsalat at 2021-11-07T12:06:24+01:00 Add GtkSource4 dependency
- - - - - d8cab9ad by wurstsalat at 2021-11-07T12:30:21+01:00 GroupchatControl: Improve Kick/Ban
- - - - -
5 changed files:
- README.md - gajim/gajim.py - gajim/gtk/controls/groupchat.py - gajim/gtk/conversation/plain_widget.py - win/_base.sh
Changes:
===================================== README.md ===================================== @@ -1,12 +1,12 @@ # Welcome to Gajim
- ### Runtime Requirements
- python3.9 or higher - python3-gi - python3-gi-cairo - gir1.2-gtk-3.0 (>=3.22) +- gir1.2-gtksource-4 - python3-nbxmpp (>=2.99.0) - python3-openssl (>=16.2) - python3-css-parser @@ -35,7 +35,6 @@ ### Compile-time Requirements - python3-setuptools - gettext
- ### Installation Procedure
#### Packages @@ -86,15 +85,12 @@ #### Links - [FAQ](https://dev.gajim.org/gajim/gajim/wikis/help/gajimfaq) - [Wiki](https://dev.gajim.org/gajim/gajim/wikis/home)
- - That is all, **enjoy**!
(C) 2003-2021 The Gajim Team [https://gajim.org%5D(https://gajim.org)
- We use original art and parts of sounds and other art from Psi, Gossip, Gnomebaker, Gaim and some icons from various gnome-icons (mostly Dropline Etiquette) we found at art.gnome.org. If you think we're violating a license please inform us. Thank you.
===================================== gajim/gajim.py ===================================== @@ -58,6 +58,7 @@ def _check_required_deps(): gi.require_versions({'GLib': '2.0', 'Gio': '2.0', 'Gtk': '3.0', + 'GtkSource': '4', 'GObject': '2.0', 'Pango': '1.0', 'Soup': '2.4'})
===================================== gajim/gtk/controls/groupchat.py ===================================== @@ -570,16 +570,19 @@ def _on_contact_information(self, _action, param): def _on_kick(self, _action, param): nick = param.get_string() self._kick_nick = nick - self.xml.kick_label.set_text(_('Kick %s') % nick) + text = _('Kick %s') % nick + self.xml.kick_label.set_text(text) + self.xml.kick_label.set_tooltip_text(text) self.xml.kick_reason_entry.grab_focus() self.xml.kick_participant_button.grab_default() self._show_page('kick')
def _on_ban(self, _action, param): jid = param.get_string() - contact = self._client.get_module('Contacts').get_contact(jid) self._ban_jid = jid - self.xml.ban_label.set_text(_('Ban %s') % contact.name) + text = _('Ban %s') % jid + self.xml.ban_label.set_text(text) + self.xml.ban_label.set_tooltip_text(text) self.xml.ban_reason_entry.grab_focus() self.xml.ban_participant_button.grab_default() self._show_page('ban')
===================================== gajim/gtk/conversation/plain_widget.py ===================================== @@ -12,7 +12,11 @@ # You should have received a copy of the GNU General Public License # along with Gajim. If not, see http://www.gnu.org/licenses/.
+from typing import Any +from typing import Dict + import logging +import os
from gi.repository import Gtk from gi.repository import Pango @@ -24,6 +28,8 @@ from gajim.common.helpers import open_uri from gajim.common.helpers import reduce_chars_newlines from gajim.common.helpers import parse_uri +from gajim.common.structs import URI +from gajim.common.styling import PlainBlock
from gajim.gui_menu_builder import get_conv_action_context_menu from gajim.gui_menu_builder import get_conv_uri_context_menu @@ -38,26 +44,30 @@
class PlainWidget(Gtk.Box): - def __init__(self, account, selectable): + def __init__(self, account: str, selectable: bool) -> None: Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL) self.set_vexpand(True)
self._account = account
- # TODO: Window/Linux handling - # self._text_widget = MessageTextview(self._account) - self._text_widget = MessageLabel(self._account, selectable) + # We use a Gtk.Textview on Windows, since there is no support for + # rendering color fonts (Emojis) on Windows yet, see: + # https://gitlab.freedesktop.org/cairo/cairo/-/merge_requests/244 + if os.name == 'nt': + self._text_widget = MessageTextview(self._account) + else: + self._text_widget = MessageLabel(self._account, selectable) self.add(self._text_widget)
- def add_content(self, block): + def add_content(self, block: PlainBlock) -> None: self._text_widget.print_text_with_styling(block)
- def update_text_tags(self): + def update_text_tags(self) -> None: self._text_widget.update_text_tags()
class MessageLabel(Gtk.Label): - def __init__(self, account, selectable): + def __init__(self, account: str, selectable: bool) -> None: Gtk.Label.__init__(self) self.set_hexpand(True) self.set_selectable(selectable) @@ -72,7 +82,7 @@ def __init__(self, account, selectable):
self.connect('populate-popup', self._on_populate_popup)
- def _on_populate_popup(self, label, menu): + def _on_populate_popup(self, label: Gtk.Label, menu: Gtk.Menu) -> None: selected, start, end = label.get_selection_bounds() if not selected: menu.show_all() @@ -84,7 +94,7 @@ def _on_populate_popup(self, label, menu): menu.prepend(action_menu_item) menu.show_all()
- def print_text_with_styling(self, block): + def print_text_with_styling(self, block: PlainBlock) -> None: text = GLib.markup_escape_text(block.text.strip()) for uri in block.uris: text = text.replace(uri.text, uri.get_markup_string()) @@ -97,12 +107,12 @@ def print_text_with_styling(self, block): self.set_markup(text) self.set_attributes(attr_list)
- def update_text_tags(self): + def update_text_tags(self) -> None: pass
class MessageTextview(Gtk.TextView): - def __init__(self, account): + def __init__(self, account: str) -> None: Gtk.TextView.__init__(self) self.set_hexpand(True) self.set_margin_start(0) @@ -115,7 +125,7 @@ def __init__(self, account): self.set_cursor_visible(False) self.set_wrap_mode(Gtk.WrapMode.WORD_CHAR)
- self._handlers = {} + self._handlers: Dict[str, MessageTextview] = {}
id_ = self.connect('query-tooltip', self._query_tooltip) self._handlers[id_] = self @@ -127,10 +137,10 @@ def __init__(self, account): self._account = account
# Used for changing the mouse pointer when hovering clickable URIs - self._cursor_changed = False + self._cursor_changed: bool = False
# Keeps text selections for quoting and search actions - self._selected_text = '' + self._selected_text: str = ''
self.get_style_context().add_class('gajim-conversation-text')
@@ -149,7 +159,7 @@ def _on_destroy(self, *args): widget.disconnect(id_) self._handlers.clear()
- def _create_url_tags(self): + def _create_url_tags(self) -> None: color = app.css_config.get_value('.gajim-url', StyleAttr.COLOR) for name in URI_TAGS: tag = self.get_buffer().create_tag(name, @@ -157,23 +167,23 @@ def _create_url_tags(self): underline=Pango.Underline.SINGLE) tag.connect('event', self._on_uri_clicked, tag)
- def update_text_tags(self): + def update_text_tags(self) -> None: tag_table = self.get_buffer().get_tag_table() url_color = app.css_config.get_value('.gajim-url', StyleAttr.COLOR) for tag in URI_TAGS: tag_table.lookup(tag).set_property('foreground', url_color)
- def clear(self): + def clear(self) -> None: buffer_ = self.get_buffer() start, end = buffer_.get_bounds() buffer_.delete(start, end)
- def get_text(self): + def get_text(self) -> str: buffer_ = self.get_buffer() start, end = buffer_.get_bounds() return buffer_.get_text(start, end, False)
- def print_text_with_styling(self, block): + def print_text_with_styling(self, block: PlainBlock) -> None: buffer_ = self.get_buffer() buffer_.insert(buffer_.get_start_iter(), block.text.strip())
@@ -187,7 +197,8 @@ def print_text_with_styling(self, block): end_iter = buffer_.get_iter_at_offset(uri.end) buffer_.apply_tag_by_name(uri.name, start_iter, end_iter)
- def _query_tooltip(self, widget, x_pos, y_pos, _keyboard_mode, tooltip): + def _query_tooltip(self, widget: Any, x_pos: int, y_pos: int, + _keyboard_mode: bool, tooltip: Gtk.Tooltip) -> bool: window = widget.get_window(Gtk.TextWindowType.TEXT) x_pos, y_pos = self.window_to_buffer_coords( Gtk.TextWindowType.TEXT, x_pos, y_pos) @@ -214,7 +225,7 @@ def _query_tooltip(self, widget, x_pos, y_pos, _keyboard_mode, tooltip): self._cursor_changed = False return False
- def _on_button_press(self, _widget, event): + def _on_button_press(self, _widget: Any, event: Gdk.EventButton) -> bool: ''' We don’t open the standard context menu when receiving a click on tagged text. @@ -263,7 +274,8 @@ def _on_button_press(self, _widget, event): start_sel, finish_sel, True) return False
- def _on_populate_popup(self, _textview, menu): + def _on_populate_popup(self, _textview: Gtk.TextView, + menu: Gtk.Menu) -> None: ''' Overrides the default context menu. If text is selected, a submenu with actions on the selection is added. @@ -278,7 +290,9 @@ def _on_populate_popup(self, _textview, menu): menu.prepend(action_menu_item) menu.show_all()
- def _on_uri_clicked(self, texttag, _widget, event, iter_, _kind): + def _on_uri_clicked(self, texttag: Gtk.TextTag, _widget: Any, + event: Gdk.Event, iter_: Gtk.TextIter, + _kind: Gtk.TextTag) -> int: if event.type != Gdk.EventType.BUTTON_PRESS: return Gdk.EVENT_PROPAGATE
@@ -311,7 +325,7 @@ def _on_uri_clicked(self, texttag, _widget, event, iter_, _kind): open_uri(uri, account=self._account) return Gdk.EVENT_STOP
- def _show_uri_context_menu(self, uri): + def _show_uri_context_menu(self, uri: URI) -> None: menu = get_conv_uri_context_menu(self._account, uri) if menu is None: log.warning('No handler for URI type: %s', uri)
===================================== win/_base.sh ===================================== @@ -78,6 +78,7 @@ function create_root { function install_deps { build_pacman --noconfirm -S mingw-w64-"${ARCH}"-python \ mingw-w64-"${ARCH}"-python-gobject \ + mingw-w64-"${ARCH}"-gtksourceview4 \ mingw-w64-"${ARCH}"-python-pip \ mingw-w64-"${ARCH}"-adwaita-icon-theme \ mingw-w64-"${ARCH}"-libwebp \
View it on GitLab: https://dev.gajim.org/gajim/gajim/-/compare/06d18602f593edabe24317447742d4a6...