Exemplo n.º 1
0
def install_locally_required_files():
    source_share_folder = resources.get_data_file_path()
    if not source_share_folder:
        logger.warning(
            "Cannot find repository required for installation of icons and gtksourceview styles"
        )

    for folder in ["gtksourceview-3.0", "icons"]:
        try:
            logger.info("Copying '{}' files...".format(folder))
            copy_tree(join(source_share_folder, folder),
                      join(resources.xdg_user_data_folder, folder),
                      update=1)
        except IOError as e:
            logger.error("Could not copy '{}' files: {}".format(
                folder, str(e)))

    if is_custom_design_enabled():
        try:
            logger.info(
                "Copying custom design files '{}' files...".format(folder))
            copy_tree(
                global_design_config.get_config_value("SOURCE_VIEW_FOLDER"),
                join(resources.xdg_user_data_folder, "gtksourceview-3.0"),
                update=1)
            copy_tree(global_design_config.get_config_value("ICONS_FOLDER"),
                      join(resources.xdg_user_data_folder, "icons"),
                      update=1)
        except IOError as e:
            logger.error("Could not copy '{}' files: {}".format(
                folder, str(e)))
Exemplo n.º 2
0
    def configure_gtk(self):
        theme_path = self._get_theme_path()
        if not theme_path:
            raise ValueError("GTK theme 'RAFCON' does not exist")

        if is_custom_design_enabled():
            theme_path = self._get_custom_theme_path()

        theme_name = "RAFCON"
        dark_theme = self.get_config_value('THEME_DARK_VARIANT', True)

        # GTK_DATA_PREFIX must point to a path that contains share/themes/THEME_NAME
        gtk_data_prefix = os.path.dirname(os.path.dirname(os.path.dirname(theme_path)))
        os.environ['GTK_DATA_PREFIX'] = gtk_data_prefix
        os.environ['GTK_THEME'] = "{}{}".format(theme_name, ":dark" if dark_theme else "")

        # The env vars GTK_DATA_PREFIX and GTK_THEME must be set before Gtk is imported first to prevent GTK warnings
        # from other themes
        try:
            from gi.repository import Gtk
            settings = Gtk.Settings.get_default()
            if settings:
                settings.set_property("gtk-theme-name", theme_name)
                settings.set_property("gtk-enable-animations", True)
                settings.set_property("gtk-application-prefer-dark-theme", dark_theme)

            Gtk.Window.set_default_icon_name("rafcon" if dark_theme else "rafcon-light")
        except ImportError:
            pass
Exemplo n.º 3
0
    def new_buffer(self):
        style_scheme_manager = GtkSource.StyleSchemeManager()
        b = GtkSource.Buffer()
        b.set_language(self.language_manager.get_language(self.language))
        b.set_highlight_syntax(True)

        user_editor_style = global_gui_config.get_config_value(
            self.editor_style, "classic")
        if user_editor_style.startswith("rafcon"):
            user_editor_style = "rafcon"
            dark_theme = global_gui_config.get_config_value(
                'THEME_DARK_VARIANT', True)
            if dark_theme:
                user_editor_style = "rafcon-dark"
        if is_custom_design_enabled():
            user_editor_style = global_design_config.get_config_value(
                "SOURCE_VIEW_THEME")
        scheme = style_scheme_manager.get_scheme(user_editor_style)
        if scheme:
            self.style_scheme = scheme
        else:
            logger.debug(
                "The editor style '{}' is not supported. Using the default 'classic'"
                .format(user_editor_style))
            self.style_scheme = style_scheme_manager.get_scheme('classic')
        b.set_style_scheme(self.style_scheme)
        return b
Exemplo n.º 4
0
 def set_text(self, text):
     if is_custom_design_enabled() and not global_design_config.get_config_value("SPLASH_SCREEN_SHOW_TEXT", True):
         return
     logger.info(text)
     self.label.set_text(text)
     while Gtk.events_pending():
         Gtk.main_iteration_do(False)
     return
Exemplo n.º 5
0
 def __init__(self, logger_object=None):
     super(GuiConfig, self).__init__(DEFAULT_CONFIG, logger_object)
     if self.get_config_value("TYPE") != "GUI_CONFIG":
         raise ConfigError("Type should be GUI_CONFIG for GUI configuration. "
                           "Please add \"TYPE: GUI_CONFIG\" to your gui_config.yaml file.")
     if not is_custom_design_enabled():
         self.configure_gtk()
         self.configure_colors()
