def __init__(self, user): super(VolumeList, self).__init__() self.user = user self.checkbox_volume_dic = {} self.volume_list = self.user.getVolumeList() self.selected_volume_list = [] self.label = QLabel('VOLUME LIST') self.label.setStyleSheet('font-size: 16pt;') self.buttonTab = ButtonWidget(3) self.buttonTab.setupButtons(['Refresh', 'Add volume', 'Remove'], ['#397D00', 'Red', '#b06a00']) self.buttonList = self.buttonTab.getButtonList() self.buttonList[0].clicked.connect(self.refresh) self.buttonList[1].clicked.connect(self.addButtonIsClicked) self.buttonList[2].clicked.connect(self.removeButtonIsClicked) self.volume_list_view = QListWidget() self.volume_list_view.ScrollMode(True) self.setup() layout = QVBoxLayout(self) layout.addWidget(self.label) layout.addWidget(self.buttonTab) layout.addWidget(self.volume_list_view) layout.setSpacing(20)
def __init__(self, user): QWidget.__init__(self, None) self.user = user self.images_list = self.user.getImagesList() self.checkbox_tag_dic = {} self.selected_image_list = [] self.layout = QVBoxLayout(self) self.label = QLabel('IMAGES LIST') self.label.setStyleSheet('font-family: Optima; font-size: 40pt;') self.label2 = QLabel('SEARCH') self.label2.setStyleSheet('font-family: Optima; font-size: 16pt;') self.lineEdit = QLineEdit() self.lineEdit.textChanged.connect(self.searching) base_dir = os.path.dirname(os.path.abspath(__file__)) path = os.path.join(base_dir, 'images') images_path = os.path.join(path, 'images.png') self.images_pic = QLabel() self.images_pic.setPixmap(QPixmap(images_path)) self.filterView = None self.listImageView = QListWidget() self.listImageView.ScrollMode(True) self.createImageList(self.images_list) # Button Setup self.buttonTab = ButtonWidget(4) self.buttonTab.setupButtons(['Refresh', 'Pull', 'Build', 'Remove'], ['#397D00', 'Red', 'Blue', '#b06a00']) self.buttonList = self.buttonTab.getButtonList() self.buttonList[0].clicked.connect(self.refreshButtonIsClicked) self.buttonList[1].clicked.connect(self.pullButtonIsClicked) self.buttonList[2].clicked.connect(self.buildButtonIsClicked) self.buttonList[3].clicked.connect(self.removeButtonIsClicked) # Row Setup self.row1 = QHBoxLayout() self.row1.addWidget(self.label) self.row1.addWidget(self.images_pic) self.row1.setAlignment(Qt.AlignCenter) self.row2 = QHBoxLayout() self.row2.setSpacing(55) self.row2.addWidget(self.label2) self.row2.addWidget(self.lineEdit) # Set Layout self.layout.addLayout(self.row1) self.layout.addWidget(self.buttonTab) self.layout.addLayout(self.row2) self.layout.addWidget(self.listImageView) self.layout.setSpacing(20) self.layout.setAlignment(Qt.AlignTop)
def __init__(self, user): QWidget.__init__(self, None) self.user = user self.images_list = self.user.getImagesList() self.checkbox_tag_dic = {} self.selected_image_list = [] self.layout = QVBoxLayout(self) self.label = QLabel('IMAGES VIEWER') self.label.setStyleSheet('font-size: 16pt;') self.label2 = QLabel('SEARCH') self.label2.setStyleSheet('font-size: 16pt;') self.lineEdit = QLineEdit() self.lineEdit.textChanged.connect(self.searching) self.filterView = None self.listImageView = QListWidget() self.listImageView.ScrollMode(True) self.createImageList(self.images_list) # Button Setup self.buttonTab = ButtonWidget(3) self.buttonTab.setupButtons(['Refresh', 'Pull', 'Remove'], ['#397D00', 'Red', '#b06a00']) self.buttonList = self.buttonTab.getButtonList() self.buttonList[0].clicked.connect(self.refreshButtonIsClicked) self.buttonList[1].clicked.connect(self.pullButtonIsClicked) self.buttonList[2].clicked.connect(self.removeButtonIsClicked) # Row Setup self.row1 = QHBoxLayout() self.row1.addWidget(self.label) self.row1.setAlignment(Qt.AlignLeft) self.row2 = QHBoxLayout() self.row2.setSpacing(55) self.row2.addWidget(self.label2) self.row2.addWidget(self.lineEdit) # Set Layout self.layout.addLayout(self.row1) self.layout.addWidget(self.buttonTab) self.layout.addLayout(self.row2) self.layout.addWidget(self.listImageView) self.layout.setSpacing(20) self.layout.setAlignment(Qt.AlignTop)
def __init__(self): QtWidgets.QWidget.__init__(self, None) self.list_widget = ListWidget() self.button_array = ButtonWidget(7) titles = [ "start", "stop", "kill", "restart", "pause", "unpause", "remove" ] colors = ["green", "red", "red", "blue", "blue", "blue", "red"] func = [ self.startContainers, self.stopContainers, self.killContainers, self.restartContainers, self.pauseContainers, self.unpauseContainers, self.removeContainers ] self.button_array.setupButtons(titles, colors, func) self.set_ui()
def __init__(self, user): super(VolumeList, self).__init__() self.user = user self.checkbox_volume_dic = {} self.volume_list = self.user.getVolumeList() self.selected_volume_list = [] self.label = QLabel('VOLUME LIST') self.label.setStyleSheet('font-family: Optima; font-size: 40pt; ') base_dir = os.path.dirname(os.path.abspath(__file__)) path = os.path.join(base_dir, 'images') volumes_path = os.path.join(path, 'volumes.png') self.volume_pic = QLabel() self.volume_pic.setPixmap(QPixmap(volumes_path)) self.buttonTab = ButtonWidget(3) self.buttonTab.setupButtons(['Refresh', 'Add volume', 'Remove'], ['#397D00', 'Red', '#b06a00']) self.buttonList = self.buttonTab.getButtonList() self.buttonList[0].clicked.connect(self.refresh) self.buttonList[1].clicked.connect(self.addButtonIsClicked) self.buttonList[2].clicked.connect(self.removeButtonIsClicked) self.volume_list_view = QListWidget() self.volume_list_view.ScrollMode(True) self.setup() self.row1 = QHBoxLayout() self.row1.setSpacing(40) self.row1.addWidget(self.label) self.row1.addWidget(self.volume_pic) self.row1.setAlignment(Qt.AlignCenter) layout = QVBoxLayout(self) layout.addLayout(self.row1) layout.addWidget(self.buttonTab) layout.addWidget(self.volume_list_view) layout.setSpacing(20)
def __init__(self, user): QtWidgets.QWidget.__init__(self, None) self.user = user self.containerForm = QDialog() self.list_widget = ListWidget() self.button_array = ButtonWidget(8) titles = [ "start", "stop", "kill", "restart", "pause", "unpause", "remove", "Create +" ] colors = [ "green", "red", "red", "blue", "blue", "blue", "red", "black" ] func = [ self.startContainers, self.stopContainers, self.killContainers, self.restartContainers, self.pauseContainers, self.unpauseContainers, self.removeContainers, self.createContainerForm ] self.button_array.setupButtons(titles, colors, func) self.set_ui()
def __init__(self, filename = 'text.txt'): QWidget.__init__(self, None) self.layout = QVBoxLayout(self) self.label = QLabel('LOG VIEWER') # self.label.setStyleSheet('font-family: Optima; font-size: 16pt;') self.label.setStyleSheet('font-size: 16pt;') self.row1 = QHBoxLayout() self.row1.addWidget(self.label) self.row1.setAlignment(Qt.AlignLeft) self.label2 = QLabel('SEARCH') # self.label2.setStyleSheet('font-family: Optima; font-size: 16pt;') self.label2.setStyleSheet('font-size: 16pt;') self.lineEdit = QLineEdit() self.lineEdit.textChanged.connect(self.searching) self.row2 = QHBoxLayout() self.row2.setSpacing(55) self.row2.addWidget(self.label2) self.row2.addWidget(self.lineEdit) self.buttonTab = ButtonWidget(1) self.buttonTab.setupButtons(['copy'], ['#397D00']) self.buttonList = self.buttonTab.getButtonList() self.buttonList[0].clicked.connect(self.copyButtonIsClicked) self.logDisplay = QTextBrowser() self.logDisplay.setStyleSheet('font-size: 14pt; font-weight: normal;') self.layout.addLayout(self.row1) self.layout.addLayout(self.row2) self.layout.addWidget(self.buttonTab) self.layout.addWidget(self.logDisplay) self.layout.setSpacing(15) self.layout.setAlignment(Qt.AlignTop) self.readFile(filename)
class ListImages(QWidget): def __init__(self, user): QWidget.__init__(self, None) self.user = user self.images_list = self.user.getImagesList() self.checkbox_tag_dic = {} self.selected_image_list = [] self.layout = QVBoxLayout(self) self.label = QLabel('IMAGES VIEWER') self.label.setStyleSheet('font-size: 16pt;') self.label2 = QLabel('SEARCH') self.label2.setStyleSheet('font-size: 16pt;') self.lineEdit = QLineEdit() self.lineEdit.textChanged.connect(self.searching) self.filterView = None self.listImageView = QListWidget() self.listImageView.ScrollMode(True) self.createImageList(self.images_list) # Button Setup self.buttonTab = ButtonWidget(3) self.buttonTab.setupButtons(['Refresh', 'Pull', 'Remove'], ['#397D00', 'Red', '#b06a00']) self.buttonList = self.buttonTab.getButtonList() self.buttonList[0].clicked.connect(self.refreshButtonIsClicked) self.buttonList[1].clicked.connect(self.pullButtonIsClicked) self.buttonList[2].clicked.connect(self.removeButtonIsClicked) # Row Setup self.row1 = QHBoxLayout() self.row1.addWidget(self.label) self.row1.setAlignment(Qt.AlignLeft) self.row2 = QHBoxLayout() self.row2.setSpacing(55) self.row2.addWidget(self.label2) self.row2.addWidget(self.lineEdit) # Set Layout self.layout.addLayout(self.row1) self.layout.addWidget(self.buttonTab) self.layout.addLayout(self.row2) self.layout.addWidget(self.listImageView) self.layout.setSpacing(20) self.layout.setAlignment(Qt.AlignTop) def searching(self): keyword = self.lineEdit.text() if len(keyword) == 0: self.refreshButtonIsClicked() return temp = [] for image in self.images_list: if keyword in image.tags[0]: temp.append(image) self.images_list = temp self.refresh(self.images_list) return def refreshButtonIsClicked(self): self.listImageView.clear() images_list = self.user.getImagesList() self.createImageList(images_list) return def refresh(self, images_list): self.listImageView.clear() self.createImageList(images_list) return def createListItem(self, image_detail): item = QtWidgets.QListWidgetItem(self.listImageView) item.setSizeHint(QtCore.QSize(100, 60)) item.setFlags(Qt.NoItemFlags) cb = image_detail.getCheckbox() self.checkbox_tag_dic[cb] = image_detail.getTag() self.listImageView.addItem(item) self.listImageView.setItemWidget(item, image_detail) cb.stateChanged.connect(lambda state, c=cb: (self.checkboxIsPressed(c))) def createImageList(self, image_list): header = ['Id', 'Tags', 'Size', 'Created'] imageDetail = ImageDetails(header, True) self.createListItem(imageDetail) self.images_list = image_list for i in range(len(image_list)): imageDetail = ImageDetails(self.user.getImageDetail(i)) self.createListItem(imageDetail) def checkboxIsPressed(self, cb): if cb.isChecked(): self.selected_image_list.append(self.checkbox_tag_dic[cb]) else: self.selected_image_list.remove(self.checkbox_tag_dic[cb]) def pullButtonIsClicked(self): self.dlg = QDialog(self) self.dlg.setWindowTitle("Pull Image") label = QLabel("Enter image repository") label.setStyleSheet('font-size: 14pt; font-weight: bold;') self.reposity = QLineEdit() self.reposity.setPlaceholderText('eg. busybox') pull_button = QPushButton('Pull') pull_button.clicked.connect(self.pullExecuteButtonIsClicked) cancel_button = QPushButton('Cancel') cancel_button.clicked.connect(self.cancelButtonIsClicked) sub_layout1 = QHBoxLayout() sub_layout1.addWidget(label) sub_layout1.addWidget(self.reposity) sub_layout2 = QHBoxLayout() sub_layout2.addWidget(pull_button) sub_layout2.addWidget(cancel_button) sub_layout2.setAlignment(Qt.AlignCenter) layout = QVBoxLayout(self.dlg) layout.addLayout(sub_layout1) layout.addLayout(sub_layout2) layout.setAlignment(Qt.AlignCenter) self.dlg.setMinimumSize(500, 100) self.dlg.exec_() def pullExecuteButtonIsClicked(self): image_repo = str(self.reposity.text()) + ':latest' image = self.user.pullImage(image_repo) if image: self.reposity.setPlaceholderText('pull success') self.reposity.setText('') self.user.addImage(image) image_detail = ImageDetails( self.user.getImageDetail(self.user.getNumberOfImageList() - 1)) self.createListItem(image_detail) self.dlg.close() else: self.reposity.setPlaceholderText('invalid image repository name') self.reposity.setText('') def cancelButtonIsClicked(self): self.dlg.close() def removeButtonIsClicked(self): for image in self.selected_image_list: self.user.removeImage(image) self.user.setup() self.selected_image_list.clear() self.refreshButtonIsClicked()
class Container(QtWidgets.QWidget): def __init__(self): QtWidgets.QWidget.__init__(self, None) self.list_widget = ListWidget() self.button_array = ButtonWidget(7) titles = [ "start", "stop", "kill", "restart", "pause", "unpause", "remove" ] colors = ["green", "red", "red", "blue", "blue", "blue", "red"] func = [ self.startContainers, self.stopContainers, self.killContainers, self.restartContainers, self.pauseContainers, self.unpauseContainers, self.removeContainers ] self.button_array.setupButtons(titles, colors, func) self.set_ui() def set_ui(self): self.c = Connection() lst = self.c.getContainersDetail() self.list_widget.UpdateList(lst) label = QtWidgets.QLabel('CONTAINERS') label.setStyleSheet('font-size: 16pt;') vertical_layout = QtWidgets.QVBoxLayout() vertical_layout.addWidget(label) vertical_layout.addWidget(self.button_array) vertical_layout.addWidget(self.list_widget) self.setLayout(vertical_layout) self.show() def startContainers(self): for container in self.c.getContainersDetail(): if self.list_widget.checkbox_dict[container.id]: container.start() print("starting", container) def stopContainers(self): for container in self.c.getContainersDetail(): if self.list_widget.checkbox_dict[container.id]: container.stop() print("stop", container) def killContainers(self): for container in self.c.getContainersDetail(): if self.list_widget.checkbox_dict[container.id]: try: container.kill() print("kill", container) except docker.errors.APIError as e: print(e) p = Popup(e) def restartContainers(self): for container in self.c.getContainersDetail(): if self.list_widget.checkbox_dict[container.id]: try: container.restart() print("restart", container) except docker.errors.APIError as e: print(e) p = Popup(e) def pauseContainers(self): for container in self.c.getContainersDetail(): if self.list_widget.checkbox_dict[container.id]: try: container.pause() print("pause", container) except docker.errors.APIError as e: print(e) p = Popup(e) def unpauseContainers(self): for container in self.c.getContainersDetail(): if self.list_widget.checkbox_dict[container.id]: try: container.unpause() print("unpause", container) except docker.errors.APIError as e: print(e) p = Popup(e) def removeContainers(self): for container in self.c.getContainersDetail(): if self.list_widget.checkbox_dict[container.id]: try: container.remove() print("remove", container) except docker.errors.APIError as e: print(e) p = Popup(e) time.sleep(5) self.list_widget.UpdateList(self.c.getContainersDetail())
class VolumeList(QWidget): def __init__(self, user): super(VolumeList, self).__init__() self.user = user self.checkbox_volume_dic = {} self.volume_list = self.user.getVolumeList() self.selected_volume_list = [] self.label = QLabel('VOLUME LIST') self.label.setStyleSheet('font-family: Optima; font-size: 40pt; ') base_dir = os.path.dirname(os.path.abspath(__file__)) path = os.path.join(base_dir, 'images') volumes_path = os.path.join(path, 'volumes.png') self.volume_pic = QLabel() self.volume_pic.setPixmap(QPixmap(volumes_path)) self.buttonTab = ButtonWidget(3) self.buttonTab.setupButtons(['Refresh', 'Add volume', 'Remove'], ['#397D00', 'Red', '#b06a00']) self.buttonList = self.buttonTab.getButtonList() self.buttonList[0].clicked.connect(self.refresh) self.buttonList[1].clicked.connect(self.addButtonIsClicked) self.buttonList[2].clicked.connect(self.removeButtonIsClicked) self.volume_list_view = QListWidget() self.volume_list_view.ScrollMode(True) self.setup() self.row1 = QHBoxLayout() self.row1.setSpacing(40) self.row1.addWidget(self.label) self.row1.addWidget(self.volume_pic) self.row1.setAlignment(Qt.AlignCenter) layout = QVBoxLayout(self) layout.addLayout(self.row1) layout.addWidget(self.buttonTab) layout.addWidget(self.volume_list_view) layout.setSpacing(20) def setup(self): self.createHeader() for volume in self.volume_list: self.createListItem(volume) def createHeader(self): name = 'Name' created = 'Created' point = 'Mount Point' driver = 'Driver' item = QtWidgets.QListWidgetItem(self.volume_list_view) item.setSizeHint(QSize(100, 60)) item.setFlags(Qt.NoItemFlags) self.volume_list_view.addItem(item) custom_item = VolumeItem(name, driver, point, created, True) self.volume_list_view.setItemWidget(item, custom_item) def createListItem(self, volume): name = volume.name created = volume.attrs['CreatedAt'] point = volume.attrs['Mountpoint'] driver = volume.attrs['Driver'] item = QtWidgets.QListWidgetItem(self.volume_list_view) item.setSizeHint(QSize(100, 60)) item.setFlags(Qt.NoItemFlags) self.volume_list_view.addItem(item) custom_item = VolumeItem(name, driver, point, created) self.volume_list_view.setItemWidget(item, custom_item) cb = custom_item.get_checkbox() self.checkbox_volume_dic[cb] = volume cb.stateChanged.connect(lambda state, c=cb: (self.checkboxIsPressed(c))) def checkboxIsPressed(self, cb): if cb.isChecked(): self.selected_volume_list.append(self.checkbox_volume_dic[cb]) else: self.selected_volume_list.remove(self.checkbox_volume_dic[cb]) print(self.selected_volume_list) def addButtonIsClicked(self): self.dlg = QDialog(self) self.dlg.setWindowTitle("Add Volume") label = QLabel("Enter volume name ") label.setStyleSheet('font-size: 14pt; font-weight: bold;') self.name = QLineEdit() self.name.setPlaceholderText('eg. korkrane') add_button = QPushButton('Add') add_button.clicked.connect(self.addExecuteButtonIsClicked) cancel_button = QPushButton('Cancel') cancel_button.clicked.connect(self.cancelButtonIsClicked) sub_layout1 = QHBoxLayout() sub_layout1.addWidget(label) sub_layout1.addWidget(self.name) sub_layout2 = QHBoxLayout() sub_layout2.addWidget(add_button) sub_layout2.addWidget(cancel_button) sub_layout2.setAlignment(Qt.AlignCenter) layout = QVBoxLayout(self.dlg) layout.addLayout(sub_layout1) layout.addLayout(sub_layout2) layout.setAlignment(Qt.AlignCenter) self.dlg.setMinimumSize(500, 100) self.dlg.exec_() def addExecuteButtonIsClicked(self): volume = str(self.name.text()) if len(volume) > 0: new_volume = self.user.addVolume(volume) if new_volume: self.createListItem(new_volume) self.dlg.close() else: self.name.setText('') self.name.setPlaceholderText('error from server') def removeButtonIsClicked(self): for volume in self.selected_volume_list: self.user.removeVolume(volume) self.selected_volume_list.clear() self.refresh() def refresh(self): self.volume_list_view.clear() self.user.setup() self.volume_list = self.user.getVolumeList() self.setup() def cancelButtonIsClicked(self): self.dlg.close()
class Log(QWidget): def __init__(self, filename = 'text.txt'): QWidget.__init__(self, None) self.layout = QVBoxLayout(self) self.label = QLabel('LOG VIEWER') # self.label.setStyleSheet('font-family: Optima; font-size: 16pt;') self.label.setStyleSheet('font-size: 16pt;') self.row1 = QHBoxLayout() self.row1.addWidget(self.label) self.row1.setAlignment(Qt.AlignLeft) self.label2 = QLabel('SEARCH') # self.label2.setStyleSheet('font-family: Optima; font-size: 16pt;') self.label2.setStyleSheet('font-size: 16pt;') self.lineEdit = QLineEdit() self.lineEdit.textChanged.connect(self.searching) self.row2 = QHBoxLayout() self.row2.setSpacing(55) self.row2.addWidget(self.label2) self.row2.addWidget(self.lineEdit) self.buttonTab = ButtonWidget(1) self.buttonTab.setupButtons(['copy'], ['#397D00']) self.buttonList = self.buttonTab.getButtonList() self.buttonList[0].clicked.connect(self.copyButtonIsClicked) self.logDisplay = QTextBrowser() self.logDisplay.setStyleSheet('font-size: 14pt; font-weight: normal;') self.layout.addLayout(self.row1) self.layout.addLayout(self.row2) self.layout.addWidget(self.buttonTab) self.layout.addWidget(self.logDisplay) self.layout.setSpacing(15) self.layout.setAlignment(Qt.AlignTop) self.readFile(filename) # filename.txt def readFile(self, filename): file = open(filename, 'r') self.lines = file.readlines() file.close() file = open(filename, 'r') whole_text = file.read() file.close() self.logDisplay.setText(whole_text) def searching(self): keyword = self.lineEdit.text() display = '' for line in self.lines: if search(keyword.lower(), line.lower()): display += line self.logDisplay.setText(display) def copyButtonIsClicked(self): cb = QGuiApplication.clipboard() qString = self.logDisplay.toPlainText() cb.setText(str(qString))
class Container(QtWidgets.QWidget): def __init__(self, user): QtWidgets.QWidget.__init__(self, None) self.user = user self.containerForm = QDialog() self.list_widget = ListWidget() self.button_array = ButtonWidget(8) titles = [ "start", "stop", "kill", "restart", "pause", "unpause", "remove", "Create +" ] colors = [ "green", "red", "red", "blue", "blue", "blue", "red", "black" ] func = [ self.startContainers, self.stopContainers, self.killContainers, self.restartContainers, self.pauseContainers, self.unpauseContainers, self.removeContainers, self.createContainerForm ] self.button_array.setupButtons(titles, colors, func) self.set_ui() def set_ui(self): self.c = Connection() lst = self.c.getContainersDetail() self.list_widget.UpdateList(lst) label = QLabel('CONTAINER LIST') label.setStyleSheet('font-family: Optima; font-size: 40pt;') vertical_layout = QtWidgets.QVBoxLayout() vertical_layout.addWidget(label) vertical_layout.addWidget(self.button_array) vertical_layout.addWidget(self.list_widget) vertical_layout.setSpacing(20) self.setLayout(vertical_layout) self.show() def startContainers(self): for container in self.c.getContainersDetail(): if self.list_widget.checkbox_dict[container.id]: container.start() print("starting", container) time.sleep(5) self.list_widget.UpdateList(self.c.getContainersDetail()) def stopContainers(self): for container in self.c.getContainersDetail(): if self.list_widget.checkbox_dict[container.id]: container.stop() print("stop", container) time.sleep(5) self.list_widget.UpdateList(self.c.getContainersDetail()) def killContainers(self): for container in self.c.getContainersDetail(): if self.list_widget.checkbox_dict[container.id]: try: container.kill() print("kill", container) except docker.errors.APIError as e: print(e) p = Popup(e) time.sleep(5) self.list_widget.UpdateList(self.c.getContainersDetail()) def restartContainers(self): for container in self.c.getContainersDetail(): if self.list_widget.checkbox_dict[container.id]: try: container.restart() print("restart", container) except docker.errors.APIError as e: print(e) p = Popup(e) time.sleep(5) self.list_widget.UpdateList(self.c.getContainersDetail()) def pauseContainers(self): for container in self.c.getContainersDetail(): if self.list_widget.checkbox_dict[container.id]: try: container.pause() print("pause", container) except docker.errors.APIError as e: print(e) p = Popup(e) time.sleep(5) self.list_widget.UpdateList(self.c.getContainersDetail()) def unpauseContainers(self): for container in self.c.getContainersDetail(): if self.list_widget.checkbox_dict[container.id]: try: container.unpause() print("unpause", container) except docker.errors.APIError as e: print(e) p = Popup(e) time.sleep(5) self.list_widget.UpdateList(self.c.getContainersDetail()) def removeContainers(self): for container in self.c.getContainersDetail(): if self.list_widget.checkbox_dict[container.id]: try: container.remove() print("remove", container) except docker.errors.APIError as e: print(e) p = Popup(e) #time.sleep(5) self.list_widget.UpdateList(self.c.getContainersDetail()) def createContainerForm(self): self.containerForm = QDialog() image = QLabel('Image') self.imageEdit = QLineEdit() grid = QGridLayout() grid.setSpacing(10) grid.addWidget(image, 1, 0) grid.addWidget(self.imageEdit, 1, 1) ok = QPushButton("Ok") grid.addWidget(ok, 2, 0) ok.clicked.connect(self.executeCreateContainer) cancel = QPushButton("Cancel") grid.addWidget(cancel, 2, 1, 1, 1) cancel.clicked.connect(self.cancelButtonIsClicked) self.containerForm.setLayout(grid) self.containerForm.setGeometry(300, 300, 500, 200) self.containerForm.setWindowTitle('Create container') self.containerForm.exec_() def cancelButtonIsClicked(self): self.containerForm.close() def executeCreateContainer(self): client = docker.from_env() client.containers.run(image = self.imageEdit.text()),\ #environment = None,\ #name = None,\ #port = None) self.containerForm.close() self.list_widget.UpdateList(self.c.getContainersDetail()) return
class Image(QWidget): def __init__(self, user): QWidget.__init__(self, None) self.user = user self.images_list = self.user.getImagesList() self.checkbox_tag_dic = {} self.selected_image_list = [] self.layout = QVBoxLayout(self) self.label = QLabel('IMAGES LIST') self.label.setStyleSheet('font-family: Optima; font-size: 40pt;') self.label2 = QLabel('SEARCH') self.label2.setStyleSheet('font-family: Optima; font-size: 16pt;') self.lineEdit = QLineEdit() self.lineEdit.textChanged.connect(self.searching) base_dir = os.path.dirname(os.path.abspath(__file__)) path = os.path.join(base_dir, 'images') images_path = os.path.join(path, 'images.png') self.images_pic = QLabel() self.images_pic.setPixmap(QPixmap(images_path)) self.filterView = None self.listImageView = QListWidget() self.listImageView.ScrollMode(True) self.createImageList(self.images_list) # Button Setup self.buttonTab = ButtonWidget(4) self.buttonTab.setupButtons(['Refresh', 'Pull', 'Build', 'Remove'], ['#397D00', 'Red', 'Blue', '#b06a00']) self.buttonList = self.buttonTab.getButtonList() self.buttonList[0].clicked.connect(self.refreshButtonIsClicked) self.buttonList[1].clicked.connect(self.pullButtonIsClicked) self.buttonList[2].clicked.connect(self.buildButtonIsClicked) self.buttonList[3].clicked.connect(self.removeButtonIsClicked) # Row Setup self.row1 = QHBoxLayout() self.row1.addWidget(self.label) self.row1.addWidget(self.images_pic) self.row1.setAlignment(Qt.AlignCenter) self.row2 = QHBoxLayout() self.row2.setSpacing(55) self.row2.addWidget(self.label2) self.row2.addWidget(self.lineEdit) # Set Layout self.layout.addLayout(self.row1) self.layout.addWidget(self.buttonTab) self.layout.addLayout(self.row2) self.layout.addWidget(self.listImageView) self.layout.setSpacing(20) self.layout.setAlignment(Qt.AlignTop) def searching(self): keyword = self.lineEdit.text() if len(keyword) == 0: self.refreshButtonIsClicked() return temp = [] for image in self.images_list: if keyword in image.tags[0]: print(image.tags[0]) temp.append(image) self.images_list = temp self.user.setImageList(self.images_list) self.refresh(self.images_list) return def refreshButtonIsClicked(self): self.listImageView.clear() self.user.setup() images_list = self.user.getImagesList() self.createImageList(images_list) return def refresh(self, images_list): self.listImageView.clear() self.createImageList(images_list) return def createListItem(self, ImageListItem): item = QtWidgets.QListWidgetItem(self.listImageView) item.setSizeHint(QtCore.QSize(100, 60)) item.setFlags(Qt.NoItemFlags) cb = ImageListItem.getCheckbox() self.checkbox_tag_dic[cb] = ImageListItem.getId() self.listImageView.addItem(item) self.listImageView.setItemWidget(item, ImageListItem) cb.stateChanged.connect(lambda state, c=cb: (self.checkboxIsPressed(c))) def createImageList(self, image_list): header = ['Id', 'Tags', 'Size', 'Created'] im = ImageListItem(header, True) self.createListItem(im) self.images_list = image_list for i in range(len(image_list)): im = ImageListItem(self.user.getImageDetail(i)) self.createListItem(im) def checkboxIsPressed(self, cb): if cb.isChecked(): self.selected_image_list.append(self.checkbox_tag_dic[cb]) else: self.selected_image_list.remove(self.checkbox_tag_dic[cb]) def buildButtonIsClicked(self): self.dlg = QDialog(self) self.dlg.setWindowTitle("Build Image") label = QLabel("Enter path to directoty") label.setStyleSheet('font-size: 14pt; font-weight: bold;') self.path = QLineEdit() self.path.setPlaceholderText('eg. user\dockerV') pull_button = QPushButton('Build') pull_button.clicked.connect(self.buildExecuteButtonIsClicked) cancel_button = QPushButton('Cancel') cancel_button.clicked.connect(self.cancelButtonIsClicked) sub_layout1 = QHBoxLayout() sub_layout1.addWidget(label) sub_layout1.addWidget(self.path) sub_layout2 = QHBoxLayout() sub_layout2.addWidget(pull_button) sub_layout2.addWidget(cancel_button) sub_layout2.setAlignment(Qt.AlignCenter) layout = QVBoxLayout(self.dlg) layout.addLayout(sub_layout1) layout.addLayout(sub_layout2) layout.setAlignment(Qt.AlignCenter) self.dlg.setMinimumSize(500, 100) self.dlg.exec_() def buildExecuteButtonIsClicked(self): path_to_directory = str(self.path.text()) if len(path_to_directory) > 0: print(path_to_directory) try: self.user.client.images.build(path=path_to_directory) self.user.setup() self.refreshButtonIsClicked() self.dlg.close() except: self.path.setText('') self.path.setPlaceholderText( 'invalid path or don\'t has docker file') def pullButtonIsClicked(self): self.dlg = QDialog(self) self.dlg.setWindowTitle("Pull Image") label = QLabel("Enter image repository") label.setStyleSheet('font-size: 14pt; font-weight: bold;') self.reposity = QLineEdit() self.reposity.setPlaceholderText('eg. busybox') pull_button = QPushButton('Pull') pull_button.clicked.connect(self.pullExecuteButtonIsClicked) cancel_button = QPushButton('Cancel') cancel_button.clicked.connect(self.cancelButtonIsClicked) sub_layout1 = QHBoxLayout() sub_layout1.addWidget(label) sub_layout1.addWidget(self.reposity) sub_layout2 = QHBoxLayout() sub_layout2.addWidget(pull_button) sub_layout2.addWidget(cancel_button) sub_layout2.setAlignment(Qt.AlignCenter) layout = QVBoxLayout(self.dlg) layout.addLayout(sub_layout1) layout.addLayout(sub_layout2) layout.setAlignment(Qt.AlignCenter) self.dlg.setMinimumSize(500, 100) self.dlg.exec_() def pullExecuteButtonIsClicked(self): image_repo = str(self.reposity.text()) + ':latest' image = self.user.pullImage(image_repo) if image: self.reposity.setPlaceholderText('pull success') self.reposity.setText('') self.user.addImage(image) self.refreshButtonIsClicked() self.dlg.close() else: self.reposity.setPlaceholderText('invalid image repository name') self.reposity.setText('') def cancelButtonIsClicked(self): self.dlg.close() def removeButtonIsClicked(self): for image in self.selected_image_list: self.user.removeImage(image) self.user.setup() self.selected_image_list.clear() self.refreshButtonIsClicked()