예제 #1
0
    def __init__(self):
        super(Main, self).__init__()
        self.curPath, curFilename = os.path.split(os.path.abspath(sys.argv[0]))
        self.rootPath = self.curPath.replace("\\", "/")
        # 全局日志对象
        self.logger = Log()
        # 布局窗口切分对象组
        self.layoutFormScale = {'obj': None, 'offset': 0}
        # 监听对象表
        self.listeners = {}
        # 服务端通讯参数
        self.token = r''
        # 检查数据库链接
        try:
            # 本地配置
            self.configs = Config()
            # 远程配置
            Na_Business_Report.select().limit(1).count()
        except Exception as e:
            self.logger.info(e)
            if (QMessageBox.question(None, "系统提示", " 数据库链接异常,请与管理员联系!",
                                     QMessageBox.Yes) == QMessageBox.Yes):
                self.closeMain(True)

        # 语言对象
        self.trans = QTranslator(self)
        self.changeLanguage(self.configs.language.value)
예제 #2
0
    def keywordListAll(self):
        """
        获取全部记录
        :return: result list
        """
        try:
            rows = Pub_Sku_Keyword.select().order_by(Pub_Sku_Keyword.updated_at.desc()).dicts()
        except Exception as e:
            Log().error('查询数据失败')
            Log().error(e)

        return rows
예제 #3
0
    def __init__(self, mainWin):

        # qssStyle = self.load_qss('app/resource/css/app_style.css')

        super(DlgLogin, self).__init__()

        self.mainWin = mainWin
        self.dlg = self
        self.setupUi(self.dlg)
        #self.setStyleSheet(qssStyle)

        self.log = Log('info')
        self.tbSetting.clicked.connect(self.actionSetting)
        self.pbOk.clicked.connect(self.actionOk)
        self.pbCancel.clicked.connect(self.actionCancel)

        # self.setStyleSheet('QWidget{background-color:rgb(0,0,0)}')  # 增加的代码

        T = DbConfig().get(main_key='user', minor_key='account')
        self.leAccount.setText(T.value)
        T = DbConfig().get(main_key='user', minor_key='password')
        self.lePassword.setText(T.value)
        T = DbConfig().get(main_key='user', minor_key='language')
        self.cbLanguage.setCurrentText(T.value)
        # 语言切换
        self.cbLanguage.currentTextChanged.connect(self.changeLanguage)

        self.dlg.exec_()
예제 #4
0
    def __init__(self, mainWin, keyCode):
        super(WidgetWeb, self).__init__()
        self.mainWin = mainWin
        self.myWidget = QWidget()
        self.log = Log('info')
        self.setupUi(self.myWidget)
        self.canMoveView = False

        self.loadBegin = datetime.datetime.now()
        self.loadEnd = datetime.datetime.now()
        self.loginCount = 0

        # 定义二级对象动态元素
        self.labelFields = []
        self.leFields = []
        self.tbGos = []
        self.pbGos = []
        self.actBtDynamicClicked = []

        self.labelField.setHidden(True)
        self.leField.setHidden(True)
        self.tbGo.setHidden(True)
        self.pbGo.setHidden(True)

        # 浏览器设置WebView
        self.webview = WebEngineView(self.mainWin)
        self.widgetContentVL.addWidget(self.webview)

        # 右键菜单
        self.webview.setContextMenuPolicy(Qt.CustomContextMenu)
        self.webview.customContextMenuRequested.connect(
            self.webviewGenerateMenu)
        self.webview.setMouseTracking(True)
        self.webview.setTabletTracking(True)
        self.webview.setFocusPolicy(QtCore.Qt.ClickFocus)
        self.webview.setAcceptDrops(True)
        # self.webview.createWindow(self.mainWin, QWebEnginePage.OpenLinkInThisWindow)

        self.plusin = DbPlusIn().get(code=keyCode)
        if (self.plusin.id > 0):
            self.myWidget.setWindowTitle(self.plusin.title_en)
            self.plusinFunction = DbPlusInFunction().select().where(
                DbPlusInFunction.fid == self.plusin.id).order_by(
                    DbPlusInFunction.sort.asc())
        else:
            self.plusinFunction = None

        self.initFields()

        # 公用按钮
        self.tbRefresh.clicked.connect(self.actTbRefresh)
        self.tbGoBack.clicked.connect(self.actTbGoBack)
        self.tbRedo.clicked.connect(self.actTbRedo)
        self.tbStop.clicked.connect(self.actTbStop)
        self.tbSide.clicked.connect(self.actTbSide)

        # 初始化布局
        self.setLayout(self.myWidget.layout())
