Exemplo n.º 1
0
    def add_var(self, source = 'input'):
        '''
        Adds a variable to the margins

        Parameters
        ----------
        source : str, default to 'free'
                 Can be 'free' (default), 'input' or 'output' according to the variable
        '''

#        TODO: fix this lists      = {'input': self.input_vars_list, 'output': self.output_vars_list, 'free': self.free_vars_list}

        lists      = {'input': self.input_vars_list}

        variables_list = lists[source]
        varnames = self.get_name_label_dict(variables_list) # {varname: varlabel}

        varlabel, ok = QInputDialog.getItem(self.parent(), "Ajouter une variable", "Nom de la variable",
                                           sorted(varnames.keys()))

        insertion = ok and (varlabel in sorted(varnames.keys()))
        if insertion:
            varname = varnames[varlabel]
            datatable_name = self.get_var_datatable(varname)
            target = None
            if source=='input' and self.input_margins_df:
                index = self.input_margins_df.index
                indices = [ (var, mod)  for (var, mod) in index if var==varname ]
                target_df = (self.input_margins_df['target'][indices]).reset_index()
                target = dict(zip(target_df['mod'] ,target_df['target']))
            else:
                if datatable_name =='output_table':
                    varcol = self.output_table.column_by_name.get(varname)
                elif datatable_name =='inputs':
                    varcol = self.inputs.column_by_name.get(varname)

                if varcol.__class__ not in MODCOLS:
                        val, ok = QInputDialog.getDouble(self.parent(), "Valeur de la  marge", unicode(varlabel) + "  (millions d'euros)")
                        if ok:
                            target = {str(varname): val*1e6}
                else:
                    if datatable_name =='output_table':
                        unique_values = unique(self.output_table.get_value(varname, self.entity))
                    elif datatable_name =='inputs':
                        unique_values = unique(self.inputs.get_value(varname, self.entity))
                    target = {}

                    for mod in unique_values:
                        val, ok = QInputDialog.getDouble(self.parent(), "Valeur de la  marge", unicode(varlabel) + u" pour la modalité " + str(mod) )
                        if ok:
                            target[mod] = val
                        else:
                            return

            if target:
                self.calibration.add_var2(varname, target = target, source=source)
                self.param_or_margins_changed()
Exemplo n.º 2
0
    def add_var(self, source = 'input'):
        '''
        Adds a variable to the margins

        Parameters
        ----------
        source : str, default to 'free'
                 Can be 'free' (default), 'input' or 'output' according to the variable
        '''

#        TODO: fix this lists      = {'input': self.input_vars_list, 'output': self.output_vars_list, 'free': self.free_vars_list}

        lists      = {'input': self.input_vars_list}

        variables_list = lists[source]
        varnames = self.get_name_label_dict(variables_list) # {varname: varlabel}

        varlabel, ok = QInputDialog.getItem(self.parent(), "Ajouter une variable", "Nom de la variable",
                                           sorted(varnames.keys()))

        insertion = ok and (varlabel in sorted(varnames.keys()))
        if insertion:
            varname = varnames[varlabel]
            datatable_name = self.get_var_datatable(varname)
            target = None
            if source=='input' and self.input_margins_df:
                index = self.input_margins_df.index
                indices = [ (var, mod)  for (var, mod) in index if var==varname ]
                target_df = (self.input_margins_df['target'][indices]).reset_index()
                target = dict(zip(target_df['mod'] ,target_df['target']))
            else:
                if datatable_name =='output_table':
                    varcol = self.output_table.column_by_name.get(varname)
                elif datatable_name =='inputs':
                    varcol = self.inputs.column_by_name.get(varname)

                if varcol.__class__ not in MODCOLS:
                        val, ok = QInputDialog.getDouble(self.parent(), "Valeur de la  marge", unicode(varlabel) + "  (millions d'euros)")
                        if ok:
                            target = {str(varname): val*1e6}
                else:
                    if datatable_name =='output_table':
                        unique_values = unique(self.output_table.get_value(varname, self.entity))
                    elif datatable_name =='inputs':
                        unique_values = unique(self.inputs.get_value(varname, self.entity))
                    target = {}

                    for mod in unique_values:
                        val, ok = QInputDialog.getDouble(self.parent(), "Valeur de la  marge", unicode(varlabel) + u" pour la modalité " + str(mod) )
                        if ok:
                            target[mod] = val
                        else:
                            return

            if target:
                self.calibration.add_var2(varname, target = target, source=source)
                self.param_or_margins_changed()
