Exemplo n.º 1
0
    def __init__(self):
        QMainWindow.__init__(self)

        self.setWindowIcon(createIcon('main.ico'))

        self.createStatusBar()
        menubar = self.menuBar()

        self.collectionActs = []

        settingsAct = QAction(createIcon('cog.png'),
                                    self.tr("Settings..."), self)
        settingsAct.triggered.connect(self.settingsEvent)

        cancelFilteringAct = QAction(createIcon('funnel.png'),
                                    self.tr("Clear all filters"), self)
        cancelFilteringAct.triggered.connect(self.cancelFilteringEvent)
        self.collectionActs.append(cancelFilteringAct)

        self.exitAct = QAction(createIcon('door_in.png'),
                                self.tr("E&xit"), self)
        self.exitAct.setShortcut(QKeySequence.Quit)
        self.exitAct.triggered.connect(self.close)

        newCollectionAct = QAction(self.tr("&New..."), self)
        newCollectionAct.triggered.connect(self.newCollectionEvent)

        style = QApplication.style()
        icon = style.standardIcon(QStyle.SP_DialogOpenButton)
        openCollectionAct = QAction(icon, self.tr("&Open..."), self)
        openCollectionAct.setShortcut(QKeySequence.Open)
        openCollectionAct.triggered.connect(self.openCollectionEvent)

        backupCollectionAct = QAction(
                                    createIcon('database_backup.png'),
                                    self.tr("Backup"), self)
        backupCollectionAct.triggered.connect(self.backupCollectionEvent)
        self.collectionActs.append(backupCollectionAct)

        vacuumCollectionAct = QAction(
                                    createIcon('compress.png'),
                                    self.tr("Vacuum"), self)
        vacuumCollectionAct.triggered.connect(self.vacuumCollectionEvent)
        self.collectionActs.append(vacuumCollectionAct)

        descriptionCollectionAct = QAction(self.tr("Description"), self)
        descriptionCollectionAct.triggered.connect(
                                            self.descriptionCollectionEvent)
        self.collectionActs.append(descriptionCollectionAct)

        passwordCollectionAct = QAction(createIcon('key.png'),
                                              self.tr("Set password..."), self)
        passwordCollectionAct.triggered.connect(self.passwordCollectionEvent)
        self.collectionActs.append(passwordCollectionAct)

        importMenu = QMenu(self.tr("Import"), self)
        self.collectionActs.append(importMenu)

        if ImportNumizmat.isAvailable():
            importNumizmatAct = QAction(
                                    createIcon('numizmat.ico'),
                                    self.tr("Numizmat 2.1"), self)
            importNumizmatAct.triggered.connect(self.importNumizmat)
            self.collectionActs.append(importNumizmatAct)
            importMenu.addAction(importNumizmatAct)

        if ImportCabinet.isAvailable():
            importCabinetAct = QAction(
                                    createIcon('cabinet.ico'),
                                    self.tr("Cabinet 2.2.2.1, 2013"), self)
            importCabinetAct.triggered.connect(self.importCabinet)
            self.collectionActs.append(importCabinetAct)
            importMenu.addAction(importCabinetAct)

        if ImportCoinsCollector.isAvailable():
            importCoinsCollectorAct = QAction(
                                    createIcon('CoinsCollector.ico'),
                                    self.tr("CoinsCollector 2.6"), self)
            importCoinsCollectorAct.triggered.connect(
                                                    self.importCoinsCollector)
            self.collectionActs.append(importCoinsCollectorAct)
            importMenu.addAction(importCoinsCollectorAct)

        if ImportCoinManage.isAvailable():
            importCoinManageAct = QAction(
                                    createIcon('CoinManage.ico'),
                                    self.tr("CoinManage 2011"), self)
            importCoinManageAct.triggered.connect(self.importCoinManage)
            self.collectionActs.append(importCoinManageAct)
            importMenu.addAction(importCoinManageAct)

        if ImportCollectionStudio.isAvailable():
            importCollectionStudioAct = QAction(
                                    createIcon('CollectionStudio.ico'),
                                    self.tr("Collection Studio 3.65"), self)
            importCollectionStudioAct.triggered.connect(
                                                self.importCollectionStudio)
            self.collectionActs.append(importCollectionStudioAct)
            importMenu.addAction(importCollectionStudioAct)

        if ImportTellico.isAvailable():
            importTellicoAct = QAction(
                                    createIcon('tellico.png'),
                                    self.tr("Tellico"), self)
            importTellicoAct.triggered.connect(
                                                self.importTellico)
            self.collectionActs.append(importTellicoAct)
            importMenu.addAction(importTellicoAct)

        if ImportNumizmatik_Ru.isAvailable():
            importNumizmaticRuAct = QAction(
                                    createIcon('Numizmatik_Ru.ico'),
                                    self.tr("Numizmatik_Ru 1.0.0.82"), self)
            importNumizmaticRuAct.triggered.connect(self.importNumizmatik_Ru)
            self.collectionActs.append(importNumizmaticRuAct)
            importMenu.addAction(importNumizmaticRuAct)

        if ImportUcoin.isAvailable():
            importUcoinAct = QAction(
                                    createIcon('ucoin.png'),
                                    self.tr("uCoin.net"), self)
            importUcoinAct.triggered.connect(self.importUcoin)
            self.collectionActs.append(importUcoinAct)
            importMenu.addAction(importUcoinAct)


        exportMenu = QMenu(self.tr("Export"), self)
        self.collectionActs.append(exportMenu)

        exportMobileAct = QAction(self.tr("For Android version"), self)
        exportMobileAct.triggered.connect(self.exportMobile)
        self.collectionActs.append(exportMobileAct)
        exportMenu.addAction(exportMobileAct)

        file = menubar.addMenu(self.tr("&File"))

        file.addAction(newCollectionAct)
        file.addAction(openCollectionAct)
        file.addSeparator()
        file.addAction(backupCollectionAct)
        file.addAction(vacuumCollectionAct)
        file.addAction(passwordCollectionAct)
        file.addAction(descriptionCollectionAct)
        file.addSeparator()
        file.addMenu(importMenu)
        file.addSeparator()
        file.addMenu(exportMenu)
        file.addSeparator()

        self.latestActions = []
        self.__updateLatest(file)

        file.addAction(settingsAct)
        file.addSeparator()

        file.addAction(self.exitAct)

        addCoinAct = QAction(createIcon('add.png'),
                                   self.tr("Add"), self)
        addCoinAct.setShortcut('Insert')
        addCoinAct.triggered.connect(self.addCoin)
        self.collectionActs.append(addCoinAct)

        editCoinAct = QAction(createIcon('pencil.png'),
                                   self.tr("Edit..."), self)
        editCoinAct.triggered.connect(self.editCoin)
        self.collectionActs.append(editCoinAct)

        style = QApplication.style()
        icon = style.standardIcon(QStyle.SP_TrashIcon)
        deleteCoinAct = QAction(icon,
                                   self.tr("Delete"), self)
        deleteCoinAct.setShortcut(QKeySequence.Delete)
        deleteCoinAct.triggered.connect(self.deleteCoin)
        self.collectionActs.append(deleteCoinAct)

        copyCoinAct = QAction(createIcon('page_copy.png'),
                                   self.tr("Copy"), self)
        copyCoinAct.setShortcut(QKeySequence.Copy)
        copyCoinAct.triggered.connect(self.copyCoin)
        self.collectionActs.append(copyCoinAct)

        pasteCoinAct = QAction(createIcon('page_paste.png'),
                                   self.tr("Paste"), self)
        pasteCoinAct.setShortcut(QKeySequence.Paste)
        pasteCoinAct.triggered.connect(self.pasteCoin)
        self.collectionActs.append(pasteCoinAct)

        coin = menubar.addMenu(self.tr("Coin"))
        self.collectionActs.append(coin)
        coin.addAction(addCoinAct)
        coin.addAction(editCoinAct)
        coin.addSeparator()
        coin.addAction(copyCoinAct)
        coin.addAction(pasteCoinAct)
        coin.addSeparator()
        coin.addAction(deleteCoinAct)

        viewBrowserAct = QAction(createIcon('page_white_world.png'),
                                   self.tr("View in browser"), self)
        viewBrowserAct.triggered.connect(self.viewBrowser)
        self.collectionActs.append(viewBrowserAct)

        self.viewTab = TabView(self)

        actions = self.viewTab.actions()
        listMenu = menubar.addMenu(self.tr("List"))
        self.collectionActs.append(listMenu)
        listMenu.addAction(actions['new'])
        listMenu.addMenu(actions['open'])
        listMenu.aboutToShow.connect(self.viewTab.updateOpenPageMenu)
        listMenu.addAction(actions['rename'])
        listMenu.addSeparator()
        listMenu.addAction(actions['select'])
        listMenu.addSeparator()
        listMenu.addAction(actions['close'])
        listMenu.addAction(actions['remove'])

        self.referenceMenu = menubar.addMenu(self.tr("Reference"))

        reportAct = QAction(self.tr("Report..."), self)
        reportAct.setShortcut(Qt.CTRL + Qt.Key_P)
        reportAct.triggered.connect(self.report)
        self.collectionActs.append(reportAct)

        saveTableAct = QAction(createIcon('table.png'),
                                     self.tr("Save current list..."), self)
        saveTableAct.triggered.connect(self.saveTable)
        self.collectionActs.append(saveTableAct)

        report = menubar.addMenu(self.tr("Report"))
        self.collectionActs.append(report)
        report.addAction(reportAct)
        report.addAction(saveTableAct)
        report.addAction(viewBrowserAct)

        helpAct = QAction(createIcon('help.png'),
                                self.tr("Online help"), self)
        helpAct.setShortcut(QKeySequence.HelpContents)
        helpAct.triggered.connect(self.onlineHelp)
        checkUpdatesAct = QAction(self.tr("Check for updates"), self)
        checkUpdatesAct.triggered.connect(self.manualUpdate)
        aboutAct = QAction(self.tr("About %s") % version.AppName, self)
        aboutAct.triggered.connect(self.about)

        help_ = menubar.addMenu(self.tr("&Help"))
        help_.addAction(helpAct)
        help_.addSeparator()
        help_.addAction(checkUpdatesAct)
        help_.addSeparator()
        help_.addAction(aboutAct)

        toolBar = QToolBar(self.tr("Toolbar"), self)
        toolBar.setMovable(False)
        toolBar.addAction(openCollectionAct)
        toolBar.addSeparator()
        toolBar.addAction(addCoinAct)
        toolBar.addAction(editCoinAct)
        toolBar.addAction(viewBrowserAct)
        toolBar.addSeparator()
        toolBar.addAction(cancelFilteringAct)
        toolBar.addSeparator()
        toolBar.addAction(settingsAct)
        self.addToolBar(toolBar)

        self.setWindowTitle(version.AppName)

        self.reference = Reference(self)
        self.reference.open(Settings()['reference'])

        if len(sys.argv) > 1:
            fileName = sys.argv[1]
        else:
            latest = LatestCollections(self)
            fileName = latest.latest()

        self.collection = Collection(self.reference, self)
        self.openCollection(fileName)

        self.setCentralWidget(self.viewTab)

        settings = QSettings()
        pageIndex = settings.value('tabwindow/page')
        if pageIndex != None:
            self.viewTab.setCurrentIndex(int(pageIndex))

        if settings.value('mainwindow/maximized') == 'true':
            self.showMaximized()
            size = settings.value('mainwindow/maximizedsize')
        else:
            size = settings.value('mainwindow/size')

        if size:
            self.resize(size)

        self.autoUpdate()
Exemplo n.º 2
0
    buffer.open(QtCore.QIODevice.WriteOnly)

    image = QtGui.QImage(fileName)
    image.save(buffer, 'png')

    return ba

import sys
sys.path.append('..')
from OpenNumismat.Reference.Reference import Reference

shutil.copy("../OpenNumismat/db/reference_en.ref", ".")

app = QApplication(sys.argv)

ref = Reference()
ref.open('reference_en.ref')

place = ref.section('payplace')
place.addItem('eBay', convertImage('icons/ebay.png'))
place.model.submitAll()

rarity = ref.section('rarity')
rarity.addItem('Common')
rarity.addItem('Normal')
rarity.addItem('Scarce')
rarity.addItem('Rare')
rarity.addItem('Unique')
rarity.addItem('In sets only')
rarity.model.submitAll()
Exemplo n.º 3
0
    buffer.open(QtCore.QIODevice.WriteOnly)

    image = QtGui.QImage(fileName)
    image.save(buffer, 'png')

    return ba

import sys
sys.path.append('..')
from OpenNumismat.Reference.Reference import Reference