예제 #5
0
    def __init__(self, mainWin):
        super(DlgSetting, self).__init__()
        self.mainWin = mainWin
        self.dlg = QDialog()
        self.setupUi(self.dlg)
        self.log = Log('info')

        self.init()
        self.pbSave.clicked.connect(self.actionSave)

        self.dlg.exec_()
예제 #6
0
    def __init__(self, mainWindow):
        super(WinMain, self).__init__()
        self.setupUi(mainWindow)
        self.app = mainWindow
        self.log = Log('info')

        #系统菜单初始化
        self.actionSetting.triggered.connect(self.actSetting)
        self.actionAbout.triggered.connect(self.actAbout)
        self.actionHelp.triggered.connect(self.help)
        self.actionExit.triggered.connect(self.actExit)
        self.actionBusinessReport.triggered.connect(
            lambda: self.actLoadModelView('BUSINESS-REPORT'))
        self.actionProductList.triggered.connect(
            lambda: self.actLoadModelView('PRODUCT-LIST'))
        self.actionChartsBusinessReport.triggered.connect(
            lambda: self.actLoadModelView('CHARTS'))
        # self.actionCategories.triggered.connect(lambda: self.actLoadModelView('CATEGORY-LIST'))
        # self.actionProduct_Line.triggered.connect(lambda: self.actLoadModelView('PRODUCT-LINE'))
        # self.actionCategory_List.triggered.connect(lambda: self.actLoadModelView('NEWAIM-CATEGORY'))
        self.actionKeywords_List.triggered.connect(
            lambda: self.actLoadModelView('KEYWORD-LIST'))
        self.actionProduct_Category_Relation.triggered.connect(
            lambda: self.actLoadModelView('PRODUCT-CATEGORY'))
        self.actionProduct_And_Category_Relationship.triggered.connect(
            lambda: self.actLoadModelView('AMAZON-PRODUCT-CATEGORY'))
        self.actionAmazon_Category_Relation.triggered.connect(
            lambda: self.actLoadModelView('AMAZON-CATEGORY-KEYWORD'))
        self.actionDashboard.triggered.connect(
            lambda: self.actLoadModelView('DASHBOARD'))

        # 设置main tab 关闭功能
        self.mainTabs.setTabsClosable(True)
        self.mainTabs.tabCloseRequested.connect(self.actMainTabsClose)
        self.mainTabs.removeTab(0)

        self.plTab = WidgetDashboard(self)
        _wgTemp = self.plTab
        tabIndex = self.mainTabs.addTab(_wgTemp,
                                        _wgTemp.myWidget.windowTitle())
        self.mainTabs.setCurrentIndex(tabIndex)
예제 #7
0
        leDbPort = DbConfig().get(main_key='setting', minor_key='leDbPort')
        leDbName = DbConfig().get(main_key='setting', minor_key='leDbName')
        leDbUsername = DbConfig().get(main_key='setting', minor_key='leDbUsername')
        leDbPassword = DbConfig().get(main_key='setting', minor_key='leDbPassword')

        try:
            conn = peewee.PostgresqlDatabase(
                leDbName.value
                , host=leDbHost.value
                , port=int(leDbPort.value)
                , user=leDbUsername.value
                , password=leDbPassword.value
                , encoding='utf8'
            )
            return conn
        except Exception as e:
            print(e)

        pass

'''创建数据库链接'''
try:
    pbConn = pgDbClection().Conn()
except Exception as e:
    logger.info(e)

'''PgSQL数据库基础类'''
class BasePgDbModel(peewee.Model):

    class Meta:
        database = pbConn