Exemplo n.º 3
0
 def onChangeLineWidth(self):
     msg = self.tr('Line Width:')
     value, ok = QInputDialog.getDouble(self, self.tr('Input Dialog'), msg, self.lineWidth, 0)
     if ok:
         self.lineWidth = value
         self.line.set_linewidth(self.lineWidth)
         self.canvas.draw()
Exemplo n.º 4
0
 def actionTimeShiftPhotos(self):
     """
     This method will be triggered when a user chooses the "Time Shift Photos"
     option from the action menu.
     """
     dialogtxt = "Warning: Only use this if you know what you're doing."
     hours, ok = QInputDialog.getDouble(self,
                                        'Offset in Hours',
                                        dialogtxt,
                                        decimals=4)
     if ok:
         try:
             tdelta = td(hours=float(hours))
             conf_msg = "Are you sure you want to shift the timestamp on your \
                         photos by %f hours?" % float(hours)
             reply = QMessageBox.warning(None, "Confirm", conf_msg,
                                         QMessageBox.Yes, QMessageBox.No)
             if reply == QMessageBox.Yes:
                 self.timeShiftPhotos(tdelta)
                 result_str = "Great Success: photos time shifted."
                 self.statusBar().showMessage(result_str, 8000)
                 return True
             else:
                 return False
         except ValueError:
             msg = QMessageBox()
             msg.setText(
                 "You must enter a float or integer value. Try again.")
             msg.setText("You lose")
             msg._exec()
             return False
Exemplo n.º 5
0
 def _getValue(self, title, label, valueType=QVariant.String, defaultValue='', minValue=0, maxValue=0, decimals=0):
     if valueType == QVariant.Double:
         return QInputDialog.getDouble(None, title, label, defaultValue, minValue, maxValue, decimals)
     elif valueType == QVariant.Int:
         return QInputDialog.getInt(None, title, label, defaultValue, minValue, maxValue)
     else:
         return QInputDialog.getText(None, title, label, text=defaultValue)
Exemplo n.º 6
0
 def onChangeLineWidth(self):
     msg = self.tr('Line Width:')
     value, ok = QInputDialog.getDouble(self, self.tr('Input Dialog'), msg, self.lineWidth, 0)
     if ok:
         self.lineWidth = value
         self.line.set_linewidth(self.lineWidth)
         self.canvas.draw()
Exemplo n.º 7
0
 def _getValue(self, title, label, valueType=QVariant.String, defaultValue='', minValue=0, maxValue=0, decimals=0):
     if valueType == QVariant.Double:
         return QInputDialog.getDouble(None, title, label, defaultValue, minValue, maxValue, decimals)
     elif valueType == QVariant.Int:
         return QInputDialog.getInt(None, title, label, defaultValue, minValue, maxValue)
     else:
         return QInputDialog.getText(None, title, label, text=defaultValue)
Exemplo n.º 8
0
 def actionTimeShiftPhotos(self):
     """
     This method will be triggered when a user chooses the "Time Shift Photos"
     option from the action menu.
     """
     dialogtxt = "Warning: Only use this if you know what you're doing."
     hours, ok = QInputDialog.getDouble(self,'Offset in Hours', dialogtxt,decimals=4)
     if ok:
         try:
             tdelta = td(hours=float(hours))
             conf_msg = "Are you sure you want to shift the timestamp on your \
                         photos by %f hours?" % float(hours)
             reply = QMessageBox.warning(None,"Confirm",conf_msg,QMessageBox.Yes,QMessageBox.No)
             if reply==QMessageBox.Yes:
                 self.timeShiftPhotos(tdelta)
                 result_str = "Great Success: photos time shifted."
                 self.statusBar().showMessage( result_str, 8000)
                 return True
             else:
                 return False
         except ValueError:
             msg = QMessageBox()
             msg.setText("You must enter a float or integer value. Try again.")
             msg.setText("You lose")
             msg._exec()
             return False
