From a26e392bb7203e8cc6f795b7a92f4073fa82c334 Mon Sep 17 00:00:00 2001
From: Ali Lown <ali@lown.me.uk>
Date: Wed, 21 Nov 2012 22:18:02 +0000
Subject: [PATCH] Implement Preview Window using TiledDrawWidget

Rebase of:
- Add a popup preview window
- Make PreviewWindow a more normal tool widget, add TiledDrawWidget
- Bind to correct 'model'
- Add todo:
---
 gui/application.py         |  3 +++
 gui/drawwindow.py          |  1 +
 gui/menu.xml               |  1 +
 gui/previewwindow.py       | 31 +++++++++++++++++++++++++++++++
 gui/stock.py               |  2 ++
 gui/toolbar-subwindows.xml |  1 +
 6 files changed, 39 insertions(+)
 create mode 100644 gui/previewwindow.py

diff --git a/gui/application.py b/gui/application.py
index b711e56..ca75dea 100644
--- a/gui/application.py
+++ b/gui/application.py
@@ -246,6 +246,9 @@ class Application: # singleton
                 'scratchWindow': dict(
                         sbindex=4, floating=True, hidden=True,
                         x=-555, y=125, w=300, h=250, sbheight=250),
+                'previewWindow': dict(
+                        sbindex=5, floating=True, hidden=True,
+                        x=-600, y=150, w=250, h=250, sbheight=250),
 
                 # Non-tool subwindows. These cannot be docked, and are all
                 # intially hidden.
diff --git a/gui/drawwindow.py b/gui/drawwindow.py
index f5ba5f9..8cad43b 100644
--- a/gui/drawwindow.py
+++ b/gui/drawwindow.py
@@ -302,6 +302,7 @@ class Window (windowing.MainWindow, layout.MainWindow):
             ('ScratchWindow',  stock.TOOL_SCRATCHPAD, 
                     None, None, _('Toggle the scratchpad'),
                     self.toggle_window_cb),
+            ('PreviewWindow', None, _('Toggle the Preview Window'), None, None, self.toggle_window_cb),
             ]
         ag.add_toggle_actions(toggle_actions)
 
diff --git a/gui/menu.xml b/gui/menu.xml
index ac75ee6..c604f5a 100644
--- a/gui/menu.xml
+++ b/gui/menu.xml
@@ -35,6 +35,7 @@
       </menu>
       <menuitem action='ShowPopupMenu'/>
       <menuitem action='ToggleSubwindows'/>
+      <menuitem action='PreviewWindow'/>
       <separator/>
       <!-- ResetView is on its own because it also recentres the canvas, -->
       <menuitem action='ResetView'/>
diff --git a/gui/previewwindow.py b/gui/previewwindow.py
new file mode 100644
index 0000000..f2921f2
--- /dev/null
+++ b/gui/previewwindow.py
@@ -0,0 +1,31 @@
+# This file is part of MyPaint.
+# Copyright (C) 2012 by Ali Lown <ali@lown.me.uk>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+
+from gettext import gettext as _
+import gtk, gobject, pango
+gdk = gtk.gdk
+import stock
+import dialogs
+import tileddrawwidget
+
+
+class ToolWidget(gtk.VBox):
+    """Tool widget for previewing the whole canvas"""
+
+    stock_id = stock.TOOL_PREVIEW_WINDOW
+
+    def __init__(self, app):
+        gtk.VBox.__init__(self)
+        self.set_size_request(250, 250)
+
+        self.tdw = tileddrawwidget.TiledDrawWidget(app, app.doc.model)
+        self.tdw.set_size_request(250, 250)
+        #TODO: perhaps configure this based on used area?
+        self.tdw.scale = 0.03
+        self.tdw.set_sensitive(False)
+        self.add(self.tdw)
diff --git a/gui/stock.py b/gui/stock.py
index bedd8e6..c7d31c4 100644
--- a/gui/stock.py
+++ b/gui/stock.py
@@ -20,6 +20,7 @@ TOOL_COLOR_SELECTOR = "mypaint-tool-color-triangle"
 TOOL_COLOR_SAMPLER = "mypaint-tool-hue-wheel"
 TOOL_SCRATCHPAD = "mypaint-tool-scratchpad"
 TOOL_LAYERS = "mypaint-tool-layers"
+TOOL_PREVIEW_WINDOW = "mypaint-tool-preview-window"
 ROTATE_LEFT = "object-rotate-left"
 ROTATE_RIGHT = "object-rotate-right"
 MIRROR_HORIZONTAL = "object-flip-horizontal"
@@ -41,6 +42,7 @@ _stock_items = [
     (TOOL_COLOR_SAMPLER, _("Color Sampler"), 0, ord("t"), None),
     (TOOL_SCRATCHPAD, _("Scratchpad"), gdk.SHIFT_MASK, ord("s"), None),
     (TOOL_LAYERS, _("Layers"), 0, ord("l"), None),
+    (TOOL_PREVIEW_WINDOW, _("Preview Window"), 0, 0, None),
     (ROTATE_LEFT, _("Rotate Counterclockwise"),
         gdk.CONTROL_MASK, gdk.keyval_from_name("Left"), None),
     (ROTATE_RIGHT, _("Rotate Clockwise"),
diff --git a/gui/toolbar-subwindows.xml b/gui/toolbar-subwindows.xml
index f12eb73..e38537d 100644
--- a/gui/toolbar-subwindows.xml
+++ b/gui/toolbar-subwindows.xml
@@ -16,6 +16,7 @@ the Free Software Foundation; either version 2 of the License, or
       <toolitem action="BrushSelectionWindow"/>
       <toolitem action="LayersWindow"/>
       <toolitem action="ScratchWindow"/>
+      <toolitem action="PreviewWindow"/>
     </placeholder>
 
   </toolbar>
-- 
1.8.0

