cross-stitch

Interactively turn images into patterns for cross stitching
git clone git://src.adamsgaard.dk/cross-stitch
Log | Files | Refs

commit df5c2e0a88206408ff029ff93dfe729a8919a025
parent d37e43fe9fd4de97dbbe3164bb52d209bb210ab4
Author: Anders Damsgaard <anders.damsgaard@geo.au.dk>
Date:   Fri, 14 Feb 2014 20:34:05 +0100

Added preview panel, it's in a separate window, however

Diffstat:
Mcross-stitch.py | 51++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 42 insertions(+), 9 deletions(-)

diff --git a/cross-stitch.py b/cross-stitch.py @@ -5,15 +5,20 @@ import argparse import scipy.ndimage import scipy.misc import scipy.cluster -import numpy as np +import numpy import matplotlib -import matplotlib.pyplot as plt +matplotlib.use('WXAgg') +import matplotlib.figure +import matplotlib.backends +import matplotlib.backends.backend_wxagg +#import matplotlib.pyplot as plt import wx class CrossStitch: def __init__(self): - pass + self.img = numpy.zeros(3) + self.read_image("fiskeren.jpg") def read_image(self, infile): try: @@ -38,25 +43,54 @@ class CrossStitch: self.img = tmp.reshape(self.img.shape[0], self.img.shape[1], 3) def save_image(self, filename): - fig = plt.figure() - imgplot = plt.imshow(self.img) + fig = matplotlib.pyplot.figure() + imgplot = matplotlib.pyplot.imshow(self.img) imgplot.set_interpolation('nearest') - plt.grid() - plt.savefig(filename) + matplotlib.pyplot.grid() + matplotlib.pyplot.savefig(filename) + + def image(self): + return self.img + +class CanvasPanel(wx.Panel): + + def __init__(self, parent, cs): + wx.Panel.__init__(self, parent) + self.figure = matplotlib.figure.Figure() + self.axes = self.figure.add_subplot(111) + self.canvas = matplotlib.backends.backend_wxagg.FigureCanvasWxAgg(\ + self, -1, self.figure) + self.sizer = wx.BoxSizer(wx.VERTICAL) + self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) + self.SetSizer(self.sizer) + self.Fit() + + def set_csobj(self, csobj): + self.cs = csobj + + def draw(self): + self.axes.imshow(self.cs.image()) + self.axes.grid() class MainScreen(wx.Frame): def __init__(self, *args, **kwargs): super(MainScreen, self).__init__(*args, **kwargs) - self.InitUI() self.cs = CrossStitch() + self.InitUI() def InitUI(self): self.InitMenu() #self.InitToolbar() + preview = wx.Frame(self) + panel = CanvasPanel(preview, 'preview') + panel.set_csobj(self.cs) + panel.draw() + preview.Show() + self.SetSize((600, 400)) self.SetTitle('Main menu') self.Centre() @@ -96,7 +130,6 @@ class MainScreen(wx.Frame): self.Bind(wx.EVT_TOOL, self.OnQuit, qtool) toolbar.Realize() - def OnQuit(self, e):