Skip to content

Commit

Permalink
added tooltip for characters
Browse files Browse the repository at this point in the history
  • Loading branch information
Nokse22 committed May 14, 2024
1 parent c221383 commit 1c1f75a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/ascii-draw.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<file preprocess="xml-stripblanks">ui/window.ui</file>
<file preprocess="xml-stripblanks">ui/new_palette.ui</file>
<file preprocess="xml-stripblanks">ui/canvas.ui</file>
<file preprocess="xml-stripblanks">ui/unicode_tooltip.ui</file>
<file preprocess="xml-stripblanks">icons/16x16/actions/eraser-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/16x16/actions/paintbrush-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/16x16/actions/text-symbolic.svg</file>
Expand Down
39 changes: 39 additions & 0 deletions data/ui/unicode_tooltip.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version='1.0' encoding='UTF-8'?>
<!-- Created with Cambalache 0.90.2 -->
<interface>
<!-- interface-name tooltip.ui -->
<requires lib="gtk" version="4.12"/>
<object class="GtkBox" id="main_box">
<property name="halign">start</property>
<property name="orientation">vertical</property>
<property name="valign">start</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox">
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="char_label">
<property name="css-classes">title-4</property>
<property name="hexpand">True</property>
<property name="xalign">0.0</property>
</object>
</child>
<child>
<object class="GtkLabel" id="unicode_label">
<property name="css-classes">title-4</property>
<property name="hexpand">True</property>
<property name="xalign">1.0</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkLabel" id="char_name_label">
<property name="lines">1</property>
<property name="max-width-chars">20</property>
<property name="wrap">True</property>
<property name="xalign">0.0</property>
</object>
</child>
</object>
</interface>
20 changes: 20 additions & 0 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import unicodedata
import emoji
import os
import unicodedata

@Gtk.Template(resource_path='/io/github/nokse22/asciidraw/ui/window.ui')
class AsciiDrawWindow(Adw.ApplicationWindow):
Expand Down Expand Up @@ -320,6 +321,9 @@ def add_palette_to_ui(self, palette):
for char in palette.chars:
new_button = Gtk.Button(label=char, css_classes=["flat", "ascii"])
new_button.connect("clicked", self.change_char, flow_box)
# new_button.set_tooltip_text(f"{char} : {unicodedata.name(char).title()}")
new_button.set_has_tooltip(True)
new_button.connect("query-tooltip", self.on_show_char_tooltip, char)
flow_box.append(new_button)
scrolled_window = Gtk.ScrolledWindow(name=palette.name, hexpand=True, vexpand=True)
scrolled_window.set_child(flow_box)
Expand All @@ -329,6 +333,22 @@ def add_palette_to_ui(self, palette):
if pos != self.chars_carousel.get_n_pages() - 1:
self.char_carousel_go_next.set_sensitive(True)

def on_show_char_tooltip(self, btn, x, y, keyboard, tooltip, _char):
builder = Gtk.Builder.new_from_resource("/io/github/nokse22/asciidraw/ui/unicode_tooltip.ui")

main_box = builder.get_object("main_box")
char_label = builder.get_object("char_label")
unicode_label = builder.get_object("unicode_label")
char_name_label = builder.get_object("char_name_label")

char_label.set_label(_char)
unicode_label.set_label(f"U+{hex(ord(_char))[2:].upper()}")
char_name_label.set_label(unicodedata.name(_char).title())

tooltip.set_custom(main_box)

return True

def save_new_palette(self, palette):
with open(f"{self.data_dir}/palettes/{palette.name}.txt", 'w') as file:
file.write(palette.chars)
Expand Down

0 comments on commit 1c1f75a

Please sign in to comment.