# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'InsertDocument.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.

from Barangnya import Document,Category,Topic
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QMessageBox

class Ui_InsertDocument(object):
    def setupUi(self, InsertDocument):
        InsertDocument.setObjectName("InsertDocument")
        InsertDocument.resize(800, 600)
        InsertDocument.setStyleSheet("background-color: rgb(255, 235, 235);")
        self.centralwidget = QtWidgets.QWidget(InsertDocument)
        self.centralwidget.setObjectName("centralwidget")
        self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
        self.groupBox.setGeometry(QtCore.QRect(60, 70, 681, 441))
        self.groupBox.setStyleSheet("background-color: rgb(0, 255, 127);")
        self.groupBox.setTitle("")
        self.groupBox.setObjectName("groupBox")
        self.label = QtWidgets.QLabel(self.groupBox)
        self.label.setGeometry(QtCore.QRect(150, 20, 381, 41))
        font = QtGui.QFont()
        font.setFamily("Adobe Gothic Std B")
        font.setPointSize(21)
        font.setBold(True)
        font.setWeight(75)
        self.label.setFont(font)
        self.label.setAlignment(QtCore.Qt.AlignCenter)
        self.label.setObjectName("label")
        self.BackIcon = QtWidgets.QLabel(self.groupBox)
        self.BackIcon.setGeometry(QtCore.QRect(10, 10, 31, 31))
        self.BackIcon.setText("")
        self.BackIcon.setPixmap(QtGui.QPixmap("TubesPBO/icon/BackIcon.png"))
        self.BackIcon.setScaledContents(True)
        self.BackIcon.setObjectName("BackIcon")
        self.BackButton = QtWidgets.QPushButton(self.groupBox)
        self.BackButton.setGeometry(QtCore.QRect(10, 10, 31, 31))
        font = QtGui.QFont()
        font.setKerning(False)
        self.BackButton.setFont(font)
        self.BackButton.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
        self.BackButton.setMouseTracking(False)
        self.BackButton.setAutoFillBackground(False)
        self.BackButton.setStyleSheet("color: rgb(170, 255, 255);\n"
"background-color: transparent;\n"
"")
        self.BackButton.setText("")
        self.BackButton.setObjectName("BackButton")
        self.frame = QtWidgets.QFrame(self.groupBox)
        self.frame.setGeometry(QtCore.QRect(40, 80, 601, 321))
        self.frame.setStyleSheet("background-color: rgb(240, 240, 240);")
        self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
        self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
        self.frame.setObjectName("frame")
        self.formLayoutWidget = QtWidgets.QWidget(self.frame)
        self.formLayoutWidget.setGeometry(QtCore.QRect(10, 10, 581, 251))
        self.formLayoutWidget.setObjectName("formLayoutWidget")
        self.formLayout = QtWidgets.QFormLayout(self.formLayoutWidget)
        self.formLayout.setContentsMargins(0, 0, 0, 0)
        self.formLayout.setObjectName("formLayout")
        self.label_2 = QtWidgets.QLabel(self.formLayoutWidget)
        self.label_2.setObjectName("label_2")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.label_2)
        self.Category = QtWidgets.QComboBox(self.formLayoutWidget)
        self.Category.setObjectName("Category")
        self.Category.addItem("")
        self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.Category)
        self.label_3 = QtWidgets.QLabel(self.formLayoutWidget)
        self.label_3.setObjectName("label_3")
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.LabelRole, self.label_3)
        self.Topic = QtWidgets.QComboBox(self.formLayoutWidget)
        self.Topic.setObjectName("Topic")
        self.Topic.addItem("")
        self.formLayout.setWidget(1, QtWidgets.QFormLayout.FieldRole, self.Topic)
        self.label_4 = QtWidgets.QLabel(self.formLayoutWidget)
        self.label_4.setObjectName("label_4")
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.label_4)
        self.Tag = QtWidgets.QLineEdit(self.formLayoutWidget)
        self.Tag.setObjectName("Tag")
        self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.Tag)
        self.label_5 = QtWidgets.QLabel(self.formLayoutWidget)
        self.label_5.setObjectName("label_5")
        self.formLayout.setWidget(3, QtWidgets.QFormLayout.LabelRole, self.label_5)
        self.FileName = QtWidgets.QLineEdit(self.formLayoutWidget)
        self.FileName.setObjectName("FileName")
        self.formLayout.setWidget(3, QtWidgets.QFormLayout.FieldRole, self.FileName)
        self.CariinDirec = QtWidgets.QPushButton(self.formLayoutWidget)
        self.CariinDirec.setObjectName("CariinDirec")
        self.formLayout.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.CariinDirec)
        self.pushButton_2 = QtWidgets.QPushButton(self.frame)
        self.pushButton_2.setGeometry(QtCore.QRect(500, 270, 93, 28))
        self.pushButton_2.setObjectName("pushButton_2")
        InsertDocument.setCentralWidget(self.centralwidget)

        self.retranslateUi(InsertDocument)
        QtCore.QMetaObject.connectSlotsByName(InsertDocument)

        for i in Category.getList():
            self.nambahinCat(i)
        for i in Topic.getList():
            self.nambahinTop(i)

        #code here
        self.CariinDirec.clicked.connect(self.CariinDung)
        self.pushButton_2.clicked.connect(self.Inputin)

    def retranslateUi(self, InsertDocument):
        _translate = QtCore.QCoreApplication.translate
        InsertDocument.setWindowTitle(_translate("InsertDocument", "MainWindow"))
        self.label.setText(_translate("InsertDocument", "Insert New Document"))
        self.label_2.setText(_translate("InsertDocument", "Category ID"))
        self.Category.setItemText(0, _translate("InsertDocument", "-Category ID-"))
        self.label_3.setText(_translate("InsertDocument", "Topic ID"))
        self.Topic.setItemText(0, _translate("InsertDocument", "-Topic ID-"))
        self.label_4.setText(_translate("InsertDocument", "Tag"))
        self.Tag.setPlaceholderText(_translate("InsertDocument", "Tag"))
        self.label_5.setText(_translate("InsertDocument", "File Name"))
        self.FileName.setPlaceholderText(_translate("InsertDocument", "Filename"))
        self.CariinDirec.setText(_translate("InsertDocument", "..."))
        self.pushButton_2.setText(_translate("InsertDocument", "Insert"))

    def Inputin(self):
        CatID = self.Category.currentText()
        TopID = self.Topic.currentText()
        FName = self.FileName.text()
        Tag = self.Tag.text()
        if CatID == "-Category ID-" or TopID == "-Topic ID-" or not(FName and Tag):
            self.show_Popup("Harap Isi Semua Kelengkapan Data")
            return 0
        print(CatID,TopID,Tag,FName)
        self.a = Document(CatID,TopID,Tag,FName)
        self.a.masukin()

    def CariinDung(self):
        filename = QtWidgets.QFileDialog.getOpenFileName()
        nama = ''
        filename = filename[0]
        for i in range(len(filename)-1,0,-1):
            if filename[i] != '/':
                nama = filename[i]+nama
            else:
                break
        self.FileName.setText(nama)
        self.Dir=filename

    def nambahinCat(self,nilai):
        self.Category.addItem(nilai)

    def nambahinTop(self,nilai):
        self.Topic.addItem(nilai)

    def show_Popup(self,message):
        msg = QMessageBox()
        msg.setWindowTitle("Message")
        msg.setText(message)
        x = msg.exec_()


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    InsertDocument = QtWidgets.QMainWindow()
    ui = Ui_InsertDocument()
    ui.setupUi(InsertDocument)
    InsertDocument.show()
    sys.exit(app.exec_())
