2019-11-30 22:56:50 +01:00
|
|
|
#!/usr/bin/python3
|
2015-08-24 08:32:07 +03:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2015-08-24 20:18:31 +03:00
|
|
|
# dialog_box.py file is part of slpkg.
|
2015-08-24 08:32:07 +03:00
|
|
|
|
2022-02-06 18:46:27 +02:00
|
|
|
# Copyright 2014-2022 Dimitris Zlatanidis <d.zlatanidis@gmail.com>
|
2015-08-24 08:32:07 +03:00
|
|
|
# All rights reserved.
|
|
|
|
|
|
|
|
# Slpkg is a user-friendly package manager for Slackware installations
|
|
|
|
|
2018-06-09 22:00:52 +02:00
|
|
|
# https://gitlab.com/dslackw/slpkg
|
2015-08-24 08:32:07 +03:00
|
|
|
|
|
|
|
# Slpkg is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
2015-08-31 21:57:08 +03:00
|
|
|
import os
|
|
|
|
|
2015-08-24 08:32:07 +03:00
|
|
|
|
2019-12-07 17:14:46 +01:00
|
|
|
class DialogUtil:
|
2015-08-24 08:32:07 +03:00
|
|
|
"""Create dialog checklist
|
|
|
|
"""
|
2015-09-02 16:01:13 +03:00
|
|
|
def __init__(self, *args):
|
2020-02-15 19:54:42 +01:00
|
|
|
self.imp_dialog()
|
2015-09-02 16:01:13 +03:00
|
|
|
self.data = args[0]
|
|
|
|
self.text = args[1]
|
|
|
|
self.title = args[2]
|
|
|
|
self.backtitle = args[3]
|
|
|
|
self.status = args[4]
|
2015-08-24 08:32:07 +03:00
|
|
|
self.ununicode = []
|
|
|
|
self.tags = []
|
|
|
|
|
2020-02-15 19:54:42 +01:00
|
|
|
def imp_dialog(self):
|
|
|
|
try:
|
|
|
|
from dialog import Dialog
|
2022-05-12 19:22:25 +03:00
|
|
|
except ImportError as er:
|
|
|
|
raise SystemExit(er)
|
2020-02-15 19:54:42 +01:00
|
|
|
self.d = Dialog(dialog="dialog", autowidgetsize=True)
|
|
|
|
|
2015-08-24 20:18:31 +03:00
|
|
|
def checklist(self):
|
2015-08-24 08:32:07 +03:00
|
|
|
"""Run dialog checklist
|
|
|
|
"""
|
2015-09-15 16:01:06 +03:00
|
|
|
choice = []
|
|
|
|
for item in self.data:
|
|
|
|
choice.append((item, "", self.status))
|
|
|
|
code, self.tags = self.d.checklist(
|
|
|
|
text=self.text, height=20, width=65, list_height=13,
|
|
|
|
choices=choice, title=self.title, backtitle=self.backtitle)
|
2015-08-24 08:32:07 +03:00
|
|
|
if code == "ok":
|
2015-08-29 20:07:32 +03:00
|
|
|
self.unicode_to_string()
|
|
|
|
return self.ununicode
|
2015-09-15 08:16:06 +03:00
|
|
|
if code in ["cancel", "esc"]:
|
2015-08-29 20:07:32 +03:00
|
|
|
self.exit()
|
|
|
|
|
|
|
|
def buildlist(self, enabled):
|
2015-08-31 06:55:17 +03:00
|
|
|
"""Run dialog buildlist
|
|
|
|
"""
|
2015-09-15 16:01:06 +03:00
|
|
|
choice = []
|
|
|
|
for item in self.data:
|
|
|
|
choice.append((item, False))
|
|
|
|
for item in enabled:
|
|
|
|
choice.append((item, True))
|
|
|
|
items = [(tag, tag, sta) for (tag, sta) in choice]
|
|
|
|
code, self.tags = self.d.buildlist(
|
|
|
|
text=self.text, items=items, visit_items=True, item_help=False,
|
|
|
|
title=self.title)
|
2015-08-29 20:07:32 +03:00
|
|
|
if code == "ok":
|
|
|
|
self.unicode_to_string()
|
2015-08-24 08:32:07 +03:00
|
|
|
return self.ununicode
|
2015-09-15 08:16:06 +03:00
|
|
|
if code in ["cancel", "esc"]:
|
2015-08-24 08:32:07 +03:00
|
|
|
self.exit()
|
|
|
|
|
|
|
|
def exit(self):
|
|
|
|
"""Exit from dialog
|
|
|
|
"""
|
2015-08-31 21:57:08 +03:00
|
|
|
self.clear_screen()
|
2015-08-24 08:32:07 +03:00
|
|
|
raise SystemExit()
|
|
|
|
|
2015-08-31 21:57:08 +03:00
|
|
|
def clear_screen(self):
|
|
|
|
"""Clear screen
|
|
|
|
"""
|
|
|
|
os.system("clear")
|
|
|
|
|
2015-08-29 20:07:32 +03:00
|
|
|
def unicode_to_string(self):
|
2015-08-24 08:32:07 +03:00
|
|
|
"""Convert unicode in string
|
|
|
|
"""
|
|
|
|
for tag in self.tags:
|
|
|
|
self.ununicode.append(str(tag))
|