tAdded grid toggle - cross-stitch - interactively turn images into patterns for… | |
git clone git://src.adamsgaard.dk/cross-stitch | |
Log | |
Files | |
Refs | |
LICENSE | |
--- | |
commit a6cb3cbb779bbf8269a85093e3e04e04601dc2eb | |
parent cce24f74ed67f216ee40c3a73ae1341d1356edb4 | |
Author: Anders Damsgaard <[email protected]> | |
Date: Sat, 15 Feb 2014 20:22:17 +0100 | |
Added grid toggle | |
Diffstat: | |
M README.rst | 1 - | |
M cross-stitch.py | 28 ++++++++++++++++++++++------ | |
2 files changed, 22 insertions(+), 7 deletions(-) | |
--- | |
diff --git a/README.rst b/README.rst | |
t@@ -32,7 +32,6 @@ Todo | |
- Show color-by-color output images | |
- Show product names of needed yarn colors | |
- Add option to restrict to 256 standard colors | |
-- Add toggle for grid and axis marks | |
Example | |
------- | |
diff --git a/cross-stitch.py b/cross-stitch.py | |
t@@ -28,9 +28,9 @@ class CrossStitch: | |
self.orig_img = self.img.copy() | |
def down_sample(self, width): | |
- hw_ratio = float(self.img.shape[0])/self.img.shape[1] | |
+ hw_ratio = float(self.orig_img.shape[0])/self.orig_img.shape[1] | |
size = (int(round(hw_ratio*width)), width) | |
- self.img = scipy.misc.imresize(self.img, size) | |
+ self.img = scipy.misc.imresize(self.orig_img, size) | |
def limit_colors(self, ncolors): | |
ar = self.img.reshape(scipy.product(self.img.shape[:2]),\ | |
t@@ -42,10 +42,10 @@ class CrossStitch: | |
tmp[scipy.r_[scipy.where(vecs == i)],:] = color | |
self.img = tmp.reshape(self.img.shape[0], self.img.shape[1], 3) | |
- def save_image(self, filename): | |
+ def save_image(self, filename, grid=True): | |
fig = matplotlib.pyplot.figure() | |
imgplot = matplotlib.pyplot.imshow(self.img, interpolation='nearest') | |
- matplotlib.pyplot.grid(True) | |
+ matplotlib.pyplot.grid(grid) | |
matplotlib.pyplot.savefig(filename) | |
def image(self): | |
t@@ -68,6 +68,7 @@ class MainScreen(wx.Frame): | |
self.cs = CrossStitch() | |
self.InitUI() | |
self.contentNotSaved = False | |
+ self.grid = True | |
def InitUI(self): | |
t@@ -103,6 +104,13 @@ class MainScreen(wx.Frame): | |
self.Bind(wx.EVT_MENU, self.OnLimitColors, fitem) | |
menubar.Append(processingMenu, '&Image processing') | |
+ viewMenu = wx.Menu() | |
+ self.gridtoggle = viewMenu.Append(wx.ID_ANY, 'Show grid', | |
+ 'Show grid in image', kind=wx.ITEM_CHECK) | |
+ viewMenu.Check(self.gridtoggle.GetId(), True) | |
+ self.Bind(wx.EVT_MENU, self.ToggleGrid, self.gridtoggle) | |
+ menubar.Append(viewMenu, '&View') | |
+ | |
helpMenu = wx.Menu() | |
fitem = helpMenu.Append(wx.ID_ABOUT, 'About', 'About') | |
self.Bind(wx.EVT_MENU, self.OnAbout, fitem) | |
t@@ -130,7 +138,7 @@ class MainScreen(wx.Frame): | |
self.Fit() | |
def DrawPreview(self): | |
- self.axes.grid(True) | |
+ self.axes.grid(self.grid) | |
self.axes.imshow(self.cs.image(), interpolation='nearest') | |
self.canvas.draw() | |
t@@ -174,7 +182,7 @@ class MainScreen(wx.Frame): | |
if saveFileDialog.ShowModal() == wx.ID_CANCEL: | |
return | |
- self.cs.save_image(saveFileDialog.GetPath()) | |
+ self.cs.save_image(saveFileDialog.GetPath(), grid=self.grid) | |
self.contentNotSaved = False | |
def OnDownSample(self, event): | |
t@@ -195,6 +203,14 @@ class MainScreen(wx.Frame): | |
self.contentNotSaved = True | |
self.DrawPreview() | |
+ def ToggleGrid(self, event): | |
+ if self.gridtoggle.IsChecked(): | |
+ self.grid = True | |
+ self.DrawPreview() | |
+ else: | |
+ self.grid = False | |
+ self.DrawPreview() | |
+ | |
def OnAbout(self, event): | |
description = '''Cross Stitch is a raster pattern generator for Linux, |