예제 #8
0
class WinMain(Ui_mainWindow):
    _ = QCoreApplication.translate

    def __init__(self, mainWindow):
        super(WinMain, self).__init__()
        self.setupUi(mainWindow)
        self.app = mainWindow
        self.log = Log('info')

        #系统菜单初始化
        self.actionSetting.triggered.connect(self.actSetting)
        self.actionAbout.triggered.connect(self.actAbout)
        self.actionHelp.triggered.connect(self.help)
        self.actionExit.triggered.connect(self.actExit)
        self.actionBusinessReport.triggered.connect(
            lambda: self.actLoadModelView('BUSINESS-REPORT'))
        self.actionProductList.triggered.connect(
            lambda: self.actLoadModelView('PRODUCT-LIST'))
        self.actionChartsBusinessReport.triggered.connect(
            lambda: self.actLoadModelView('CHARTS'))
        # self.actionCategories.triggered.connect(lambda: self.actLoadModelView('CATEGORY-LIST'))
        # self.actionProduct_Line.triggered.connect(lambda: self.actLoadModelView('PRODUCT-LINE'))
        # self.actionCategory_List.triggered.connect(lambda: self.actLoadModelView('NEWAIM-CATEGORY'))
        self.actionKeywords_List.triggered.connect(
            lambda: self.actLoadModelView('KEYWORD-LIST'))
        self.actionProduct_Category_Relation.triggered.connect(
            lambda: self.actLoadModelView('PRODUCT-CATEGORY'))
        self.actionProduct_And_Category_Relationship.triggered.connect(
            lambda: self.actLoadModelView('AMAZON-PRODUCT-CATEGORY'))
        self.actionAmazon_Category_Relation.triggered.connect(
            lambda: self.actLoadModelView('AMAZON-CATEGORY-KEYWORD'))
        self.actionDashboard.triggered.connect(
            lambda: self.actLoadModelView('DASHBOARD'))

        # 设置main tab 关闭功能
        self.mainTabs.setTabsClosable(True)
        self.mainTabs.tabCloseRequested.connect(self.actMainTabsClose)
        self.mainTabs.removeTab(0)

        self.plTab = WidgetDashboard(self)
        _wgTemp = self.plTab
        tabIndex = self.mainTabs.addTab(_wgTemp,
                                        _wgTemp.myWidget.windowTitle())
        self.mainTabs.setCurrentIndex(tabIndex)

    '''关于程序'''

    def actAbout(self):
        QMessageBox.information(
            None, self._("sscode", "About Program"),
            " NEWAIM Analysis for Amazon\n 主要功能:AMAZON 销售分析 \n 版本:V{0} \n 发布:2019-08-09"
            .format(self.app.configs.version.value), QMessageBox.Yes)

    '''退出系统'''

    def actExit(self):
        self.app.closeMain()

    '''打开help'''

    def help(self):
        try:
            rootPath, rootFile = os.path.split(os.path.abspath(sys.argv[0]))
            rootPath = rootPath.replace("\\", "/")
            win32api.ShellExecute(0, 'open',
                                  rootPath + '/app/resource/help.chm', '', '',
                                  1)
        except Exception as e:
            print(e)
        pass

    '''系统配置'''

    def actSetting(self):
        try:
            DlgSetting(self.app)
        except Exception as e:
            print(e)
        pass

    def actMainTabsClose(self, index):
        if (index > -1):
            self.mainTabs.removeTab(index)
        else:
            self.statusMsg('不允许关闭工作区—“{0}”'.format(
                self.mainTabs.tabText(index)))

    '''动态加载系统模块'''

    def actLoadModelView(self, code):
        tabIndex = -1
        try:
            mdPlusin = DbPlusIn().get(code=code)
            for i in range(self.mainTabs.count()):
                if (self.mainTabs.tabText(i) == mdPlusin.title_cn
                        or self.mainTabs.tabText(i) == mdPlusin.title_en
                        or self.mainTabs.tabText(i) == mdPlusin.code):
                    tabIndex = i
                    pass

            if (tabIndex == -1):
                if (code == 'BUSINESS-REPORT'):
                    self.brTab = WidgetBusinessReport(self)
                    _wgTemp = self.brTab
                elif (code == 'PRODUCT-LIST'):
                    self.plTab = WidgetProduct(self)
                    _wgTemp = self.plTab
                elif (code == 'CHARTS'):
                    self.plTab = WidgetWeb(self, mdPlusin.code)
                    _wgTemp = self.plTab
                elif (code == 'CATEGORY-LIST'):
                    self.plTab = WidgetCategory(self)
                    _wgTemp = self.plTab
                elif (code == 'PRODUCT-LINE'):
                    self.plTab = WidgetProductLine(self)
                    _wgTemp = self.plTab
                elif (code == 'NEWAIM-CATEGORY'):
                    self.plTab = WidgetNewaimCategory(self)
                    _wgTemp = self.plTab
                elif (code == 'KEYWORD-LIST'):
                    self.plTab = WidgetSkuKeyword(self)
                    _wgTemp = self.plTab
                elif (code == 'PRODUCT-CATEGORY'):
                    self.plTab = WidgetProductNewaimCategory(self)
                    _wgTemp = self.plTab

                elif (code == 'AMAZON-PRODUCT-CATEGORY'):
                    self.plTab = WidgetProductAmazonCategory(self)
                    _wgTemp = self.plTab

                elif (code == 'AMAZON-SKU-KEYWORD'):
                    self.plTab = WidgetAmazonSkuKeywordRelation(self)
                    _wgTemp = self.plTabel
                if (code == 'AMAZON-CATEGORY-KEYWORD'):
                    self.plTab = WidgetAmazonCategoryKeywordRelation(self)
                    _wgTemp = self.plTab
                if (code == 'DASHBOARD'):
                    self.plTab = WidgetDashboard(self)
                    _wgTemp = self.plTab

                tabIndex = self.mainTabs.addTab(_wgTemp,
                                                _wgTemp.myWidget.windowTitle())
                self.mainTabs.setCurrentIndex(tabIndex)
            else:
                self.mainTabs.setCurrentIndex(tabIndex)

            mdPlusin = None
            pass
        except Exception as e:
            self.log.info(e)
            import traceback
            traceback.print_exc()
            QMessageBox.information(None, self._("sscode", "Run Error"), e,
                                    QMessageBox.Yes)
        pass

    '''进度条 BEGIN ============================'''
    '''显示进度条'''

    def progressBarShow(self, totalNumber=100, curNumber=0, title=''):
        if (totalNumber is None): totalNumber = 100
        self.app.progressBar.setRange(0, totalNumber)
        self.app.progressBar.setValue(curNumber)
        self.app.progressBar.show()

    '''隐藏进累加'''

    def progressBarContinue(self):
        self.app.progressBar.setValue(self.app.progressBar.value() + 1)

    '''隐藏进度条'''

    def progressBarHide(self):
        self.app.progressBar.hide()

    '''进度条 END ============================'''
    '''状态信息 BEGIN ============================'''

    def statusMsg(self, message):
        if message is not None:
            self.app.statusBar().showMessage(message)

    '''状态信息 END ============================'''
