Beispiel #1
0
    def grant_permission(self):
        permissions = []
        if self.connect_ch.isChecked():
            permissions.append('connect')
        if self.send_ch.isChecked():
            permissions.append('send')
        if self.receive_ch.isChecked():
            permissions.append('receive')
        if self.issue_ch.isChecked():
            permissions.append('issue')
        if self.create_ch.isChecked():
            permissions.append('create')
        permissions = ','.join(permissions)
        if permissions == '':
            msg = QtWidgets.QMessageBox.critical(
                self, 'Invalid Permission!', 'Choose permission(s) to grant')
            return

        if self.yes_rbtn.isChecked():
            name = self.name_ledit.text()
            if not functions.check_name(self, self.chain, name, False):
                return
            addr = self.addr_ledit.text()
            if len(addr) < 38:
                msg = QtWidgets.QMessageBox.information(
                    self, 'Invalid Address!', 'Enter a valid address')
                return
            permissions = permissions + ',send'
        else:
            addr = self.addr_cbox.currentText()
            if addr == functions.blank:
                msg = QtWidgets.QMessageBox.information(
                    self, 'Invalid Address!', 'Choose a valid address')
                return

            for key, val in self.wallets.items():
                if val == addr:
                    addr = key
                    break

        msg = QtWidgets.QMessageBox.question(
            self, 'Confirm', 'Are you sure you want to grant "' + permissions +
            '" permission(s) to this wallet?',
            QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
        if msg == QtWidgets.QMessageBox.Yes:
            arr = ['multichain-cli', self.chain, 'grant', addr, permissions]
            data = functions.execute(self, arr)
            if data:
                if self.yes_rbtn.isChecked():
                    self.save_wallet(name, addr)
                    self.addr_ledit.clear()
                msg = QtWidgets.QMessageBox.information(
                    self, 'Successful!', 'Permissions successfully granted!')
                self.wallets = functions.fetch_from_stream(
                    self, self.chain, 'root')
                self.fill_addresses()
        else:
            return
Beispiel #2
0
def pkmn_search(app, message):
    try:
        if message.text == '/data' or message.text == '/data@Rotom3_Bot':
            app.send_message(message.chat.id, texts['error1'], parse_mode='HTML')
            return None
        pkmn = func.find_name(message.text)
        result = func.check_name(pkmn, data)

        if type(result) == str:
            app.send_message(message.chat.id, result)
            return None
        elif type(result) == list:
            best_matches(app, message, result)
            return None
        else:
            pkmn = result['pkmn']
            form = result['form']
    except AttributeError:
        pkmn = re.split('/', message.data)[1]
        form = re.split('/', message.data)[2]


    if pkmn in form:
        text = func.set_message(data[pkmn][form], reduced=True)
    else:
        base_form = re.sub('_', ' ', pkmn.title())
        name = base_form + ' (' + data[pkmn][form]['name'] + ')'
        text = func.set_message(data[pkmn][form], name, reduced=True)

    markup_list = [[
        InlineKeyboardButton(
            text='➕ Expand',
            callback_data='all_infos/'+pkmn+'/'+form
        )
    ],
    [
        InlineKeyboardButton(
            text='⚔️ Moveset',
            callback_data='moveset/'+pkmn+'/'+form
        ),
        InlineKeyboardButton(
            text='🏠 Locations',
            callback_data='locations/'+pkmn+'/'+form
        )
    ]]
    for alt_form in data[pkmn]:
        if alt_form != form:
            markup_list.append([
                InlineKeyboardButton(
                    text=data[pkmn][alt_form]['name'],
                    callback_data='basic_infos/'+pkmn+'/'+alt_form
                )
            ])
    markup = InlineKeyboardMarkup(markup_list)

    func.bot_action(app, message, text, markup)
Beispiel #3
0
def traditional_check(req):
    """
        Traditional way to do check
        import and call each functions to get result
        It takes long and complex code to do this
        It is hard to change and manage those functions
    """

    import functions

    result = functions.check_time(req.request_time, req.user_name)
    print 'check_time %s' % result
    result = functions.check_name(req.user_name)
    print 'check_name %s' % result
    result = functions.check_hash(req.request_token)
    print 'check_hash %s' % result
Beispiel #4
0
    def get_new_wallet(self):
        name = self.wallet_ledit.text()
        if not functions.check_name(self, self.chain, name):
            return

        msg = QtWidgets.QMessageBox.information(
            self, 'Confirm',
            'Are you sure you want to create a new wallet with this name?',
            QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
        if msg == QtWidgets.QMessageBox.Yes:
            arr = ['multichain-cli', self.chain, 'getnewaddress']
            data = functions.execute(self, arr)
            if data:
                addr = data.decode('utf-8').split('\n')[0]
                self.save_wallet(name, addr)
        else:
            return
Beispiel #5
0
    if settings["fps"]:
        settings["fps"] = functions.check_fps(settings, constants)

    if settings["speed"]:
        settings["speed"] = functions.check_speed(settings, constants)

    if settings["legend"]:
        settings["legend"] = functions.check_legend(settings["legend"])

    if settings["gnuplot"]:
        settings["gnuplot"] = functions.check_gnuplot(settings)

    if settings["effect"]:
        settings["effect"] = functions.check_effect(settings, constants)

    settings["name"] = functions.check_name(settings["name"],
                                            constants["name"])

    if settings["max_val"] not in ["max"] and settings["min_val"] not in [
            "min"
    ] and settings["max_val"] <= settings["min_val"]:
        functions.soft_error(
            "WARNING: 'max_val' has to be bigger than 'min_val",
            settings["verbose"], 1, settings["ignore_error"])
        functions.verbose(" - Using default values.", settings["verbose"], 1)
        settings["max_val"] = constants["max_val"]
        settings["min_val"] = constants["min_val"]

    if settings["max_time"] not in ["max"] and settings["min_time"] not in [
            "min"
    ] and settings["max_time"] <= settings["min_time"]:
        functions.soft_error(
    if settings["fps"]:
        settings["fps"] = functions.check_fps(settings, constants)

    if settings["speed"]:
        settings["speed"] = functions.check_speed(settings, constants)

    if settings["legend"]:
        settings["legend"] = functions.check_legend(settings["legend"])

    if settings["gnuplot"]:
        settings["gnuplot"] = functions.check_gnuplot(settings)

    if settings["effect"]:
        settings["effect"] = functions.check_effect(settings, constants)

    settings["name"] = functions.check_name(settings["name"], constants["name"])

    if settings["max_val"] not in [ "max" ] and settings["min_val"] not in [ "min" ] and settings["max_val"] <= settings["min_val"]:
        functions.soft_error("WARNING: 'max_val' has to be bigger than 'min_val", settings["verbose"], 1, settings["ignore_error"])
        functions.verbose(" - Using default values.", settings["verbose"], 1)
        settings["max_val"] = constants["max_val"]
        settings["min_val"] = constants["min_val"]

    if settings["max_time"] not in [ "max" ] and settings["min_time"] not in [ "min" ] and settings["max_time"] <= settings["min_time"]:
        functions.soft_error("WARNING: 'max_time' has to be bigger than 'min_time", settings["verbose"], 1, settings["ignore_error"])
        functions.verbose(" - Using default values.", settings["verbose"], 1)
        settings["max_time"] = constants["max_time"]
        settings["min_val"] = constants["min_time"]

    "Loading data from files"
    data = {}
Beispiel #7
0
def cli(select: bool, new: bool, input: bool, output: bool):
    """Produces PNG maps from tiff files with QGis

    Args:
        select (bool): Select the countries to map
        new (bool): Only map products which are not already in the map folder
        input (bool):  Select input path
        output (bool):  Select output path
    """

    # Setting paths
    template_path = "templates/_qgz"
    tab_path = "csv/product_type.csv"
    tab_path2 = "csv/dimensions.csv"
    colorRamp_path = "templates/_layer_styles"

    # Selecting path of input directory
    if input:
        products_path = str(
            QFileDialog.getExistingDirectory(None, "Select Input directory"))
    else:
        products_path = "products"

    # Selecting path of ouput directory
    if output:
        export_path = str(
            QFileDialog.getExistingDirectory(None, "Select Output directory"))
    else:
        export_path = "maps"

    # Getting products to map
    products_names = [
        p for p in os.listdir(products_path) if p.endswith('.tif')
    ]

    # reading csv files
    tab = pd.read_csv(tab_path, index_col=0, header=0)
    tab2 = pd.read_csv(tab_path2, index_col=0, header=0)

    # check if name correct
    for filename in products_names:

        check = functions.check_name(filename, tab)

        if not check:
            w = QWidget()
            w.resize(400, 100)
            w.setWindowTitle('ERROR')
            vbox = QVBoxLayout(w)
            label = QLabel("Incorrect filename: " + filename)
            label.setAlignment(QtCore.Qt.AlignCenter)
            vbox.addWidget(label)
            w.show()
            sys.exit(qgs.exec_())

    # Only select new products
    if new:
        input_names = [
            p for p in os.listdir(products_path) if p.endswith('.tif')
        ]
        output_names = [
            p[:-4] + '.tif' for p in os.listdir(export_path)
            if p.endswith('.png')
        ]
        products_names = list(set(input_names).difference(output_names))

        if len(products_names) == 0:
            print('No new products to map !')

    products = [
        QgsRasterLayer(os.path.join(products_path, p), p)
        for p in products_names
    ]
    all_countries = [
        functions.get_country(filename, tab2) for filename in products_names
    ]
    countries = list(dict.fromkeys(all_countries))
    nb_countries = [all_countries.count(c) for c in countries]

    # Select countries to map
    if select:

        w = QWidget()
        w.resize(400, int(w.height() / 10))
        w.setWindowTitle('Automap - Select countries to map')

        vbox = QVBoxLayout(w)

        # Products checkbox
        bxs = []
        bxs_name = []
        for i, c in enumerate(countries):
            bxs.append(QCheckBox(c + '\t \t \t(' + str(nb_countries[i]) + ')'))
            bxs_name.append(c)
            bxs[i].setChecked(True)
            vbox.addWidget(bxs[i])

        # Produce maps button
        hbox = QHBoxLayout()
        btn = QPushButton("Produce maps")
        btn.setFixedSize(QtCore.QSize(200, 30))
        hbox.addWidget(btn)
        vbox.addLayout(hbox)
        btn.clicked.connect(lambda: mapping(
            w, bxs, bxs_name, template_path, colorRamp_path, products_names,
            products_path, export_path, tab, tab2))

        w.show()
        sys.exit(qgs.exec_())

    else:
        produce.Map(template_path, colorRamp_path, products, products_names,
                    export_path, tab)