Skip to content

Commit

Permalink
fixed various bugs with preview
Browse files Browse the repository at this point in the history
  • Loading branch information
Nokse22 committed Jan 20, 2024
1 parent 81ebf79 commit b2fd183
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 69 deletions.
1 change: 1 addition & 0 deletions src/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ def set_content(self, content):
self.change_canvas_size(max(max_chars, 10), max(num_lines - 1, 5))
self.clear_preview()
self.__draw_text(0, 0, content, False, False, self.drawing)
self.update()

def top_horizontal(self):
return self.styles[self._style - 1][0]
Expand Down
20 changes: 10 additions & 10 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,28 +196,28 @@ def create_action(self, name, callback, shortcuts=None):
self.set_accels_for_action(f"app.{name}", shortcuts)

def on_shutdown(self, *args):
dialog = Gtk.MessageDialog(
# heading=_("Save Changes"),
# body="A valid password is needed to continue",
# close_response="cancel",
dialog = Adw.MessageDialog(
heading=_("Save Changes"),
body="A valid password is needed to continue",
close_response="cancel",
modal=True,
transient_for=self.win,
)

# dialog.add_response("cancel", _("Cancel"))
# dialog.add_response("discard", _("Discard"))
# dialog.add_response("save", _("Save"))
dialog.add_response("cancel", _("Cancel"))
dialog.add_response("discard", _("Discard"))
dialog.add_response("save", _("Save"))

# dialog.set_response_appearance("discard", Adw.ResponseAppearance.DESTRUCTIVE)
# dialog.set_response_appearance("save", Adw.ResponseAppearance.SUGGESTED)
dialog.set_response_appearance("discard", Adw.ResponseAppearance.DESTRUCTIVE)
dialog.set_response_appearance("save", Adw.ResponseAppearance.SUGGESTED)

# entry = Gtk.Entry()
# dialog.set_extra_child(entry)

# dialog.choose(None, self.on_response_selected_advanced)
# dialog.choose_finish(task)

dialog.run()
# dialog.run()

print(quit)

Expand Down
2 changes: 0 additions & 2 deletions src/new_palette_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ def __init__(self, window, palette_chars=''):

self.palette_chars_buffer.set_text(self.palette_chars)

print(f"chars: {self.palette_chars}")

@Gtk.Template.Callback("on_add_clicked")
def on_add_clicked(self, btn):
palette_name = self.palette_name_entry.get_text()
Expand Down
2 changes: 0 additions & 2 deletions src/tools/picker.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ def on_click_pressed(self, click, arg, x, y):
char = self.canvas.get_char_at(x_char, y_char)
self.canvas.set_selected_char(char)

print(char)

def on_click_stopped(self, click):
if not self._active: return
pass
Expand Down
4 changes: 0 additions & 4 deletions src/tools/select.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def on_drag_begin(self, gesture, this_x, this_y):
start_y_char + self.dragging_delta_char_y + 1, self.moved_text, True, False)
self.canvas.update()
else:
print("new selection")
self.selection_start_x_char = this_x // self.x_mul
self.selection_start_y_char = this_y // self.y_mul

Expand Down Expand Up @@ -176,19 +175,16 @@ def on_drag_end(self, gesture, delta_x, delta_y):

def on_click_pressed(self, click, arg, x, y):
if not self._active: return
print("pressed")

self.click_released = False

def on_click_released(self, click, arg, x, y):
if not self._active: return
print("released")

self.click_released = True

def on_click_stopped(self, click):
if not self._active: return
print(f"stopped {self.click_released}")

if not self.click_released:
return
Expand Down
9 changes: 5 additions & 4 deletions src/tools/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def table_type(self, value):
self._table_type = value
self.notify('table_type')

self.preview_table()
self.preview()

def on_click_pressed(self, click, arg, x, y):
if not self._active: return
Expand All @@ -101,14 +101,15 @@ def on_click_released(self, click, arg, x, y):
self.table_x = x_char
self.table_y = y_char
self.canvas.clear_preview()
self.preview_table()
self.preview()

def insert_table(self):
def insert(self):
self.canvas.add_undo_action(_("Table"))
self.draw_table(self._table_type, True)
self.canvas.update()

def preview_table(self):
def preview(self):
if not self._active: return
self.canvas.clear_preview()
self.draw_table(self._table_type, False)
self.canvas.update_preview()
Expand Down
13 changes: 6 additions & 7 deletions src/tools/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def on_drag_follow(self, gesture, x, y):
self.drag_y = y_char

self.canvas.clear_preview()
self.preview_tree()
self.preview()

def on_drag_end(self, gesture, delta_x, delta_y):
if not self._active: return
Expand All @@ -130,7 +130,7 @@ def on_click_pressed(self, click, arg, x, y):
self.tree_y = y_char

self.canvas.clear_preview()
self.preview_tree()
self.preview()

def on_click_stopped(self, click):
if not self._active: return
Expand All @@ -140,12 +140,14 @@ def on_click_released(self, click, arg, x, y):
if not self._active: return
pass

def preview_tree(self):
def preview(self):
if not self._active: return
self.canvas.clear_preview()
self.draw_tree(self.tree_x + self.drag_x, self.tree_y + self.drag_y, False)
self.canvas.update_preview()

def insert_tree(self):
def insert(self):
self.canvas.add_undo_action(_("Tree"))
self.canvas.clear_preview()
self.draw_tree(self.tree_x, self.tree_y, True)
self.canvas.update()
Expand All @@ -156,9 +158,7 @@ def draw_tree(self, start_x, start_y, draw):
current_indent = 0
leading_spaces = []
indent_level = 0
# print("------tree------")
for index, line in enumerate(lines):
# print("------line------")
stripped_line = line.lstrip(' ') # Remove leading underscores
indent_space = len(line) - len(stripped_line)
line_number = len(leading_spaces)
Expand All @@ -181,7 +181,6 @@ def draw_tree(self, start_x, start_y, draw):
indent_level -= 1
previos_spaces = leading_spaces[i]
elif leading_spaces[i] > previos_spaces:
# print(f"the indent is {processed_lines[i - line_number][0]} was {indent_level}")
indent_level = processed_lines[i - line_number][0]
previos_spaces = leading_spaces[i]
current_indent = indent_level
Expand Down
Loading

0 comments on commit b2fd183

Please sign in to comment.