shutil.copy("../OpenNumismat/db/reference_es.ref", ".")

app = QApplication(sys.argv)

ref = Reference()
ref.open('reference_es.ref')

place = ref.section('payplace')
place.addItem('eBay', convertImage('icons/ebay.png'))
place.model.submitAll()

rarity = ref.section('rarity')
rarity.addItem('Común')
rarity.addItem('Normal')
rarity.addItem('Limitada')
rarity.addItem('Rara')
rarity.addItem('Única')
rarity.addItem('Sólo en sets')
rarity.model.submitAll()
Exemplo n.º 4
0
class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.setWindowIcon(createIcon('main.ico'))

        self.createStatusBar()
        menubar = self.menuBar()

        self.collectionActs = []

        settingsAct = QAction(createIcon('cog.png'),
                                    self.tr("Settings..."), self)
        settingsAct.triggered.connect(self.settingsEvent)

        cancelFilteringAct = QAction(createIcon('funnel.png'),
                                    self.tr("Clear all filters"), self)
        cancelFilteringAct.triggered.connect(self.cancelFilteringEvent)
        self.collectionActs.append(cancelFilteringAct)

        self.exitAct = QAction(createIcon('door_in.png'),
                                self.tr("E&xit"), self)
        self.exitAct.setShortcut(QKeySequence.Quit)
        self.exitAct.triggered.connect(self.close)

        newCollectionAct = QAction(self.tr("&New..."), self)
        newCollectionAct.triggered.connect(self.newCollectionEvent)

        style = QApplication.style()
        icon = style.standardIcon(QStyle.SP_DialogOpenButton)
        openCollectionAct = QAction(icon, self.tr("&Open..."), self)
        openCollectionAct.setShortcut(QKeySequence.Open)
        openCollectionAct.triggered.connect(self.openCollectionEvent)

        backupCollectionAct = QAction(
                                    createIcon('database_backup.png'),
                                    self.tr("Backup"), self)
        backupCollectionAct.triggered.connect(self.backupCollectionEvent)
        self.collectionActs.append(backupCollectionAct)

        vacuumCollectionAct = QAction(
                                    createIcon('compress.png'),
                                    self.tr("Vacuum"), self)
        vacuumCollectionAct.triggered.connect(self.vacuumCollectionEvent)
        self.collectionActs.append(vacuumCollectionAct)

        descriptionCollectionAct = QAction(self.tr("Description"), self)
        descriptionCollectionAct.triggered.connect(
                                            self.descriptionCollectionEvent)
        self.collectionActs.append(descriptionCollectionAct)

        passwordCollectionAct = QAction(createIcon('key.png'),
                                              self.tr("Set password..."), self)
        passwordCollectionAct.triggered.connect(self.passwordCollectionEvent)
        self.collectionActs.append(passwordCollectionAct)

        importMenu = QMenu(self.tr("Import"), self)
        self.collectionActs.append(importMenu)

        if ImportNumizmat.isAvailable():
            importNumizmatAct = QAction(
                                    createIcon('numizmat.ico'),
                                    self.tr("Numizmat 2.1"), self)
            importNumizmatAct.triggered.connect(self.importNumizmat)
            self.collectionActs.append(importNumizmatAct)
            importMenu.addAction(importNumizmatAct)

        if ImportCabinet.isAvailable():
            importCabinetAct = QAction(
                                    createIcon('cabinet.ico'),
                                    self.tr("Cabinet 2.2.2.1, 2013"), self)
            importCabinetAct.triggered.connect(self.importCabinet)
            self.collectionActs.append(importCabinetAct)
            importMenu.addAction(importCabinetAct)

        if ImportCoinsCollector.isAvailable():
            importCoinsCollectorAct = QAction(
                                    createIcon('CoinsCollector.ico'),
                                    self.tr("CoinsCollector 2.6"), self)
            importCoinsCollectorAct.triggered.connect(
                                                    self.importCoinsCollector)
            self.collectionActs.append(importCoinsCollectorAct)
            importMenu.addAction(importCoinsCollectorAct)

        if ImportCoinManage.isAvailable():
            importCoinManageAct = QAction(
                                    createIcon('CoinManage.ico'),
                                    self.tr("CoinManage 2011"), self)
            importCoinManageAct.triggered.connect(self.importCoinManage)
            self.collectionActs.append(importCoinManageAct)
            importMenu.addAction(importCoinManageAct)

        if ImportCollectionStudio.isAvailable():
            importCollectionStudioAct = QAction(
                                    createIcon('CollectionStudio.ico'),
                                    self.tr("Collection Studio 3.65"), self)
            importCollectionStudioAct.triggered.connect(
                                                self.importCollectionStudio)
            self.collectionActs.append(importCollectionStudioAct)
            importMenu.addAction(importCollectionStudioAct)

        if ImportTellico.isAvailable():
            importTellicoAct = QAction(
                                    createIcon('tellico.png'),
                                    self.tr("Tellico"), self)
            importTellicoAct.triggered.connect(
                                                self.importTellico)
            self.collectionActs.append(importTellicoAct)
            importMenu.addAction(importTellicoAct)

        if ImportNumizmatik_Ru.isAvailable():
            importNumizmaticRuAct = QAction(
                                    createIcon('Numizmatik_Ru.ico'),
                                    self.tr("Numizmatik_Ru 1.0.0.82"), self)
            importNumizmaticRuAct.triggered.connect(self.importNumizmatik_Ru)
            self.collectionActs.append(importNumizmaticRuAct)
            importMenu.addAction(importNumizmaticRuAct)

        if ImportUcoin.isAvailable():
            importUcoinAct = QAction(
                                    createIcon('ucoin.png'),
                                    self.tr("uCoin.net"), self)
            importUcoinAct.triggered.connect(self.importUcoin)
            self.collectionActs.append(importUcoinAct)
            importMenu.addAction(importUcoinAct)


        exportMenu = QMenu(self.tr("Export"), self)
        self.collectionActs.append(exportMenu)

        exportMobileAct = QAction(self.tr("For Android version"), self)
        exportMobileAct.triggered.connect(self.exportMobile)
        self.collectionActs.append(exportMobileAct)
        exportMenu.addAction(exportMobileAct)

        file = menubar.addMenu(self.tr("&File"))

        file.addAction(newCollectionAct)
        file.addAction(openCollectionAct)
        file.addSeparator()
        file.addAction(backupCollectionAct)
        file.addAction(vacuumCollectionAct)
        file.addAction(passwordCollectionAct)
        file.addAction(descriptionCollectionAct)
        file.addSeparator()
        file.addMenu(importMenu)
        file.addSeparator()
        file.addMenu(exportMenu)
        file.addSeparator()

        self.latestActions = []
        self.__updateLatest(file)

        file.addAction(settingsAct)
        file.addSeparator()

        file.addAction(self.exitAct)

        addCoinAct = QAction(createIcon('add.png'),
                                   self.tr("Add"), self)
        addCoinAct.setShortcut('Insert')
        addCoinAct.triggered.connect(self.addCoin)
        self.collectionActs.append(addCoinAct)

        editCoinAct = QAction(createIcon('pencil.png'),
                                   self.tr("Edit..."), self)
        editCoinAct.triggered.connect(self.editCoin)
        self.collectionActs.append(editCoinAct)

        style = QApplication.style()
        icon = style.standardIcon(QStyle.SP_TrashIcon)
        deleteCoinAct = QAction(icon,
                                   self.tr("Delete"), self)
        deleteCoinAct.setShortcut(QKeySequence.Delete)
        deleteCoinAct.triggered.connect(self.deleteCoin)
        self.collectionActs.append(deleteCoinAct)

        copyCoinAct = QAction(createIcon('page_copy.png'),
                                   self.tr("Copy"), self)
        copyCoinAct.setShortcut(QKeySequence.Copy)
        copyCoinAct.triggered.connect(self.copyCoin)
        self.collectionActs.append(copyCoinAct)

        pasteCoinAct = QAction(createIcon('page_paste.png'),
                                   self.tr("Paste"), self)
        pasteCoinAct.setShortcut(QKeySequence.Paste)
        pasteCoinAct.triggered.connect(self.pasteCoin)
        self.collectionActs.append(pasteCoinAct)

        coin = menubar.addMenu(self.tr("Coin"))
        self.collectionActs.append(coin)
        coin.addAction(addCoinAct)
        coin.addAction(editCoinAct)
        coin.addSeparator()
        coin.addAction(copyCoinAct)
        coin.addAction(pasteCoinAct)
        coin.addSeparator()
        coin.addAction(deleteCoinAct)

        viewBrowserAct = QAction(createIcon('page_white_world.png'),
                                   self.tr("View in browser"), self)
        viewBrowserAct.triggered.connect(self.viewBrowser)
        self.collectionActs.append(viewBrowserAct)

        self.viewTab = TabView(self)

        actions = self.viewTab.actions()
        listMenu = menubar.addMenu(self.tr("List"))
        self.collectionActs.append(listMenu)
        listMenu.addAction(actions['new'])
        listMenu.addMenu(actions['open'])
        listMenu.aboutToShow.connect(self.viewTab.updateOpenPageMenu)
        listMenu.addAction(actions['rename'])
        listMenu.addSeparator()
        listMenu.addAction(actions['select'])
        listMenu.addSeparator()
        listMenu.addAction(actions['close'])
        listMenu.addAction(actions['remove'])

        self.referenceMenu = menubar.addMenu(self.tr("Reference"))

        reportAct = QAction(self.tr("Report..."), self)
        reportAct.setShortcut(Qt.CTRL + Qt.Key_P)
        reportAct.triggered.connect(self.report)
        self.collectionActs.append(reportAct)

        saveTableAct = QAction(createIcon('table.png'),
                                     self.tr("Save current list..."), self)
        saveTableAct.triggered.connect(self.saveTable)
        self.collectionActs.append(saveTableAct)

        report = menubar.addMenu(self.tr("Report"))
        self.collectionActs.append(report)
        report.addAction(reportAct)
        report.addAction(saveTableAct)
        report.addAction(viewBrowserAct)

        helpAct = QAction(createIcon('help.png'),
                                self.tr("Online help"), self)
        helpAct.setShortcut(QKeySequence.HelpContents)
        helpAct.triggered.connect(self.onlineHelp)
        checkUpdatesAct = QAction(self.tr("Check for updates"), self)
        checkUpdatesAct.triggered.connect(self.manualUpdate)
        aboutAct = QAction(self.tr("About %s") % version.AppName, self)
        aboutAct.triggered.connect(self.about)

        help_ = menubar.addMenu(self.tr("&Help"))
        help_.addAction(helpAct)
        help_.addSeparator()
        help_.addAction(checkUpdatesAct)
        help_.addSeparator()
        help_.addAction(aboutAct)

        toolBar = QToolBar(self.tr("Toolbar"), self)
        toolBar.setMovable(False)
        toolBar.addAction(openCollectionAct)
        toolBar.addSeparator()
        toolBar.addAction(addCoinAct)
        toolBar.addAction(editCoinAct)
        toolBar.addAction(viewBrowserAct)
        toolBar.addSeparator()
        toolBar.addAction(cancelFilteringAct)
        toolBar.addSeparator()
        toolBar.addAction(settingsAct)
        self.addToolBar(toolBar)

        self.setWindowTitle(version.AppName)

        self.reference = Reference(self)
        self.reference.open(Settings()['reference'])

        if len(sys.argv) > 1:
            fileName = sys.argv[1]
        else:
            latest = LatestCollections(self)
            fileName = latest.latest()

        self.collection = Collection(self.reference, self)
        self.openCollection(fileName)

        self.setCentralWidget(self.viewTab)

        settings = QSettings()
        pageIndex = settings.value('tabwindow/page')
        if pageIndex != None:
            self.viewTab.setCurrentIndex(int(pageIndex))

        if settings.value('mainwindow/maximized') == 'true':
            self.showMaximized()
            size = settings.value('mainwindow/maximizedsize')
        else:
            size = settings.value('mainwindow/size')

        if size:
            self.resize(size)

        self.autoUpdate()

    def createStatusBar(self):
        self.collectionFileLabel = QLabel()
        self.statusBar().addWidget(self.collectionFileLabel)

    def __updateLatest(self, menu=None):
        if menu:
            self.__menu = menu
        for act in self.latestActions:
            self.__menu.removeAction(act)

        self.latestActions = []
        latest = LatestCollections(self)
        for act in latest.actions():
            self.latestActions.append(act)
            act.latestTriggered.connect(self.openCollection)
            self.__menu.insertAction(self.exitAct, act)
        self.__menu.insertSeparator(self.exitAct)

    def cancelFilteringEvent(self):
        listView = self.viewTab.currentListView()
        listView.clearAllFilters()

    def settingsEvent(self):
        dialog = SettingsDialog(self.collection, self)
        res = dialog.exec_()
        if res == QDialog.Accepted:
            self.__restart()

    def __restart(self):
        result = QMessageBox.question(self, self.tr("Settings"),
                    self.tr("The application will need to restart to apply "
                            "the new settings. Restart it now?"),
                    QMessageBox.Yes | QMessageBox.No,
                    QMessageBox.Yes)
        if result == QMessageBox.Yes:
            self.close()
            program = sys.executable
            argv = []
            if program != sys.argv[0]:
                # Process running as Python arg
                argv.append(sys.argv[0])
            QProcess.startDetached(program, argv)

    def importNumizmat(self):
        defaultDir = ImportNumizmat.defaultDir()
        file, _selectedFilter = QFileDialog.getOpenFileName(self,
                                self.tr("Select file"), defaultDir, "*.fdb")
        if file:
            imp = ImportNumizmat(self)
            imp.importData(file, self.viewTab.currentModel())

    def importCabinet(self):
        QMessageBox.information(self, self.tr("Importing"),
                self.tr("Before importing you should export existing "
                        "collection from Cabinet."))

        defaultDir = ImportCabinet.defaultDir()
        directory = QFileDialog.getExistingDirectory(self,
                                self.tr("Select directory"), defaultDir)
        if directory:
            imp = ImportCabinet(self)
            imp.importData(directory, self.viewTab.currentModel())

    def importCoinsCollector(self):
        defaultDir = ImportCoinsCollector.defaultDir()
        directory = QFileDialog.getExistingDirectory(self,
                                self.tr("Select directory"), defaultDir)
        if directory:
            imp = ImportCoinsCollector(self)
            imp.importData(directory, self.viewTab.currentModel())

    def importCoinManage(self):
        defaultDir = ImportCoinManage.defaultDir()
        file, _selectedFilter = QFileDialog.getOpenFileName(self,
                                self.tr("Select file"), defaultDir, "*.mdb")
        if file:
            btn = QMessageBox.question(self, self.tr("Importing"),
                                self.tr("Import pre-defined coins?"),
                                QMessageBox.Yes | QMessageBox.No,
                                QMessageBox.Yes)
            if btn == QMessageBox.Yes:
                imp = ImportCoinManagePredefined(self)
                res = imp.importData(file, self.viewTab.currentModel())
                if not res:
                    return

            imp = ImportCoinManage(self)
            imp.importData(file, self.viewTab.currentModel())

    def importCollectionStudio(self):
        QMessageBox.information(self, self.tr("Importing"),
                self.tr("Before importing you should export existing "
                        "collection from Collection Studio to XML Table "
                        "(choose Collection Studio menu Tools > Export...)."))

        defaultDir = ImportCollectionStudio.defaultDir()
        file, _selectedFilter = QFileDialog.getOpenFileName(self,
                                self.tr("Select file"), defaultDir, "*.xml")
        if file:
            imp = ImportCollectionStudio(self)
            imp.importData(file, self.viewTab.currentModel())

    def importTellico(self):