Exemplo n.º 9
0
def ts_change_width():
    global ts_line_width
    value, accepted = QInputDialog.getDouble(mw, "Touch Screen",
                                             "Enter the width:", ts_line_width)
    if accepted:
        ts_line_width = value
        execute_js("line_width = '" + str(ts_line_width) + "'")
        ts_refresh()
 def onEditLevel(self):
     ids = self.findSelectedItemIds()
     if len(ids) > 1:
         QMessageBox.warning(self, self.tr('Warning'), self.tr('Only one item can be edited at a time'))
     elif len(ids) < 1:
         pass
     else:
         selectedSound = ids[0]
         msg = self.tr('RMS Level:')
         text, ok = QInputDialog.getDouble(self, self.tr('Input Dialog'), msg, self.wavsList[selectedSound]['level'])
         if ok:
             self.wavsTableWidget.item(self.wavsList[selectedSound]['qid'].row(), 2).setText(self.currLocale.toString(text))
             self.wavsList[selectedSound]['level'] = text
Exemplo n.º 11
0
 def new_city_clicked(self):
     dialog = QInputDialog(self)
     city_name = QInputDialog.getText(dialog, "Имя города",
                                      "Введите имя города:")
     if not city_name[1] and city_name[0] == '':
         return
     ill_percent = QInputDialog.getDouble(dialog, "Заболеваемость",
                                          "Введите процент заболевших:", 0,
                                          0, 100, 2)
     if not ill_percent[1] and ill_percent[0] == '':
         return
     town = Town(city_name[0], 1000000, 0, 0)
     state = TownInfectionState(town)
     ill_percent = ill_percent[0] * 0.01
     state.ill_population = (1000000 * ill_percent, 0, 0, 0)
     state.vaccinated_population = (1000000 * (1 - ill_percent), 0, 0, 0)
     town.infection_state = state
     self.model.towns.append(town)
Exemplo n.º 12
0
 def onEditMaxLevel(self):
     ids = self.findSelectedItemIds()
     if len(ids) > 1:
         QMessageBox.warning(
             self, self.tr('Warning'),
             self.tr('Only one item can be edited at a time'))
     elif len(ids) < 1:
         pass
     else:
         selectedSound = ids[0]
         msg = self.tr('Level:')
         text, ok = QInputDialog.getDouble(
             self, self.tr('Input Dialog'), msg,
             self.phonesList[selectedSound]['maxLevel'])
         if ok:
             self.phonesTableWidget.item(
                 self.phonesList[selectedSound]['qid'].row(),
                 1).setText(self.currLocale.toString(text))
             self.phonesList[selectedSound]['maxLevel'] = text
Exemplo n.º 13
0
 def onChangeSpinesLineWidth(self):
     msg = self.tr('Spines Line Width:')
     value, ok = QInputDialog.getDouble(self, self.tr('Input Dialog'), msg, self.spinesLineWidth, 0)
     if ok:
         self.spinesLineWidth = value
         self.setBaseFigureProperties()
Exemplo n.º 14
0
 def onChangeMinorTickWidth(self):
     msg = self.tr('Tick Width:')
     value, ok = QInputDialog.getDouble(self, self.tr('Input Dialog'), msg, self.minorTickWidth, 0)
     if ok:
         self.minorTickWidth = value
         self.setBaseFigureProperties()
Exemplo n.º 15
0
 def onEditPhones(self):
     currCal = self.getPhonesCal()
     val, ok = QInputDialog.getDouble(self, self.tr('Phones Calibration'), self.tr('Phones Max. Level'), currCal)
     self.writePhonesCal(val)
     self.maxLevel = val
Exemplo n.º 16
0
 def onChangeSpinesLineWidth(self):
     msg = self.tr('Spines Line Width:')
     value, ok = QInputDialog.getDouble(self, self.tr('Input Dialog'), msg, self.spinesLineWidth, 0)
     if ok:
         self.spinesLineWidth = value
         self.setBaseFigureProperties()
Exemplo n.º 17
0
 def onChangeMinorTickWidth(self):
     msg = self.tr('Tick Width:')
     value, ok = QInputDialog.getDouble(self, self.tr('Input Dialog'), msg, self.minorTickWidth, 0)
     if ok:
         self.minorTickWidth = value
         self.setBaseFigureProperties()