Exemplo n.º 6
0
    def get_images(self):
        images = list()
        if is_custom_design_enabled():
            splash_screen_path = global_design_config.get_config_value("SPLASH_SCREEN_FOLDER")
            for image_filename in os.listdir(splash_screen_path):
                images.append(os.path.join(splash_screen_path, image_filename))
        else:
            for image_filename in resource_listdir(rafcon.gui.__name__, os.path.join("assets", "splashscreens")):
                images.append(resource_filename(rafcon.gui.__name__, os.path.join(
                    "assets", "splashscreens", image_filename)))

        return images
Exemplo n.º 7
0
 def load_image(self, image_path):
     if image_path:
         horizontal_spacing = 50
         if is_custom_design_enabled():
             horizontal_spacing = global_design_config.get_config_value("SPLASH_SCREEN_HORIZONTAL_SPACING")
         pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_size(image_path, self.get_size()[0] - horizontal_spacing,
                                                         self.get_size()[1] - horizontal_spacing)
         self.image.set_from_pixbuf(pixbuf)
         while Gtk.events_pending():
             Gtk.main_iteration_do(False)
     else:
         logger.debug("Splash screen image path is None")
Exemplo n.º 8
0
    def __init__(self, width=530, height=350, contains_image=False):
        # init Gtk.Window with type popup
        super(SplashScreen, self).__init__(type=Gtk.WindowType.POPUP)

        # index for the image rotator
        self.image_index = 0

        # Set the title to rafcon so it is detectable in taskbars
        # set width and height to parameter values and position the window in the center
        self.set_title('RAFCON')
        self.set_default_size(width, height)
        self.set_position(Gtk.WindowPosition.CENTER)

        main_vbox = Gtk.Box.new(Gtk.Orientation.VERTICAL, 0)
        self.add(main_vbox)
        self.image = Gtk.Image()
        # If an img path was defined, create a gtk img and fill it from a pixelbuffer which is created from the
        # set file path
        if contains_image:
            main_vbox.pack_start(self.image, True, True, 0)

        if is_custom_design_enabled() and not global_design_config.get_config_value("SPLASH_SCREEN_SHOW_TEXT", True):
            pass
        else:
            # add label to display text, the text can be changed by the text() method.
            # Align it in the middle of the gtk window
            self.label = Gtk.Label(label="")
            self.label.set_xalign(0.5)
            self.label.set_yalign(0.5)
            main_vbox.pack_start(self.label, False, True, 10)
            main_vbox.set_spacing(0)
            label_height = 40
            if is_custom_design_enabled():
                label_height = global_design_config.get_config_value("SPLASH_SCREEN_LABEL_HEIGHT")
            self.label.set_size_request(-1, label_height)

        if not os.getenv("RAFCON_START_MINIMIZED", False):
            self.show_all()
Exemplo n.º 9
0
def install_fonts(restart=False):
    # do not import from rafcon.gui.constants, as this script can be used standalone
    font_names_to_be_installed = [
        "SourceSansPro", "FontAwesome5Free", "RAFCON"
    ]

    custom_fonts = list(
    )  # support a list in case we also support secondary or tertiary fonts
    if is_custom_design_enabled():
        custom_fonts.append(
            global_design_config.get_config_value("PRIMARY_FONT"))
    font_names_to_be_installed += custom_fonts

    user_otf_fonts_folder = join(resources.xdg_user_data_folder, "fonts")

    font_installed = False
    try:
        for font_name in font_names_to_be_installed:
            # A font is a folder one or more font faces
            rel_font_folder = join("type1", font_name)
            fonts_folder = resources.get_data_file_path(
                "fonts", rel_font_folder)
            if not os.path.exists(
                    fonts_folder):  # this is the case for a custom font
                fonts_folder = join(
                    global_design_config.get_config_value("FONTS_FOLDER"),
                    rel_font_folder)
                assert os.path.exists(
                    fonts_folder), "Custom font path does not exist"
            num_faces_to_be_installed = len([
                name for name in os.listdir(fonts_folder)
                if name.endswith(".otf")
            ])
            num_faces_installed = installed_font_faces_for_font(font_name)
            if num_faces_to_be_installed <= num_faces_installed:
                logger.debug("Font '{0}' already installed".format(font_name))
                continue
            specific_user_otf_fonts_folder = join(user_otf_fonts_folder,
                                                  rel_font_folder)
            logger.info("Installing font '{0}' to {1}".format(
                font_name, specific_user_otf_fonts_folder))
            copy_tree(fonts_folder, specific_user_otf_fonts_folder, update=1)
            font_installed = True
    except IOError as e:
        logger.error("Could not install fonts, IOError: {}".format(e))
        return

    if font_installed:
        logger.info("Running font detection ...")
        if not update_font_cache(user_otf_fonts_folder):
            logger.warning(
                "Could not run font detection using 'fc-cache'. RAFCON might not find the correct fonts."
            )
        if restart:
            python = sys.executable
            environ = dict(**os.environ)
            # Passing this to the new RAFCON environment will prevent further checks and thus restarts
            environ["RAFCON_CHECK_INSTALLATION"] = "False"
            args_and_env = list(sys.argv)
            args_and_env.append(environ)
            logger.info("Restarting RAFCON ...")
            os.execle(python, python, *args_and_env)
