Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 54 additions & 33 deletions data/ui/Drawing.ui
Original file line number Diff line number Diff line change
@@ -1,56 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkImage" id="icon_download">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">document-save-as-symbolic</property>
<property name="can-focus">False</property>
<property name="icon-name">document-save-as-symbolic</property>
</object>
<object class="GtkImage" id="icon_remove">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">edit-delete-symbolic</property>
<property name="can-focus">False</property>
<property name="icon-name">edit-delete-symbolic</property>
</object>
<object class="GtkImage" id="icon_split">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="icon-name">edit-cut-symbolic</property>
</object>
<object class="GtkImage" id="image_rotate_left">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">object-rotate-left-symbolic</property>
<property name="can-focus">False</property>
<property name="icon-name">object-rotate-left-symbolic</property>
</object>
<object class="GtkImage" id="image_rotate_right">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">object-rotate-right-symbolic</property>
<property name="can-focus">False</property>
<property name="icon-name">object-rotate-right-symbolic</property>
</object>
<template class="Drawing" parent="GtkEventBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<signal name="enter-notify-event" handler="_on_enter" swapped="no"/>
<signal name="leave-notify-event" handler="_on_leave" swapped="no"/>
<child>
<object class="GtkBox" id="box_drawing">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">20</property>
<property name="margin_right">20</property>
<property name="can-focus">False</property>
<property name="margin-left">20</property>
<property name="margin-right">20</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox" id="box_toolbar">
<property name="height_request">20</property>
<property name="height-request">20</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="valign">start</property>
<property name="margin_left">10</property>
<property name="margin_right">10</property>
<property name="margin_top">10</property>
<property name="margin_bottom">10</property>
<property name="margin-left">10</property>
<property name="margin-right">10</property>
<property name="margin-top">10</property>
<property name="margin-bottom">10</property>
<property name="hexpand">True</property>
<child>
<object class="GtkButton" id="btn_rotate_left">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">image_rotate_left</property>
<signal name="clicked" handler="_on_rotate_button_clicked" swapped="no"/>
</object>
Expand All @@ -63,8 +68,8 @@
<child>
<object class="GtkButton" id="btn_rotate_right">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">image_rotate_right</property>
<signal name="clicked" handler="_on_rotate_button_clicked" swapped="no"/>
</object>
Expand All @@ -77,8 +82,8 @@
<child>
<object class="GtkButton" id="btn_download">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="halign">center</property>
<property name="image">icon_download</property>
<signal name="clicked" handler="_on_download_button_clicked" swapped="no"/>
Expand All @@ -89,25 +94,41 @@
<property name="position">3</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn_split">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="tooltip-text" translatable="yes">Split the drawing</property>
<property name="halign">center</property>
<property name="image">icon_split</property>
<signal name="clicked" handler="_on_split_button_clicked" swapped="no"/>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">4</property>
</packing>
</child>
<child>
<object class="GtkSeparator">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">10</property>
<property name="margin_right">10</property>
<property name="can-focus">False</property>
<property name="margin-left">10</property>
<property name="margin-right">10</property>
<property name="orientation">vertical</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">4</property>
<property name="position">5</property>
</packing>
</child>
<child>
<object class="GtkButton" id="btn_remove">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="image">icon_remove</property>
<signal name="clicked" handler="_on_delete_button_clicked" swapped="no"/>
</object>
Expand All @@ -127,10 +148,10 @@
<child>
<object class="GtkImage" id="image_svg">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="margin_bottom">10</property>
<property name="margin-bottom">10</property>
<property name="stock">gtk-missing-image</property>
<style>
<class name="bg-paper"/>
Expand Down
91 changes: 91 additions & 0 deletions data/ui/Splitter.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkAdjustment" id="split_adjustment">
<property name="lower">1</property>
<property name="upper">100</property>
<property name="step-increment">1</property>
<property name="page-increment">10</property>
</object>
<template class="Splitter" parent="GtkDialog">
<property name="width-request">500</property>
<property name="height-request">500</property>
<property name="can-focus">False</property>
<property name="title" translatable="yes">Splitter</property>
<property name="type-hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox">
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">2</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
<property name="can-focus">False</property>
<property name="layout-style">end</property>
<child>
<object class="GtkButton" id="cancel_button">
<property name="label" translatable="yes">Cancel</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="_on_cancel" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="ok_button">
<property name="label" translatable="yes">OK</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<signal name="clicked" handler="_on_ok" swapped="no"/>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkScale" id="scale">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="adjustment">split_adjustment</property>
<property name="digits">0</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack-type">end</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkDrawingArea" id="drawing_area">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
</child>
</template>
</interface>
3 changes: 3 additions & 0 deletions tuhi/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from gi.repository import GObject
import svgwrite
import os
from svgwrite import mm
import cairo