#        QMessageBox.information(self, self.tr("Importing"),
#                self.tr("Before importing you should export existing "
#                        "collection from Collection Studio to XML Table "
#                        "(choose Collection Studio menu Tools > Export...)."))

        defaultDir = ImportTellico.defaultDir()
        file, _selectedFilter = QFileDialog.getOpenFileName(self,
                                self.tr("Select file"), defaultDir, "*.tc *.xml")
        if file:
            imp = ImportTellico(self)
            imp.importData(file, self.viewTab.currentModel())

    def importNumizmatik_Ru(self):
        defaultDir = ImportNumizmatik_Ru.defaultDir()
        file, _selectedFilter = QFileDialog.getOpenFileName(self,
                                self.tr("Select file"), defaultDir, "*.mdb")
        if file:
            btn = QMessageBox.question(self, self.tr("Importing"),
                                self.tr("Import club catalog?"),
                                QMessageBox.Yes | QMessageBox.No,
                                QMessageBox.Yes)
            if btn == QMessageBox.Yes:
                imp = ImportNumizmatik_RuPredefined(self)
                res = imp.importData(file, self.viewTab.currentModel())
                if not res:
                    return

            imp = ImportNumizmatik_Ru(self)
            imp.importData(file, self.viewTab.currentModel())

    def importUcoin(self):
        QMessageBox.information(self, self.tr("Importing"),
                self.tr("Before importing you should export existing "
                        "collection from uCoin.net to Comma-Separated (CSV) "
                        "format."))

        defaultDir = ImportUcoin.defaultDir()
        file, _selectedFilter = QFileDialog.getOpenFileName(self,
                                self.tr("Select file"), defaultDir, "*.csv")
        if file:
            imp = ImportUcoin(self)
            imp.importData(file, self.viewTab.currentModel())

    def exportMobile(self):
        dialog = ExportDialog(self.collection, self)
        res = dialog.exec_()
        if res == QDialog.Accepted:
            self.collection.exportToMobile(dialog.params)

    def addCoin(self):
        model = self.viewTab.currentModel()
        model.addCoin(model.record(), self)

    def editCoin(self):
        listView = self.viewTab.currentListView()
        indexes = listView.selectedRows()
        if len(indexes) == 1:
            listView._edit(indexes[0])
        elif len(indexes) > 1:
            listView._multiEdit(indexes)

    def deleteCoin(self):
        listView = self.viewTab.currentListView()
        indexes = listView.selectedRows()
        if len(indexes):
            listView._delete(indexes)

    def copyCoin(self):
        listView = self.viewTab.currentListView()
        indexes = listView.selectedRows()
        if len(indexes):
            listView._copy(indexes)

    def pasteCoin(self):
        listView = self.viewTab.currentListView()
        listView._paste()

    def viewBrowser(self):
        listView = self.viewTab.currentListView()
        listView.viewInBrowser()

    def report(self):
        listView = self.viewTab.currentListView()
        indexes = listView.selectedRows()
        model = listView.model()

        records = []
        for index in indexes:
            records.append(model.record(index.row()))

        preview = PreviewDialog(model, records, self)
        preview.exec_()

    def saveTable(self):
        listView = self.viewTab.currentListView()
        listView.saveTable()

    def __workingDir(self):
        fileName = self.collection.fileName
        if not fileName:
            fileName = LatestCollections.DefaultCollectionName
        return QFileInfo(fileName).absolutePath()

    def openCollectionEvent(self):
        fileName, _selectedFilter = QFileDialog.getOpenFileName(self,
                self.tr("Open collection"), self.__workingDir(),
                self.tr("Collections (*.db)"))
        if fileName:
            self.openCollection(fileName)

    def newCollectionEvent(self):
        fileName, _selectedFilter = QFileDialog.getSaveFileName(self,
                self.tr("New collection"), self.__workingDir(),
                self.tr("Collections (*.db)"), "",
                QFileDialog.DontConfirmOverwrite)
        if fileName:
            self.__saveParams()

            self.__closeCollection()
            if self.collection.create(fileName):
                self.setCollection(self.collection)

    def descriptionCollectionEvent(self, checked):
        dialog = DescriptionDialog(self.collection.getDescription(), self)
        dialog.exec_()

    def passwordCollectionEvent(self, checked):
        dialog = PasswordSetDialog(self.collection, self)
        dialog.exec_()

    def backupCollectionEvent(self, checked):
        self.collection.backup()

    def vacuumCollectionEvent(self, checked):
        self.collection.vacuum()

    def openCollection(self, fileName):
        self.__saveParams()

        self.__closeCollection()
        if self.collection.open(fileName):
            self.setCollection(self.collection)
        else:
            # Remove wrong collection from latest collections list
            latest = LatestCollections(self)
            latest.delete(fileName)
            self.__updateLatest()

    @waitCursorDecorator
    def setCollection(self, collection):
        self.__setEnabledActs(True)

        self.collectionFileLabel.setText(collection.getFileName())
        title = "%s - %s" % (collection.getCollectionName(), version.AppName)
        self.setWindowTitle(title)

        latest = LatestCollections(self)
        latest.add(collection.getFileName())
        self.__updateLatest()

        self.viewTab.setCollection(collection)

        self.referenceMenu.clear()
        for action in self.collection.referenceMenu(self):
            self.referenceMenu.addAction(action)

    def __setEnabledActs(self, enabled):
        for act in self.collectionActs:
            act.setEnabled(enabled)

    def __closeCollection(self):
        self.__setEnabledActs(False)
        self.viewTab.clear()

        self.referenceMenu.clear()

        self.collectionFileLabel.setText(
                self.tr("Create new collection or open one of the existing"))

        self.setWindowTitle(version.AppName)

    def closeEvent(self, e):
        self.__shutDown()

    def __shutDown(self):
        self.__saveParams()

        settings = QSettings()

        if self.collection.fileName:
            self.viewTab.savePagePositions()
            # Save latest opened page
            settings.setValue('tabwindow/page', self.viewTab.currentIndex())

        # Save main window size
        settings.setValue('mainwindow/maximized', self.isMaximized())
        if self.isMaximized():
            settings.setValue('mainwindow/maximizedsize', self.size())
        else:
            settings.setValue('mainwindow/size', self.size())

    def __saveParams(self):
        if self.collection.pages():
            for param in self.collection.pages().pagesParam():
                param.listParam.save()

    def about(self):
        QMessageBox.about(self, self.tr("About %s") % version.AppName,
                self.tr("%s %s\n\n"
                        "Copyright (C) 2011-2015 Vitaly Ignatov\n\n"
                        "%s is freeware licensed under a GPLv3.") %
                        (version.AppName, version.Version, version.AppName))

    def onlineHelp(self):
        url = QUrl(version.Web)

        executor = QDesktopServices()
        executor.openUrl(url)

    def autoUpdate(self):
        if Settings()['updates']:
            currentDate = QDate.currentDate()

            settings = QSettings()
            lastUpdateDateStr = settings.value('mainwindow/last_update')
            if lastUpdateDateStr:
                lastUpdateDate = QDate.fromString(lastUpdateDateStr,
                                                         Qt.ISODate)
                if lastUpdateDate.addDays(10) < currentDate:
                    self.checkUpdates()
            else:
                self.checkUpdates()

    def manualUpdate(self):
        if not self.checkUpdates():
            QMessageBox.information(self, self.tr("Updates"),
                    self.tr("You already have the latest version."))

    def checkUpdates(self):
        currentDate = QDate.currentDate()
        currentDateStr = currentDate.toString(Qt.ISODate)
        settings = QSettings()
        settings.setValue('mainwindow/last_update', currentDateStr)

        newVersion = self.__getNewVersion()
        if newVersion and newVersion != version.Version:
            result = QMessageBox.question(self, self.tr("New version"),
                        self.tr("New version is available. Download it now?"),
                        QMessageBox.Yes | QMessageBox.No,
                        QMessageBox.Yes)
            if result == QMessageBox.Yes:
                url = QUrl(version.Web)

                executor = QDesktopServices()
                executor.openUrl(url)

            return True
        else:
            return False

    @waitCursorDecorator
    def __getNewVersion(self):
        import urllib.request
        from xml.dom.minidom import parseString

        newVersion = version.Version

        try:
            url = "http://opennumismat.github.io/data/pad.xml"
            req = urllib.request.Request(url)
            data = urllib.request.urlopen(req).read()
            xml = parseString(data)
            tag = xml.getElementsByTagName('Program_Version')[0]
            newVersion = tag.firstChild.nodeValue
        except:
            return None

        return newVersion
