Ejemplo n.º 1
0
    def _setup_ui_dialogs(self):
        # This needs to be here otherwise we can't install the dialog
        if 'STOQ_TEST_MODE' in os.environ:
            return
        log.debug('providing graphical notification dialogs')
        from stoqlib.gui.base.dialogs import DialogSystemNotifier
        from stoqlib.lib.interfaces import ISystemNotifier
        from kiwi.component import provide_utility
        provide_utility(ISystemNotifier, DialogSystemNotifier(), replace=True)

        import gtk
        from kiwi.environ import environ
        from kiwi.ui.pixbufutils import pixbuf_from_string
        data = environ.get_resource_string(
            'stoq', 'pixmaps', 'stoq-stock-app-24x24.png')
        gtk.window_set_default_icon(pixbuf_from_string(data))

        if platform.system() == 'Darwin':
            from AppKit import NSApplication, NSData, NSImage
            bytes = environ.get_resource_string(
                'stoq', 'pixmaps', 'stoq-stock-app-48x48.png')
            data = NSData.alloc().initWithBytes_length_(bytes, len(bytes))
            icon = NSImage.alloc().initWithData_(data)
            app = NSApplication.sharedApplication()
            app.setApplicationIconImage_(icon)
Ejemplo n.º 2
0
    def _setup_ui_dialogs(self):
        # This needs to be here otherwise we can't install the dialog
        if 'STOQ_TEST_MODE' in os.environ:
            return
        log.debug('providing graphical notification dialogs')
        from stoqlib.gui.base.dialogs import DialogSystemNotifier
        from stoqlib.lib.interfaces import ISystemNotifier
        from kiwi.component import provide_utility
        provide_utility(ISystemNotifier, DialogSystemNotifier(), replace=True)

        from gi.repository import Gtk
        from kiwi.environ import environ
        from kiwi.ui.pixbufutils import pixbuf_from_string
        data = environ.get_resource_string('stoq', 'pixmaps',
                                           'stoq-stock-app-24x24.png')
        Gtk.Window.set_default_icon(pixbuf_from_string(data))

        if platform.system() == 'Darwin':
            from AppKit import NSApplication, NSData, NSImage
            bytes = environ.get_resource_string('stoq', 'pixmaps',
                                                'stoq-stock-app-48x48.png')
            data = NSData.alloc().initWithBytes_length_(bytes, len(bytes))
            icon = NSImage.alloc().initWithData_(data)
            app = NSApplication.sharedApplication()
            app.setApplicationIconImage_(icon)
Ejemplo n.º 3
0
    def __init__(self):
        gtk.Window.__init__(self)
        self.set_name('SplashWindow')
        self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_SPLASHSCREEN)
        self.resize(WIDTH, HEIGHT)
        # Ubuntu has backported the 3.0 has-resize-grip property,
        # disable it as it doesn't make sense for splash screens
        if hasattr(self.props, 'has_resize_grip'):
            self.props.has_resize_grip = False
        frame = gtk.Frame()
        frame.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        self.add(frame)

        darea = gtk.DrawingArea()
        try:
            darea.connect("expose-event", self.expose)
        except TypeError:
            darea.connect("draw", self.draw)
        frame.add(darea)

        self.show_all()
        pixbuf_data = environ.get_resource_string("stoq", "pixmaps", "splash.png")
        self._pixbuf = pixbuf_from_string(pixbuf_data)

        glib.timeout_add(_WINDOW_TIMEOUT, self._hide_splash_timeout)
Ejemplo n.º 4
0
    def __init__(self):
        gtk.Window.__init__(self)
        self.set_name('SplashWindow')
        self.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_SPLASHSCREEN)
        self.resize(WIDTH, HEIGHT)
        # Ubuntu has backported the 3.0 has-resize-grip property,
        # disable it as it doesn't make sense for splash screens
        if hasattr(self.props, 'has_resize_grip'):
            self.props.has_resize_grip = False
        frame = gtk.Frame()
        frame.set_shadow_type(gtk.SHADOW_ETCHED_IN)
        self.add(frame)

        darea = gtk.DrawingArea()
        try:
            darea.connect("expose-event", self.expose)
        except TypeError:
            darea.connect("draw", self.draw)
        frame.add(darea)

        self.show_all()
        pixbuf_data = environ.get_resource_string("stoq", "pixmaps",
                                                  "splash.png")
        self._pixbuf = pixbuf_from_string(pixbuf_data)

        glib.timeout_add(_WINDOW_TIMEOUT, self._hide_splash_timeout)
