<commit_before># coding: utf-8
from collections import OrderedDict
from os import path
from math import pi as PI

import numpy as np

from PyQt4 import QtCore, QtGui

from Orange.widgets import widget, gui, settings
from Orange.data import Table
from orangecontrib.text.country_codes import \
    CC_EUROPE, INV_CC_EUROPE, SET_CC_EUROPE, \
    CC_WORLD, INV_CC_WORLD, \
    CC_USA, INV_CC_USA, SET_CC_USA


class Map:
    WORLD = 'world_mill_en'
    EUROPE = 'europe_mill_en'
    USA = 'us_aea_en'
    all = (('World',  WORLD),
           ('Europe', EUROPE),
           ('USA',    USA))


class OWGeoMap(widget.OWWidget):
    name = "GeoMap"
    priority = 20000
    icon = "icons/GeoMap.svg"
    inputs = [("Data", Table, "on_data")]
    outputs = [('Data', Table)]

    want_main_area = False

    selected_attr = settings.Setting(0)
    selected_map = settings.Setting(0)
    regions = settings.Setting([])

    def __init__(self):
        super().__init__()
        self._create_layout()

    @QtCore.pyqtSlot(str, result=str)
    def region_selected(self, regions):
        """Called from JavaScript"""
        if not regions:
            return self.send('Data', None)
        self.regions = regions.split(',')
        from Orange.data.filter import FilterStringList
        # TODO, FIXME: make this work for discrete attrs also
        filter = FilterStringList(self.metas[self.selected_attr], self.regions)
        self.send('Data', self.data._filter_values(filter))

    def _create_layout(self):
        box = gui.widgetBox(self.controlArea,
                            orientation='horizontal')
        self.attr_combo = gui.comboBox(box, self, 'selected_attr',
                                       orientation='horizontal',
                                       label='Region attribute:',
                                       callback=self.on_attr_change)
        self.map_combo = gui.comboBox(box, self, 'selected_map',
                                      orientation='horizontal',
                                      label='Map type:',
                                      callback=self.on_map_change,
                                      items=Map.all)
        hexpand = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
                                    QtGui.QSizePolicy.Fixed)
        self.attr_combo.setSizePolicy(hexpand)
        self.map_combo.setSizePolicy(hexpand)
        html = '''
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
html, body, #map {margin:0px;padding:0px;width:100%;height:100%;}
</style>
<link  href="resources/jquery-jvectormap-2.0.2.css" rel="stylesheet">
</head>
<body>
<div id="map"></div>
</body>
</html>'''
        self.webview = gui.WebviewWidget(self.controlArea, self, debug=True)
        self.webview.setHtml(html, 'file://{}/'.format(path.dirname(__file__)))
        for script in ('jquery-2.1.4.min.js',
                       'jquery-jvectormap-2.0.2.min.js',
                       'jquery-jvectormap-world-mill-en.js',
                       'jquery-jvectormap-europe-mill-en.js',
                       'jquery-jvectormap-us-aea-en.js',
                       'geomap-script.js'):
            self.webview.evalJS(open(path.join(path.dirname(__file__), 'resources', script), encoding='utf-8').read())
        self.webview.evalJS('REGIONS = {};'.format({Map.WORLD: CC_WORLD,
                                                    Map.EUROPE: CC_EUROPE,
                                                    Map.USA: CC_USA}))<commit_msg>OWGeoMap: fixes #4 where local CSS would fail to load<commit_after># coding: utf-8
from collections import OrderedDict
from os import path
from math import pi as PI

import numpy as np

from PyQt4 import QtCore, QtGui

from Orange.widgets import widget, gui, settings
from Orange.data import Table
from orangecontrib.text.country_codes import \
    CC_EUROPE, INV_CC_EUROPE, SET_CC_EUROPE, \
    CC_WORLD, INV_CC_WORLD, \
    CC_USA, INV_CC_USA, SET_CC_USA


class Map:
    WORLD = 'world_mill_en'
    EUROPE = 'europe_mill_en'
    USA = 'us_aea_en'
    all = (('World',  WORLD),
           ('Europe', EUROPE),
           ('USA',    USA))


class OWGeoMap(widget.OWWidget):
    name = "GeoMap"
    priority = 20000
    icon = "icons/GeoMap.svg"
    inputs = [("Data", Table, "on_data")]
    outputs = [('Data', Table)]

    want_main_area = False

    selected_attr = settings.Setting(0)
    selected_map = settings.Setting(0)
    regions = settings.Setting([])

    def __init__(self):
        super().__init__()
        self._create_layout()

    @QtCore.pyqtSlot(str, result=str)
    def region_selected(self, regions):
        """Called from JavaScript"""
        if not regions:
            return self.send('Data', None)
        self.regions = regions.split(',')
        from Orange.data.filter import FilterStringList
        # TODO, FIXME: make this work for discrete attrs also
        filter = FilterStringList(self.metas[self.selected_attr], self.regions)
        self.send('Data', self.data._filter_values(filter))

    def _create_layout(self):
        box = gui.widgetBox(self.controlArea,
                            orientation='horizontal')
        self.attr_combo = gui.comboBox(box, self, 'selected_attr',
                                       orientation='horizontal',
                                       label='Region attribute:',
                                       callback=self.on_attr_change)
        self.map_combo = gui.comboBox(box, self, 'selected_map',
                                      orientation='horizontal',
                                      label='Map type:',
                                      callback=self.on_map_change,
                                      items=Map.all)
        hexpand = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding,
                                    QtGui.QSizePolicy.Fixed)
        self.attr_combo.setSizePolicy(hexpand)
        self.map_combo.setSizePolicy(hexpand)
        html = '''
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<base href="file://{}/"/>
<style>
html, body, #map {{margin:0px;padding:0px;width:100%;height:100%;}}
</style>
<link  href="resources/jquery-jvectormap-2.0.2.css" rel="stylesheet">
</head>
<body>
<div id="map"></div>
</body>
</html>'''.format(path.abspath(path.dirname(__file__)))
        self.webview = gui.WebviewWidget(self.controlArea, self, debug=True)
        self.webview.setHtml(html)
        for script in ('jquery-2.1.4.min.js',
                       'jquery-jvectormap-2.0.2.min.js',
                       'jquery-jvectormap-world-mill-en.js',
                       'jquery-jvectormap-europe-mill-en.js',
                       'jquery-jvectormap-us-aea-en.js',
                       'geomap-script.js'):
            self.webview.evalJS(open(path.join(path.dirname(__file__), 'resources', script), encoding='utf-8').read())
        self.webview.evalJS('REGIONS = {};'.format({Map.WORLD: CC_WORLD,
                                                    Map.EUROPE: CC_EUROPE,
                                                    Map.USA: CC_USA}))
{'fraction_non_alphanumeric': 0.12440056417489422, 'fraction_numerical': 0.008039492242595205, 'mean_word_length': 1.970674486803519, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 30, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3384430', 'n_tokens_mistral': 2240, 'n_tokens_neox': 2135, 'n_words': 405}