Skip to content

Commit

Permalink
- Fix images
Browse files Browse the repository at this point in the history
- Add url image scale support (experimental)
- Removed `scale_support` flag from config file
- Code cleanup
  • Loading branch information
Wemmy0 committed Feb 2, 2024
1 parent d79614b commit ecf2ff9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 30 deletions.
34 changes: 15 additions & 19 deletions src/ImageInsert.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@


class ImageDialogue(Gtk.Window):
def __init__(self, url_source, file_source, wikimedia_source, web_source, cache_support, scale_support):
def __init__(self, url_source, file_source, wikimedia_source, web_source, cache_support):
super().__init__()
self.cache_support = cache_support
self.scale_support = scale_support
self.set_title("Insert Image")

self.page = Adw.PreferencesPage()
Expand Down Expand Up @@ -80,17 +79,16 @@ def __init__(self, url_source, file_source, wikimedia_source, web_source, cache_
# endregion

# region Scale slider
# TODO: Actually do this
if self.scale_support:
self.scale_row = Adw.ActionRow(visible=False)
self.scale_slider = Gtk.Scale(round_digits=1)
self.scale_slider.set_range(0, 10)
for i in range(1, 10):
self.scale_slider.add_mark(i, Gtk.PositionType.BOTTOM)
# self.scale_slider.add_mark(1, Gtk.PositionType.BOTTOM)
# # self.scale_slider = Gtk.Range()
# self.scale_row.add_suffix(self.scale_slider)
self.group.add(self.scale_slider)
self.scale_row = Adw.ActionRow(visible=False)
self.scale_slider = Gtk.Scale(round_digits=1)
self.scale_slider.set_range(0, 1.5)
self.scale_slider.set_digits(True)
for i in range(0, 15):
self.scale_slider.add_mark(i/10, Gtk.PositionType.BOTTOM)
# self.scale_slider.add_mark(1, Gtk.PositionType.BOTTOM)
# # self.scale_slider = Gtk.Range()
# self.scale_row.add_suffix(self.scale_slider)
self.group.add(self.scale_slider)

# region Tooltip
self.tooltip_row = Adw.ActionRow(title="Description",
Expand Down Expand Up @@ -127,8 +125,7 @@ def change_source(self, text):
self.file_row.hide()
self.wikipedia_row.hide()
self.web_embed_row.hide()
if self.scale_support:
self.scale_slider.hide()
self.scale_slider.hide()
if self.cache_support:
self.cache_image_row.hide()
self.tooltip_row.show()
Expand All @@ -137,7 +134,6 @@ def change_source(self, text):
self.url_row.show()
if self.cache_support:
self.cache_image_row.show()
if self.scale_support:
self.scale_slider.show()
case "Local File":
self.file_row.show()
Expand Down Expand Up @@ -165,13 +161,13 @@ def get_values(self):
file = self.file_entry.get_text()
tooltip = self.tooltip_entry.get_text()
scale = self.scale_slider.get_value()
cache = self.cache_image_switch.get_state()
# cache = self.cache_image_switch.get_state()
sources = {"URL": "url", "Local File": "file", "Wikipedia": "wikimedia"}
data = {"type": "image" if source_dropdown != "Web Embed" else "iframe",
"source": sources[source_dropdown],
"url": url,
"file": file,
"scale": scale,
"tooltip": tooltip,
"cache": cache}
"tooltip": tooltip}
# "cache": cache}
return data
15 changes: 8 additions & 7 deletions src/NoteView.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ class Image(Gtk.Box):
def __init__(self, data, read_only):
super().__init__()
if data["source"] == "url":
print(f"Has scale {data['scale']}")
self.data = data
self.main = Gtk.Spinner(hexpand=True)
self.append(self.main)
Expand All @@ -307,15 +306,17 @@ def get_image_from_url(self):
loader.close()
self.remove(self.main)
self.main = Gtk.Image.new_from_pixbuf(loader.get_pixbuf())
self.main.set_size_request((loader.get_pixbuf().get_width() / self.data["scale"]).__floor__(),
(loader.get_pixbuf().get_height() / self.data["scale"]).__floor__())
# self.main.set_hexpand(True)
# self.main.set_vexpand(True)
except requests.exceptions.ConnectionError:
self.main.set_size_request((loader.get_pixbuf().get_width() * self.data["scale"]).__floor__(),
(loader.get_pixbuf().get_height() * self.data["scale"]).__floor__())
self.main.set_vexpand(True)
except (requests.exceptions.ConnectionError, requests.exceptions.MissingSchema) as err:
self.remove(self.main)
self.main = Gtk.Box(orientation=Gtk.Orientation.VERTICAL,
hexpand=True)
self.main.append(Gtk.Image(icon_name="auth-sim-missing-symbolic"))
self.main.append(Gtk.Label(label="Unable to get image"))
self.main.append(Gtk.Label(label="Unable to get image" + (" - No internet connection"
if isinstance(err, requests.exceptions.ConnectionError)
else " - Invalid URL")))
self.append(self.main)

def save(self):
Expand Down
2 changes: 1 addition & 1 deletion src/Queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __iter__(self):
return self._data

def en_queue(self, item):
if not self.size == len(self._data):
if self.size != len(self._data):
self._data.append(item)
else:
raise self.FullQueue
Expand Down
3 changes: 1 addition & 2 deletions src/configuration-default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ url_source = true
file_source = true
wikimedia_source = false # Not implamented yet
web_source = false # Not implamented yet
cache_support = false
scale_support = false
cache_support = false
2 changes: 1 addition & 1 deletion src/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def new_image_dialogue(self, *args):
log("Opening image dialogue")
sources = self.config["image-configuration"]
dialogue = ImageDialogue(sources["url_source"], sources["file_source"], sources["wikimedia_source"],
sources["web_source"], sources["cache_support"], sources["scale_support"])
sources["web_source"], sources["cache_support"])
dialogue.present()
self.inserting_image = True

Expand Down

0 comments on commit ecf2ff9

Please sign in to comment.