Ejemplo n.º 5
0
    def __init__(self):
        super(SplashScreen, self).__init__()
        self.set_decorated(False)

        self.set_name('SplashWindow')
        self.set_type_hint(Gdk.WindowTypeHint.SPLASHSCREEN)
        self.resize(WIDTH, HEIGHT)
        # Ubuntu has backported the 3.0 has-resize-grip property,
        # disable it as it doesn't make sense for splash screens
        if hasattr(self.props, 'has_resize_grip'):
            self.props.has_resize_grip = False

        darea = Gtk.DrawingArea()
        try:
            darea.connect("expose-event", self.expose)
        except TypeError:
            darea.connect("draw", self.draw)
        self.add(darea)

        self.show_all()
        pixbuf_data = environ.get_resource_string("stoq", "pixmaps",
                                                  "splash.png")
        self._pixbuf = pixbuf_from_string(pixbuf_data)

        GLib.timeout_add(_WINDOW_TIMEOUT, self._hide_splash_timeout)
Ejemplo n.º 6
0
    def __init__(self, label, chars=0, container=None):
        """
        Create a new StringSearchFilter object.
        :param label: label of the search filter
        :param chars: maximum number of chars used by the search entry
        """
        self._container = container
        SearchFilter.__init__(self, label=label)
        self.title_label = Gtk.Label(label=label)
        self.pack_start(self.title_label, False, False, 0)
        self.title_label.show()

        self._options = {}
        self.mode = ProxyComboBox()
        self.mode.connect('content-changed', self._on_mode__content_changed)
        self.pack_start(self.mode, False, False, 6)

        self.entry = Gtk.Entry()
        self.entry.set_placeholder_text(_("Search"))
        self.entry.props.secondary_icon_sensitive = False
        data = environ.get_resource_string('stoq', 'pixmaps',
                                           'stoq-funnel-16x16.png')
        image = pixbuf_from_string(data)
        self.entry.set_icon_from_pixbuf(Gtk.EntryIconPosition.PRIMARY, image)
        self.entry.set_icon_tooltip_text(Gtk.EntryIconPosition.PRIMARY,
                                         _("Add a filter"))
        self.entry.set_icon_from_stock(Gtk.EntryIconPosition.SECONDARY,
                                       Gtk.STOCK_CLEAR)
        self.entry.set_icon_tooltip_text(Gtk.EntryIconPosition.SECONDARY,
                                         _("Clear the search"))
        self.entry.connect("icon-release", self._on_entry__icon_release)
        self.entry.connect('activate', self._on_entry__activate)
        self.entry.connect('changed', self._on_entry__changed)
        if chars:
            self.entry.set_width_chars(chars)
        self.pack_start(self.entry, False, False, 6)
        self.entry.show()

        for option in [
                ContainsAll, ContainsExactly, IdenticalTo, DoesNotContain
        ]:
            self._add_option(option)
        self.mode.select_item_by_position(0)
Ejemplo n.º 7
0
    def __init__(self, label, chars=0, container=None):
        """
        Create a new StringSearchFilter object.
        :param label: label of the search filter
        :param chars: maximum number of chars used by the search entry
        """
        self._container = container
        SearchFilter.__init__(self, label=label)
        self.title_label = gtk.Label(label)
        self.pack_start(self.title_label, False, False)
        self.title_label.show()

        self._options = {}
        self.mode = ProxyComboBox()
        self.mode.connect('content-changed', self._on_mode__content_changed)
        self.pack_start(self.mode, False, False, 6)

        self.entry = HintedEntry()
        self.entry.set_hint(_("Search"))
        self.entry.show_hint()
        self.entry.props.secondary_icon_sensitive = False
        data = environ.get_resource_string('stoq', 'pixmaps',
                                           'stoq-funnel-16x16.png')
        image = pixbuf_from_string(data)
        self.entry.set_icon_from_pixbuf(gtk.ENTRY_ICON_PRIMARY,
                                        image)
        self.entry.set_icon_tooltip_text(gtk.ENTRY_ICON_PRIMARY,
                                         _("Add a filter"))
        self.entry.set_icon_from_stock(gtk.ENTRY_ICON_SECONDARY,
                                       gtk.STOCK_CLEAR)
        self.entry.set_icon_tooltip_text(gtk.ENTRY_ICON_SECONDARY,
                                         _("Clear the search"))
        self.entry.connect("icon-release", self._on_entry__icon_release)
        self.entry.connect('activate', self._on_entry__activate)
        self.entry.connect('changed', self._on_entry__changed)
        if chars:
            self.entry.set_width_chars(chars)
        self.pack_start(self.entry, False, False, 6)
        self.entry.show()

        for option in (ContainsAll, ContainsExactly, DoesNotContain):
            self._add_option(option)
        self.mode.select_item_by_position(0)
