Skip to content
Browse files

Merge latest changes from MyPaint HEAD

Conflicts:
	gui/drawwindow.py
  • Loading branch information...
2 parents d7e1a1c + d071f64 commit 2cdb865dec4edc8ff1207661fade925605e7e568 @davissorenson davissorenson committed Nov 10, 2013
Showing with 309 additions and 288 deletions.
  1. +1 −0 gui/application.py
  2. +5 −6 gui/dialogs.py
  3. +1 −2 gui/drawwindow.py
  4. +1 −0 gui/freehand.py
  5. +226 −0 gui/history.py
  6. +1 −1 gui/linemode.py
  7. +1 −0 gui/menu.xml
  8. +10 −0 gui/resources.xml
  9. +52 −209 gui/toolbar.py
  10. +11 −70 gui/workspace.py
View
1 gui/application.py
@@ -53,6 +53,7 @@ def get_app():
import scratchwindow
import inputtestwindow
import brushiconeditor
+import history
import colortools
import brushmodifier
import toolbar
View
11 gui/dialogs.py
@@ -314,12 +314,11 @@ def __init__(self, app, on_select):
scrolledwin = Gtk.ScrolledWindow()
scrolledwin.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.ALWAYS)
scrolledwin.add_with_viewport(self.brushlist)
- icon_size = self.ICON_SIZE
- w = icon_size * 4
- h = icon_size * 4
- scrolledwin.set_size_request(-1, h)
- self.brushlist.set_size_request(w, -1)
- scrolledwin.get_child().set_size_request(w, -1)
+ w = int(self.ICON_SIZE * 4.5)
+ h = int(self.ICON_SIZE * 5.0)
+ scrolledwin.set_min_content_width(w)
+ scrolledwin.set_min_content_height(h)
+ scrolledwin.get_child().set_size_request(w, h)
self.pack_start(self.groups_sb, False, False)
self.pack_start(scrolledwin, True, True)
View
3 gui/drawwindow.py
@@ -35,7 +35,6 @@
import colorpicker
import windowing
import toolbar
-import previewwindow
import animation
import dialogs
from lib import helpers
@@ -384,7 +383,7 @@ def toggle_window_cb(self, action):
"""
action_name = action.get_name()
- if action_name.endswith("Tool"):
+ if action_name.endswith("Tool") or action_name.endswith("Panel"):
gtype_name = "MyPaint%s" % (action.get_name(),)
workspace = self.app.workspace
showing = workspace.get_tool_widget_showing(gtype_name, [])
View
1 gui/freehand.py
@@ -9,6 +9,7 @@
## Imports
+import math
from numpy import array
from numpy import isfinite
from lib.helpers import clamp
View
226 gui/history.py
@@ -0,0 +1,226 @@
+# This file is part of MyPaint.
+# Copyright (C) 2011-2013 by Andrew Chadwick <a.t.chadwick@gmail.com>
+#
+# 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.
+
+
+"""Color and brush history view widgets"""
+
+
+## Imports
+
+import gi
+from gi.repository import Gtk
+from gi.repository import GObject
+from gi.repository import GdkPixbuf
+
+from colors import RGBColor, ColorAdjuster, HSVTriangle
+from colors import PreviousCurrentColorAdjuster, ColorPickerButton
+from lib.observable import event
+import widgets
+
+
+## Module constants
+
+HISTORY_PREVIEW_SIZE = 32
+
+
+## Class definitions
+
+
+class BrushHistoryView (Gtk.HBox):
+ """A set of clickable images showing the brush usage history"""
+
+ def __init__(self, app):
+ Gtk.HBox.__init__(self)
+ self._app = app
+ bm = app.brushmanager
+ self._history_images = []
+ s = HISTORY_PREVIEW_SIZE
+ self.set_border_width(widgets.SPACING)
+ for i, brush in enumerate(bm.history):
+ image = ManagedBrushPreview()
+ image.set_size_request(s, s)
+ self._history_images.append(image)
+ button = widgets.borderless_button()
+ button.add(image)
+ button.connect("clicked", self._history_button_clicked_cb, i)
+ self.pack_end(button, True, False, 0)
+ app.doc.input_stroke_ended_observers.append(self._stroke_ended_cb)
+ self._update_history_images()
+
+ def _stroke_ended_cb(self, event):
+ GObject.idle_add(self._update_history_images)
+
+ def _update_history_images(self):
+ bm = self._app.brushmanager
+ assert self._history_images is not None
+ assert len(bm.history) == len(self._history_images)
+ for image, brush in zip(self._history_images, bm.history):
+ image.set_from_managed_brush(brush)
+
+ def _history_button_clicked_cb(self, button, i):
+ bm = self._app.brushmanager
+ brush = bm.history[i]
+ bm.select_brush(brush)
+ self.button_clicked()
+
+ @event
+ def button_clicked(self):
+ """Event: a color history button was clicked"""
+
+
+class ManagedBrushPreview (Gtk.Image):
+ """Updateable widget displaying a brushmanager.ManagedBrush's preview"""
+
+ ICON_SIZE = HISTORY_PREVIEW_SIZE
+ TOOLTIP_ICON_SIZE = 48
+
+ def __init__(self, brush=None):
+ Gtk.Image.__init__(self)
+ self.pixbuf = None
+ self.image_size = None
+ self.brush_name = None
+ self.set_from_managed_brush(brush)
+ s = self.ICON_SIZE
+ self.set_size_request(s, s)
+ self.connect("size-allocate", self.on_size_allocate)
+ self.connect("query-tooltip", self.on_query_tooltip)
+ self.set_property("has-tooltip", True)
+
+ def set_from_managed_brush(self, brush):
+ if brush is None:
+ return
+ self.pixbuf = brush.preview.copy()
+ self.brush_name = brush.get_display_name()
+ self._update()
+
+ def on_size_allocate(self, widget, alloc):
+ new_size = alloc.width, alloc.height
+ # if new_size != self.image_size:
+ if self.image_size is None:
+ # XXX dubious fix: what if the preview receives a new size in the
+ # middle of its lifetime? Under GTK3 however, permitting this makes
+ # the preview keep growing by about 4px each penstroke or brush
+ # selection. Not sure why.
+ self.image_size = alloc.width, alloc.height
+ self._update()
+
+ def _get_scaled_pixbuf(self, size):
+ if self.pixbuf is None:
+ theme = Gtk.IconTheme.get_default()
+ return theme.load_icon(Gtk.STOCK_MISSING_IMAGE, size, 0)
+ else:
+ interp = GdkPixbuf.InterpType.BILINEAR
+ return self.pixbuf.scale_simple(size, size, interp)
+
+ def on_query_tooltip(self, widget, x, y, keyboard_mode, tooltip):
+ s = self.TOOLTIP_ICON_SIZE
+ scaled_pixbuf = self._get_scaled_pixbuf(s)
+ tooltip.set_icon(scaled_pixbuf)
+ tooltip.set_text(self.brush_name)
+ # TODO: use markup, and summarize changes (i18n fun)
+ return True
+
+ def _update(self):
+ if not self.image_size:
+ return
+ w, h = self.image_size
+ s = min(w, h)
+ scaled_pixbuf = self._get_scaled_pixbuf(s)
+ self.set_from_pixbuf(scaled_pixbuf)
+
+
+class ColorHistoryView (Gtk.HBox, ColorAdjuster):
+ """A set of clickable ColorPreviews showing the usage history"""
+
+ def __init__(self, app):
+ Gtk.HBox.__init__(self)
+ self._app = app
+ self._history = []
+ self.set_border_width(widgets.SPACING)
+ s = HISTORY_PREVIEW_SIZE
+ mgr = app.brush_color_manager
+ for i, color in enumerate(mgr.get_history()):
+ button = widgets.borderless_button()
+ preview = ColorPreview(color)
+ preview.set_size_request(s, s)
+ button.add(preview)
+ button.connect("clicked", self._button_clicked_cb, i)
+ self.pack_end(button, True, False, 0)
+ self._history.append(preview)
+ self.set_color_manager(mgr)
+
+ def color_history_updated(self):
+ """Callback: history got updated via the ColorManager"""
+ mgr = self.get_color_manager()
+ for preview, color in zip(self._history, mgr.get_history()):
+ preview.color = color
+
+ def _button_clicked_cb(self, button, i):
+ """Internal: on history button clicks, set the current color"""
+ mgr = self.get_color_manager()
+ history = mgr.get_history()
+ color = history[i]
+ mgr.set_color(color)
+ self.button_clicked()
+
+ @event
+ def button_clicked(self):
+ """Event: a color history button was clicked"""
+
+
+class ColorPreview (Gtk.AspectFrame):
+ """Updatable widget displaying a single colour"""
+
+ def __init__(self, color=None):
+ """Initialize with a color (default is black"""
+ Gtk.AspectFrame.__init__(self, xalign=0.5, yalign=0.5,
+ ratio=1.0, obey_child=False)
+ self.set_shadow_type(Gtk.ShadowType.IN)
+ self.drawingarea = Gtk.DrawingArea()
+ self.add(self.drawingarea)
+ if color is None:
+ color = RGBColor(0, 0, 0)
+ self._color = color
+ self.drawingarea.set_size_request(8, 8)
+ self.drawingarea.connect("draw", self._draw_cb)
+
+ def set_color(self, color):
+ self._color = color
+ self.drawingarea.queue_draw()
+
+ def get_color(self):
+ return self._color
+
+ color = property(get_color, set_color)
+
+ def _draw_cb(self, widget, cr):
+ cr.set_source_rgb(*self._color.get_rgb())
+ cr.paint()
+
+
+class HistoryPanel (Gtk.VBox):
+
+ __gtype_name__ = "MyPaintHistoryPanel"
+
+ tool_widget_icon_name = "document-open-recent"
+ tool_widget_title = "Recent Brushes & Colors"
+ tool_widget_description = ("The most recently used brush\n"
+ "presets and painting colors")
+
+ def __init__(self):
+ Gtk.VBox.__init__(self)
+ from application import get_app
+ app = get_app()
+ color_hist_view = ColorHistoryView(app)
+ self.pack_start(color_hist_view, True, False, 0)
+ brush_hist_view = BrushHistoryView(app)
+ self.pack_start(brush_hist_view, True, False, 0)
+
+
+
+
View
2 gui/linemode.py
@@ -177,7 +177,7 @@ def init_specialized_widgets(self, row=0):
def reset_button_clicked_cb(self, button):
super(LineModeOptionsWidget, self).reset_button_clicked_cb(button)
- self.curve._update(from_defaults=True)
+ self._curve._update(from_defaults=True)
## Interaction modes for making lines
View
1 gui/menu.xml
@@ -48,6 +48,7 @@
</menu>
<separator/>
<menuitem action='ModeOptionsTool'/>
+ <menuitem action='HistoryPanel'/>
<separator/>
<menuitem action='PreferencesWindow'/>
</menu>
View
10 gui/resources.xml
@@ -1407,6 +1407,16 @@ The circular slices are equiluminant.</property>
<signal name="activate" handler="toggle_window_cb"/>
</object>
</child>
+ <child>
+ <object class="GtkToggleAction" id="HistoryPanel">
+ <property name="label" translatable="yes"
+ >Recent Brushes &amp; Colors</property>
+ <property name="icon-name">document-open-recent</property>
+ <property name="tooltip"
+ translatable="yes">Recently used</property>
+ <signal name="activate" handler="toggle_window_cb"/>
+ </object>
+ </child>
<child>
<object class="GtkToggleAction" id="FullscreenAutohide">
View
261 gui/toolbar.py
@@ -1,13 +1,15 @@
# This file is part of MyPaint.
-# Copyright (C) 2011 by Andrew Chadwick <andrewc-git@piffle.org>
+# Copyright (C) 2011-2013 by Andrew Chadwick <a.t.chadwick@gmail.com>
#
# 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.
-"""The application toolbar, and its specialised widgets.
-"""
+"""The application toolbar, and its specialised widgets"""
+
+
+## Imports
import os
@@ -25,9 +27,15 @@
import widgets
from colors import RGBColor, ColorAdjuster, HSVTriangle
from colors import PreviousCurrentColorAdjuster, ColorPickerButton
+from history import ColorHistoryView, BrushHistoryView
+from history import ManagedBrushPreview, ColorPreview
from lib.helpers import escape
from linemode import LineModeCurveWidget
+
+## Module constants
+
+
FRAMEWORK_XML = 'gui/toolbar.xml'
MERGEABLE_XML = [
("toolbar1_file", 'gui/toolbar-file.xml', _("File handling")),
@@ -40,7 +48,10 @@
("toolbar1_view_resets", 'gui/toolbar-view-resets.xml', _("View (Resetting)")),
("toolbar1_subwindows", 'gui/toolbar-subwindows.xml', _("Subwindows")),
]
-HISTORY_PREVIEW_SIZE = 48
+
+
+## Class definitions
+
class ToolbarManager (object):
@@ -218,27 +229,27 @@ def linemode_button_clicked_cb(self, widget):
class ColorDropdownToolItem (gtk.ToolItem):
- """Toolbar colour indicator, history access, and changer.
- """
+ """Toolbar colour indicator, history access, and changer"""
__gtype_name__ = "MyPaintColorDropdownToolItem"
def __init__(self):
gtk.ToolItem.__init__(self)
- self.main_blob = ColorBlob()
- self.dropdown_button = dropdownpanel.DropdownPanelButton(self.main_blob)
- self.app = None
- self.blob_size = ToolbarManager.icon_size
- self.connect("toolbar-reconfigured", self.on_toolbar_reconf)
+ preview = ColorPreview()
+ self.dropdown_button = dropdownpanel.DropdownPanelButton(preview)
+ self.preview_size = ToolbarManager.icon_size
+ self.connect("toolbar-reconfigured", self._toolbar_reconf_cb)
self.connect("create-menu-proxy", lambda *a: True)
self.set_tooltip_text(_("Color History and other tools"))
self.add(self.dropdown_button)
from application import get_app
app = get_app()
- self.app = app
- self.app.brush.observers.append(self.on_brush_settings_changed)
- self.main_blob.color = self.app.brush_color_manager.get_color()
+ app.brush.observers.append(self._brush_settings_changed_cb)
+ preview.color = app.brush_color_manager.get_color()
+
+ self._app = app
+ self._main_preview = preview
panel_frame = gtk.Frame()
panel_frame.set_shadow_type(gtk.SHADOW_OUT)
@@ -281,7 +292,7 @@ def hide_panel_idle_cb(*a):
section_table.attach(side_vbox, 1, 2, 0, 1)
def init_proxy(widget, action_name):
- action = self.app.find_action(action_name)
+ action = app.find_action(action_name)
assert action is not None, \
"Must be able to find action %s" % (action_name,)
widget.set_related_action(action)
@@ -304,28 +315,27 @@ def init_proxy(widget, action_name):
section_frame = widgets.section_frame(_("Recently Used"))
panel_vbox.pack_start(section_frame, True, True)
- history_view = ColorHistoryView(self)
- section_frame.add(history_view)
+ history = ColorHistoryView(app)
+ history.button_clicked += self._history_button_clicked
+ section_frame.add(history)
- def on_history_button_clicked(self):
+ def _history_button_clicked(self, view):
self.dropdown_button.panel_hide()
- def on_toolbar_reconf(self, toolitem):
+ def _toolbar_reconf_cb(self, toolitem):
toolbar = self.get_parent()
lookup_ret = gtk.icon_size_lookup(self.get_icon_size())
- if gtk2compat.USE_GTK3:
- lookup_succeeded, iw, ih = lookup_ret
- assert lookup_succeeded
- else:
- iw, ih = lookup_ret
- self.blob_size = max(iw, ih)
- self.main_blob.set_size_request(iw, ih)
+ lookup_succeeded, iw, ih = lookup_ret
+ assert lookup_succeeded
+ size = max(iw, ih)
+ self._main_preview.set_size_request(size, size)
- def on_brush_settings_changed(self, changes):
+ def _brush_settings_changed_cb(self, changes):
if not changes.intersection(set(['color_h', 'color_s', 'color_v'])):
return
- mgr = self.app.brush_color_manager
- self.main_blob.color = mgr.get_color()
+ mgr = self._app.brush_color_manager
+ color = mgr.get_color()
+ self._main_preview.set_color(color)
@@ -342,7 +352,7 @@ def __init__(self):
self.dropdown_button = dropdownpanel.DropdownPanelButton(self.main_image)
self.app = None
self.image_size = ToolbarManager.icon_size
- self.connect("toolbar-reconfigured", self.on_toolbar_reconf)
+ self.connect("toolbar-reconfigured", self._toolbar_reconf_cb)
self.connect("create-menu-proxy", lambda *a: True)
self.set_tooltip_text(_("Brush history etc."))
self.add(self.dropdown_button)
@@ -351,10 +361,7 @@ def __init__(self):
app = get_app()
self.app = app
bm = self.app.brushmanager
- bm.brush_selected += self.on_brush_selected
- self.app.doc.input_stroke_ended_observers\
- .append(self.doc_input_stroke_ended_cb)
- self.update_history_images()
+ bm.brush_selected += self._brush_selected_cb
panel_frame = gtk.Frame()
panel_frame.set_shadow_type(gtk.SHADOW_OUT)
@@ -373,7 +380,7 @@ def __init__(self):
section_vbox.set_spacing(widgets.SPACING_TIGHT)
section_frame.add(section_vbox)
- quick_changer = dialogs.QuickBrushChooser(app, self.on_quick_change_select)
+ quick_changer = dialogs.QuickBrushChooser(app, self._quick_change_select_cb)
evbox = gtk.EventBox()
evbox.add(quick_changer)
section_vbox.pack_start(evbox, True, True)
@@ -385,62 +392,31 @@ def __init__(self):
section_frame = widgets.section_frame(_("Recently Used"))
panel_vbox.pack_start(section_frame, True, True)
- history_hbox = gtk.HBox()
- history_hbox.set_border_width(widgets.SPACING)
- section_frame.add(history_hbox)
- for i, image in enumerate(self.history_images):
- button = widgets.borderless_button()
- button.add(image)
- button.connect("clicked", self.on_history_button_clicked, i)
- history_hbox.pack_end(button, True, True)
-
+ history = BrushHistoryView(app)
+ history.set_border_width(widgets.SPACING)
+ history.button_clicked += self._history_button_clicked_cb
+ section_frame.add(history)
- def doc_input_stroke_ended_cb(self, event):
- gobject.idle_add(self.update_history_images)
-
- def update_history_images(self):
- bm = self.app.brushmanager
- if not self.history_images:
- s = HISTORY_PREVIEW_SIZE
- for brush in bm.history:
- image = ManagedBrushPreview()
- image.set_size_request(s, s)
- self.history_images.append(image)
- for i, brush in enumerate(bm.history):
- image = self.history_images[i]
- image.set_from_managed_brush(brush)
-
-
- def on_toolbar_reconf(self, toolitem):
+ def _toolbar_reconf_cb(self, toolitem):
toolbar = self.get_parent()
lookup_ret = gtk.icon_size_lookup(self.get_icon_size())
- if gtk2compat.USE_GTK3:
- lookup_succeeded, iw, ih = lookup_ret
- assert lookup_succeeded
- else:
- iw, ih = lookup_ret
+ lookup_succeeded, iw, ih = lookup_ret
+ assert lookup_succeeded
self.image_size = max(iw, ih)
self.main_image.set_size_request(iw, ih)
-
- def on_brush_selected(self, bm, brush, brushinfo):
+ def _brush_selected_cb(self, bm, brush, brushinfo):
self.main_image.set_from_managed_brush(brush)
-
- def on_history_button_clicked(self, button, i):
- bm = self.app.brushmanager
- brush = bm.history[i]
- bm.select_brush(brush)
+ def _history_button_clicked_cb(self, view):
self.dropdown_button.panel_hide()
-
- def on_quick_change_select(self, brush):
+ def _quick_change_select_cb(self, brush):
self.dropdown_button.panel_hide(immediate=False)
self.app.brushmanager.select_brush(brush)
-
class BrushSettingsDropdownToolItem (gtk.ToolItem):
__gtype_name__ = "MyPaintBrushSettingsDropdownToolItem"
@@ -651,139 +627,6 @@ def _current_brush_is_modified(self):
return not parent_b.brushinfo.matches(current_bi)
-class ManagedBrushPreview (gtk.Image):
- """Updateable widget displaying a brushmanager.ManagedBrush`'s preview.
- """
-
- ICON_SIZE = 32
- TOOLTIP_ICON_SIZE = 48
-
- def __init__(self, brush=None):
- gtk.Image.__init__(self)
- self.pixbuf = None
- self.image_size = None
- self.brush_name = None
- self.set_from_managed_brush(brush)
- s = self.ICON_SIZE
- self.set_size_request(s, s)
- self.connect("size-allocate", self.on_size_allocate)
- self.connect("query-tooltip", self.on_query_tooltip)
- self.set_property("has-tooltip", True)
-
-
- def set_from_managed_brush(self, brush):
- if brush is None:
- return
- self.pixbuf = brush.preview.copy()
- self.brush_name = brush.get_display_name()
- self._update()
-
-
- def on_size_allocate(self, widget, alloc):
- new_size = alloc.width, alloc.height
- # if new_size != self.image_size:
- if self.image_size is None:
- # XXX dubious fix: what if the preview receives a new size in the
- # middle of its lifetime? Under GTK3 however, permitting this makes
- # the preview keep growing by about 4px each penstroke or brush
- # selection. Not sure why.
- self.image_size = alloc.width, alloc.height
- self._update()
-
- def _get_scaled_pixbuf(self, size):
- if self.pixbuf is None:
- theme = gtk.icon_theme_get_default()
- return theme.load_icon(gtk.STOCK_MISSING_IMAGE, size, 0)
- else:
- return self.pixbuf.scale_simple(size, size, gdk.INTERP_BILINEAR)
-
- def on_query_tooltip(self, widget, x, y, keyboard_mode, tooltip):
- s = self.TOOLTIP_ICON_SIZE
- scaled_pixbuf = self._get_scaled_pixbuf(s)
- tooltip.set_icon(scaled_pixbuf)
- tooltip.set_text(self.brush_name) # TODO: use markup, and summarize changes (i18n fun)
- return True
-
- def _update(self):
- if not self.image_size:
- return
- w, h = self.image_size
- s = min(w, h)
- scaled_pixbuf = self._get_scaled_pixbuf(s)
- self.set_from_pixbuf(scaled_pixbuf)
-
-
-class ColorHistoryView (gtk.HBox, ColorAdjuster):
- """A set of ColorBlobs showing the usage history.
- """
-
- def __init__(self, toolitem):
- gtk.HBox.__init__(self)
- self.__history_blobs = []
- self.__app = toolitem.app
- self.__toolitem = toolitem
- self.set_border_width(widgets.SPACING)
- s = HISTORY_PREVIEW_SIZE
- mgr = self.__app.brush_color_manager
- for color in mgr.get_history():
- button = widgets.borderless_button()
- blob = ColorBlob(color)
- blob.set_size_request(s, s)
- button.add(blob)
- button.connect("clicked", self.__button_clicked_cb)
- self.pack_end(button, True, True)
- self.__history_blobs.append(blob)
- self.set_color_manager(mgr)
-
- def color_history_updated(self):
- mgr = self.get_color_manager()
- for blob, color in zip(self.__history_blobs, mgr.get_history()):
- blob.color = color
-
- def __button_clicked_cb(self, button):
- blob = button.get_child()
- mgr = self.get_color_manager()
- mgr.set_color(blob.color)
- self.__toolitem.on_history_button_clicked()
-
-
-class ColorBlob (gtk.AspectFrame):
- """Updatable widget displaying a single colour.
- """
-
- def __init__(self, color=None):
- gtk.AspectFrame.__init__(self, xalign=0.5, yalign=0.5, ratio=1.0, obey_child=False)
- self.set_name("thinborder-color-blob-%d" % id(self))
- self.set_shadow_type(gtk.SHADOW_IN)
- self.drawingarea = gtk.DrawingArea()
- self.add(self.drawingarea)
- if color is None:
- color = RGBColor(0, 0, 0)
- self._color = color
- self.drawingarea.set_size_request(1, 1)
- if gtk2compat.USE_GTK3:
- self.drawingarea.connect("draw", self.on_draw)
- else:
- self.drawingarea.connect("expose-event", self.on_expose)
-
- def set_color(self, color):
- self._color = color
- self.drawingarea.queue_draw()
-
- def get_color(self):
- return self._color
-
- color = property(get_color, set_color)
-
- def on_expose(self, widget, event):
- cr = widget.get_window().cairo_create()
- self.on_draw(widget, cr)
-
- def on_draw(self, widget, cr):
- cr.set_source_rgb(*self._color.get_rgb())
- cr.paint()
-
-
class MainMenuButton (gtk.ToggleButton):
"""Launches the popup menu when clicked.
View
81 gui/workspace.py
@@ -220,8 +220,8 @@ def __init__(self):
self._fs_event_handlers = []
# Initial layout happens in several phases
self._initial_layout = None
- self._complete_initial_layout_cb_id = None
self.connect("realize", self._realize_cb)
+ self.connect("map", self._map_cb)
# Tool widget cache and factory
self._tool_widgets = objfactory.ObjFactory(gtype=Gtk.Widget)
self._tool_widgets.object_rebadged += self._tool_widget_rebadged
@@ -272,8 +272,10 @@ def build_from_layout(self, layout):
if toplevel_pos:
set_initial_window_position(toplevel_win, toplevel_pos)
if layout.get("fullscreen", False):
+ toplevel_win.fullscreen()
GObject.idle_add(lambda *a: toplevel_win.fullscreen())
- if layout.get("maximized", False):
+ elif layout.get("maximized", False):
+ toplevel_win.maximize()
GObject.idle_add(lambda *a: toplevel_win.maximize())
toplevel_win.connect("window-state-event",
self._toplevel_window_state_event_cb)
@@ -303,11 +305,6 @@ def get_layout(self):
def _realize_cb(self, widget):
"""Kick off the deferred layout code when the widget is realized"""
- self._start_initial_layout()
-
-
- def _start_initial_layout(self):
- """Layout: all that can be done before the toplevel is positioned"""
# Set up monitoring of the toplevel's size changes.
toplevel = self.get_toplevel()
@@ -317,12 +314,6 @@ def _start_initial_layout(self):
layout = self._initial_layout
if layout is None:
return
- if layout.get("fullscreen", False):
- complete_state = Gdk.WindowState.FULLSCREEN
- elif layout.get("mazimize", False):
- complete_state = Gdk.WindowState.MAXIMIZE
- else:
- complete_state = None
llayout = layout.get("left_sidebar", {})
rlayout = layout.get("right_sidebar", {})
self._lstack.build_from_layout(llayout)
@@ -338,63 +329,16 @@ def _start_initial_layout(self):
# have had a chance to run.
for win in self._floating:
GObject.idle_add(win.show_all)
- # Arrange for part 2 to be run
- toplevel = self.get_toplevel()
- if not complete_state:
- # Nothing too fancy; we're hopefully going to be mapped with
- # the right initial size for the sidebars etc.
- assert not self.get_mapped()
- cb = self._complete_initial_layout_map_cb
- cb_id = self.connect("map", cb)
- else:
- # If we're about to fullscreen or maximize, wait for that state.
- # Otherwise the paned positions won't be right for the window.
- cb = self._complete_layout_toplevel_window_state_cb
- cb_id = toplevel.connect("window-state-event", cb, complete_state)
- # But time out just case the state is never reached. Window
- # managers can be fickle.
- timeout = self._complete_layout_toplevel_window_state_timeout_cb
- GObject.timeout_add_seconds(3, timeout)
- self._complete_initial_layout_cb_id = cb_id
- # Give the toolstacks a chance to do something here too.
- for stack in self._get_tool_stacks():
- stack._start_initial_layout()
- def _complete_initial_layout_map_cb(self, widget):
+ def _map_cb(self, widget):
+ assert self.get_realized()
logger.debug("Completing layout (mapped)")
GObject.idle_add(self._complete_initial_layout)
- widget.disconnect(self._complete_initial_layout_cb_id)
- self._complete_initial_layout_cb_id = None
-
-
- def _complete_layout_toplevel_window_state_cb(self, toplevel, event,
- expected_state):
- # Wait for the window to transition to the right initial state
- if event.changed_mask & expected_state:
- if event.new_window_state & expected_state:
- logger.debug("Completing layout (toplevel state-transition)")
- GObject.idle_add(self._complete_initial_layout)
- toplevel.disconnect(self._complete_initial_layout_cb_id)
- self._complete_initial_layout_cb_id = None
-
-
- def _complete_layout_toplevel_window_state_timeout_cb(self):
- # Too long waiting for the expected state transition...
- if self._complete_initial_layout_cb_id is None:
- return False
- toplevel = self.get_toplevel()
- toplevel.disconnect(self._complete_initial_layout_cb_id)
- self._complete_initial_layout_cb_id = None
- logger.debug("Completing layout (expected toplevel state-transition "
- "didn't happen within the timeout)")
- GObject.idle_add(self._complete_initial_layout)
- return False
def _complete_initial_layout(self):
"""Finish initial layout; called after toplevel win is positioned"""
- assert self.get_realized()
# Restore saved widths for the sidebar
layout = self._initial_layout
if layout is not None:
@@ -1559,12 +1503,7 @@ def get_layout(self):
return stack_desc
- ## Initial layout (pre/post-realize)
-
-
- def _start_initial_layout(self):
- """Layout: all that can be done before the toplevel is positioned"""
- pass
+ ## Initial layout (post-realize)
def _complete_initial_layout(self):
@@ -2288,9 +2227,9 @@ def _floating_window_created(*a):
logger.debug("FLOATING-WINDOW-CREATED %r", a)
workspace = Workspace()
workspace.floating_window_title_suffix = u" - Test"
- canvas = Gtk.Label("<Placeholder>")
+ button = Gtk.Button("Click to close this demo")
frame = Gtk.Frame()
- frame.add(canvas)
+ frame.add(button)
frame.set_shadow_type(Gtk.ShadowType.IN)
workspace.set_canvas(frame)
window = Gtk.Window()
@@ -2316,13 +2255,15 @@ def _floating_window_created(*a):
'groups': [{'tools': [('TestLabel', "4"), ('TestLabel', "5")]}],
},
'maximized': False,
+ 'fullscreen': True,
})
window.show_all()
def _quit_cb(*a):
logger.info("Demo quit, workspace dump follows")
print workspace.get_layout()
Gtk.main_quit()
window.connect("destroy", _quit_cb)
+ button.connect("clicked", _quit_cb)
Gtk.main()

0 comments on commit 2cdb865

Please sign in to comment.
Something went wrong with that request. Please try again.