def __init__(self, parent=None): super(InequalityWidget, self).__init__(parent) self.setStyleSheet(OfSs.dock_style) # Create geometry self.dockWidgetContents = QWidget() widget_list = [] self.lorenzWidget = MatplotlibWidget( self.dockWidgetContents, title=_("Lorenz curve"), # 'Courbe de Lorenz', xlabel=_('Population'), ylabel=_('Variable'), hold=True, xlim=[0, 1], ylim=[0, 1]) widget_list.append(self.lorenzWidget) self.ineqFrameWidget = DataFrameViewWidget(self.dockWidgetContents) widget_list.append(self.ineqFrameWidget) verticalLayout = QVBoxLayout(self.dockWidgetContents) for widget in widget_list: verticalLayout.addWidget(widget) self.setLayout(verticalLayout) # Initialize attributes self.parent = parent self.inequality = Inequality()
def __init__(self, parent = None): super(InequalityWidget, self).__init__(parent) self.setStyleSheet(OfSs.dock_style) # Create geometry self.dockWidgetContents = QWidget() widget_list = [] self.lorenzWidget = MatplotlibWidget(self.dockWidgetContents, title= _("Lorenz curve"), # 'Courbe de Lorenz', xlabel= _('Population'), ylabel= _('Variable'), hold=True, xlim = [0,1], ylim = [0,1]) widget_list.append(self.lorenzWidget) self.ineqFrameWidget = DataFrameViewWidget(self.dockWidgetContents) widget_list.append(self.ineqFrameWidget) verticalLayout = QVBoxLayout(self.dockWidgetContents) for widget in widget_list: verticalLayout.addWidget(widget) self.setLayout(verticalLayout) # Initialize attributes self.parent = parent self.inequality = Inequality()
class InequalityWidget(OpenfiscaPluginWidget): """ Distribution Widget """ CONF_SECTION = 'inequality' CONFIGWIDGET_CLASS = InequalityConfigPage LOCATION = Qt.LeftDockWidgetArea FEATURES = QDockWidget.DockWidgetClosable | \ QDockWidget.DockWidgetFloatable | \ QDockWidget.DockWidgetMovable DISABLE_ACTIONS_WHEN_HIDDEN = False def __init__(self, parent=None): super(InequalityWidget, self).__init__(parent) self.setStyleSheet(OfSs.dock_style) # Create geometry self.dockWidgetContents = QWidget() widget_list = [] self.lorenzWidget = MatplotlibWidget( self.dockWidgetContents, title=_("Lorenz curve"), # 'Courbe de Lorenz', xlabel=_('Population'), ylabel=_('Variable'), hold=True, xlim=[0, 1], ylim=[0, 1]) widget_list.append(self.lorenzWidget) self.ineqFrameWidget = DataFrameViewWidget(self.dockWidgetContents) widget_list.append(self.ineqFrameWidget) verticalLayout = QVBoxLayout(self.dockWidgetContents) for widget in widget_list: verticalLayout.addWidget(widget) self.setLayout(verticalLayout) # Initialize attributes self.parent = parent self.inequality = Inequality() #------ Public API --------------------------------------------- def plot(self): ''' Plots the Lorenz Curve ''' axes = self.lorenzWidget.axes axes.clear() output = self.inequality.simulation.output_table simulation = self.inequality.simulation WEIGHT = model.WEIGHT entities = ['ind', 'men'] weights = {} for entity in entities: weights[entity] = output._inputs.get_value(WEIGHT, entity) for varname, entities in self.inequality.vars.iteritems(): for entity in entities: values = output.get_value(varname, entity) x, y = lorenz(values, weights[entity]) label = varname + ' (' + entity + ') ' axes.plot(x, y, linewidth=2, label=label) axes.plot(x, x, label="") axes.legend(loc=2, prop={'size': 'medium'}) axes.set_xlim([0, 1]) axes.set_ylim([0, 1]) self.lorenzWidget.update() def set_simulation(self, simulation): ''' Set the simulation Parameters ---------- simulation : SurveySimulation the simulation object to extract the data from ''' self.inequality.set_simulation(simulation) def update_frame(self): """ Update frame """ self.inequality.compute() self.ineqFrameWidget.set_dataframe( self.inequality.inequality_dataframe) self.ineqFrameWidget.reset() def calculated(self): self.emit(SIGNAL('calculated()')) #------ OpenfiscaPluginMixin API --------------------------------------------- #------ OpenfiscaPluginWidget API --------------------------------------------- def get_plugin_title(self): """ Return plugin title Note: after some thinking, it appears that using a method is more flexible here than using a class attribute """ return _("Inequality") def get_plugin_icon(self): """ Return plugin icon (QIcon instance) Note: this is required for plugins creating a main window and for configuration dialog widgets creation """ return get_icon('OpenFisca22.png') def get_plugin_actions(self): """ Return a list of actions related to plugin Note: these actions will be enabled when plugin's dockwidget is visible and they will be disabled when it's hidden """ raise NotImplementedError def register_plugin(self): """ Register plugin in OpenFisca's main window """ self.main.add_dockwidget(self) def refresh_plugin(self): ''' Update Inequality Table ''' self.starting_long_process(_("Refreshing inequality widget ...")) self.set_simulation(self.main.survey_simulation) self.update_frame() self.plot() self.ending_long_process(_("Inequality widget refreshed")) def closing_plugin(self, cancelable=False): """ Perform actions before parent main window is closed Return True or False whether the plugin may be closed immediately or not Note: returned value is ignored if *cancelable* is False """ return True
class InequalityWidget(OpenfiscaPluginWidget): """ Distribution Widget """ CONF_SECTION = 'inequality' CONFIGWIDGET_CLASS = InequalityConfigPage LOCATION = Qt.LeftDockWidgetArea FEATURES = QDockWidget.DockWidgetClosable | \ QDockWidget.DockWidgetFloatable | \ QDockWidget.DockWidgetMovable DISABLE_ACTIONS_WHEN_HIDDEN = False def __init__(self, parent = None): super(InequalityWidget, self).__init__(parent) self.setStyleSheet(OfSs.dock_style) # Create geometry self.dockWidgetContents = QWidget() widget_list = [] self.lorenzWidget = MatplotlibWidget(self.dockWidgetContents, title= _("Lorenz curve"), # 'Courbe de Lorenz', xlabel= _('Population'), ylabel= _('Variable'), hold=True, xlim = [0,1], ylim = [0,1]) widget_list.append(self.lorenzWidget) self.ineqFrameWidget = DataFrameViewWidget(self.dockWidgetContents) widget_list.append(self.ineqFrameWidget) verticalLayout = QVBoxLayout(self.dockWidgetContents) for widget in widget_list: verticalLayout.addWidget(widget) self.setLayout(verticalLayout) # Initialize attributes self.parent = parent self.inequality = Inequality() #------ Public API --------------------------------------------- def plot(self): ''' Plots the Lorenz Curve ''' axes = self.lorenzWidget.axes axes.clear() output = self.inequality.simulation.output_table simulation = self.inequality.simulation WEIGHT = model.WEIGHT entities = ['ind', 'men'] weights = {} for entity in entities: weights[entity] = output._inputs.get_value(WEIGHT, entity) for varname, entities in self.inequality.vars.iteritems(): for entity in entities: values = output.get_value(varname, entity) x, y = lorenz(values, weights[entity]) label = varname + ' (' + entity + ') ' axes.plot(x,y, linewidth = 2, label = label) axes.plot(x,x, label ="") axes.legend(loc= 2, prop = {'size':'medium'}) axes.set_xlim([0,1]) axes.set_ylim([0,1]) self.lorenzWidget.update() def set_simulation(self, simulation): ''' Set the simulation Parameters ---------- simulation : SurveySimulation the simulation object to extract the data from ''' self.inequality.set_simulation(simulation) def update_frame(self): """ Update frame """ self.inequality.compute() self.ineqFrameWidget.set_dataframe(self.inequality.inequality_dataframe) self.ineqFrameWidget.reset() def calculated(self): self.emit(SIGNAL('calculated()')) #------ OpenfiscaPluginMixin API --------------------------------------------- #------ OpenfiscaPluginWidget API --------------------------------------------- def get_plugin_title(self): """ Return plugin title Note: after some thinking, it appears that using a method is more flexible here than using a class attribute """ return _("Inequality") def get_plugin_icon(self): """ Return plugin icon (QIcon instance) Note: this is required for plugins creating a main window and for configuration dialog widgets creation """ return get_icon('OpenFisca22.png') def get_plugin_actions(self): """ Return a list of actions related to plugin Note: these actions will be enabled when plugin's dockwidget is visible and they will be disabled when it's hidden """ raise NotImplementedError def register_plugin(self): """ Register plugin in OpenFisca's main window """ self.main.add_dockwidget(self) def refresh_plugin(self): ''' Update Inequality Table ''' self.starting_long_process(_("Refreshing inequality widget ...")) self.set_simulation(self.main.survey_simulation) self.update_frame() self.plot() self.ending_long_process(_("Inequality widget refreshed")) def closing_plugin(self, cancelable=False): """ Perform actions before parent main window is closed Return True or False whether the plugin may be closed immediately or not Note: returned value is ignored if *cancelable* is False """ return True