Exemplo n.º 5
0
class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.setWindowIcon(createIcon('main.ico'))

        self.createStatusBar()
        menubar = self.menuBar()

        self.collectionActs = []

        settingsAct = QAction(createIcon('cog.png'), self.tr("Settings..."),
                              self)
        settingsAct.triggered.connect(self.settingsEvent)

        cancelFilteringAct = QAction(createIcon('funnel.png'),
                                     self.tr("Clear all filters"), self)
        cancelFilteringAct.triggered.connect(self.cancelFilteringEvent)
        self.collectionActs.append(cancelFilteringAct)

        self.exitAct = QAction(createIcon('door_in.png'), self.tr("E&xit"),
                               self)
        self.exitAct.setShortcut(QKeySequence.Quit)
        self.exitAct.triggered.connect(self.close)

        newCollectionAct = QAction(self.tr("&New..."), self)
        newCollectionAct.triggered.connect(self.newCollectionEvent)

        style = QApplication.style()
        icon = style.standardIcon(QStyle.SP_DialogOpenButton)
        openCollectionAct = QAction(icon, self.tr("&Open..."), self)
        openCollectionAct.setShortcut(QKeySequence.Open)
        openCollectionAct.triggered.connect(self.openCollectionEvent)

        backupCollectionAct = QAction(createIcon('database_backup.png'),
                                      self.tr("Backup"), self)
        backupCollectionAct.triggered.connect(self.backupCollectionEvent)
        self.collectionActs.append(backupCollectionAct)

        vacuumCollectionAct = QAction(createIcon('compress.png'),
                                      self.tr("Vacuum"), self)
        vacuumCollectionAct.triggered.connect(self.vacuumCollectionEvent)
        self.collectionActs.append(vacuumCollectionAct)

        descriptionCollectionAct = QAction(self.tr("Description"), self)
        descriptionCollectionAct.triggered.connect(
            self.descriptionCollectionEvent)
        self.collectionActs.append(descriptionCollectionAct)

        passwordCollectionAct = QAction(createIcon('key.png'),
                                        self.tr("Set password..."), self)
        passwordCollectionAct.triggered.connect(self.passwordCollectionEvent)
        self.collectionActs.append(passwordCollectionAct)

        importMenu = QMenu(self.tr("Import"), self)
        self.collectionActs.append(importMenu)

        if ImportNumizmat.isAvailable():
            importNumizmatAct = QAction(createIcon('numizmat.ico'),
                                        self.tr("Numizmat 2.1"), self)
            importNumizmatAct.triggered.connect(self.importNumizmat)
            self.collectionActs.append(importNumizmatAct)
            importMenu.addAction(importNumizmatAct)

        if ImportCabinet.isAvailable():
            importCabinetAct = QAction(createIcon('cabinet.ico'),
                                       self.tr("Cabinet 2.2.2.1, 2013"), self)
            importCabinetAct.triggered.connect(self.importCabinet)
            self.collectionActs.append(importCabinetAct)
            importMenu.addAction(importCabinetAct)

        if ImportCoinsCollector.isAvailable():
            importCoinsCollectorAct = QAction(createIcon('CoinsCollector.ico'),
                                              self.tr("CoinsCollector 2.6"),
                                              self)
            importCoinsCollectorAct.triggered.connect(
                self.importCoinsCollector)
            self.collectionActs.append(importCoinsCollectorAct)
            importMenu.addAction(importCoinsCollectorAct)

        if ImportCoinManage.isAvailable():
            importCoinManageAct = QAction(createIcon('CoinManage.ico'),
                                          self.tr("CoinManage 2011"), self)
            importCoinManageAct.triggered.connect(self.importCoinManage)
            self.collectionActs.append(importCoinManageAct)
            importMenu.addAction(importCoinManageAct)

        if ImportCollectionStudio.isAvailable():
            importCollectionStudioAct = QAction(
                createIcon('CollectionStudio.ico'),
                self.tr("Collection Studio 3.65"), self)
            importCollectionStudioAct.triggered.connect(
                self.importCollectionStudio)
            self.collectionActs.append(importCollectionStudioAct)
            importMenu.addAction(importCollectionStudioAct)

        if ImportNumizmatik_Ru.isAvailable():
            importNumizmaticRuAct = QAction(createIcon('Numizmatik_Ru.ico'),
                                            self.tr("Numizmatik_Ru 1.0.0.82"),
                                            self)
            importNumizmaticRuAct.triggered.connect(self.importNumizmatik_Ru)
            self.collectionActs.append(importNumizmaticRuAct)
            importMenu.addAction(importNumizmaticRuAct)

        if ImportUcoin.isAvailable():
            importUcoinAct = QAction(createIcon('ucoin.png'),
                                     self.tr("uCoin.net"), self)
            importUcoinAct.triggered.connect(self.importUcoin)
            self.collectionActs.append(importUcoinAct)
            importMenu.addAction(importUcoinAct)

        mergeCollectionAct = QAction(self.tr("Add from another..."), self)
        mergeCollectionAct.triggered.connect(self.mergeCollectionEvent)
        self.collectionActs.append(mergeCollectionAct)

        exportMenu = QMenu(self.tr("Export"), self)
        self.collectionActs.append(exportMenu)

        exportMobileAct = QAction(self.tr("For Android version"), self)
        exportMobileAct.triggered.connect(self.exportMobile)
        self.collectionActs.append(exportMobileAct)
        exportMenu.addAction(exportMobileAct)

        file = menubar.addMenu(self.tr("&File"))

        file.addAction(newCollectionAct)
        file.addAction(openCollectionAct)
        file.addSeparator()
        file.addAction(backupCollectionAct)
        file.addAction(vacuumCollectionAct)
        file.addAction(passwordCollectionAct)
        file.addAction(descriptionCollectionAct)
        file.addSeparator()
        file.addMenu(importMenu)
        file.addAction(mergeCollectionAct)
        file.addSeparator()
        file.addMenu(exportMenu)
        file.addSeparator()

        self.latestActions = []
        self.__updateLatest(file)

        file.addAction(settingsAct)
        file.addSeparator()

        file.addAction(self.exitAct)

        addCoinAct = QAction(createIcon('add.png'), self.tr("Add"), self)
        addCoinAct.setShortcut('Insert')
        addCoinAct.triggered.connect(self.addCoin)
        self.collectionActs.append(addCoinAct)

        editCoinAct = QAction(createIcon('pencil.png'), self.tr("Edit..."),
                              self)
        editCoinAct.triggered.connect(self.editCoin)
        self.collectionActs.append(editCoinAct)

        style = QApplication.style()
        icon = style.standardIcon(QStyle.SP_TrashIcon)
        deleteCoinAct = QAction(icon, self.tr("Delete"), self)
        deleteCoinAct.setShortcut(QKeySequence.Delete)
        deleteCoinAct.triggered.connect(self.deleteCoin)
        self.collectionActs.append(deleteCoinAct)

        copyCoinAct = QAction(createIcon('page_copy.png'), self.tr("Copy"),
                              self)
        copyCoinAct.setShortcut(QKeySequence.Copy)
        copyCoinAct.triggered.connect(self.copyCoin)
        self.collectionActs.append(copyCoinAct)

        pasteCoinAct = QAction(createIcon('page_paste.png'), self.tr("Paste"),
                               self)
        pasteCoinAct.setShortcut(QKeySequence.Paste)
        pasteCoinAct.triggered.connect(self.pasteCoin)
        self.collectionActs.append(pasteCoinAct)

        coin = menubar.addMenu(self.tr("Coin"))
        self.collectionActs.append(coin)
        coin.addAction(addCoinAct)
        coin.addAction(editCoinAct)
        coin.addSeparator()
        coin.addAction(copyCoinAct)
        coin.addAction(pasteCoinAct)
        coin.addSeparator()
        coin.addAction(deleteCoinAct)

        viewBrowserAct = QAction(createIcon('page_white_world.png'),
                                 self.tr("View in browser"), self)
        viewBrowserAct.triggered.connect(self.viewBrowser)
        self.collectionActs.append(viewBrowserAct)

        self.viewTab = TabView(self)

        actions = self.viewTab.actions()
        listMenu = menubar.addMenu(self.tr("List"))
        self.collectionActs.append(listMenu)
        listMenu.addAction(actions['new'])
        listMenu.addMenu(actions['open'])
        listMenu.aboutToShow.connect(self.viewTab.updateOpenPageMenu)
        listMenu.addAction(actions['rename'])
        listMenu.addSeparator()
        listMenu.addAction(actions['select'])
        listMenu.addSeparator()
        listMenu.addAction(actions['close'])
        listMenu.addAction(actions['remove'])

        self.referenceMenu = menubar.addMenu(self.tr("Reference"))

        reportAct = QAction(self.tr("Report..."), self)
        reportAct.setShortcut(Qt.CTRL + Qt.Key_P)
        reportAct.triggered.connect(self.report)
        self.collectionActs.append(reportAct)

        saveTableAct = QAction(createIcon('table.png'),
                               self.tr("Save current list..."), self)
        saveTableAct.triggered.connect(self.saveTable)
        self.collectionActs.append(saveTableAct)

        report = menubar.addMenu(self.tr("Report"))
        self.collectionActs.append(report)
        report.addAction(reportAct)
        report.addAction(saveTableAct)
        report.addAction(viewBrowserAct)

        helpAct = QAction(createIcon('help.png'), self.tr("Online help"), self)
        helpAct.setShortcut(QKeySequence.HelpContents)
        helpAct.triggered.connect(self.onlineHelp)
        checkUpdatesAct = QAction(self.tr("Check for updates"), self)
        checkUpdatesAct.triggered.connect(self.manualUpdate)
        aboutAct = QAction(self.tr("About %s") % version.AppName, self)
        aboutAct.triggered.connect(self.about)

        help_ = menubar.addMenu(self.tr("&Help"))
        help_.addAction(helpAct)
        help_.addSeparator()
        help_.addAction(checkUpdatesAct)
        help_.addSeparator()
        help_.addAction(aboutAct)

        toolBar = QToolBar(self.tr("Toolbar"), self)
        toolBar.setMovable(False)
        toolBar.addAction(openCollectionAct)
        toolBar.addSeparator()
        toolBar.addAction(addCoinAct)
        toolBar.addAction(editCoinAct)
        toolBar.addAction(viewBrowserAct)
        toolBar.addSeparator()
        toolBar.addAction(cancelFilteringAct)
        toolBar.addSeparator()
        toolBar.addAction(settingsAct)
        self.addToolBar(toolBar)

        self.setWindowTitle(version.AppName)

        self.reference = Reference(self)
        self.reference.open(Settings()['reference'])

        if len(sys.argv) > 1:
            fileName = sys.argv[1]
        else:
            latest = LatestCollections(self)
            fileName = latest.latest()

        self.collection = Collection(self.reference, self)
        self.openCollection(fileName)

        self.setCentralWidget(self.viewTab)

        settings = QSettings()
        pageIndex = settings.value('tabwindow/page')
        if pageIndex != None:
            self.viewTab.setCurrentIndex(int(pageIndex))

        if settings.value('mainwindow/maximized') == 'true':
            self.showMaximized()
            size = settings.value('mainwindow/maximizedsize')
        else:
            size = settings.value('mainwindow/size')

        if size:
            self.resize(size)

        self.autoUpdate()

    def createStatusBar(self):
        self.collectionFileLabel = QLabel()
        self.statusBar().addWidget(self.collectionFileLabel)

    def __updateLatest(self, menu=None):
        if menu:
            self.__menu = menu
        for act in self.latestActions:
            self.__menu.removeAction(act)

        self.latestActions = []
        latest = LatestCollections(self)
        for act in latest.actions():
            self.latestActions.append(act)
            act.latestTriggered.connect(self.openCollection)
            self.__menu.insertAction(self.exitAct, act)
        self.__menu.insertSeparator(self.exitAct)

    def cancelFilteringEvent(self):
        listView = self.viewTab.currentListView()
        listView.clearAllFilters()

    def settingsEvent(self):
        dialog = SettingsDialog(self.collection, self)
        res = dialog.exec_()
        if res == QDialog.Accepted:
            result = QMessageBox.question(
                self, self.tr("Settings"),
                self.tr("The application will need to restart to apply "
                        "the new settings. Restart it now?"),
                QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
            if result == QMessageBox.Yes:
                self.restart()

    def restart(self):
        self.close()
        program = sys.executable
        argv = []
        if program != sys.argv[0]:
            # Process running as Python arg
            argv.append(sys.argv[0])
        QProcess.startDetached(program, argv)

    def importNumizmat(self):
        defaultDir = ImportNumizmat.defaultDir()
        file, _selectedFilter = QFileDialog.getOpenFileName(
            self, self.tr("Select file"), defaultDir, "*.fdb")
        if file:
            imp = ImportNumizmat(self)
            imp.importData(file, self.viewTab.currentModel())

    def importCabinet(self):
        QMessageBox.information(
            self, self.tr("Importing"),
            self.tr("Before importing you should export existing "
                    "collection from Cabinet."))

        defaultDir = ImportCabinet.defaultDir()
        directory = QFileDialog.getExistingDirectory(
            self, self.tr("Select directory"), defaultDir)
        if directory:
            imp = ImportCabinet(self)
            imp.importData(directory, self.viewTab.currentModel())

    def importCoinsCollector(self):
        defaultDir = ImportCoinsCollector.defaultDir()
        directory = QFileDialog.getExistingDirectory(
            self, self.tr("Select directory"), defaultDir)
        if directory:
            imp = ImportCoinsCollector(self)
            imp.importData(directory, self.viewTab.currentModel())

    def importCoinManage(self):
        defaultDir = ImportCoinManage.defaultDir()
        file, _selectedFilter = QFileDialog.getOpenFileName(
            self, self.tr("Select file"), defaultDir, "*.mdb")
        if file:
            btn = QMessageBox.question(self, self.tr("Importing"),
                                       self.tr("Import pre-defined coins?"),
                                       QMessageBox.Yes | QMessageBox.No,
                                       QMessageBox.Yes)
            if btn == QMessageBox.Yes:
                imp = ImportCoinManagePredefined(self)
                res = imp.importData(file, self.viewTab.currentModel())
                if not res:
                    return

            imp = ImportCoinManage(self)
            imp.importData(file, self.viewTab.currentModel())

    def importCollectionStudio(self):
        QMessageBox.information(
            self, self.tr("Importing"),
            self.tr("Before importing you should export existing "
                    "collection from Collection Studio to XML Table "
                    "(choose Collection Studio menu Tools > Export...)."))

        defaultDir = ImportCollectionStudio.defaultDir()
        file, _selectedFilter = QFileDialog.getOpenFileName(
            self, self.tr("Select file"), defaultDir, "*.xml")
        if file:
            imp = ImportCollectionStudio(self)
            imp.importData(file, self.viewTab.currentModel())

    def importNumizmatik_Ru(self):
        defaultDir = ImportNumizmatik_Ru.defaultDir()
        file, _selectedFilter = QFileDialog.getOpenFileName(
            self, self.tr("Select file"), defaultDir, "*.mdb")
        if file:
            btn = QMessageBox.question(self, self.tr("Importing"),
                                       self.tr("Import club catalog?"),
                                       QMessageBox.Yes | QMessageBox.No,
                                       QMessageBox.Yes)
            if btn == QMessageBox.Yes:
                imp = ImportNumizmatik_RuPredefined(self)
                res = imp.importData(file, self.viewTab.currentModel())
                if not res:
                    return

            imp = ImportNumizmatik_Ru(self)
            imp.importData(file, self.viewTab.currentModel())

    def importUcoin(self):
        QMessageBox.information(
            self, self.tr("Importing"),
            self.tr("Before importing you should export existing "
                    "collection from uCoin.net to Comma-Separated (CSV) "
                    "format."))

        defaultDir = ImportUcoin.defaultDir()
        file, _selectedFilter = QFileDialog.getOpenFileName(
            self, self.tr("Select file"), defaultDir, "*.csv")
        if file:
            imp = ImportUcoin(self)
            imp.importData(file, self.viewTab.currentModel())

    def exportMobile(self):
        dialog = ExportDialog(self.collection, self)
        res = dialog.exec_()
        if res == QDialog.Accepted:
            self.collection.exportToMobile(dialog.params)

    def addCoin(self):
        model = self.viewTab.currentModel()
        model.addCoin(model.record(), self)

    def editCoin(self):
        listView = self.viewTab.currentListView()
        indexes = listView.selectedRows()
        if len(indexes) == 1:
            listView._edit(indexes[0])
        elif len(indexes) > 1:
            listView._multiEdit(indexes)

    def deleteCoin(self):
        listView = self.viewTab.currentListView()
        indexes = listView.selectedRows()
        if len(indexes):
            listView._delete(indexes)

    def copyCoin(self):
        listView = self.viewTab.currentListView()
        indexes = listView.selectedRows()
        if len(indexes):
            listView._copy(indexes)

    def pasteCoin(self):
        listView = self.viewTab.currentListView()
        listView._paste()

    def viewBrowser(self):
        listView = self.viewTab.currentListView()
        listView.viewInBrowser()

    def report(self):
        listView = self.viewTab.currentListView()
        indexes = listView.selectedRows()
        model = listView.model()

        records = []
        for index in indexes:
            records.append(model.record(index.row()))

        preview = PreviewDialog(model, records, self)
        preview.exec_()

    def saveTable(self):
        listView = self.viewTab.currentListView()
        listView.saveTable()

    def __workingDir(self):
        fileName = self.collection.fileName
        if not fileName:
            fileName = LatestCollections.DefaultCollectionName
        return QFileInfo(fileName).absolutePath()

    def openCollectionEvent(self):
        fileName, _selectedFilter = QFileDialog.getOpenFileName(
            self, self.tr("Open collection"), self.__workingDir(),
            self.tr("Collections (*.db)"))
        if fileName:
            self.openCollection(fileName)

    def newCollectionEvent(self):
        fileName, _selectedFilter = QFileDialog.getSaveFileName(
            self, self.tr("New collection"), self.__workingDir(),
            self.tr("Collections (*.db)"), "",
            QFileDialog.DontConfirmOverwrite)
        if fileName:
            self.__saveParams()

            self.__closeCollection()
            if self.collection.create(fileName):
                self.setCollection(self.collection)

    def descriptionCollectionEvent(self, checked):
        dialog = DescriptionDialog(self.collection.getDescription(), self)
        dialog.exec_()

    def passwordCollectionEvent(self, checked):
        dialog = PasswordSetDialog(self.collection.settings, self)
        dialog.exec_()

    def backupCollectionEvent(self, checked):
        self.collection.backup()

    def vacuumCollectionEvent(self, checked):
        self.collection.vacuum()

    def mergeCollectionEvent(self, checked):
        fileName, _selectedFilter = QFileDialog.getOpenFileName(
            self, self.tr("Open collection"), self.__workingDir(),
            self.tr("Collections (*.db)"))
        if fileName:
            self.collection.merge(fileName)

    def openCollection(self, fileName):
        self.__saveParams()

        self.__closeCollection()
        if self.collection.open(fileName):
            self.setCollection(self.collection)
        else:
            # Remove wrong collection from latest collections list
            latest = LatestCollections(self)
            latest.delete(fileName)
            self.__updateLatest()

    @waitCursorDecorator
    def setCollection(self, collection):
        self.__setEnabledActs(True)

        self.collectionFileLabel.setText(collection.getFileName())
        title = "%s - %s" % (collection.getCollectionName(), version.AppName)
        self.setWindowTitle(title)

        latest = LatestCollections(self)
        latest.add(collection.getFileName())
        self.__updateLatest()

        self.viewTab.setCollection(collection)

        self.referenceMenu.clear()
        for action in self.collection.referenceMenu(self):
            self.referenceMenu.addAction(action)

    def __setEnabledActs(self, enabled):
        for act in self.collectionActs:
            act.setEnabled(enabled)

    def __closeCollection(self):
        self.__setEnabledActs(False)
        self.viewTab.clear()

        self.referenceMenu.clear()

        self.collectionFileLabel.setText(
            self.tr("Create new collection or open one of the existing"))

        self.setWindowTitle(version.AppName)

    def closeEvent(self, e):
        self.__shutDown()

    def __shutDown(self):
        self.__saveParams()

        settings = QSettings()

        if self.collection.fileName:
            self.viewTab.savePagePositions()
            # Save latest opened page
            settings.setValue('tabwindow/page', self.viewTab.currentIndex())

        # Save main window size
        settings.setValue('mainwindow/maximized', self.isMaximized())
        if self.isMaximized():
            settings.setValue('mainwindow/maximizedsize', self.size())
        else:
            settings.setValue('mainwindow/size', self.size())

    def __saveParams(self):
        if self.collection.pages():
            for param in self.collection.pages().pagesParam():
                param.listParam.save()

    def about(self):
        QMessageBox.about(
            self,
            self.tr("About %s") % version.AppName,
            self.tr("%s %s\n\n"
                    "Copyright (C) 2011-2016 Vitaly Ignatov\n\n"
                    "%s is freeware licensed under a GPLv3.") %
            (version.AppName, version.Version, version.AppName))

    def onlineHelp(self):
        url = QUrl(version.Web)

        executor = QDesktopServices()
        executor.openUrl(url)

    def autoUpdate(self):
        if Settings()['updates']:
            currentDate = QDate.currentDate()

            settings = QSettings()
            lastUpdateDateStr = settings.value('mainwindow/last_update')
            if lastUpdateDateStr:
                lastUpdateDate = QDate.fromString(lastUpdateDateStr,
                                                  Qt.ISODate)
                if lastUpdateDate.addDays(10) < currentDate:
                    self.checkUpdates()
            else:
                self.checkUpdates()

    def manualUpdate(self):
        if not self.checkUpdates():
            QMessageBox.information(
                self, self.tr("Updates"),
                self.tr("You already have the latest version."))

    def checkUpdates(self):
        currentDate = QDate.currentDate()
        currentDateStr = currentDate.toString(Qt.ISODate)
        settings = QSettings()
        settings.setValue('mainwindow/last_update', currentDateStr)

        newVersion = self.__getNewVersion()
        if newVersion and newVersion != version.Version:
            result = QMessageBox.question(
                self, self.tr("New version"),
                self.tr("New version is available. Download it now?"),
                QMessageBox.Yes | QMessageBox.No, QMessageBox.Yes)
            if result == QMessageBox.Yes:
                url = QUrl(version.Web)

                executor = QDesktopServices()
                executor.openUrl(url)

            return True
        else:
            return False

    @waitCursorDecorator
    def __getNewVersion(self):
        import urllib.request
        from xml.dom.minidom import parseString

        newVersion = version.Version

        try:
            url = "http://opennumismat.github.io/data/pad.xml"
            req = urllib.request.Request(url)
            data = urllib.request.urlopen(req).read()
            xml = parseString(data)
            tag = xml.getElementsByTagName('Program_Version')[0]
            newVersion = tag.firstChild.nodeValue
        except:
            return None

        return newVersion
Exemplo n.º 6
0
    def __init__(self):
        QMainWindow.__init__(self)

        self.setWindowIcon(createIcon('main.ico'))

        self.createStatusBar()
        menubar = self.menuBar()

        self.collectionActs = []

        settingsAct = QAction(createIcon('cog.png'), self.tr("Settings..."),
                              self)
        settingsAct.triggered.connect(self.settingsEvent)

        cancelFilteringAct = QAction(createIcon('funnel.png'),
                                     self.tr("Clear all filters"), self)
        cancelFilteringAct.triggered.connect(self.cancelFilteringEvent)
        self.collectionActs.append(cancelFilteringAct)

        self.exitAct = QAction(createIcon('door_in.png'), self.tr("E&xit"),
                               self)
        self.exitAct.setShortcut(QKeySequence.Quit)
        self.exitAct.triggered.connect(self.close)

        newCollectionAct = QAction(self.tr("&New..."), self)
        newCollectionAct.triggered.connect(self.newCollectionEvent)

        style = QApplication.style()
        icon = style.standardIcon(QStyle.SP_DialogOpenButton)
        openCollectionAct = QAction(icon, self.tr("&Open..."), self)
        openCollectionAct.setShortcut(QKeySequence.Open)
        openCollectionAct.triggered.connect(self.openCollectionEvent)

        backupCollectionAct = QAction(createIcon('database_backup.png'),
                                      self.tr("Backup"), self)
        backupCollectionAct.triggered.connect(self.backupCollectionEvent)
        self.collectionActs.append(backupCollectionAct)

        vacuumCollectionAct = QAction(createIcon('compress.png'),
                                      self.tr("Vacuum"), self)
        vacuumCollectionAct.triggered.connect(self.vacuumCollectionEvent)
        self.collectionActs.append(vacuumCollectionAct)

        descriptionCollectionAct = QAction(self.tr("Description"), self)
        descriptionCollectionAct.triggered.connect(
            self.descriptionCollectionEvent)
        self.collectionActs.append(descriptionCollectionAct)

        passwordCollectionAct = QAction(createIcon('key.png'),
                                        self.tr("Set password..."), self)
        passwordCollectionAct.triggered.connect(self.passwordCollectionEvent)
        self.collectionActs.append(passwordCollectionAct)

        importMenu = QMenu(self.tr("Import"), self)
        self.collectionActs.append(importMenu)

        if ImportNumizmat.isAvailable():
            importNumizmatAct = QAction(createIcon('numizmat.ico'),
                                        self.tr("Numizmat 2.1"), self)
            importNumizmatAct.triggered.connect(self.importNumizmat)
            self.collectionActs.append(importNumizmatAct)
            importMenu.addAction(importNumizmatAct)

        if ImportCabinet.isAvailable():
            importCabinetAct = QAction(createIcon('cabinet.ico'),
                                       self.tr("Cabinet 2.2.2.1, 2013"), self)
            importCabinetAct.triggered.connect(self.importCabinet)
            self.collectionActs.append(importCabinetAct)
            importMenu.addAction(importCabinetAct)

        if ImportCoinsCollector.isAvailable():
            importCoinsCollectorAct = QAction(createIcon('CoinsCollector.ico'),
                                              self.tr("CoinsCollector 2.6"),
                                              self)
            importCoinsCollectorAct.triggered.connect(
                self.importCoinsCollector)
            self.collectionActs.append(importCoinsCollectorAct)
            importMenu.addAction(importCoinsCollectorAct)

        if ImportCoinManage.isAvailable():
            importCoinManageAct = QAction(createIcon('CoinManage.ico'),
                                          self.tr("CoinManage 2011"), self)
            importCoinManageAct.triggered.connect(self.importCoinManage)
            self.collectionActs.append(importCoinManageAct)
            importMenu.addAction(importCoinManageAct)

        if ImportCollectionStudio.isAvailable():
            importCollectionStudioAct = QAction(
                createIcon('CollectionStudio.ico'),
                self.tr("Collection Studio 3.65"), self)
            importCollectionStudioAct.triggered.connect(
                self.importCollectionStudio)
            self.collectionActs.append(importCollectionStudioAct)
            importMenu.addAction(importCollectionStudioAct)

        if ImportNumizmatik_Ru.isAvailable():
            importNumizmaticRuAct = QAction(createIcon('Numizmatik_Ru.ico'),
                                            self.tr("Numizmatik_Ru 1.0.0.82"),
                                            self)
            importNumizmaticRuAct.triggered.connect(self.importNumizmatik_Ru)
            self.collectionActs.append(importNumizmaticRuAct)
            importMenu.addAction(importNumizmaticRuAct)

        if ImportUcoin.isAvailable():
            importUcoinAct = QAction(createIcon('ucoin.png'),
                                     self.tr("uCoin.net"), self)
            importUcoinAct.triggered.connect(self.importUcoin)
            self.collectionActs.append(importUcoinAct)
            importMenu.addAction(importUcoinAct)

        mergeCollectionAct = QAction(self.tr("Add from another..."), self)
        mergeCollectionAct.triggered.connect(self.mergeCollectionEvent)
        self.collectionActs.append(mergeCollectionAct)

        exportMenu = QMenu(self.tr("Export"), self)
        self.collectionActs.append(exportMenu)

        exportMobileAct = QAction(self.tr("For Android version"), self)
        exportMobileAct.triggered.connect(self.exportMobile)
        self.collectionActs.append(exportMobileAct)
        exportMenu.addAction(exportMobileAct)

        file = menubar.addMenu(self.tr("&File"))

        file.addAction(newCollectionAct)
        file.addAction(openCollectionAct)
        file.addSeparator()
        file.addAction(backupCollectionAct)
        file.addAction(vacuumCollectionAct)
        file.addAction(passwordCollectionAct)
        file.addAction(descriptionCollectionAct)
        file.addSeparator()
        file.addMenu(importMenu)
        file.addAction(mergeCollectionAct)
        file.addSeparator()
        file.addMenu(exportMenu)
        file.addSeparator()

        self.latestActions = []
        self.__updateLatest(file)

        file.addAction(settingsAct)
        file.addSeparator()

        file.addAction(self.exitAct)

        addCoinAct = QAction(createIcon('add.png'), self.tr("Add"), self)
        addCoinAct.setShortcut('Insert')
        addCoinAct.triggered.connect(self.addCoin)
        self.collectionActs.append(addCoinAct)

        editCoinAct = QAction(createIcon('pencil.png'), self.tr("Edit..."),
                              self)
        editCoinAct.triggered.connect(self.editCoin)
        self.collectionActs.append(editCoinAct)

        style = QApplication.style()
        icon = style.standardIcon(QStyle.SP_TrashIcon)
        deleteCoinAct = QAction(icon, self.tr("Delete"), self)
        deleteCoinAct.setShortcut(QKeySequence.Delete)
        deleteCoinAct.triggered.connect(self.deleteCoin)
        self.collectionActs.append(deleteCoinAct)

        copyCoinAct = QAction(createIcon('page_copy.png'), self.tr("Copy"),
                              self)
        copyCoinAct.setShortcut(QKeySequence.Copy)
        copyCoinAct.triggered.connect(self.copyCoin)
        self.collectionActs.append(copyCoinAct)

        pasteCoinAct = QAction(createIcon('page_paste.png'), self.tr("Paste"),
                               self)
        pasteCoinAct.setShortcut(QKeySequence.Paste)
        pasteCoinAct.triggered.connect(self.pasteCoin)
        self.collectionActs.append(pasteCoinAct)

        coin = menubar.addMenu(self.tr("Coin"))
        self.collectionActs.append(coin)
        coin.addAction(addCoinAct)
        coin.addAction(editCoinAct)
        coin.addSeparator()
        coin.addAction(copyCoinAct)
        coin.addAction(pasteCoinAct)
        coin.addSeparator()
        coin.addAction(deleteCoinAct)

        viewBrowserAct = QAction(createIcon('page_white_world.png'),
                                 self.tr("View in browser"), self)
        viewBrowserAct.triggered.connect(self.viewBrowser)
        self.collectionActs.append(viewBrowserAct)

        self.viewTab = TabView(self)

        actions = self.viewTab.actions()
        listMenu = menubar.addMenu(self.tr("List"))
        self.collectionActs.append(listMenu)
        listMenu.addAction(actions['new'])
        listMenu.addMenu(actions['open'])
        listMenu.aboutToShow.connect(self.viewTab.updateOpenPageMenu)
        listMenu.addAction(actions['rename'])
        listMenu.addSeparator()
        listMenu.addAction(actions['select'])
        listMenu.addSeparator()
        listMenu.addAction(actions['close'])
        listMenu.addAction(actions['remove'])

        self.referenceMenu = menubar.addMenu(self.tr("Reference"))

        reportAct = QAction(self.tr("Report..."), self)
        reportAct.setShortcut(Qt.CTRL + Qt.Key_P)
        reportAct.triggered.connect(self.report)
        self.collectionActs.append(reportAct)

        saveTableAct = QAction(createIcon('table.png'),
                               self.tr("Save current list..."), self)
        saveTableAct.triggered.connect(self.saveTable)
        self.collectionActs.append(saveTableAct)

        report = menubar.addMenu(self.tr("Report"))
        self.collectionActs.append(report)
        report.addAction(reportAct)
        report.addAction(saveTableAct)
        report.addAction(viewBrowserAct)

        helpAct = QAction(createIcon('help.png'), self.tr("Online help"), self)
        helpAct.setShortcut(QKeySequence.HelpContents)
        helpAct.triggered.connect(self.onlineHelp)
        checkUpdatesAct = QAction(self.tr("Check for updates"), self)
        checkUpdatesAct.triggered.connect(self.manualUpdate)
        aboutAct = QAction(self.tr("About %s") % version.AppName, self)
        aboutAct.triggered.connect(self.about)

        help_ = menubar.addMenu(self.tr("&Help"))
        help_.addAction(helpAct)
        help_.addSeparator()
        help_.addAction(checkUpdatesAct)
        help_.addSeparator()
        help_.addAction(aboutAct)

        toolBar = QToolBar(self.tr("Toolbar"), self)
        toolBar.setMovable(False)
        toolBar.addAction(openCollectionAct)
        toolBar.addSeparator()
        toolBar.addAction(addCoinAct)
        toolBar.addAction(editCoinAct)
        toolBar.addAction(viewBrowserAct)
        toolBar.addSeparator()
        toolBar.addAction(cancelFilteringAct)
        toolBar.addSeparator()
        toolBar.addAction(settingsAct)
        self.addToolBar(toolBar)

        self.setWindowTitle(version.AppName)

        self.reference = Reference(self)
        self.reference.open(Settings()['reference'])

        if len(sys.argv) > 1:
            fileName = sys.argv[1]
        else:
            latest = LatestCollections(self)
            fileName = latest.latest()

        self.collection = Collection(self.reference, self)
        self.openCollection(fileName)

        self.setCentralWidget(self.viewTab)

        settings = QSettings()
        pageIndex = settings.value('tabwindow/page')
        if pageIndex != None:
            self.viewTab.setCurrentIndex(int(pageIndex))

        if settings.value('mainwindow/maximized') == 'true':
            self.showMaximized()
            size = settings.value('mainwindow/maximizedsize')
        else:
            size = settings.value('mainwindow/size')

        if size:
            self.resize(size)

        self.autoUpdate()
Exemplo n.º 7
0
    image = QtGui.QImage(fileName)
    image.save(buffer, 'png')

    return ba


import sys

sys.path.append('..')
from OpenNumismat.Reference.Reference import Reference

shutil.copy("../OpenNumismat/db/reference_es.ref", ".")

app = QApplication(sys.argv)

ref = Reference()
ref.open('reference_es.ref')

place = ref.section('payplace')
place.addItem('eBay', convertImage('icons/ebay.png'))
place.model.submitAll()

rarity = ref.section('rarity')
rarity.addItem('Común')
rarity.addItem('Normal')
rarity.addItem('Limitada')
rarity.addItem('Rara')
rarity.addItem('Única')
rarity.addItem('Sólo en sets')
rarity.model.submitAll()
Exemplo n.º 8
0
    ba = QtCore.QByteArray()
    buffer = QtCore.QBuffer(ba)
    buffer.open(QtCore.QIODevice.WriteOnly)

    image = QtGui.QImage(fileName)
    image.save(buffer, 'png')

    return ba


import sys
sys.path.append('..')
from OpenNumismat.Reference.Reference import Reference

app = QApplication(sys.argv)
ref = Reference()

f = open('langs')
langs = [x.strip('\n') for x in f.readlines()]

for lang in langs:
    src_file = "../OpenNumismat/db/reference_%s.ref" % lang
    if not os.path.isfile(src_file):
        src_file = "../OpenNumismat/db/reference_en.ref"

    shutil.copy(src_file, ".")

    ref.open('reference_%s.ref' % lang)

    src_ref_file = "reference_%s.json" % lang
    if not os.path.isfile(src_ref_file):
Exemplo n.º 9
0
    buffer.open(QtCore.QIODevice.WriteOnly)

    image = QtGui.QImage(fileName)
    image.save(buffer, 'png')

    return ba

import sys
sys.path.append('..')
from OpenNumismat.Reference.Reference import Reference

shutil.copy("../OpenNumismat/db/reference_ru.ref", ".")

app = QApplication(sys.argv)

ref = Reference()
ref.open('reference_ru.ref')

place = ref.section('payplace')
place.addItem('Молоток.Ру', convertImage('icons/molotok.ico'))
place.addItem('Конрос', convertImage('icons/conros.ico'))
place.addItem('Wolmar', convertImage('icons/wolmar.ico'))
place.addItem('eBay', convertImage('icons/ebay.png'))
place.addItem('АукционЪ.СПб')
place.model.submitAll()

rarity = ref.section('rarity')
rarity.addItem('Рядовая')
rarity.addItem('Нечастая')
rarity.addItem('Редкая')
rarity.addItem('Очень редкая')
Exemplo n.º 10
0
        ba = QtCore.QByteArray()
        buffer = QtCore.QBuffer(ba)
        buffer.open(QtCore.QIODevice.WriteOnly)

        image.save(buffer, 'png')

        return ba
    else:
        return None


sys.path.append('..')

app = QApplication(sys.argv)
fields = CollectionFieldsBase()
ref = Reference(fields)

file = "ref/colors_en.json"
json_data = codecs.open(file, "r", "utf-8").read()
colors = json.loads(json_data)

file = "ref/countries.json"
json_data = codecs.open(file, "r", "utf-8").read()
countries = json.loads(json_data)

file = "ref/countries_en.json"
json_data = codecs.open(file, "r", "utf-8").read()
en_translations = json.loads(json_data)

f = open('langs')
langs = [x.strip('\n') for x in f.readlines()]
    def __init__(self):
        QMainWindow.__init__(self)

        self.setWindowIcon(createIcon('main.ico'))

        self.createStatusBar()

        settingsAct = QAction(createIcon('cog.png'),
                                    self.tr("Settings..."), self)
        settingsAct.triggered.connect(self.settingsEvent)

        importAct = QAction(self.tr("Import..."), self)
        importAct.triggered.connect(self.importEvent)

        uploadImagesAct = QAction(self.tr("Upload images"), self)
        uploadImagesAct.triggered.connect(self.uploadImagesEvent)

        cancelFilteringAct = QAction(createIcon('funnel.png'),
                                    self.tr("Clear all filters"), self)
        cancelFilteringAct.triggered.connect(self.cancelFilteringEvent)

        newCollectionAct = QAction(self.tr("&New..."), self)
        newCollectionAct.triggered.connect(self.newCollectionEvent)

        style = QApplication.style()
        icon = style.standardIcon(QStyle.SP_DialogOpenButton)
        openCollectionAct = QAction(icon, self.tr("&Open..."), self)
        openCollectionAct.setShortcut(QtGui.QKeySequence.Open)
        openCollectionAct.triggered.connect(self.openCollectionEvent)

        backupCollectionAct = QAction(
                                    createIcon('database_backup.png'),
                                    self.tr("Backup"), self)
        backupCollectionAct.triggered.connect(self.backupCollectionEvent)

        vacuumCollectionAct = QAction(
                                    createIcon('compress.png'),
                                    self.tr("Vacuum"), self)
        vacuumCollectionAct.triggered.connect(self.vacuumCollectionEvent)

        descriptionCollectionAct = QAction(self.tr("Description"), self)
        descriptionCollectionAct.triggered.connect(
                                            self.descriptionCollectionEvent)

        passwordCollectionAct = QAction(createIcon('key.png'),
                                              self.tr("Set password..."), self)
        passwordCollectionAct.triggered.connect(self.passwordCollectionEvent)

        self.exitAct = QAction(createIcon('door_in.png'),
                                self.tr("E&xit"), self)
        self.exitAct.setShortcut(QtGui.QKeySequence.Quit)
        self.exitAct.triggered.connect(self.close)

        menubar = self.menuBar()
        file = menubar.addMenu(self.tr("&File"))
        file.addAction(newCollectionAct)
        file.addAction(openCollectionAct)
        file.addSeparator()
        file.addAction(backupCollectionAct)
        file.addAction(vacuumCollectionAct)
        file.addAction(passwordCollectionAct)
        file.addAction(descriptionCollectionAct)
        file.addSeparator()
        file.addAction(importAct)
        file.addAction(uploadImagesAct)
        file.addSeparator()
        file.addAction(settingsAct)
        file.addSeparator()
        file.addAction(self.exitAct)

        self.latestActions = []
        self.__updateLatest(file)

        addCoinAct = QAction(createIcon('add.png'),
                                   self.tr("Add"), self)
        addCoinAct.setShortcut('Insert')
        addCoinAct.triggered.connect(self.addCoin)

        editCoinAct = QAction(createIcon('pencil.png'),
                                   self.tr("Edit..."), self)
        editCoinAct.triggered.connect(self.editCoin)

        style = QApplication.style()
        icon = style.standardIcon(QStyle.SP_TrashIcon)
        deleteCoinAct = QAction(icon,
                                   self.tr("Delete"), self)
        deleteCoinAct.setShortcut(QtGui.QKeySequence.Delete)
        deleteCoinAct.triggered.connect(self.deleteCoin)

        coin = menubar.addMenu(self.tr("Coin"))
        coin.addAction(addCoinAct)
        coin.addAction(editCoinAct)
        coin.addAction(deleteCoinAct)

        viewBrowserAct = QAction(createIcon('page_white_world.png'),
                                   self.tr("View in browser"), self)
        viewBrowserAct.triggered.connect(self.viewBrowser)

        self.viewTab = TabView(self)

        actions = self.viewTab.actions()
        listMenu = menubar.addMenu(self.tr("List"))
        listMenu.addAction(actions['new'])
        listMenu.addMenu(actions['open'])
        listMenu.aboutToShow.connect(self.viewTab.updateOpenPageMenu)
        listMenu.addAction(actions['rename'])
        listMenu.addSeparator()
        listMenu.addAction(actions['select'])
        listMenu.addSeparator()
        listMenu.addAction(actions['close'])
        listMenu.addAction(actions['remove'])

        self.referenceMenu = menubar.addMenu(self.tr("Reference"))

        reportAct = QAction(self.tr("Report..."), self)
        reportAct.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_P)
        reportAct.triggered.connect(self.report)

        saveTableAct = QAction(createIcon('table.png'),
                                     self.tr("Save current list..."), self)
        saveTableAct.triggered.connect(self.saveTable)

        report = menubar.addMenu(self.tr("Report"))
        report.addAction(reportAct)
        report.addAction(saveTableAct)
        report.addAction(viewBrowserAct)

        helpAct = QAction(createIcon('help.png'),
                                self.tr("Online help"), self)
        helpAct.setShortcut(QtGui.QKeySequence.HelpContents)
        helpAct.triggered.connect(self.onlineHelp)
        checkUpdatesAct = QAction(self.tr("Check for updates"), self)
        checkUpdatesAct.triggered.connect(self.manualUpdate)
        aboutAct = QAction(self.tr("About %s") % version.AppName, self)
        aboutAct.triggered.connect(self.about)

        help_ = menubar.addMenu(self.tr("&Help"))
        help_.addAction(helpAct)
        help_.addSeparator()
        help_.addAction(checkUpdatesAct)
        help_.addSeparator()
        help_.addAction(aboutAct)

        toolBar = QToolBar(self.tr("Toolbar"), self)
        toolBar.setMovable(False)
        toolBar.addAction(openCollectionAct)
        toolBar.addSeparator()
        toolBar.addAction(addCoinAct)
        toolBar.addAction(editCoinAct)
        toolBar.addAction(viewBrowserAct)
        toolBar.addSeparator()
        toolBar.addAction(cancelFilteringAct)
        toolBar.addSeparator()
        toolBar.addAction(settingsAct)
        self.addToolBar(toolBar)

        self.setWindowTitle(version.AppName)

        self.reference = Reference(self)
        self.reference.open(Settings()['reference'])

        if len(sys.argv) > 1:
            fileName = sys.argv[1]
        else:
            latest = LatestCollections(self)
            fileName = latest.latest()

        self.collection = Collection(self.reference, self)
        self.openCollection(fileName)

        self.setCentralWidget(self.viewTab)

        settings = QtCore.QSettings()
        pageIndex = settings.value('tabwindow/page')
        if pageIndex != None:
            self.viewTab.setCurrentIndex(int(pageIndex))

        if settings.value('mainwindow/maximized') == 'true':
            self.setWindowState(self.windowState() | QtCore.Qt.WindowMaximized)
        else:
            size = settings.value('mainwindow/size')
            if size:
                self.resize(size)

        self.autoUpdate()