Ejemplo n.º 8
0
def render_pixbuf(color_name, width=16, height=16, radius=4):
    pixbuf = _pixbuf_cache.get(color_name)
    if pixbuf is not None:
        return pixbuf

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    cr = cairo.Context(surface)

    if color_name:
        pi2 = math.pi / 2
        cr.new_sub_path()
        cr.arc(radius, radius, radius, math.pi, 3 * pi2)
        cr.arc(height - radius, radius, radius, 3 * pi2, 4 * pi2)
        cr.arc(height - radius, width - radius, radius, 0, pi2)
        cr.arc(radius, width - radius, radius, pi2, math.pi)
        cr.close_path()

        color = gtk.gdk.color_parse(color_name)
        cr.set_source_rgb(
            float(color.red) / 65536,
            float(color.green) / 65536,
            float(color.blue) / 65536)
    else:
        cr.set_source_rgba(0, 0, 0, 0.0)

    cr.fill_preserve()
    cr.set_source_rgba(0, 0, 0, 0.5)

    cr.set_line_width(1)
    cr.stroke()

    buf = StringIO.StringIO()
    surface.write_to_png(buf)

    buf.seek(0)
    pixbuf = pixbuf_from_string(buf.getvalue())

    _pixbuf_cache[color_name] = pixbuf
    return pixbuf
Ejemplo n.º 9
0
def render_pixbuf(color_name, width=16, height=16, radius=4):
    pixbuf = _pixbuf_cache.get(color_name)
    if pixbuf is not None:
        return pixbuf

    surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height)
    cr = cairo.Context(surface)

    if color_name:
        pi2 = math.pi / 2
        cr.new_sub_path()
        cr.arc(radius, radius, radius, math.pi, 3 * pi2)
        cr.arc(height - radius, radius, radius, 3 * pi2, 4 * pi2)
        cr.arc(height - radius, width - radius, radius, 0, pi2)
        cr.arc(radius, width - radius, radius, pi2, math.pi)
        cr.close_path()

        color = gtk.gdk.color_parse(color_name)
        cr.set_source_rgb(
            float(color.red) / 65536,
            float(color.green) / 65536,
            float(color.blue) / 65536)
    else:
        cr.set_source_rgba(0, 0, 0, 0.0)

    cr.fill_preserve()
    cr.set_source_rgba(0, 0, 0, 0.5)

    cr.set_line_width(1)
    cr.stroke()

    buf = io.BytesIO()
    surface.write_to_png(buf)

    buf.seek(0)
    pixbuf = pixbuf_from_string(buf.getvalue())

    _pixbuf_cache[color_name] = pixbuf
    return pixbuf
