Moved to dialog_box file

This commit is contained in:
Dimitris Zlatanidis 2022-12-25 12:39:49 +02:00
parent 7907f90cdb
commit d43039eb0d
2 changed files with 39 additions and 12 deletions

27
slpkg/dialog_box.py Normal file
View file

@ -0,0 +1,27 @@
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import locale
from dialog import Dialog
from slpkg.configs import Configs
from slpkg.views.version import Version
locale.setlocale(locale.LC_ALL, '')
class DialogBox:
def __init__(self):
self.configs = Configs()
self.d = Dialog(dialog="dialog")
self.d.set_background_title(f'{self.configs.prog_name} {Version().version}')
def checklist(self, text, title, height, width, list_height, choices):
""" Choose packages for upgrade. """
code, tags = self.d.checklist(text, title=title, height=height, width=width,
list_height=list_height, choices=choices)
return code, tags

View file

@ -2,19 +2,15 @@
# -*- coding: utf-8 -*-
import os
import locale
from dialog import Dialog
from distutils.version import LooseVersion
from slpkg.configs import Configs
from slpkg.dialog_box import DialogBox
from slpkg.queries import SBoQueries
from slpkg.utilities import Utilities
from slpkg.blacklist import Blacklist
from slpkg.dependencies import Requires
from slpkg.views.version import Version
locale.setlocale(locale.LC_ALL, '')
class Upgrade:
@ -23,8 +19,7 @@ class Upgrade:
def __init__(self):
self.configs = Configs
self.utils = Utilities()
self.d = Dialog(dialog="dialog")
self.d.set_background_title(f'{self.configs.prog_name} {Version().version}')
self.dialog = DialogBox()
def search(self):
""" Compares version of packages and returns the maximum. """
@ -53,6 +48,7 @@ class Upgrade:
def packages(self):
""" Choose packages for upgrade. """
title = ' Choose packages you want to upgrade '
choices = []
packages = list(self.search())
@ -63,11 +59,15 @@ class Upgrade:
repo_ver = SBoQueries(package).version()
choices += [(package, f'{inst_ver} -> {repo_ver}', True)]
code, tags = self.d.checklist(f'There are {len(choices)} packages for upgrade:',
title=' Choose packages you want to upgrade ',
height=10, width=70, list_height=0, choices=choices)
text = f'There are {len(choices)} packages for upgrade:'
height = 10
width = 70
list_height = 0
code, tags = self.dialog.checklist(text, title, height, width, list_height, choices)
os.system('clear')
if code == self.d.OK:
if code == 'ok':
if not tags:
raise SystemExit()
return tags