Beispiel #1
0
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.about = About()

        self.filelist = None
        self.file_save_path = None
        # self.setMinimumSize(850, 814)
        # self.setWindowTitle("PDF- ja TIF-mittaaja")
        # Tab 1 widgets & connections
        self.tableView = TableView()
        self.tableView.filelist_signal.connect(self.update_filelist)
        self.tableView.file_save_path_signal.connect(self.update_file_save_path)
        # Fixaa UI-tiedosto!
        self.horizontalLayout_2.addWidget(self.tableView)
        self.horizontalLayout_2.addWidget(self.summaryBrowser)
        self.summaryBrowser.setMaximumWidth(200)
        self.horizontalLayout_2.setStretch(7, 1)
        # Signals
        self.saveXlsButton.clicked.connect(self.save_dialog_xls)
        self.saveXmlButton.clicked.connect(self.save_dialog_xml)
        self.rotateButton.clicked.connect(self.rotate)
        self.chooseFolderButton.clicked.connect(self.open_dialog_folders)
        self.summaryButton.clicked.connect(self.summary_create)
        self.clearTableButton.clicked.connect(self.clear_table)
        self.actionTietoja_ohjelmasta.triggered.connect(self.aboutOpen)
        self.actionAvaa_tiedosto.setDisabled(True)
        self.actionAvaa_kansio.triggered.connect(self.open_dialog_folders)
        self.actionTallenna_XLS.triggered.connect(self.save_dialog_xls)
        self.actionTallenna_XML.triggered.connect(self.save_dialog_xml)
        self.actionSulje_ohjelma.triggered.connect(self.closeApp)
Beispiel #2
0
    def __init__(self):
        #Build out UI
        QtGui.QMainWindow.__init__(self)
        self.setupUi(self)

        #Setup Inherited Tab Classes
        ManagementTasks.ManagementTasks.__init__(self)
        Slabs.Slabs.__init__(self)
        Stats.Stats.__init__(self)
        self.currentTab = 'MTasks'

        #Startup the Dialogs
        self.addDialog = Add.AddServersClusters()
        self.preferencesDialog = Preferences.Preferences()
        self.aboutDialog = About.About()
        self.cachedItemDialog = CachedItem.CachedItem()

        #Load Settings
        self.settings = Settings()

        #Bind to events
        self.connect(self.actionAddClusterServer, QtCore.SIGNAL("triggered()"),
                     self.displayAdd)
        self.connect(self.actionAbout, QtCore.SIGNAL("triggered()"),
                     self.displayAbout)
        self.connect(self.addDialog, QtCore.SIGNAL('savedCluster'),
                     self.addCluster)

        self.connect(self.actionSave, QtCore.SIGNAL('triggered()'), self.save)
        self.connect(self.actionPreferences, QtCore.SIGNAL('triggered()'),
                     self.displayPreferences)
        self.connect(self.tabsMain, QtCore.SIGNAL('currentChanged(QWidget*)'),
                     self.mainTabChanged)

        self.treeCluster.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.connect(self.treeCluster,
                     QtCore.SIGNAL('itemDoubleClicked(QTreeWidgetItem*, int)'),
                     self.setClusterByTree)
        self.connect(self.treeCluster,
                     QtCore.SIGNAL('customContextMenuRequested(QPoint)'),
                     self.displayTreeContextMenu)

        self.currentCluster = None

        #Build out Cluster Tree
        for cluster in self.settings.servers.getClusters():
            self.addCluster(cluster)

        #Create the Icons
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap(Main.getIconPath("memLogo.png")),
                       QtGui.QIcon.Normal, QtGui.QIcon.Off)
        addIcon = QtGui.QIcon()
        addIcon.addPixmap(QtGui.QPixmap(Main.getIconPath("Add.png")),
                          QtGui.QIcon.Normal, QtGui.QIcon.On)
        removeIcon = QtGui.QIcon()
        removeIcon.addPixmap(QtGui.QPixmap(Main.getIconPath("Remove.png")),
                             QtGui.QIcon.Normal, QtGui.QIcon.On)
        activeIcon = QtGui.QIcon()
        activeIcon.addPixmap(QtGui.QPixmap(Main.getIconPath("Active.png")),
                             QtGui.QIcon.Normal, QtGui.QIcon.On)

        #Reset the Window Icon as paths change
        self.setWindowIcon(icon)

        #Build out the Cluster Tree Context Menus
        self.treeCMServer = QtGui.QMenu()
        self.treeCMServerActions = {
            "addServer": QtGui.QAction(self),
            "deleteServer": QtGui.QAction(self)
        }

        self.treeCMServerActions['addServer'].setText("Add Server/Cluster")
        self.treeCMServerActions['addServer'].setIcon(addIcon)
        self.treeCMServer.addAction(self.treeCMServerActions['addServer'])

        self.treeCMServerActions['deleteServer'].setText("Delete")
        self.treeCMServerActions['deleteServer'].setIcon(removeIcon)
        self.treeCMServer.addAction(self.treeCMServerActions['deleteServer'])

        self.connect(self.treeCMServerActions['addServer'],
                     QtCore.SIGNAL("triggered()"), self.displayAdd)
        self.connect(self.treeCMServerActions['deleteServer'],
                     QtCore.SIGNAL("triggered()"), self.deleteServer)

        self.treeCMCluster = QtGui.QMenu()
        self.treeCMClusterActions = {
            "addServer": QtGui.QAction(self),
            "deleteCluster": QtGui.QAction(self),
            "makeActive": QtGui.QAction(self)
        }

        self.treeCMClusterActions['addServer'].setText("Add Server/Cluster")
        self.treeCMClusterActions['addServer'].setIcon(addIcon)
        self.treeCMCluster.addAction(self.treeCMClusterActions['addServer'])

        self.treeCMClusterActions['deleteCluster'].setText("Delete")
        self.treeCMClusterActions['deleteCluster'].setIcon(removeIcon)
        self.treeCMCluster.addAction(
            self.treeCMClusterActions['deleteCluster'])

        self.treeCMClusterActions['makeActive'].setText("Make Active")
        self.treeCMClusterActions['makeActive'].setIcon(activeIcon)
        self.treeCMCluster.addAction(self.treeCMClusterActions['makeActive'])

        self.connect(self.treeCMClusterActions['addServer'],
                     QtCore.SIGNAL("triggered()"), self.displayAdd)
        self.connect(self.treeCMClusterActions['deleteCluster'],
                     QtCore.SIGNAL("triggered()"), self.deleteCluster)
        self.connect(self.treeCMClusterActions['makeActive'],
                     QtCore.SIGNAL("triggered()"),
                     self.setClusterByContextMenu)
