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)
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)
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)
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)
def _setup_gtk(self): import gtk from kiwi.environ import environ gtk.gdk.threads_init() # Total madness to make sure we can draw treeview lines, # this affects the GtkTreeView::grid-line-pattern style property # # Two bytes are sent in, see gtk_tree_view_set_grid_lines in gtktreeview.c # Byte 1 should be as high as possible, gtk+ 0x7F appears to be # the highest allowed for Gtk+ 2.22 while 0xFF worked in # earlier versions # Byte 2 should ideally be allowed to be 0, but neither C nor Python # allows that. # data = environ.get_resource_string("stoq", "misc", "stoq.gtkrc") data = data.replace('\\x7f\\x01', '\x7f\x01') gtk.rc_parse_string(data) # Creating a button as a temporary workaround for bug # https://bugzilla.gnome.org/show_bug.cgi?id=632538, until gtk 3.0 gtk.Button() settings = gtk.settings_get_default() settings.props.gtk_button_images = True
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 stoqlib.gui.stockicons import STOQ_LAUNCHER Gtk.Window.set_default_icon_name(STOQ_LAUNCHER) if platform.system() == 'Darwin': from AppKit import NSApplication, NSData, NSImage # FIXME: This should be a 48x48 icon data = environ.get_resource_string('stoq', 'pixmaps', 'hicolor', '24x24', 'actions', 'stoq-launcher.png') data = NSData.alloc().initWithBytes_length_(data, len(data)) icon = NSImage.alloc().initWithData_(data) app = NSApplication.sharedApplication() app.setApplicationIconImage_(icon)
def _glade_loader_func(self, view, filename, domain): from kiwi.environ import environ from kiwi.ui.builderloader import BuilderWidgetTree if not filename.endswith('ui'): filename += '.ui' ui_string = environ.get_resource_string('stoq', 'glade', filename) return BuilderWidgetTree(view, None, domain, ui_string)
def get_logo_data(store): logo_domain = sysparam(store).CUSTOM_LOGO_FOR_REPORTS if logo_domain and logo_domain.image: data = logo_domain.image else: data = environ.get_resource_string("stoq", "pixmaps", "stoq_logo_bgwhite.png") return "data:image/png;base64," + base64.b64encode(data)
def get_logo_data(store): logo_domain = sysparam.get_object(store, 'CUSTOM_LOGO_FOR_REPORTS') if logo_domain and logo_domain.image: data = logo_domain.image else: data = environ.get_resource_string('stoq', 'pixmaps', 'stoq_logo_bgwhite.png') return 'data:image/png;base64,' + base64.b64encode(data)
def _read_resource(self, domain, name): try: data = environ.get_resource_string('stoq', domain, name) if data: return data except EnvironmentError: pass license = environ.find_resource(domain, name + '.gz') return gzip.GzipFile(license).read()
def _read_resource(self, domain, name): try: data = environ.get_resource_string("stoq", domain, name) if data: return data except EnvironmentError: pass license = environ.find_resource(domain, name + ".gz") return gzip.GzipFile(license).read()
def create_database_functions(): """Create some functions we define on the database This will simply read data/sql/functions.sql and execute it """ with tempfile.NamedTemporaryFile(suffix='stoqfunctions-') as tmp_f: functions = environ.get_resource_string('stoq', 'sql', 'functions.sql') tmp_f.write(render_template_string(functions)) tmp_f.flush() if db_settings.execute_sql(tmp_f.name) != 0: error(u'Failed to create functions')
def _read_resource(self, domain, name): from stoqlib.lib.kiwilibrary import library # On development, documentation resources (e.g. COPYING) will # be located directly on the library's root devpath = os.path.join(library.get_root(), name) if os.path.exists(devpath): with open(devpath) as f: return f.read() return environ.get_resource_string('stoq', domain, name)
def _read_resource(self, domain, name): from stoqlib.lib.kiwilibrary import library # On development, documentation resources (e.g. COPYING) will # be located directly on the library's root devpath = os.path.join(library.get_root(), name) if os.path.exists(devpath): with open(devpath) as f: return f.read() return environ.get_resource_string('stoq', domain, name).decode()
def create_database_functions(): """Create some functions we define on the database This will simply read data/sql/functions.sql and execute it """ # We cant remove the file, otherwise it will fail on windows. with tempfile.NamedTemporaryFile(prefix='stoqfunctions-', delete=False) as tmp_f: functions = environ.get_resource_string('stoq', 'sql', 'functions.sql') tmp_f.write(render_template_string(functions)) tmp_f.flush() if db_settings.execute_sql(tmp_f.name) != 0: error(u'Failed to create functions')
def add_ui_actions(self, ui_string, actions, name='Actions', action_type='normal', filename=None, instance=None): if instance is None: instance = self ag = self._get_action_group(name) to_add = [entry[0] for entry in actions] for action in ag.list_actions(): if action.get_name() in to_add: ag.remove_action(action) if action_type == 'normal': ag.add_actions(actions) elif action_type == 'toggle': ag.add_toggle_actions(actions) elif action_type == 'radio': ag.add_radio_actions(actions) else: raise ValueError(action_type) if filename is not None: ui_string = environ.get_resource_string('stoq', 'uixml', filename) ui_string = ui_string.decode() ui_id = self.uimanager.add_ui_from_string(ui_string) self.action_permissions.update(self.common_action_permissions) pm = PermissionManager.get_permission_manager() for action in ag.list_actions(): action_name = action.get_name() setattr(instance, action_name, action) # Check permissions key, required = instance.action_permissions.get( action_name, (None, pm.PERM_ALL)) if not pm.get(key) & required: action.set_visible(False) # Disable keyboard shortcut path = action.get_accel_path() Gtk.AccelMap.change_entry(path, 0, 0, True) return ui_id
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)
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)
def add_ui_actions(self, ui_string, actions, name='Actions', action_type='normal', filename=None, instance=None): if instance is None: instance = self ag = self._get_action_group(name) to_add = [entry[0] for entry in actions] for action in ag.list_actions(): if action.get_name() in to_add: ag.remove_action(action) if action_type == 'normal': ag.add_actions(actions) elif action_type == 'toggle': ag.add_toggle_actions(actions) elif action_type == 'radio': ag.add_radio_actions(actions) else: raise ValueError(action_type) if filename is not None: ui_string = environ.get_resource_string('stoq', 'uixml', filename) ui_id = self.uimanager.add_ui_from_string(ui_string) self.action_permissions.update(self.common_action_permissions) pm = PermissionManager.get_permission_manager() for action in ag.list_actions(): action_name = action.get_name() setattr(instance, action_name, action) # Check permissions key, required = instance.action_permissions.get(action_name, (None, pm.PERM_ALL)) if not pm.get(key) & required: action.set_visible(False) # Disable keyboard shortcut path = action.get_accel_path() gtk.accel_map_change_entry(path, 0, 0, True) return ui_id
def _setup_gtk(self): from gi.repository import Gtk, Gdk from kiwi.environ import environ from stoqlib.lib.template import render_template_string # Total madness to make sure we can draw treeview lines, # this affects the GtkTreeView::grid-line-pattern style property # # Two bytes are sent in, see gtk_tree_view_set_grid_lines in gtktreeview.c # Byte 1 should be as high as possible, gtk+ 0x7F appears to be # the highest allowed for Gtk+ 2.22 while 0xFF worked in # earlier versions # Byte 2 should ideally be allowed to be 0, but neither C nor Python # allows that. # data = environ.get_resource_string("stoq", "misc", "stoq.css") data = render_template_string(data) style_provider = Gtk.CssProvider() style_provider.load_from_data(data) Gtk.StyleContext.add_provider_for_screen( Gdk.Screen.get_default(), style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) settings = Gtk.Settings.get_default() settings.props.gtk_button_images = True from stoqlib.lib.environment import is_developer_mode if is_developer_mode(): # Install a Control-Q handler that forcefully exits # the program without saving any kind of state def event_handler(event): state = event.get_state() if isinstance(state, tuple): state = state[1] if (event.type == Gdk.EventType.KEY_PRESS and state & Gdk.ModifierType.CONTROL_MASK and event.keyval == Gdk.KEY_q): os._exit(0) Gtk.main_do_event(event) Gdk.event_handler_set(event_handler)
def _setup_gtk(self): import gtk from kiwi.environ import environ gtk.gdk.threads_init() # Total madness to make sure we can draw treeview lines, # this affects the GtkTreeView::grid-line-pattern style property # # Two bytes are sent in, see gtk_tree_view_set_grid_lines in gtktreeview.c # Byte 1 should be as high as possible, gtk+ 0x7F appears to be # the highest allowed for Gtk+ 2.22 while 0xFF worked in # earlier versions # Byte 2 should ideally be allowed to be 0, but neither C nor Python # allows that. # data = environ.get_resource_string("stoq", "misc", "stoq.gtkrc") data = data.replace('\\x7f\\x01', '\x7f\x01') gtk.rc_parse_string(data) # Creating a button as a temporary workaround for bug # https://bugzilla.gnome.org/show_bug.cgi?id=632538, until gtk 3.0 gtk.Button() settings = gtk.settings_get_default() settings.props.gtk_button_images = True from stoqlib.lib.environment import is_developer_mode if is_developer_mode() and gtk.gtk_version[0] == 2: from gtk import gdk # Install a Control-Q handler that forcefully exits # the program without saving any kind of state def event_handler(event): if (event.type == gdk.KEY_PRESS and event.state & gdk.CONTROL_MASK and event.keyval == gtk.keysyms.q): os._exit(0) gtk.main_do_event(event) gdk.event_handler_set(event_handler)
def _setup_gtk(self): import gtk from kiwi.environ import environ # Total madness to make sure we can draw treeview lines, # this affects the GtkTreeView::grid-line-pattern style property # # Two bytes are sent in, see gtk_tree_view_set_grid_lines in gtktreeview.c # Byte 1 should be as high as possible, gtk+ 0x7F appears to be # the highest allowed for Gtk+ 2.22 while 0xFF worked in # earlier versions # Byte 2 should ideally be allowed to be 0, but neither C nor Python # allows that. # data = environ.get_resource_string("stoq", "misc", "stoq.gtkrc") data = data.replace('\\x7f\\x01', '\x7f\x01') gtk.rc_parse_string(data) # Creating a button as a temporary workaround for bug # https://bugzilla.gnome.org/show_bug.cgi?id=632538, until gtk 3.0 gtk.Button() settings = gtk.settings_get_default() settings.props.gtk_button_images = True from stoqlib.lib.environment import is_developer_mode if is_developer_mode() and gtk.gtk_version[0] == 2: from gtk import gdk # Install a Control-Q handler that forcefully exits # the program without saving any kind of state def event_handler(event): if (event.type == gdk.KEY_PRESS and event.state & gdk.CONTROL_MASK and event.keyval == gtk.keysyms.q): os._exit(0) gtk.main_do_event(event) gdk.event_handler_set(event_handler)
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()
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 stoqlib.gui.stockicons import STOQ_LAUNCHER Gtk.Window.set_default_icon_name(STOQ_LAUNCHER) if platform.system() == 'Darwin': from AppKit import NSApplication, NSData, NSImage # FIXME: This should be a 48x48 icon data = environ.get_resource_string( 'stoq', 'pixmaps', 'hicolor', '24x24', 'actions', 'stoq-launcher.png') data = NSData.alloc().initWithBytes_length_(data, len(data)) icon = NSImage.alloc().initWithData_(data) app = NSApplication.sharedApplication() app.setApplicationIconImage_(icon)
def get_resource_string(self, domain, resource, name): """ This method might be overriden by subclasses in order to use it's own resource_string function (like accessing a resource from inside an egg) """ return environ.get_resource_string(domain, resource, name)
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)