class MainWindow(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.setWindowIcon(createIcon('main.ico'))

        self.createStatusBar()

        settingsAct = QAction(createIcon('cog.png'),
                                    self.tr("Settings..."), self)
        settingsAct.triggered.connect(self.settingsEvent)

        importAct = QAction(self.tr("Import..."), self)
        importAct.triggered.connect(self.importEvent)

        uploadImagesAct = QAction(self.tr("Upload images"), self)
        uploadImagesAct.triggered.connect(self.uploadImagesEvent)

        cancelFilteringAct = QAction(createIcon('funnel.png'),
                                    self.tr("Clear all filters"), self)
        cancelFilteringAct.triggered.connect(self.cancelFilteringEvent)

        newCollectionAct = QAction(self.tr("&New..."), self)
        newCollectionAct.triggered.connect(self.newCollectionEvent)

        style = QApplication.style()
        icon = style.standardIcon(QStyle.SP_DialogOpenButton)
        openCollectionAct = QAction(icon, self.tr("&Open..."), self)
        openCollectionAct.setShortcut(QtGui.QKeySequence.Open)
        openCollectionAct.triggered.connect(self.openCollectionEvent)

        backupCollectionAct = QAction(
                                    createIcon('database_backup.png'),
                                    self.tr("Backup"), self)
        backupCollectionAct.triggered.connect(self.backupCollectionEvent)

        vacuumCollectionAct = QAction(
                                    createIcon('compress.png'),
                                    self.tr("Vacuum"), self)
        vacuumCollectionAct.triggered.connect(self.vacuumCollectionEvent)

        descriptionCollectionAct = QAction(self.tr("Description"), self)
        descriptionCollectionAct.triggered.connect(
                                            self.descriptionCollectionEvent)

        passwordCollectionAct = QAction(createIcon('key.png'),
                                              self.tr("Set password..."), self)
        passwordCollectionAct.triggered.connect(self.passwordCollectionEvent)

        self.exitAct = QAction(createIcon('door_in.png'),
                                self.tr("E&xit"), self)
        self.exitAct.setShortcut(QtGui.QKeySequence.Quit)
        self.exitAct.triggered.connect(self.close)

        menubar = self.menuBar()
        file = menubar.addMenu(self.tr("&File"))
        file.addAction(newCollectionAct)
        file.addAction(openCollectionAct)
        file.addSeparator()
        file.addAction(backupCollectionAct)
        file.addAction(vacuumCollectionAct)
        file.addAction(passwordCollectionAct)
        file.addAction(descriptionCollectionAct)
        file.addSeparator()
        file.addAction(importAct)
        file.addAction(uploadImagesAct)
        file.addSeparator()
        file.addAction(settingsAct)
        file.addSeparator()
        file.addAction(self.exitAct)

        self.latestActions = []
        self.__updateLatest(file)

        addCoinAct = QAction(createIcon('add.png'),
                                   self.tr("Add"), self)
        addCoinAct.setShortcut('Insert')
        addCoinAct.triggered.connect(self.addCoin)

        editCoinAct = QAction(createIcon('pencil.png'),
                                   self.tr("Edit..."), self)
        editCoinAct.triggered.connect(self.editCoin)

        style = QApplication.style()
        icon = style.standardIcon(QStyle.SP_TrashIcon)
        deleteCoinAct = QAction(icon,
                                   self.tr("Delete"), self)
        deleteCoinAct.setShortcut(QtGui.QKeySequence.Delete)
        deleteCoinAct.triggered.connect(self.deleteCoin)

        coin = menubar.addMenu(self.tr("Coin"))
        coin.addAction(addCoinAct)
        coin.addAction(editCoinAct)
        coin.addAction(deleteCoinAct)

        viewBrowserAct = QAction(createIcon('page_white_world.png'),
                                   self.tr("View in browser"), self)
        viewBrowserAct.triggered.connect(self.viewBrowser)

        self.viewTab = TabView(self)

        actions = self.viewTab.actions()
        listMenu = menubar.addMenu(self.tr("List"))
        listMenu.addAction(actions['new'])
        listMenu.addMenu(actions['open'])
        listMenu.aboutToShow.connect(self.viewTab.updateOpenPageMenu)
        listMenu.addAction(actions['rename'])
        listMenu.addSeparator()
        listMenu.addAction(actions['select'])
        listMenu.addSeparator()
        listMenu.addAction(actions['close'])
        listMenu.addAction(actions['remove'])

        self.referenceMenu = menubar.addMenu(self.tr("Reference"))

        reportAct = QAction(self.tr("Report..."), self)
        reportAct.setShortcut(QtCore.Qt.CTRL + QtCore.Qt.Key_P)
        reportAct.triggered.connect(self.report)

        saveTableAct = QAction(createIcon('table.png'),
                                     self.tr("Save current list..."), self)
        saveTableAct.triggered.connect(self.saveTable)

        report = menubar.addMenu(self.tr("Report"))
        report.addAction(reportAct)
        report.addAction(saveTableAct)
        report.addAction(viewBrowserAct)

        helpAct = QAction(createIcon('help.png'),
                                self.tr("Online help"), self)
        helpAct.setShortcut(QtGui.QKeySequence.HelpContents)
        helpAct.triggered.connect(self.onlineHelp)
        checkUpdatesAct = QAction(self.tr("Check for updates"), self)
        checkUpdatesAct.triggered.connect(self.manualUpdate)
        aboutAct = QAction(self.tr("About %s") % version.AppName, self)
        aboutAct.triggered.connect(self.about)

        help_ = menubar.addMenu(self.tr("&Help"))
        help_.addAction(helpAct)
        help_.addSeparator()
        help_.addAction(checkUpdatesAct)
        help_.addSeparator()
        help_.addAction(aboutAct)

        toolBar = QToolBar(self.tr("Toolbar"), self)
        toolBar.setMovable(False)
        toolBar.addAction(openCollectionAct)
        toolBar.addSeparator()
        toolBar.addAction(addCoinAct)
        toolBar.addAction(editCoinAct)
        toolBar.addAction(viewBrowserAct)
        toolBar.addSeparator()
        toolBar.addAction(cancelFilteringAct)
        toolBar.addSeparator()
        toolBar.addAction(settingsAct)
        self.addToolBar(toolBar)

        self.setWindowTitle(version.AppName)

        self.reference = Reference(self)
        self.reference.open(Settings()['reference'])

        if len(sys.argv) > 1:
            fileName = sys.argv[1]
        else:
            latest = LatestCollections(self)
            fileName = latest.latest()

        self.collection = Collection(self.reference, self)
        self.openCollection(fileName)

        self.setCentralWidget(self.viewTab)

        settings = QtCore.QSettings()
        pageIndex = settings.value('tabwindow/page')
        if pageIndex != None:
            self.viewTab.setCurrentIndex(int(pageIndex))

        if settings.value('mainwindow/maximized') == 'true':
            self.setWindowState(self.windowState() | QtCore.Qt.WindowMaximized)
        else:
            size = settings.value('mainwindow/size')
            if size:
                self.resize(size)

        self.autoUpdate()

    def createStatusBar(self):
        self.collectionFileLabel = QLabel()
        self.statusBar().addWidget(self.collectionFileLabel)

    def __updateLatest(self, menu=None):
        if menu:
            self.__menu = menu
        for act in self.latestActions:
            self.__menu.removeAction(act)

        self.latestActions = []
        latest = LatestCollections(self)
        for act in latest.actions():
            self.latestActions.append(act)
            act.latestTriggered.connect(self.openCollection)
            self.__menu.insertAction(self.exitAct, act)
        self.__menu.insertSeparator(self.exitAct)

    def cancelFilteringEvent(self):
        listView = self.viewTab.currentListView()
        listView.clearAllFilters()

    def settingsEvent(self):
        dialog = SettingsDialog(self.collection, self)
        res = dialog.exec_()
        if res == QDialog.Accepted:
            self.__restart()

    def __restart(self):
        result = QMessageBox.question(self, self.tr("Settings"),
                    self.tr("The application will need to restart to apply "
                            "the new settings. Restart it now?"),
                    QMessageBox.Yes | QMessageBox.No,
                    QMessageBox.Yes)
        if result == QMessageBox.Yes:
            self.close()
            program = sys.executable
            argv = []
            if program != sys.argv[0]:
                # Process running as Python arg
                argv.append(sys.argv[0])
            QtCore.QProcess.startDetached(program, argv)

    def addCoin(self):
        model = self.viewTab.currentModel()
        model.addCoin(model.record(), self)

    def editCoin(self):
        listView = self.viewTab.currentListView()
        indexes = listView.selectedRows()
        if len(indexes) == 1:
            listView._edit(indexes[0])
        elif len(indexes) > 1:
            listView._multiEdit(indexes)

    def deleteCoin(self):
        listView = self.viewTab.currentListView()
        indexes = listView.selectedRows()
        if len(indexes):
            listView._delete(indexes)

    def viewBrowser(self):
        listView = self.viewTab.currentListView()
        listView.viewInBrowser()

    def report(self):
        listView = self.viewTab.currentListView()
        indexes = listView.selectedRows()
        model = listView.model()

        records = []
        for index in indexes:
            records.append(model.record(index.row()))

        preview = PreviewDialog(model, records, self)
        preview.exec_()

    def saveTable(self):
        listView = self.viewTab.currentListView()
        listView.saveTable()

    def __workingDir(self):
        fileName = self.collection.fileName
        if not fileName:
            fileName = LatestCollections.DefaultCollectionName
        return QtCore.QFileInfo(fileName).absolutePath()

    def openCollectionEvent(self):
        fileName, _selectedFilter = QFileDialog.getOpenFileName(self,
                self.tr("Open collection"), self.__workingDir(),
                self.tr("Collections (*.db)"))
        if fileName:
            self.openCollection(fileName)

    def newCollectionEvent(self):
        fileName, _selectedFilter = QFileDialog.getSaveFileName(self,
                self.tr("New collection"), self.__workingDir(),
                self.tr("Collections (*.db)"))
        if fileName:
            self.__saveParams()

            if self.collection.create(fileName):
                self.setCollection(self.collection)

    def descriptionCollectionEvent(self, checked):
        dialog = DescriptionDialog(self.collection.getDescription(), self)
        dialog.exec_()

    def passwordCollectionEvent(self, checked):
        dialog = PasswordSetDialog(self.collection, self)
        dialog.exec_()

    def backupCollectionEvent(self, checked):
        self.collection.backup()

    def vacuumCollectionEvent(self, checked):
        self.collection.vacuum()

    def openCollection(self, fileName):
        self.__saveParams()

        if self.collection.open(fileName):
            self.setCollection(self.collection)
        else:
            # Remove wrong collection from latest collections list
            latest = LatestCollections(self)
            latest.delete(fileName)
            self.__updateLatest()

    @waitCursorDecorator
    def setCollection(self, collection):
        self.collectionFileLabel.setText(collection.getFileName())
        title = "%s - %s" % (collection.getCollectionName(), version.AppName)
        self.setWindowTitle(title)

        latest = LatestCollections(self)
        latest.add(collection.getFileName())
        self.__updateLatest()

        self.viewTab.setCollection(collection)

        self.referenceMenu.clear()
        for action in self.collection.referenceMenu(self):
            self.referenceMenu.addAction(action)

    def closeEvent(self, e):
        self.__shutDown()

    def __shutDown(self):
        self.__saveParams()

        settings = QtCore.QSettings()

        if self.collection.fileName:
            self.viewTab.savePagePositions()
            # Save latest opened page
            settings.setValue('tabwindow/page', self.viewTab.currentIndex())

        # Save main window size
        settings.setValue('mainwindow/size', self.size())
        settings.setValue('mainwindow/maximized', self.isMaximized())

    def __saveParams(self):
        if self.collection.pages():
            for param in self.collection.pages().pagesParam():
                param.listParam.save()

    def about(self):
        QMessageBox.about(self, self.tr("About %s") % version.AppName,
                self.tr("%s %s\n\n"
                        "Copyright (C) 2013 Vitaly Ignatov\n\n"
                        "%s is freeware licensed under a GPLv3.") %
                        (version.AppName, version.Version, version.AppName))

    def onlineHelp(self):
        url = QtCore.QUrl(version.Web)

        executor = QtGui.QDesktopServices()
        executor.openUrl(url)

    def autoUpdate(self):
        if Settings()['updates']:
            currentDate = QtCore.QDate.currentDate()

            settings = QtCore.QSettings()
            lastUpdateDateStr = settings.value('mainwindow/last_update')
            if lastUpdateDateStr:
                lastUpdateDate = QtCore.QDate.fromString(lastUpdateDateStr,
                                                         QtCore.Qt.ISODate)
                if lastUpdateDate.addDays(10) < currentDate:
                    self.checkUpdates()
            else:
                self.checkUpdates()

    def manualUpdate(self):
        if not self.checkUpdates():
            QMessageBox.information(self, self.tr("Updates"),
                    self.tr("You already have the latest version."))

    def checkUpdates(self):
        currentDate = QtCore.QDate.currentDate()
        currentDateStr = currentDate.toString(QtCore.Qt.ISODate)
        settings = QtCore.QSettings()
        settings.setValue('mainwindow/last_update', currentDateStr)

        newVersion = self.__getNewVersion()
        if newVersion and newVersion != version.Version:
            result = QMessageBox.question(self, self.tr("New version"),
                        self.tr("New version is available. Download it now?"),
                        QMessageBox.Yes | QMessageBox.No,
                        QMessageBox.Yes)
            if result == QMessageBox.Yes:
                url = QtCore.QUrl(version.Web + 'wiki/MainPage')

                executor = QtGui.QDesktopServices()
                executor.openUrl(url)

            return True
        else:
            return False

    @waitCursorDecorator
    def __getNewVersion(self):
        import urllib.request
        from xml.dom.minidom import parseString

        newVersion = version.Version

        try:
            url = "http://wiki.open-numismat-tracker.googlecode.com/git/data/pad.xml"
            req = urllib.request.Request(url)
            data = urllib.request.urlopen(req).read()
            xml = parseString(data)
            tag = xml.getElementsByTagName('Program_Version')[0]
            newVersion = tag.firstChild.nodeValue
        except:
            return None

        return newVersion

    def uploadImagesEvent(self):
        from PyQt5 import QtSql
        from OpenNumismat.Collection.Collection import Photo

        model = self.collection.model()

        query = QtSql.QSqlQuery(self.collection.db)
        query.prepare("SELECT count(*) FROM photos WHERE ifnull(url,'')<>''")
        query.exec_()
        if query.first():
            count = query.record().value(0)
            progressDlg = Gui.ProgressDialog(self.tr("Uploading images"),
                                self.tr("Cancel"), count, self)

            query = QtSql.QSqlQuery(self.collection.db)
            query.prepare("SELECT id FROM photos WHERE ifnull(url,'')<>''")
            query.exec_()

            while query.next():
                progressDlg.step()
                if progressDlg.wasCanceled():
                    break

                photo = Photo(query.record().value('id'), model)
                photo.uploadMissedImage()

            progressDlg.reset()
            query.clear()

    def importEvent(self):
        from PyQt5 import QtSql
        from OpenNumismat.Collection.Collection import Photo

        model = self.collection.model()
        dialog = ImportDialog(model, self)
        res = dialog.exec_()
        if res == QDialog.Accepted:
            if dialog.params['auction'] == 'АукционЪ.СПб':
                parser = AuctionSpbParser()
            elif dialog.params['auction'] == 'Конрос':
                parser = ConrosParser()

            if dialog.params['category'] == 0:
                categories = range(len(parser.categories()))
            else:
                categories = [dialog.params['category'] - 1, ]

            for auctNo in range(dialog.params['from_num'], dialog.params['till_num'] + 1):
                for category in categories:
                    url = parser.getPageUrl(auctNo, category, 0)
                    items = parser.parsePage(url)
                    if not items:
                        continue

                    item1 = parser.parse(items[0]['url'])

                    query = QtSql.QSqlQuery(self.collection.db)
                    query.prepare("INSERT INTO auctions (number, date, site, place, category)" \
                                  " VALUES (?, ?, ?, ?, ?)")
                    query.addBindValue(auctNo)
                    query.addBindValue(item1['date'])
                    query.addBindValue('Аукцион')
                    query.addBindValue(dialog.params['auction'])
                    query.addBindValue(parser.category(category))

                    query.exec_()

                    auct_id = query.lastInsertId()

                    for page in parser.pages(auctNo, category):
                        url = parser.getPageUrl(auctNo, category, page)
                        items = parser.parsePage(url)
                        if not items:
                            break

                        for item in items:
                            item1 = parser.parse(item['url'])

                            record_item = {
                                    'title': item1['title'],
                                    'denomination': item['denomination'],
                                    'year': item['year'],
                                    'mintmark': item['mintmark'],
                                    'category': parser.category(category),
                                    'status': 'pass',
                                    'material': item['material'],
                                    'grade': item['grade'],
                                    'price': item['price'],
                                    'totalpayprice': item['totalPayPrice'],
                                    'totalsaleprice': item['totalSalePrice'],
                                    'buyer': item['buyer'],
                                    'url': item['url'],
                                    'bids': item['bids'],
                                    'bidders': item1['bidders'],
                                    'info': item1['info'],
                                    'date': item1['date'],
                                    'auctionnum': auctNo,
                                    'site': item['site'],
                                    'place': dialog.params['auction'],
                            }
                            if 'auctionnum' in item:
                                record_item['auctionnum'] = item['auctionnum']
                            if 'lotnum' in item:
                                record_item['lotnum'] = item['lotnum']
                            else:
                                record_item['lotnum'] = item1['lotnum']
                            if 'country' in item1:
                                record_item['country'] = item1['country']
                            imageFields = ['photo1', 'photo2', 'photo3', 'photo4']
                            for i, imageUrl in enumerate(item1['images']):
                                if i < len(imageFields):
                                    photo = Photo(None, model)
                                    photo.url = imageUrl
                                    if dialog.params['download_images']:
                                        # When error - repeat uploading
                                        for _ in range(3):
                                            if photo.uploadImage():
                                                break

                                    photo.changed = True
                                    record_item[imageFields[i]] = photo

                            record = model.record()
                            for field, value in record_item.items():
                                record.setValue(field, value)
                            model.appendRecordQuiet(record)

        self.collection.open(self.collection.getFileName())
        self.setCollection(self.collection)
Exemplo n.º 13
0
def convertImage(fileName):
    ba = QtCore.QByteArray()
    buffer = QtCore.QBuffer(ba)
    buffer.open(QtCore.QIODevice.WriteOnly)

    image = QtGui.QImage(fileName)
    image.save(buffer, 'png')

    return ba

import sys
sys.path.append('..')
from OpenNumismat.Reference.Reference import Reference

app = QApplication(sys.argv)
ref = Reference()

f = open('langs')
langs = [x.strip('\n') for x in f.readlines()]

for lang in langs:
    src_file = "../OpenNumismat/db/reference_%s.ref" % lang
    if not os.path.isfile(src_file):
        src_file = "../OpenNumismat/db/reference_en.ref"

    shutil.copy(src_file, ".")

    ref.open('reference_%s.ref' % lang)

    src_ref_file = "reference_%s.json" % lang
    if not os.path.isfile(src_ref_file):