Beispiel #3
0
class MainWindow(QMainWindow, GUI.Ui_MainWindow):
    def __init__(self, parent=None):
        super(MainWindow, self).__init__(parent)
        self.setupUi(self)
        self.about = About()

        self.filelist = None
        self.file_save_path = None
        # self.setMinimumSize(850, 814)
        # self.setWindowTitle("PDF- ja TIF-mittaaja")
        # Tab 1 widgets & connections
        self.tableView = TableView()
        self.tableView.filelist_signal.connect(self.update_filelist)
        self.tableView.file_save_path_signal.connect(self.update_file_save_path)
        # Fixaa UI-tiedosto!
        self.horizontalLayout_2.addWidget(self.tableView)
        self.horizontalLayout_2.addWidget(self.summaryBrowser)
        self.summaryBrowser.setMaximumWidth(200)
        self.horizontalLayout_2.setStretch(7, 1)
        # Signals
        self.saveXlsButton.clicked.connect(self.save_dialog_xls)
        self.saveXmlButton.clicked.connect(self.save_dialog_xml)
        self.rotateButton.clicked.connect(self.rotate)
        self.chooseFolderButton.clicked.connect(self.open_dialog_folders)
        self.summaryButton.clicked.connect(self.summary_create)
        self.clearTableButton.clicked.connect(self.clear_table)
        self.actionTietoja_ohjelmasta.triggered.connect(self.aboutOpen)
        self.actionAvaa_tiedosto.setDisabled(True)
        self.actionAvaa_kansio.triggered.connect(self.open_dialog_folders)
        self.actionTallenna_XLS.triggered.connect(self.save_dialog_xls)
        self.actionTallenna_XML.triggered.connect(self.save_dialog_xml)
        self.actionSulje_ohjelma.triggered.connect(self.closeApp)

    def update_filelist(self, filelist):
        if len(filelist) > 0:
            self.filelist = filelist
            model = Model(self, filelist)
            self.tableView.setModel(model)
            return self.filelist
        return False

    def update_file_save_path(self, file_save_path):
        if len(file_save_path) > 0:
            self.file_save_path = file_save_path
            return self.file_save_path
        return False

    # Filedialogs for opening and saving files.
    def open_dialog_folders(self):

        dir = None
        try:
            dir = "V:/01 - Tilaukset/"
        except Exception:
            dir = "."

        file_path = QFileDialog.getExistingDirectory(self, "Valitse kansio", dir)
        self.file_save_path = file_path
        self.processFolderData(unicode(file_path))

    def save_dialog_xls(self):
        if self.filelist == None:
            return QMessageBox.warning(self, u"Tyhjä taulukko", "Ei tallennettavia tietoja.")

        file_path = QFileDialog.getSaveFileName(
            self, u"Tallenna Excel-muotoon", self.file_save_path, "Excel-files(*.xls)"
        )

        return Export(self, self.filelist, file_path[0]).create_xls()

    def save_dialog_xml(self):
        if self.filelist == None:
            return QMessageBox.warning(self, u"Tyhjä taulukko", "Ei tallennettavia tietoja.")

        return Export(self, self.filelist, self.file_save_path).create_xml()

    def rotate(self):
        rotator = Rotation(self.filelist)
        rotator.rotate(90)

    def summary_create(self):
        """ summary_create makes a list out of the contents of the filelist.
        summary_create displays total amount of files and how many A4/A3
        documents (+pages) the filelist has."""

        summary_data = [str(row[1]) for row in self.filelist]
        summary_data_sorted = [v for v, r in itertools.groupby(sorted(summary_data)) if len(list(r)) >= 1]

        document_data = [row[1:3] for row in self.filedata]
        pages_a4 = 0
        pages_a3 = 0
        a4 = []
        a3 = []

        for i in summary_data_sorted:

            self.summaryBrowser.append("<b>%s kpl</b> %s" % (summary_data.count(i), str(i)))

        self.summaryBrowser.append("Tiedostoja yhteens\xe4 = <b>%d</b>" % (len(summary_data)))

        for i in document_data:
            page_size = i[0]
            page_count = i[1]
            """ page_size (eg. 210x297) is transformed into a tuple holding the
            width and height of the document. page_size_tuple is put through a
            conditional to see if the size is A4 or A3 (or something else)."""
            page_size_tuple = page_size.replace("x", ",")
            page_size_tuple = tuple(size for size in page_size_tuple.split(",") if size.strip())

            if 310 > int(page_size_tuple[0]) > 200 and 310 > int(page_size_tuple[1]) > 200:

                pages_a4 += int(page_count)
                a4.append(page_size)
            elif 440 > int(page_size_tuple[0]) > 270 and 440 > int(page_size_tuple[1]) > 200:

                pages_a3 += int(page_count)
                a3.append(page_size)

        self.summaryBrowser.append("A4-kokoisia: <b>%d(%d)=%d</b>" % (len(a4), (pages_a4 - len(a4)), pages_a4))
        self.summaryBrowser.append("A3-kokoisia: <b>%d(%d)=%d</b>" % (len(a3), (pages_a3 - len(a3)), pages_a3))

    def processFolderData(self, path):
        """ processFolderData determines which processing method it's going to
        use: TIF/PDF/TIF+PDF & Recursive/Not-recursive"""

        filelist = []
        fs = Filesorter([path])

        if self.checkBox.isChecked():
            if self.fileTypeComboBox.currentIndex() == 0:
                filelist.extend(fs.sorter("tif"))
            elif self.fileTypeComboBox.currentIndex() == 1:
                filelist.extend(fs.sorter("pdf"))
            else:
                filelist.extend(fs.sorter())
        else:
            if self.fileTypeComboBox.currentIndex() == 0:
                for filename in os.listdir(path):
                    if filename.lower().endswith(".tif"):
                        filelist.append(os.path.join(path, filename))
            elif self.fileTypeComboBox.currentIndex() == 1:
                for filename in os.listdir(path):
                    if filename.lower().endswith(".pdf"):
                        filelist.append(os.path.join(path, filename))
            else:
                for filename in os.listdir(path):
                    if filename.lower().endswith(".pdf") | filename.lower().endswith(".tif"):
                        filelist.append(os.path.join(path, filename))

        process = Process(filelist)
        process.processed.connect(self.update_filelist, Qt.QueuedConnection)
        process.run()

    def clear_table(self):

        self.tableView.model.reset()
        self.summaryBrowser.clearHistory()

    def aboutOpen(self):
        self.about.exec_()

    def closeApp(self):
        sys.exit(0)