예제 #9
0
# coding:utf-8

import re
from PyQt5.QtWidgets import QTableWidgetItem
from PyQt5 import QtCore, QtGui, QtWidgets, uic
from app.lib.logger import Log
import time
import peewee
'''全局Log对象'''
logger = Log('info')
'''将None转换为目标类型'''


def utNone2Object(o, default=''):
    return o if (o is not None) else default


'''创建 QTableWidgetItem 项'''


def utQTableWidgetItem(value, default=''):
    return QTableWidgetItem('{0}'.format(utNone2Object(value, default)))


def utStr2Date(value, default=''):
    return re.search('\d{4}-\d{1,2}-\d{1,2}', value).group(0) if (re.search(
        '\d{4}-\d{1,2}-\d{1,2}', value) is not None) else ''


'''字符串中提取第一个浮点小数'''
예제 #10
0
class Main(QMainWindow):
    def __init__(self):
        super(Main, self).__init__()
        self.curPath, curFilename = os.path.split(os.path.abspath(sys.argv[0]))
        self.rootPath = self.curPath.replace("\\", "/")
        # 全局日志对象
        self.logger = Log()
        # 布局窗口切分对象组
        self.layoutFormScale = {'obj': None, 'offset': 0}
        # 监听对象表
        self.listeners = {}
        # 服务端通讯参数
        self.token = r''
        # 检查数据库链接
        try:
            # 本地配置
            self.configs = Config()
            # 远程配置
            Na_Business_Report.select().limit(1).count()
        except Exception as e:
            self.logger.info(e)
            if (QMessageBox.question(None, "系统提示", " 数据库链接异常,请与管理员联系!",
                                     QMessageBox.Yes) == QMessageBox.Yes):
                self.closeMain(True)

        # 语言对象
        self.trans = QTranslator(self)
        self.changeLanguage(self.configs.language.value)

    '''
    用户登录
    '''

    def login(self, relogin=False):
        if not relogin: self.user = User()
        if (not self.user.account):
            try:
                _dlg = DlgLogin(self)
            except Exception as e:
                print(e)
        if self.user.account:
            return True
        else:
            sys.exit(0)
            return False

    '''语言切换'''

    def changeLanguage(self, _lang):
        if (_lang == '简体中文'):
            self.trans.load(self.rootPath + '/en_ZH')
            app.installTranslator(self.trans)
        else:
            app.removeTranslator(self.trans)

        self.configs = Config()
        pass

    '''
    初始设置
    '''

    def initMain(self):
        # 设置主窗体样式
        self.setStyleSheet(utGetStyleContent(self.curPath, 'app_style'))

        # 启动提示
        self.statusBar().showMessage('可以开始了...')

        # 初始化进度条
        self.progressBar = QProgressBar()
        self.progressLabel = QLabel()
        self.progressLabel.setText("进度:")

        self.statusBar().addPermanentWidget(self.progressLabel)
        self.statusBar().addPermanentWidget(self.progressBar)
        self.progressBar.setGeometry(0, 0, 100, 5)
        self.progressBar.setRange(0, 100)  # 设置进度条的范围
        self.progressBar.setValue(0)
        self.progressBar.setFixedHeight(10)
        self.progressBar.setFixedWidth(200)
        self.progressBar.hide()
        self.progressLabel.hide()

        self.setWindowIcon(QtGui.QIcon(':icons/images/winlogo.png'))
        pass

    '''
    初始化自适应调整布局
    '''

    def resizeEvent(self, event):
        innerHeight = event.size().height() - 75

    '''
    按下退出键提示是否退出系统
    '''

    def keyPressEvent(self, e):
        if e.key() == QtCore.Qt.Key_Escape:
            self.closeMain()

    '''
    关闭主窗口提示
    '''

    def closeEvent(self, event):
        if (not self.closeMain()):
            event.ignore()

    '''关闭主程序'''

    def closeMain(self, skipInquiry=False):
        if skipInquiry == False:
            req = QMessageBox.question(None, "系统提示",
                                       "您确认要退出程序吗? \n如果配置未保存,请先保存再退出!",
                                       QMessageBox.Yes | QMessageBox.No)
            if (req == QMessageBox.Yes):
                try:
                    # TODO 需要优化退出时杀死所有 QtWebEngineProcess 进程问题
                    # 查看浏览器进程
                    # self.logger.info(os.popen('tasklist /FI "IMAGENAME eq QtWebEngineProcess.exe"').read())
                    # 杀浏览器进程
                    os.system('TASKKILL /F /IM QtWebEngineProcess.exe')

                    App.mainFrame.webview.close()
                    if (App.mainFrame.twLogs):
                        App.mainFrame.twLogs.webview.close()
                except Exception as e:
                    pass

                sys.exit(0)
            else:
                return False
        else:
            sys.exit(0)

    '''状态信息 ============================'''

    def statusMsg(self, message):
        if message is not None:
            self.statusBar().showMessage(message)

    '''刷新运行日志事件'''

    def actListenersRunLogs(self, title=''):
        if (self.listeners['RunLogsTab'] is not None):
            self.listeners['RunLogsTab']()
        pass