slpkg/slpkg/dialog_box.py

99 lines
2.9 KiB
Python
Raw Normal View History

#!/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
# 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
# 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
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):
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 = []
def imp_dialog(self):
try:
from dialog import Dialog
except ImportError as er:
raise SystemExit(er)
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":
self.unicode_to_string()
return self.ununicode
2015-09-15 08:16:06 +03:00
if code in ["cancel", "esc"]:
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)
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")
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))