Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…dd destroy jobject and objectchooser, and show message if image load unsuccessful
  • Loading branch information
srevinsaju committed Dec 20, 2019
1 parent 7b05bf8 commit cfd961a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
19 changes: 10 additions & 9 deletions activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,17 @@ def open_image(self, button):
def choose_image_from_journal_cb(self):
''' Create a chooser for image objects '''
self.image_id = None
chooser = ObjectChooser(what_filter=mime.GENERIC_TYPE_IMAGE)
result = chooser.run()
self.chooser = ObjectChooser(what_filter=mime.GENERIC_TYPE_IMAGE)
result = self.chooser.run()
if result == Gtk.ResponseType.ACCEPT:
jobject = chooser.get_selected_object()
self.image_id = str(jobject._object_id)
self.image_file_path = str(jobject.get_file_path())
puntillism.Puntillism.file_path = self.image_file_path
jobject.destroy()
chooser.destroy()
return self.image_file_path
self.jobject = self.chooser.get_selected_object()
self.image_id = str(self.jobject._object_id)
return str(self.jobject.get_file_path())
else:
self.jobject.destroy()
self.chooser.destroy()
return None


def get_preview(self):
return self._pygamecanvas.get_preview()
Expand Down
20 changes: 17 additions & 3 deletions puntillism.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
# Alan Aguiar <alanjas@gmail.com>
# Nirav Patel <sugarlabs@spongezone.net>

import sys
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
Expand Down Expand Up @@ -117,6 +118,14 @@ def run(self):
self.image_load_handler(screen, frames,
x_s, y_s, clock, text, text_frame)

# Destroy image load events
try:
self.parent.jobject.destroy()
self.parent.chooser.destroy()
except Exception as e:
print("ERROR {}".format(e))
pass

def create_rect(self, cad, rect, frames, clock, screen, x_size, y_size):
for z in range(max(20, int(frames)*10)):
x = random.random()
Expand All @@ -133,6 +142,7 @@ def create_rect(self, cad, rect, frames, clock, screen, x_size, y_size):
cad.get_at((int(x * 640), int(y * 480))),
(int(x * x_size), int(y * y_size)),
num, 0))
pygame.display.update()
pygame.display.update(rect)
clock.tick()
frames = clock.get_fps()
Expand All @@ -152,7 +162,7 @@ def read_events(self, events, screen):
if event.key == pygame.K_ESCAPE:
self.running = False
self.load_image_loop = False

elif event.key == pygame.K_s:
self.parent.save_image(screen)

Expand Down Expand Up @@ -183,10 +193,14 @@ def read_events(self, events, screen):
self.running = True

def image_load_handler(self, screen, frames, x_s, y_s, clock, text, text_frame):
screen.fill((0, 0, 0))
pygame.display.update()

while self.load_image_loop:

if self.file_path != "NULL":
cad = pygame.image.load(self.file_path).convert_alpha()
if self.file_path is not None:

cad = pygame.image.load(self.file_path).convert()
cad = pygame.transform.scale(cad, (640, 480))
rect = []
self.create_rect(cad, rect, frames, clock, screen, x_s, y_s)
Expand Down

0 comments on commit cfd961a

Please sign in to comment.