Exemplo n.º 10
0
    def configure_colors(self):
        # Provide black as fallback color if theme is not found instead of crashing
        self.colors = defaultdict(lambda: "#FFFFFF")
        try:
            from gi.repository import Gdk
            self.gtk_colors = defaultdict(lambda: Gdk.RGBA(0, 0, 0).to_color())
        except ImportError:
            self.gtk_colors = defaultdict(lambda: None)
            return

        dark_theme = self.get_config_value('THEME_DARK_VARIANT', True)
        css_filename = "gtk-dark.css" if dark_theme else "gtk.css"
        # Get colors from GTKrc file
        theme_path = self._get_theme_path()

        if is_custom_design_enabled():
            theme_path = self._get_custom_theme_path()

        css_file_path = os.path.join(theme_path, "gtk-3.0", css_filename)
        if not os.path.isfile(css_file_path):
            raise ValueError("GTK theme does not exist: {}".format(str(css_file_path)))

        with open(css_file_path) as f:
            lines = f.readlines()

        for line in lines:
            match = re.match("\s*@define-color (\w*) (#[\w]{3,6})", line)
            if match:
                # css colors are mapped to capital-case color names
                # these colors can then be used in the colors definition file for the gaphas colors (e.g., colors.json)
                color_name = match.group(1).upper()
                color_code = match.group(2)
                self.colors[color_name] = color_code
                gtk_color = Gdk.RGBA()
                if gtk_color.parse(color_code):
                    self.gtk_colors[color_name] = gtk_color.to_color()
                else:
                    self.logger.warning("Could not parse color with name '{}' and code '{}'".format(color_name,
                                                                                                    color_code))

        # Get color definitions
        colors_filename = "colors-dark.json" if dark_theme else "colors.json"
        color_file_path = os.path.join(theme_path, colors_filename)
        try:
            colors = storage_utils.load_objects_from_json(color_file_path)
        except IOError:
            raise ValueError("No color definitions found")

        for color_name, color_code in colors.items():
            # replace unicode strings with str strings
            color_name = str(color_name)
            color_code = str(color_code)
            gtk_color = Gdk.RGBA()
            if color_code.startswith("#"):
                if gtk_color.parse(color_code):
                    color = gtk_color.to_color()
                else:
                    self.logger.warning("Could not parse color with name '{}' and code '{}'".format(color_name,
                                                                                                    color_code))
                    continue
            elif color_code in self.colors:
                color = self.gtk_colors[color_code]
                color_code = self.gtk_colors[color_code]
            else:
                self.logger.warning("Undefined color alias '{}' for color name '{}'".format(color_code, color_name))
                continue
            self.gtk_colors[color_name] = color
            self.colors[color_name] = color_code
Exemplo n.º 11
0
from collections import OrderedDict

from gi.repository import Gdk

from rafcon.utils.constants import RAFCON_TEMP_PATH_BASE
from rafcon.gui.design_config import global_design_config, is_custom_design_enabled


def get_glade_path(glade_file):
    from os import path
    mvc_dir = path.dirname(path.dirname(__file__))
    return path.join(mvc_dir, "glade", glade_file)


INTERFACE_FONT = "Source Sans Pro"
if is_custom_design_enabled():
    # this statement has no effect if the design_config is loaded after this module is imported the first time
    INTERFACE_FONT = global_design_config.get_config_value("PRIMARY_FONT")

ICON_FONT_FONTAWESOME = "FontAwesome5Free"
ICON_FONT_RAFCON = "RAFCON"
FONTS = [INTERFACE_FONT, ICON_FONT_FONTAWESOME, ICON_FONT_RAFCON]

FONT_SIZE_SMALL = "9"
FONT_SIZE_NORMAL = "10"
FONT_SIZE_BIG = "13"
FONT_SIZE_HUGE = "17"

LETTER_SPACING_NONE = "0"
LETTER_SPACING_05PT = "512"
LETTER_SPACING_075PT = "756"