Expand Down Expand Up @@ -83,6 +84,8 @@ class JsonSvg(ImageExportBase):
_pen_pressure_width_factor = 0.2

def _convert(self):
if os.path.isfile(self.filename):
return

width, height = self.output_dimensions
size = width * mm, height * mm
Expand Down
25 changes: 25 additions & 0 deletions tuhi/gui/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,31 @@ def add_drawing(self, timestamp, json_string):
self._drawings.append(json.loads(json_string))
self.notify('drawings')

def replace_drawing(self, timestamp, json_string):
'''Replace the drawing JSON identified by the timestamp in the backend
storage. This will update self.drawings.'''
self.base_path.mkdir(parents=True, exist_ok=True)

path = Path(self.base_path, f'{timestamp}.json')
if not path.exists():
return

replaced_drawing = list(filter(lambda d: d["timestamp"] == timestamp,
self._drawings))

if len(replaced_drawing) <= 0:
return
else:
replaced_drawing = replaced_drawing[0]

with open(path, 'w') as fd:
fd.write(json_string)

self._drawings.remove(replaced_drawing)
self._drawings.append(json.loads(json_string))
self.notify('drawings')


def delete_drawing(self, timestamp):
# We don't delete json files immediately, we just rename them
# so we can resurrect them in the future if need be.
Expand Down
38 changes: 38 additions & 0 deletions tuhi/gui/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@

import xdg.BaseDirectory
import os
import json
from pathlib import Path
from .config import Config
from .splitter import Splitter
from tuhi.export import JsonSvg, JsonPng

import gi
Expand Down Expand Up @@ -158,6 +160,42 @@ def _on_download_button_clicked(self, button):

dialog.destroy()

@Gtk.Template.Callback('_on_split_button_clicked')
def _on_split_button_clicked(self, button):
dialog = Splitter(self)
response = dialog.run()

if response == Gtk.ResponseType.OK:
self._save_split_drawings(*dialog.split_drawings)

dialog.destroy()

def _save_split_drawings(self, json1, json2):
timestamp1 = json1["timestamp"]
timestamp2 = json1["timestamp"]

if timestamp2 in map(lambda d: d["timestamp"], Config().drawings):
error_dialog = Gtk.MessageDialog(
flags=0,
message_type=Gtk.MessageType.ERROR,
buttons=Gtk.ButtonsType.OK,
text="Error while splitting drawing"
)
error_dialog.format_secondary_text(
f"A drawing with timestamp {timestamp2} already exists. Cannot proceed to save split drawing, otherwise data loss might occur"
)
error_dialog.run()
error_dialog.destroy()
return

Config().replace_drawing(timestamp1, json.dumps(json1))
Config().add_drawing(timestamp2, json.dumps(json2))

# Force redraw of this drawing
os.remove(self.svg.filename)
self.process_svg()
self.redraw()

@Gtk.Template.Callback('_on_delete_button_clicked')
def _on_delete_button_clicked(self, button):
Config().delete_drawing(self.timestamp)
Expand Down
Loading