Ejemplo n.º 10
0
def register():
    import gtk
    from kiwi.environ import environ
    from kiwi.ui.pixbufutils import pixbuf_from_string

    size_dict = {
        GTK_ICON_SIZE_BUTTON: gtk.ICON_SIZE_BUTTON,
        GTK_ICON_SIZE_DIALOG: gtk.ICON_SIZE_DIALOG,
        GTK_ICON_SIZE_DND: gtk.ICON_SIZE_DND,
        GTK_ICON_SIZE_LARGE_TOOLBAR: gtk.ICON_SIZE_LARGE_TOOLBAR,
        GTK_ICON_SIZE_MENU: gtk.ICON_SIZE_MENU,
        GTK_ICON_SIZE_SMALL_TOOLBAR: gtk.ICON_SIZE_SMALL_TOOLBAR,
    }

    iconfactory = gtk.IconFactory()
    stock_ids = gtk.stock_list_ids()
    for stock_id, arg in icon_info:
        # only load image files when our stock_id is not present
        if stock_id in stock_ids:
            continue
        iconset = gtk.IconSet()
        for size, filename in arg.items():
            iconsource = gtk.IconSource()
            data = environ.get_resource_string('stoq', 'pixmaps', filename)
            if filename.endswith('png'):
                format = 'png'
            elif filename.endswith('svg'):
                format = 'svg'
            else:
                raise NotImplementedError(format)
            pixbuf = pixbuf_from_string(data, format)
            iconsource.set_pixbuf(pixbuf)
            iconsource.set_size(size_dict[size])
            iconset.add_source(iconsource)
        iconfactory.add(stock_id, iconset)
    iconfactory.add_default()
Ejemplo n.º 11
0
def register():
    import gtk
    from kiwi.environ import environ
    from kiwi.ui.pixbufutils import pixbuf_from_string

    size_dict = {
        GTK_ICON_SIZE_BUTTON: gtk.ICON_SIZE_BUTTON,
        GTK_ICON_SIZE_DIALOG: gtk.ICON_SIZE_DIALOG,
        GTK_ICON_SIZE_DND: gtk.ICON_SIZE_DND,
        GTK_ICON_SIZE_LARGE_TOOLBAR: gtk.ICON_SIZE_LARGE_TOOLBAR,
        GTK_ICON_SIZE_MENU: gtk.ICON_SIZE_MENU,
        GTK_ICON_SIZE_SMALL_TOOLBAR: gtk.ICON_SIZE_SMALL_TOOLBAR,
    }

    iconfactory = gtk.IconFactory()
    stock_ids = gtk.stock_list_ids()
    for stock_id, arg in icon_info:
        # only load image files when our stock_id is not present
        if stock_id in stock_ids:
            continue
        iconset = gtk.IconSet()
        for size, filename in arg.items():
            iconsource = gtk.IconSource()
            data = environ.get_resource_string('stoq', 'pixmaps', filename)
            if filename.endswith('png'):
                format = 'png'
            elif filename.endswith('svg'):
                format = 'svg'
            else:
                raise NotImplementedError(format)
            pixbuf = pixbuf_from_string(data, format)
            iconsource.set_pixbuf(pixbuf)
            iconsource.set_size(size_dict[size])
            iconset.add_source(iconsource)
        iconfactory.add(stock_id, iconset)
    iconfactory.add_default()
Ejemplo n.º 12
0
    def __init__(self):
        super(SplashScreen, self).__init__()
        self.set_decorated(False)

        self.set_name('SplashWindow')
        self.set_type_hint(Gdk.WindowTypeHint.SPLASHSCREEN)
        self.resize(WIDTH, HEIGHT)
        # Ubuntu has backported the 3.0 has-resize-grip property,
        # disable it as it doesn't make sense for splash screens
        if hasattr(self.props, 'has_resize_grip'):
            self.props.has_resize_grip = False

        darea = Gtk.DrawingArea()
        try:
            darea.connect("expose-event", self.expose)
        except TypeError:
            darea.connect("draw", self.draw)
        self.add(darea)

        self.show_all()
        pixbuf_data = environ.get_resource_string("stoq", "pixmaps", "splash.png")
        self._pixbuf = pixbuf_from_string(pixbuf_data)

        GLib.timeout_add(_WINDOW_TIMEOUT, self._hide_splash_timeout)
Ejemplo n.º 13
0
 def from_string(self, value, format='png'):
     try:
         return pixbuf_from_string(value, format)
     except GObject.GError as e:
         raise ValidationError(_("Could not load image: %s") % e)
Ejemplo n.º 14
0
def _load_error_icon():
    global _error_icon
    if _error_icon is None:
        value = base64.decodestring(VALIDATION_PNG)
        _error_icon = pixbuf_from_string(value, 'png')
    return _error_icon
Ejemplo n.º 15
0
def render_logo_pixbuf(size):
    width, height = sizes.get(size, (100, 32))
    logo = environ.get_resource_string('stoq', 'pixmaps', 'stoq_logo.svg')
    return pixbuf_from_string(logo, 'svg', width=width, height=height)