def _fetch_settings(self): font_name = self.font_button.get_font_name() settings = self.get_print_settings() settings.set('stoq-font-name', font_name) settings.to_file( os.path.join(self.config_dir, self.print_settings_name)) page_setup = self.get_default_page_setup() page_setup.to_file(os.path.join(self.config_dir, self.page_setup_name)) orientation = page_setup.get_orientation() paper_size = page_setup.get_paper_size() width = paper_size.get_width(Gtk.Unit.MM) height = paper_size.get_height(Gtk.Unit.MM) if orientation in [ Gtk.PageOrientation.LANDSCAPE, Gtk.PageOrientation.REVERSE_LANDSCAPE ]: width, height = height, width descr = Pango.FontDescription(font_name) # CSS expects fonts in pt, get_font_size() is scaled, # for screen display Pango.SCALE should be used, it looks # okay for printed media again, since we're multiplying # with 0.75 at the easyprint level as well. At some point # we should probably align them. font_size = descr.get_size() / Pango.SCALE self.print_css = render_template_string(self.PRINT_CSS_TEMPLATE, page_width=width, page_height=height, font_family=descr.get_family(), font_size=font_size)
def _fetch_settings(self): font_name = self.font_button.get_font_name() settings = self.get_print_settings() settings.set('stoq-font-name', font_name) settings.to_file(os.path.join(self.config_dir, self.print_settings_name)) page_setup = self.get_default_page_setup() page_setup.to_file(os.path.join(self.config_dir, self.page_setup_name)) orientation = page_setup.get_orientation() paper_size = page_setup.get_paper_size() width = paper_size.get_width(Gtk.Unit.MM) height = paper_size.get_height(Gtk.Unit.MM) if orientation in [Gtk.PageOrientation.LANDSCAPE, Gtk.PageOrientation.REVERSE_LANDSCAPE]: width, height = height, width descr = Pango.FontDescription(font_name) # CSS expects fonts in pt, get_font_size() is scaled, # for screen display Pango.SCALE should be used, it looks # okay for printed media again, since we're multiplying # with 0.75 at the easyprint level as well. At some point # we should probably align them. font_size = descr.get_size() / Pango.SCALE self.print_css = render_template_string( self.PRINT_CSS_TEMPLATE, page_width=width, page_height=height, font_family=descr.get_family(), font_size=font_size)
def _fetch_settings(self): page_setup = self.get_default_page_setup() orientation = page_setup.get_orientation() paper_size = page_setup.get_paper_size() width = paper_size.get_width(gtk.UNIT_MM) height = paper_size.get_height(gtk.UNIT_MM) if orientation in (gtk.PAGE_ORIENTATION_LANDSCAPE, gtk.PAGE_ORIENTATION_REVERSE_LANDSCAPE): width, height = height, width font_name = self.font_button.get_font_name() descr = pango.FontDescription(font_name) # CSS expects fonts in pt, get_font_size() is scaled, # for screen display pango.SCALE should be used, it looks # okay for printed media again, since we're multiplying # with 0.75 at the easyprint level as well. At some point # we should probably align them. font_size = descr.get_size() / pango.SCALE self.print_css = render_template_string( self.PRINT_CSS_TEMPLATE, page_width=width, page_height=height, font_family=descr.get_family(), font_size=font_size)
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 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: with open(environ.find_resource('sql', 'functions.sql')) as f: tmp_f.write(render_template_string(f.read())) tmp_f.flush() if db_settings.execute_sql(tmp_f.name) != 0: error(u'Failed to create functions')
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 = pkg_resources.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 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 _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): 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)