コード例 #1
0
ファイル: ui_category_report.py プロジェクト: flmnvd/jal
class Ui_CategoryReportWidget(object):
    def setupUi(self, CategoryReportWidget):
        if not CategoryReportWidget.objectName():
            CategoryReportWidget.setObjectName(u"CategoryReportWidget")
        CategoryReportWidget.resize(636, 345)
        self.verticalLayout = QVBoxLayout(CategoryReportWidget)
        self.verticalLayout.setSpacing(0)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.ReportParamsFrame = QFrame(CategoryReportWidget)
        self.ReportParamsFrame.setObjectName(u"ReportParamsFrame")
        self.ReportParamsFrame.setFrameShape(QFrame.Panel)
        self.ReportParamsFrame.setFrameShadow(QFrame.Sunken)
        self.gridLayout = QGridLayout(self.ReportParamsFrame)
        self.gridLayout.setSpacing(6)
        self.gridLayout.setObjectName(u"gridLayout")
        self.gridLayout.setContentsMargins(2, 2, 2, 2)
        self.ReportFrameSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                             QSizePolicy.Minimum)

        self.gridLayout.addItem(self.ReportFrameSpacer, 0, 3, 1, 1)

        self.ReportRange = DateRangeSelector(self.ReportParamsFrame)
        self.ReportRange.setObjectName(u"ReportRange")
        self.ReportRange.setProperty("ItemsList",
                                     u"QTD;YTD;this_year;last_year")

        self.gridLayout.addWidget(self.ReportRange, 0, 0, 1, 1)

        self.ReportCategoryLbl = QLabel(self.ReportParamsFrame)
        self.ReportCategoryLbl.setObjectName(u"ReportCategoryLbl")

        self.gridLayout.addWidget(self.ReportCategoryLbl, 0, 1, 1, 1)

        self.ReportCategoryEdit = CategorySelector(self.ReportParamsFrame)
        self.ReportCategoryEdit.setObjectName(u"ReportCategoryEdit")

        self.gridLayout.addWidget(self.ReportCategoryEdit, 0, 2, 1, 1)

        self.verticalLayout.addWidget(self.ReportParamsFrame)

        self.ReportTableView = QTableView(CategoryReportWidget)
        self.ReportTableView.setObjectName(u"ReportTableView")
        self.ReportTableView.setFrameShape(QFrame.Panel)
        self.ReportTableView.setFrameShadow(QFrame.Sunken)
        self.ReportTableView.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.ReportTableView.setAlternatingRowColors(True)
        self.ReportTableView.setGridStyle(Qt.DotLine)
        self.ReportTableView.setWordWrap(False)
        self.ReportTableView.verticalHeader().setVisible(False)
        self.ReportTableView.verticalHeader().setMinimumSectionSize(20)
        self.ReportTableView.verticalHeader().setDefaultSectionSize(20)

        self.verticalLayout.addWidget(self.ReportTableView)

        self.retranslateUi(CategoryReportWidget)

        QMetaObject.connectSlotsByName(CategoryReportWidget)

    # setupUi

    def retranslateUi(self, CategoryReportWidget):
        CategoryReportWidget.setWindowTitle(
            QCoreApplication.translate("CategoryReportWidget",
                                       u"Report by category", None))
        self.ReportCategoryLbl.setText(
            QCoreApplication.translate("CategoryReportWidget", u"Category:",
                                       None))
class IngestWindow(QDialog):
    """Subwindow dedicated to data ingest functions.

    Instance attributes:
        - config: Config object holding configuration information
        including API keys.
    """
    config: Config

    # Private Instance Attributes:
    # - _main_layout: Main grid layout
    # - _button_box: Button box holding main control buttons.
    # - _options_group_box: Group box holding most UI widgets
    # - _view: QTableView holding the pandas table viewer.
    # - _pool: QThreadPool for handeling multithreaded functions.
    # - _txt_var: Dictionary holding line edit widgets.
    # - _lists: Dictionary holding the dataset list widget and search type combo widget.
    _main_layout: QGridLayout
    _button_box: QDialogButtonBox
    _options_group_box: QGroupBox
    _view: QTableView
    _pool: QThreadPool
    _delete_btn: QDialogButtonBox
    _txt_var: dict[str, QLineEdit] = {}
    _lists: dict[str, Union[QListWidget, QComboBox]] = {}

    def __init__(self, config: Config) -> None:
        super().__init__()

        self._pool = QThreadPool.globalInstance()

        self._view = QTableView()
        self._view.horizontalHeader().setCascadingSectionResizes(True)
        self._view.horizontalHeader().setStretchLastSection(True)
        self._view.setAlternatingRowColors(True)
        self._view.setSelectionBehavior(QTableView.SelectRows)

        self.config = config

        self._init_options_group_box()
        self._init_button_box()

        main_layout = QGridLayout()
        main_layout.addWidget(self._options_group_box, 0, 0)
        main_layout.addWidget(self._button_box, 1, 0)
        main_layout.addWidget(self._view, 2, 0)
        main_layout.setSizeConstraint(QLayout.SetMinimumSize)

        self._main_layout = main_layout
        self.setLayout(self._main_layout)
        self._type_changed()

        self.setWindowTitle('Train Model')

    def show(self) -> None:
        """Override of QWidget's show() function.

        Refreshes window and then shows the window.
        """
        super().show()
        self._refresh_lists()
        self._refresh_pandas()

    def _init_button_box(self) -> None:
        """Creates the lower control buttons at the bottom of the window."""
        self._button_box = QDialogButtonBox()

        ingest_btn = self._button_box.addButton('Get Data',
                                                QDialogButtonBox.ActionRole)
        self._delete_btn = self._button_box.addButton(
            'Delete Dataset', QDialogButtonBox.ActionRole)
        refresh_btn = self._button_box.addButton('Refresh &Options',
                                                 QDialogButtonBox.ActionRole)

        ingest_btn.clicked.connect(self._ingest)
        self._delete_btn.clicked.connect(self._delete)
        refresh_btn.clicked.connect(self._refresh_lists)

    def _init_options_group_box(self) -> None:
        """Creates the group of training options."""
        self._options_group_box = QGroupBox("Options")

        options_layout = QGridLayout()
        left_options = QGridLayout()
        right_options = QGridLayout()

        self._lists['data'] = QListWidget()
        self._lists['data'].setSelectionMode(
            QtWidgets.QAbstractItemView.SingleSelection)
        self._lists['data'].currentTextChanged.connect(self._refresh_pandas)

        self._lists['type'] = QComboBox()
        for dt in IngestTypes:
            self._lists['type'].addItem(dt.value)

        self._refresh_lists()

        self._lists['type'].currentTextChanged.connect(self._type_changed)

        validator = QRegularExpressionValidator(r'^[\w\-. ]+$')
        cat_validator = QRegularExpressionValidator(r'^[0-9]\d*$')

        dataset_label = QLabel("Avaliable Datasets:")
        search_type_label = QLabel("Symbol/Search Type:")
        search_label = QLabel("Symbol/Search Term:")
        name_label = QLabel("Dataset Name:")
        cat_label = QLabel("Trends Category Code:")

        left_options.addWidget(dataset_label, 0, 0)
        left_options.addWidget(self._lists['data'], 1, 0)

        right_options.addWidget(search_type_label, 0, 0)
        right_options.addWidget(self._lists['type'], 1, 0)

        self._txt_var['ds_name'] = QLineEdit()
        self._txt_var['data_search'] = QLineEdit()
        self._txt_var['search_cat'] = QLineEdit()
        self._txt_var['ds_name'].setValidator(validator)
        self._txt_var['data_search'].setValidator(validator)
        self._txt_var['search_cat'].setValidator(cat_validator)

        self._txt_var['search_cat'].setPlaceholderText('0')

        right_options.addWidget(search_label, 2, 0)
        right_options.addWidget(self._txt_var['data_search'], 3, 0)

        right_options.addWidget(name_label, 4, 0)
        right_options.addWidget(self._txt_var['ds_name'], 5, 0)

        right_options.addWidget(cat_label, 6, 0)
        right_options.addWidget(self._txt_var['search_cat'], 7, 0)

        options_layout.addLayout(left_options, 0, 0)
        options_layout.addLayout(right_options, 0, 1)

        options_layout.setColumnStretch(0, 1)

        self._options_group_box.setLayout(options_layout)

    def _refresh_lists(self) -> None:
        """Refreshes avaliable datasets for training."""
        self._lists['data'].clear()

        data_list = data_ingest.get_avaliable_data(search_type='data')

        self._lists['data'].addItems(data_list)

    def _refresh_pandas(self) -> None:
        """Refreshes the pandas table viewer."""
        df = self._lists['data'].currentItem()
        if df is not None:
            df = df.text()
            if df in data_ingest.get_avaliable_data(search_type='data'):
                df = data_ingest.load_data(df)
                model = PandasModel(df)
                self._view.setModel(model)
                self._delete_btn.setEnabled(True)
                return

        self._delete_btn.setEnabled(False)

    def _type_changed(self) -> None:
        """Updates widget based on type combo box change."""
        if self._lists['type'].currentText() == 'Google Trends':
            self._txt_var['ds_name'].setEnabled(False)
            self._txt_var['search_cat'].setEnabled(True)
        else:
            self._txt_var['ds_name'].setEnabled(True)
            self._txt_var['search_cat'].setEnabled(False)

    def _ingest(self) -> None:
        """Ingests the user requested data and saves it accordingly."""
        self.setEnabled(False)
        search_type = self._lists['type'].currentText()
        search_type = IngestTypes.from_str(search_type)

        search_term = self._txt_var['data_search'].text().strip()
        self._txt_var['data_search'].setText(search_term)

        if search_type in {
                IngestTypes.CryptoCurrenciesDaily,
                IngestTypes.TimeSeriesDailyAdjusted
        }:
            try:
                if search_type == IngestTypes.CryptoCurrenciesDaily:
                    data = data_ingest.async_get([
                        data_ingest.get_cc_daily(search_term,
                                                 self.config,
                                                 cache=False)
                    ])[0]
                elif search_type == IngestTypes.TimeSeriesDailyAdjusted:
                    data = data_ingest.async_get([
                        data_ingest.get_ts_daily_adjusted(search_term,
                                                          self.config,
                                                          cache=False)
                    ])[0]
                else:
                    data = None  # Satisfy PyTa even though raise occurs
                    raise NotImplementedError
            except ce.RateLimited:
                self._error_event(
                    'You are being rate limited. Check Alpha Vantage API key or wait.'
                )
                return
            except ce.UnknownAVType:
                self._error_event(
                    f'{search_term} is an invalid symbol for {search_type}')
                return
        elif search_type == IngestTypes.GoogleTrends:
            trends_thread = TrendsThread(search_term,
                                         self._txt_var['search_cat'].text())

            self._pool.start(trends_thread)

            trends_thread.signals.error.connect(self._error_event)

            trends_thread.signals.dataframe_result.connect(self._ingest_save)
            return
        else:
            self._error_event('Invalid search type.')
            return

        self._ingest_save(data)

    def _ingest_save(self, data: pd.DataFrame) -> None:
        """Generates a name and saves the given dataframe.
        Returns None when complete or on error."""
        search_type = self._lists['type'].currentText()
        search_term = self._txt_var['data_search'].text()

        search_type = IngestTypes.from_str(search_type)
        if search_type == IngestTypes.GoogleTrends:
            cat = self._txt_var['search_cat'].text()

            if cat == '':
                cat = '0'
            name = f'{search_term} {cat};{data_ingest.IngestTypes.GoogleTrends.name}'
        else:
            name = self._txt_var['ds_name'].text()
            if name == '':
                name = data_ingest.name_generator(search_term, search_type)
            else:
                name = data_ingest.name_generator(search_term, search_type,
                                                  name)

        current_datasets = data_ingest.get_avaliable_data(search_type='data')

        if name in current_datasets:
            response = self._error_event(f'{name} will be overwritten.',
                                         choice=True)
            if response == QMessageBox.Abort:
                self.setEnabled(True)
                return

        data_ingest.save_data(name, data)

        self._refresh_lists()
        self.setEnabled(True)

    def _delete(self) -> None:
        """Deletes the currently selected dataset."""
        self.setEnabled(False)
        name = self._lists['data'].selectedItems()

        if len(name) != 0:
            name = name[0].text()

            warning = f'Are you sure you want to delete {name}?'

            response = QMessageBox.warning(self, self.tr("Delete Dataset"),
                                           warning, QMessageBox.Yes,
                                           QMessageBox.No)
            if response == QMessageBox.Yes:
                data_ingest.delete_data(name, file_type='data')
                self._refresh_lists()

        self.setEnabled(True)

    def _error_event(
        self,
        error: str,
        choice: bool = False,
        btn: QMessageBox = QMessageBox.Abort
    ) -> Union[QMessageBox.Ignore, QMessageBox.Abort, None]:
        """Displays an error message with the given error."""
        if choice:
            response = QMessageBox.critical(self, self.tr("Error"), error, btn,
                                            QMessageBox.Ignore)
            return response
        else:
            QMessageBox.critical(self, self.tr("Error"), error, QMessageBox.Ok)
            self.setEnabled(True)
            return None
コード例 #3
0
ファイル: ui_reference_data_dlg.py プロジェクト: flmnvd/jal
class Ui_ReferenceDataDialog(object):
    def setupUi(self, ReferenceDataDialog):
        if not ReferenceDataDialog.objectName():
            ReferenceDataDialog.setObjectName(u"ReferenceDataDialog")
        ReferenceDataDialog.resize(869, 300)
        self.verticalLayout = QVBoxLayout(ReferenceDataDialog)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.verticalLayout.setContentsMargins(2, 2, 2, 2)
        self.EditFrame = QFrame(ReferenceDataDialog)
        self.EditFrame.setObjectName(u"EditFrame")
        sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.EditFrame.sizePolicy().hasHeightForWidth())
        self.EditFrame.setSizePolicy(sizePolicy)
        self.EditFrame.setFrameShape(QFrame.Panel)
        self.EditFrame.setFrameShadow(QFrame.Plain)
        self.EditFrame.setLineWidth(0)
        self.edit_layout = QHBoxLayout(self.EditFrame)
        self.edit_layout.setObjectName(u"edit_layout")
        self.edit_layout.setContentsMargins(0, 0, 0, 0)
        self.GroupLbl = QLabel(self.EditFrame)
        self.GroupLbl.setObjectName(u"GroupLbl")

        self.edit_layout.addWidget(self.GroupLbl)

        self.GroupCombo = QComboBox(self.EditFrame)
        self.GroupCombo.setObjectName(u"GroupCombo")

        self.edit_layout.addWidget(self.GroupCombo)

        self.Toggle = QCheckBox(self.EditFrame)
        self.Toggle.setObjectName(u"Toggle")
        self.Toggle.setChecked(False)

        self.edit_layout.addWidget(self.Toggle)

        self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                            QSizePolicy.Minimum)

        self.edit_layout.addItem(self.horizontalSpacer)

        self.AddBtn = QPushButton(self.EditFrame)
        self.AddBtn.setObjectName(u"AddBtn")

        self.edit_layout.addWidget(self.AddBtn)

        self.AddChildBtn = QPushButton(self.EditFrame)
        self.AddChildBtn.setObjectName(u"AddChildBtn")

        self.edit_layout.addWidget(self.AddChildBtn)

        self.RemoveBtn = QPushButton(self.EditFrame)
        self.RemoveBtn.setObjectName(u"RemoveBtn")

        self.edit_layout.addWidget(self.RemoveBtn)

        self.CommitBtn = QPushButton(self.EditFrame)
        self.CommitBtn.setObjectName(u"CommitBtn")
        self.CommitBtn.setEnabled(False)

        self.edit_layout.addWidget(self.CommitBtn)

        self.RevertBtn = QPushButton(self.EditFrame)
        self.RevertBtn.setObjectName(u"RevertBtn")
        self.RevertBtn.setEnabled(False)

        self.edit_layout.addWidget(self.RevertBtn)

        self.verticalLayout.addWidget(self.EditFrame)

        self.SearchFrame = QFrame(ReferenceDataDialog)
        self.SearchFrame.setObjectName(u"SearchFrame")
        self.SearchFrame.setFrameShape(QFrame.Panel)
        self.SearchFrame.setFrameShadow(QFrame.Plain)
        self.SearchFrame.setLineWidth(0)
        self.search_layout = QHBoxLayout(self.SearchFrame)
        self.search_layout.setObjectName(u"search_layout")
        self.search_layout.setContentsMargins(0, 0, 0, 0)
        self.SearchLbl = QLabel(self.SearchFrame)
        self.SearchLbl.setObjectName(u"SearchLbl")

        self.search_layout.addWidget(self.SearchLbl)

        self.SearchString = QLineEdit(self.SearchFrame)
        self.SearchString.setObjectName(u"SearchString")

        self.search_layout.addWidget(self.SearchString)

        self.verticalLayout.addWidget(self.SearchFrame)

        self.DataView = QTableView(ReferenceDataDialog)
        self.DataView.setObjectName(u"DataView")
        self.DataView.setEditTriggers(QAbstractItemView.AnyKeyPressed
                                      | QAbstractItemView.EditKeyPressed
                                      | QAbstractItemView.SelectedClicked)
        self.DataView.setAlternatingRowColors(True)
        self.DataView.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.DataView.verticalHeader().setVisible(True)
        self.DataView.verticalHeader().setMinimumSectionSize(20)
        self.DataView.verticalHeader().setDefaultSectionSize(20)

        self.verticalLayout.addWidget(self.DataView)

        self.TreeView = QTreeView(ReferenceDataDialog)
        self.TreeView.setObjectName(u"TreeView")
        self.TreeView.setEditTriggers(QAbstractItemView.AnyKeyPressed
                                      | QAbstractItemView.EditKeyPressed
                                      | QAbstractItemView.SelectedClicked)
        self.TreeView.setTabKeyNavigation(True)
        self.TreeView.setAlternatingRowColors(True)
        self.TreeView.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.TreeView.setExpandsOnDoubleClick(False)
        self.TreeView.header().setStretchLastSection(False)

        self.verticalLayout.addWidget(self.TreeView)

        self.retranslateUi(ReferenceDataDialog)

        QMetaObject.connectSlotsByName(ReferenceDataDialog)

    # setupUi

    def retranslateUi(self, ReferenceDataDialog):
        ReferenceDataDialog.setWindowTitle(
            QCoreApplication.translate("ReferenceDataDialog",
                                       u"Reference Data", None))
        self.GroupLbl.setText(
            QCoreApplication.translate("ReferenceDataDialog", u"Account Type:",
                                       None))
        self.Toggle.setText(
            QCoreApplication.translate("ReferenceDataDialog", u"Show inactive",
                                       None))
        #if QT_CONFIG(tooltip)
        self.AddBtn.setToolTip(
            QCoreApplication.translate("ReferenceDataDialog", u"Add new",
                                       None))
        #endif // QT_CONFIG(tooltip)
        self.AddBtn.setText("")
        #if QT_CONFIG(tooltip)
        self.AddChildBtn.setToolTip(
            QCoreApplication.translate("ReferenceDataDialog", u"Add child",
                                       None))
        #endif // QT_CONFIG(tooltip)
        self.AddChildBtn.setText("")
        #if QT_CONFIG(tooltip)
        self.RemoveBtn.setToolTip(
            QCoreApplication.translate("ReferenceDataDialog", u"Delete", None))
        #endif // QT_CONFIG(tooltip)
        self.RemoveBtn.setText("")
        #if QT_CONFIG(tooltip)
        self.CommitBtn.setToolTip(
            QCoreApplication.translate("ReferenceDataDialog", u"Save changes",
                                       None))
        #endif // QT_CONFIG(tooltip)
        self.CommitBtn.setText("")
        #if QT_CONFIG(tooltip)
        self.RevertBtn.setToolTip(
            QCoreApplication.translate("ReferenceDataDialog",
                                       u"Revert changes", None))
        #endif // QT_CONFIG(tooltip)
        self.RevertBtn.setText("")
        self.SearchLbl.setText(
            QCoreApplication.translate("ReferenceDataDialog", u"Search:",
                                       None))
コード例 #4
0
class Ui_DealsReportWidget(object):
    def setupUi(self, DealsReportWidget):
        if not DealsReportWidget.objectName():
            DealsReportWidget.setObjectName(u"DealsReportWidget")
        DealsReportWidget.resize(821, 280)
        self.verticalLayout = QVBoxLayout(DealsReportWidget)
        self.verticalLayout.setSpacing(0)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.ReportParamsFrame = QFrame(DealsReportWidget)
        self.ReportParamsFrame.setObjectName(u"ReportParamsFrame")
        self.ReportParamsFrame.setFrameShape(QFrame.Panel)
        self.ReportParamsFrame.setFrameShadow(QFrame.Sunken)
        self.horizontalLayout = QHBoxLayout(self.ReportParamsFrame)
        self.horizontalLayout.setSpacing(6)
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.horizontalLayout.setContentsMargins(2, 2, 2, 2)
        self.ReportRange = DateRangeSelector(self.ReportParamsFrame)
        self.ReportRange.setObjectName(u"ReportRange")
        self.ReportRange.setProperty("ItemsList",
                                     u"QTD;YTD;this_year;last_year")

        self.horizontalLayout.addWidget(self.ReportRange)

        self.ReportGroupCheck = QCheckBox(self.ReportParamsFrame)
        self.ReportGroupCheck.setObjectName(u"ReportGroupCheck")

        self.horizontalLayout.addWidget(self.ReportGroupCheck)

        self.ReportAccountLbl = QLabel(self.ReportParamsFrame)
        self.ReportAccountLbl.setObjectName(u"ReportAccountLbl")

        self.horizontalLayout.addWidget(self.ReportAccountLbl)

        self.ReportAccountBtn = AccountButton(self.ReportParamsFrame)
        self.ReportAccountBtn.setObjectName(u"ReportAccountBtn")

        self.horizontalLayout.addWidget(self.ReportAccountBtn)

        self.ReportFrameSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                             QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.ReportFrameSpacer)

        self.verticalLayout.addWidget(self.ReportParamsFrame)

        self.ReportTableView = QTableView(DealsReportWidget)
        self.ReportTableView.setObjectName(u"ReportTableView")
        self.ReportTableView.setFrameShape(QFrame.Panel)
        self.ReportTableView.setFrameShadow(QFrame.Sunken)
        self.ReportTableView.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.ReportTableView.setAlternatingRowColors(True)
        self.ReportTableView.setGridStyle(Qt.DotLine)
        self.ReportTableView.setWordWrap(False)
        self.ReportTableView.verticalHeader().setVisible(False)
        self.ReportTableView.verticalHeader().setMinimumSectionSize(20)
        self.ReportTableView.verticalHeader().setDefaultSectionSize(20)

        self.verticalLayout.addWidget(self.ReportTableView)

        self.retranslateUi(DealsReportWidget)

        QMetaObject.connectSlotsByName(DealsReportWidget)

    # setupUi

    def retranslateUi(self, DealsReportWidget):
        DealsReportWidget.setWindowTitle(
            QCoreApplication.translate("DealsReportWidget", u"Deals", None))
        self.ReportGroupCheck.setText(
            QCoreApplication.translate("DealsReportWidget", u"Group dates",
                                       None))
        self.ReportAccountLbl.setText(
            QCoreApplication.translate("DealsReportWidget", u"Account:", None))
コード例 #5
0
class Ui_tfm(object):
    def setupUi(self, tfm):
        if not tfm.objectName():
            tfm.setObjectName(u"tfm")
        tfm.resize(800, 600)
        tfm.setContextMenuPolicy(Qt.NoContextMenu)
        tfm.setLocale(QLocale(QLocale.English, QLocale.UnitedStates))
        self.action_menu = QAction(tfm)
        self.action_menu.setObjectName(u"action_menu")
        self.action_new_dir = QAction(tfm)
        self.action_new_dir.setObjectName(u"action_new_dir")
        self.action_new_file = QAction(tfm)
        self.action_new_file.setObjectName(u"action_new_file")
        self.action_back = QAction(tfm)
        self.action_back.setObjectName(u"action_back")
        self.action_up = QAction(tfm)
        self.action_up.setObjectName(u"action_up")
        self.action_home = QAction(tfm)
        self.action_home.setObjectName(u"action_home")
        self.action_go = QAction(tfm)
        self.action_go.setObjectName(u"action_go")
        self.action_forward = QAction(tfm)
        self.action_forward.setObjectName(u"action_forward")
        self.action_copy = QAction(tfm)
        self.action_copy.setObjectName(u"action_copy")
        self.action_paste = QAction(tfm)
        self.action_paste.setObjectName(u"action_paste")
        self.action_cut = QAction(tfm)
        self.action_cut.setObjectName(u"action_cut")
        self.action_show_hidden = QAction(tfm)
        self.action_show_hidden.setObjectName(u"action_show_hidden")
        self.action_show_hidden.setCheckable(True)
        self.action_delete = QAction(tfm)
        self.action_delete.setObjectName(u"action_delete")
        self.action_rename = QAction(tfm)
        self.action_rename.setObjectName(u"action_rename")
        self.action_add_to_bookmarks = QAction(tfm)
        self.action_add_to_bookmarks.setObjectName(u"action_add_to_bookmarks")
        self.action_remove_bookmark = QAction(tfm)
        self.action_remove_bookmark.setObjectName(u"action_remove_bookmark")
        self.action_copy_path = QAction(tfm)
        self.action_copy_path.setObjectName(u"action_copy_path")
        self.action_extract_here = QAction(tfm)
        self.action_extract_here.setObjectName(u"action_extract_here")
        self.action_mount_iso = QAction(tfm)
        self.action_mount_iso.setObjectName(u"action_mount_iso")
        self.centralwidget = QWidget(tfm)
        self.centralwidget.setObjectName(u"centralwidget")
        self.horizontalLayout = QHBoxLayout(self.centralwidget)
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.vsplit = QSplitter(self.centralwidget)
        self.vsplit.setObjectName(u"vsplit")
        self.vsplit.setOrientation(Qt.Horizontal)
        self.hsplit = QSplitter(self.vsplit)
        self.hsplit.setObjectName(u"hsplit")
        self.hsplit.setOrientation(Qt.Vertical)
        self.fs_tree = QTreeView(self.hsplit)
        self.fs_tree.setObjectName(u"fs_tree")
        sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(1)
        sizePolicy.setHeightForWidth(
            self.fs_tree.sizePolicy().hasHeightForWidth())
        self.fs_tree.setSizePolicy(sizePolicy)
        self.fs_tree.setTabKeyNavigation(True)
        self.fs_tree.setProperty("showDropIndicator", True)
        self.fs_tree.setDragEnabled(False)
        self.fs_tree.setDragDropMode(QAbstractItemView.DropOnly)
        self.fs_tree.setDefaultDropAction(Qt.MoveAction)
        self.fs_tree.setRootIsDecorated(False)
        self.hsplit.addWidget(self.fs_tree)
        self.fs_tree.header().setVisible(False)
        self.bookmark_view = QListView(self.hsplit)
        self.bookmark_view.setObjectName(u"bookmark_view")
        self.bookmark_view.setContextMenuPolicy(Qt.ActionsContextMenu)
        self.bookmark_view.setEditTriggers(QAbstractItemView.DoubleClicked
                                           | QAbstractItemView.EditKeyPressed
                                           | QAbstractItemView.SelectedClicked)
        self.bookmark_view.setTabKeyNavigation(True)
        self.bookmark_view.setDragDropOverwriteMode(True)
        self.bookmark_view.setDragDropMode(QAbstractItemView.DropOnly)
        self.bookmark_view.setDefaultDropAction(Qt.CopyAction)
        self.bookmark_view.setAlternatingRowColors(True)
        self.hsplit.addWidget(self.bookmark_view)
        self.mounts_view = QListView(self.hsplit)
        self.mounts_view.setObjectName(u"mounts_view")
        self.mounts_view.setTabKeyNavigation(True)
        self.mounts_view.setAlternatingRowColors(True)
        self.hsplit.addWidget(self.mounts_view)
        self.vsplit.addWidget(self.hsplit)
        self.table_view = QTableView(self.vsplit)
        self.table_view.setObjectName(u"table_view")
        sizePolicy1 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        sizePolicy1.setHorizontalStretch(1)
        sizePolicy1.setVerticalStretch(0)
        sizePolicy1.setHeightForWidth(
            self.table_view.sizePolicy().hasHeightForWidth())
        self.table_view.setSizePolicy(sizePolicy1)
        self.table_view.viewport().setProperty("cursor",
                                               QCursor(Qt.ArrowCursor))
        self.table_view.setContextMenuPolicy(Qt.ActionsContextMenu)
        self.table_view.setAcceptDrops(True)
        self.table_view.setToolTipDuration(-3)
        self.table_view.setEditTriggers(QAbstractItemView.AnyKeyPressed
                                        | QAbstractItemView.EditKeyPressed
                                        | QAbstractItemView.SelectedClicked)
        self.table_view.setDragEnabled(True)
        self.table_view.setDragDropMode(QAbstractItemView.DragDrop)
        self.table_view.setDefaultDropAction(Qt.MoveAction)
        self.table_view.setAlternatingRowColors(True)
        self.table_view.setSelectionMode(QAbstractItemView.ExtendedSelection)
        self.table_view.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.table_view.setTextElideMode(Qt.ElideMiddle)
        self.table_view.setShowGrid(False)
        self.table_view.setSortingEnabled(True)
        self.table_view.setWordWrap(False)
        self.vsplit.addWidget(self.table_view)
        self.table_view.horizontalHeader().setDefaultSectionSize(150)
        self.table_view.horizontalHeader().setHighlightSections(False)
        self.table_view.horizontalHeader().setStretchLastSection(True)
        self.table_view.verticalHeader().setVisible(False)

        self.horizontalLayout.addWidget(self.vsplit)

        tfm.setCentralWidget(self.centralwidget)
        self.statusbar = QStatusBar(tfm)
        self.statusbar.setObjectName(u"statusbar")
        self.statusbar.setContextMenuPolicy(Qt.NoContextMenu)
        self.statusbar.setSizeGripEnabled(False)
        tfm.setStatusBar(self.statusbar)
        self.toolbar = QToolBar(tfm)
        self.toolbar.setObjectName(u"toolbar")
        self.toolbar.setContextMenuPolicy(Qt.PreventContextMenu)
        self.toolbar.setMovable(False)
        tfm.addToolBar(Qt.TopToolBarArea, self.toolbar)

        self.toolbar.addAction(self.action_back)
        self.toolbar.addAction(self.action_forward)
        self.toolbar.addAction(self.action_up)
        self.toolbar.addAction(self.action_home)
        self.toolbar.addAction(self.action_go)

        self.retranslateUi(tfm)

        QMetaObject.connectSlotsByName(tfm)

    # setupUi

    def retranslateUi(self, tfm):
        tfm.setWindowTitle(QCoreApplication.translate("tfm", u"tfm", None))
        self.action_menu.setText(
            QCoreApplication.translate("tfm", u"Menu", None))
        self.action_new_dir.setText(
            QCoreApplication.translate("tfm", u"New Directory", None))
        self.action_new_file.setText(
            QCoreApplication.translate("tfm", u"New File", None))
        self.action_back.setText(
            QCoreApplication.translate("tfm", u"Back", None))
        self.action_up.setText(QCoreApplication.translate("tfm", u"Up", None))
        self.action_home.setText(
            QCoreApplication.translate("tfm", u"Home", None))
        self.action_go.setText(QCoreApplication.translate("tfm", u"Go", None))
        #if QT_CONFIG(tooltip)
        self.action_go.setToolTip(
            QCoreApplication.translate("tfm", u"Go or Reload", None))
        #endif // QT_CONFIG(tooltip)
        self.action_forward.setText(
            QCoreApplication.translate("tfm", u"Forward", None))
        self.action_copy.setText(
            QCoreApplication.translate("tfm", u"Copy", None))
        self.action_paste.setText(
            QCoreApplication.translate("tfm", u"Paste", None))
        self.action_cut.setText(QCoreApplication.translate(
            "tfm", u"Cut", None))
        self.action_show_hidden.setText(
            QCoreApplication.translate("tfm", u"Show hidden files", None))
        #if QT_CONFIG(shortcut)
        self.action_show_hidden.setShortcut(
            QCoreApplication.translate("tfm", u"Ctrl+H", None))
        #endif // QT_CONFIG(shortcut)
        self.action_delete.setText(
            QCoreApplication.translate("tfm", u"Delete", None))
        self.action_rename.setText(
            QCoreApplication.translate("tfm", u"Rename", None))
        self.action_add_to_bookmarks.setText(
            QCoreApplication.translate("tfm", u"Add to bookmarks", None))
        self.action_remove_bookmark.setText(
            QCoreApplication.translate("tfm", u"Remove bookmark", None))
        #if QT_CONFIG(tooltip)
        self.action_remove_bookmark.setToolTip(
            QCoreApplication.translate("tfm", u"Remove bookmark", None))
        #endif // QT_CONFIG(tooltip)
        self.action_copy_path.setText(
            QCoreApplication.translate("tfm", u"Copy path", None))
        self.action_extract_here.setText(
            QCoreApplication.translate("tfm", u"Extract here", None))
        #if QT_CONFIG(tooltip)
        self.action_extract_here.setToolTip(
            QCoreApplication.translate("tfm", u"Extract here", None))
        #endif // QT_CONFIG(tooltip)
        self.action_mount_iso.setText(
            QCoreApplication.translate("tfm", u"Mount ISO", None))
        #if QT_CONFIG(tooltip)
        self.action_mount_iso.setToolTip(
            QCoreApplication.translate("tfm", u"Mount ISO", None))
コード例 #6
0
class IncomeSpendingWidget(AbstractOperationDetails):
    def __init__(self, parent=None):
        AbstractOperationDetails.__init__(self, parent)
        self.name = "Income/Spending"

        self.details_model = None
        self.category_delegate = CategorySelectorDelegate()
        self.tag_delegate = TagSelectorDelegate()
        self.float_delegate = FloatDelegate(2)

        self.date_label = QLabel(self)
        self.details_label = QLabel(self)
        self.account_label = QLabel(self)
        self.peer_label = QLabel(self)

        self.main_label.setText(self.tr("Income / Spending"))
        self.date_label.setText(self.tr("Date/Time"))
        self.details_label.setText(self.tr("Details"))
        self.account_label.setText(self.tr("Account"))
        self.peer_label.setText(self.tr("Peer"))

        self.timestamp_editor = QDateTimeEdit(self)
        self.timestamp_editor.setCalendarPopup(True)
        self.timestamp_editor.setTimeSpec(Qt.UTC)
        self.timestamp_editor.setFixedWidth(
            self.timestamp_editor.fontMetrics().horizontalAdvance(
                "00/00/0000 00:00:00") * 1.25)
        self.timestamp_editor.setDisplayFormat("dd/MM/yyyy hh:mm:ss")
        self.account_widget = AccountSelector(self)
        self.peer_widget = PeerSelector(self)
        self.a_currency = OptionalCurrencyComboBox(self)
        self.a_currency.setText(self.tr("Paid in foreign currency:"))
        self.add_button = QPushButton(load_icon("add.png"), '', self)
        self.add_button.setToolTip(self.tr("Add detail"))
        self.del_button = QPushButton(load_icon("remove.png"), '', self)
        self.del_button.setToolTip(self.tr("Remove detail"))
        self.copy_button = QPushButton(load_icon("copy.png"), '', self)
        self.copy_button.setToolTip(self.tr("Copy detail"))
        self.details_table = QTableView(self)
        self.details_table.horizontalHeader().setFont(self.bold_font)
        self.details_table.setAlternatingRowColors(True)
        self.details_table.verticalHeader().setVisible(False)
        self.details_table.verticalHeader().setMinimumSectionSize(20)
        self.details_table.verticalHeader().setDefaultSectionSize(20)

        self.layout.addWidget(self.date_label, 1, 0, 1, 1, Qt.AlignLeft)
        self.layout.addWidget(self.details_label, 2, 0, 1, 1, Qt.AlignLeft)

        self.layout.addWidget(self.timestamp_editor, 1, 1, 1, 4)
        self.layout.addWidget(self.add_button, 2, 1, 1, 1)
        self.layout.addWidget(self.copy_button, 2, 2, 1, 1)
        self.layout.addWidget(self.del_button, 2, 3, 1, 1)

        self.layout.addWidget(self.account_label, 1, 5, 1, 1, Qt.AlignRight)
        self.layout.addWidget(self.peer_label, 2, 5, 1, 1, Qt.AlignRight)

        self.layout.addWidget(self.account_widget, 1, 6, 1, 1)
        self.layout.addWidget(self.peer_widget, 2, 6, 1, 1)

        self.layout.addWidget(self.a_currency, 1, 7, 1, 1)

        self.layout.addWidget(self.commit_button, 0, 9, 1, 1)
        self.layout.addWidget(self.revert_button, 0, 10, 1, 1)

        self.layout.addWidget(self.details_table, 4, 0, 1, 11)
        self.layout.addItem(self.horizontalSpacer, 1, 8, 1, 1)

        self.add_button.clicked.connect(self.addChild)
        self.copy_button.clicked.connect(self.copyChild)
        self.del_button.clicked.connect(self.delChild)

        super()._init_db("actions")
        self.model.beforeInsert.connect(self.before_record_insert)
        self.model.beforeUpdate.connect(self.before_record_update)
        self.mapper.setItemDelegate(IncomeSpendingWidgetDelegate(self.mapper))

        self.details_model = DetailsModel(self.details_table, db_connection())
        self.details_model.setTable("action_details")
        self.details_model.setEditStrategy(QSqlTableModel.OnManualSubmit)
        self.details_table.setModel(self.details_model)
        self.details_model.dataChanged.connect(self.onDataChange)

        self.account_widget.changed.connect(self.mapper.submit)
        self.peer_widget.changed.connect(self.mapper.submit)
        self.a_currency.changed.connect(self.mapper.submit)
        self.a_currency.name_updated.connect(self.details_model.setAltCurrency)

        self.mapper.addMapping(self.timestamp_editor,
                               self.model.fieldIndex("timestamp"))
        self.mapper.addMapping(self.account_widget,
                               self.model.fieldIndex("account_id"))
        self.mapper.addMapping(self.peer_widget,
                               self.model.fieldIndex("peer_id"))
        self.mapper.addMapping(self.a_currency,
                               self.model.fieldIndex("alt_currency_id"))

        self.details_table.setItemDelegateForColumn(2, self.category_delegate)
        self.details_table.setItemDelegateForColumn(3, self.tag_delegate)
        self.details_table.setItemDelegateForColumn(4, self.float_delegate)
        self.details_table.setItemDelegateForColumn(5, self.float_delegate)

        self.model.select()
        self.details_model.select()
        self.details_model.configureView()

    def setId(self, id):
        super().setId(id)
        self.details_model.setFilter(f"action_details.pid = {id}")

    @Slot()
    def addChild(self):
        new_record = self.details_model.record()
        new_record.setNull("tag_id")
        new_record.setValue("amount", 0)
        new_record.setValue("amount_alt", 0)
        if not self.details_model.insertRecord(-1, new_record):
            logging.fatal(
                self.tr("Failed to add new record: ") +
                self.details_model.lastError().text())
            return

    @Slot()
    def copyChild(self):
        idx = self.details_table.selectionModel().selection().indexes()
        src_record = self.details_model.record(idx[0].row())
        new_record = self.details_model.record()
        new_record.setValue("category_id", src_record.value("category_id"))
        if src_record.value("tag_id"):
            new_record.setValue("tag_id", src_record.value("tag_id"))
        else:
            new_record.setNull("tag_id")
        new_record.setValue("amount", src_record.value("amount"))
        new_record.setValue("amount_alt", src_record.value("amount_alt"))
        new_record.setValue("note", src_record.value("note"))
        if not self.details_model.insertRecord(-1, new_record):
            logging.fatal(
                self.tr("Failed to add new record: ") +
                self.details_model.lastError().text())
            return

    @Slot()
    def delChild(self):
        selection = self.details_table.selectionModel().selection().indexes()
        for idx in selection:
            self.details_model.removeRow(idx.row())
            self.onDataChange(idx, idx, None)

    @Slot()
    def saveChanges(self):
        if not self.model.submitAll():
            logging.fatal(
                self.tr("Operation submit failed: ") +
                self.model.lastError().text())
            return
        pid = self.model.data(self.model.index(0, self.model.fieldIndex("id")))
        if pid is None:  # we just have saved new action record and need last inserted id
            pid = self.model.query().lastInsertId()
        for row in range(self.details_model.rowCount()):
            self.details_model.setData(
                self.details_model.index(row,
                                         self.details_model.fieldIndex("pid")),
                pid)
        if not self.details_model.submitAll():
            logging.fatal(
                self.tr("Operation details submit failed: ") +
                self.details_model.lastError().text())
            return
        self.modified = False
        self.commit_button.setEnabled(False)
        self.revert_button.setEnabled(False)
        self.dbUpdated.emit()

    @Slot()
    def revertChanges(self):
        self.model.revertAll()
        self.details_model.revertAll()
        self.modified = False
        self.commit_button.setEnabled(False)
        self.revert_button.setEnabled(False)

    def createNew(self, account_id=0):
        super().createNew(account_id)
        self.details_model.setFilter(f"action_details.pid = 0")

    def prepareNew(self, account_id):
        new_record = self.model.record()
        new_record.setNull("id")
        new_record.setValue(
            "timestamp",
            int(datetime.now().replace(tzinfo=tz.tzutc()).timestamp()))
        new_record.setValue("account_id", account_id)
        new_record.setValue("peer_id", 0)
        new_record.setValue("alt_currency_id", None)
        return new_record

    def copyNew(self):
        old_id = self.model.record(self.mapper.currentIndex()).value(0)
        super().copyNew()
        self.details_model.setFilter(f"action_details.pid = 0")
        query = executeSQL(
            "SELECT * FROM action_details WHERE pid = :pid ORDER BY id DESC",
            [(":pid", old_id)])
        while query.next():
            new_record = query.record()
            new_record.setNull("id")
            new_record.setNull("pid")
            assert self.details_model.insertRows(0, 1)
            self.details_model.setRecord(0, new_record)

    def copyToNew(self, row):
        new_record = self.model.record(row)
        new_record.setNull("id")
        new_record.setValue(
            "timestamp",
            int(datetime.now().replace(tzinfo=tz.tzutc()).timestamp()))
        return new_record

    def before_record_insert(self, record):
        if record.value("alt_currency_id") == 0:
            record.setNull("alt_currency_id")

    def before_record_update(self, _row, record):
        self.before_record_insert(
            record)  # processing is the same as before insert
コード例 #7
0
ファイル: ui_asset_dlg.py プロジェクト: flmnvd/jal
class Ui_AssetDialog(object):
    def setupUi(self, AssetDialog):
        if not AssetDialog.objectName():
            AssetDialog.setObjectName(u"AssetDialog")
        AssetDialog.setWindowModality(Qt.ApplicationModal)
        AssetDialog.resize(927, 323)
        AssetDialog.setModal(False)
        self.gridLayout = QGridLayout(AssetDialog)
        self.gridLayout.setSpacing(2)
        self.gridLayout.setObjectName(u"gridLayout")
        self.gridLayout.setContentsMargins(2, 2, 2, 2)
        self.horizontalSpacer_4 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.gridLayout.addItem(self.horizontalSpacer_4, 1, 2, 1, 1)

        self.frame = QFrame(AssetDialog)
        self.frame.setObjectName(u"frame")
        sizePolicy = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(self.frame.sizePolicy().hasHeightForWidth())
        self.frame.setSizePolicy(sizePolicy)
        self.frame.setFrameShape(QFrame.NoFrame)
        self.frame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_3 = QHBoxLayout(self.frame)
        self.horizontalLayout_3.setSpacing(2)
        self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
        self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0)
        self.splitter = QSplitter(self.frame)
        self.splitter.setObjectName(u"splitter")
        sizePolicy1 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
        sizePolicy1.setHorizontalStretch(0)
        sizePolicy1.setVerticalStretch(0)
        sizePolicy1.setHeightForWidth(self.splitter.sizePolicy().hasHeightForWidth())
        self.splitter.setSizePolicy(sizePolicy1)
        self.splitter.setOrientation(Qt.Horizontal)
        self.SymbolsFrame = QFrame(self.splitter)
        self.SymbolsFrame.setObjectName(u"SymbolsFrame")
        sizePolicy2 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        sizePolicy2.setHorizontalStretch(5)
        sizePolicy2.setVerticalStretch(0)
        sizePolicy2.setHeightForWidth(self.SymbolsFrame.sizePolicy().hasHeightForWidth())
        self.SymbolsFrame.setSizePolicy(sizePolicy2)
        self.SymbolsFrame.setFrameShape(QFrame.NoFrame)
        self.SymbolsFrame.setFrameShadow(QFrame.Raised)
        self.verticalLayout = QVBoxLayout(self.SymbolsFrame)
        self.verticalLayout.setSpacing(2)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.SymbolsCaptionFrame = QFrame(self.SymbolsFrame)
        self.SymbolsCaptionFrame.setObjectName(u"SymbolsCaptionFrame")
        self.SymbolsCaptionFrame.setFrameShape(QFrame.NoFrame)
        self.SymbolsCaptionFrame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_5 = QHBoxLayout(self.SymbolsCaptionFrame)
        self.horizontalLayout_5.setSpacing(2)
        self.horizontalLayout_5.setObjectName(u"horizontalLayout_5")
        self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
        self.SymbolsLabel = QLabel(self.SymbolsCaptionFrame)
        self.SymbolsLabel.setObjectName(u"SymbolsLabel")

        self.horizontalLayout_5.addWidget(self.SymbolsLabel)

        self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_5.addItem(self.horizontalSpacer_2)

        self.AddSymbolButton = QPushButton(self.SymbolsCaptionFrame)
        self.AddSymbolButton.setObjectName(u"AddSymbolButton")

        self.horizontalLayout_5.addWidget(self.AddSymbolButton)

        self.RemoveSymbolButton = QPushButton(self.SymbolsCaptionFrame)
        self.RemoveSymbolButton.setObjectName(u"RemoveSymbolButton")

        self.horizontalLayout_5.addWidget(self.RemoveSymbolButton)


        self.verticalLayout.addWidget(self.SymbolsCaptionFrame)

        self.SymbolsTable = QTableView(self.SymbolsFrame)
        self.SymbolsTable.setObjectName(u"SymbolsTable")
        self.SymbolsTable.setEditTriggers(QAbstractItemView.AnyKeyPressed|QAbstractItemView.EditKeyPressed|QAbstractItemView.SelectedClicked)
        self.SymbolsTable.setAlternatingRowColors(True)
        self.SymbolsTable.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.SymbolsTable.verticalHeader().setVisible(False)
        self.SymbolsTable.verticalHeader().setMinimumSectionSize(20)
        self.SymbolsTable.verticalHeader().setDefaultSectionSize(20)

        self.verticalLayout.addWidget(self.SymbolsTable)

        self.splitter.addWidget(self.SymbolsFrame)
        self.DataFrame = QFrame(self.splitter)
        self.DataFrame.setObjectName(u"DataFrame")
        sizePolicy3 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        sizePolicy3.setHorizontalStretch(2)
        sizePolicy3.setVerticalStretch(0)
        sizePolicy3.setHeightForWidth(self.DataFrame.sizePolicy().hasHeightForWidth())
        self.DataFrame.setSizePolicy(sizePolicy3)
        self.DataFrame.setFrameShape(QFrame.NoFrame)
        self.DataFrame.setFrameShadow(QFrame.Raised)
        self.verticalLayout_2 = QVBoxLayout(self.DataFrame)
        self.verticalLayout_2.setSpacing(2)
        self.verticalLayout_2.setObjectName(u"verticalLayout_2")
        self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.DataCaptionFrame = QFrame(self.DataFrame)
        self.DataCaptionFrame.setObjectName(u"DataCaptionFrame")
        self.DataCaptionFrame.setFrameShape(QFrame.NoFrame)
        self.DataCaptionFrame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout_2 = QHBoxLayout(self.DataCaptionFrame)
        self.horizontalLayout_2.setSpacing(2)
        self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
        self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.DataLbl = QLabel(self.DataCaptionFrame)
        self.DataLbl.setObjectName(u"DataLbl")

        self.horizontalLayout_2.addWidget(self.DataLbl)

        self.horizontalSpacer_3 = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout_2.addItem(self.horizontalSpacer_3)

        self.AddDataButton = QPushButton(self.DataCaptionFrame)
        self.AddDataButton.setObjectName(u"AddDataButton")

        self.horizontalLayout_2.addWidget(self.AddDataButton)

        self.RemoveDataButton = QPushButton(self.DataCaptionFrame)
        self.RemoveDataButton.setObjectName(u"RemoveDataButton")

        self.horizontalLayout_2.addWidget(self.RemoveDataButton)


        self.verticalLayout_2.addWidget(self.DataCaptionFrame)

        self.DataTable = QTableView(self.DataFrame)
        self.DataTable.setObjectName(u"DataTable")
        self.DataTable.setEditTriggers(QAbstractItemView.AnyKeyPressed|QAbstractItemView.EditKeyPressed|QAbstractItemView.SelectedClicked)
        self.DataTable.setAlternatingRowColors(True)
        self.DataTable.setSelectionBehavior(QAbstractItemView.SelectRows)
        self.DataTable.verticalHeader().setVisible(False)
        self.DataTable.verticalHeader().setMinimumSectionSize(20)
        self.DataTable.verticalHeader().setDefaultSectionSize(20)

        self.verticalLayout_2.addWidget(self.DataTable)

        self.splitter.addWidget(self.DataFrame)

        self.horizontalLayout_3.addWidget(self.splitter)


        self.gridLayout.addWidget(self.frame, 3, 0, 1, 5)

        self.NameLbl = QLabel(AssetDialog)
        self.NameLbl.setObjectName(u"NameLbl")

        self.gridLayout.addWidget(self.NameLbl, 0, 0, 1, 1)

        self.isinLbl = QLabel(AssetDialog)
        self.isinLbl.setObjectName(u"isinLbl")

        self.gridLayout.addWidget(self.isinLbl, 1, 0, 1, 1)

        self.BaseAssetSelector = AssetSelector(AssetDialog)
        self.BaseAssetSelector.setObjectName(u"BaseAssetSelector")

        self.gridLayout.addWidget(self.BaseAssetSelector, 2, 1, 1, 1)

        self.ButtonsFrame = QFrame(AssetDialog)
        self.ButtonsFrame.setObjectName(u"ButtonsFrame")
        self.ButtonsFrame.setFrameShape(QFrame.NoFrame)
        self.ButtonsFrame.setFrameShadow(QFrame.Raised)
        self.horizontalLayout = QHBoxLayout(self.ButtonsFrame)
        self.horizontalLayout.setSpacing(2)
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
        self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)

        self.horizontalLayout.addItem(self.horizontalSpacer)

        self.CancelButton = QPushButton(self.ButtonsFrame)
        self.CancelButton.setObjectName(u"CancelButton")

        self.horizontalLayout.addWidget(self.CancelButton)

        self.OkButton = QPushButton(self.ButtonsFrame)
        self.OkButton.setObjectName(u"OkButton")

        self.horizontalLayout.addWidget(self.OkButton)


        self.gridLayout.addWidget(self.ButtonsFrame, 10, 0, 1, 5)

        self.BaseLbl = QLabel(AssetDialog)
        self.BaseLbl.setObjectName(u"BaseLbl")

        self.gridLayout.addWidget(self.BaseLbl, 2, 0, 1, 1)

        self.TypeLbl = QLabel(AssetDialog)
        self.TypeLbl.setObjectName(u"TypeLbl")

        self.gridLayout.addWidget(self.TypeLbl, 1, 3, 1, 1)

        self.isinEdit = QLineEdit(AssetDialog)
        self.isinEdit.setObjectName(u"isinEdit")

        self.gridLayout.addWidget(self.isinEdit, 1, 1, 1, 1)

        self.CountryLbl = QLabel(AssetDialog)
        self.CountryLbl.setObjectName(u"CountryLbl")

        self.gridLayout.addWidget(self.CountryLbl, 2, 3, 1, 1)

        self.CountryCombo = CountryCombo(AssetDialog)
        self.CountryCombo.setObjectName(u"CountryCombo")

        self.gridLayout.addWidget(self.CountryCombo, 2, 4, 1, 1)

        self.TypeCombo = AssetTypeCombo(AssetDialog)
        self.TypeCombo.setObjectName(u"TypeCombo")

        self.gridLayout.addWidget(self.TypeCombo, 1, 4, 1, 1)

        self.NameEdit = QLineEdit(AssetDialog)
        self.NameEdit.setObjectName(u"NameEdit")

        self.gridLayout.addWidget(self.NameEdit, 0, 1, 1, 4)


        self.retranslateUi(AssetDialog)
        self.OkButton.clicked.connect(AssetDialog.accept)
        self.CancelButton.clicked.connect(AssetDialog.reject)

        QMetaObject.connectSlotsByName(AssetDialog)
    # setupUi

    def retranslateUi(self, AssetDialog):
        AssetDialog.setWindowTitle(QCoreApplication.translate("AssetDialog", u"Asset", None))
        self.SymbolsLabel.setText(QCoreApplication.translate("AssetDialog", u"Symbols", None))
        self.AddSymbolButton.setText("")
        self.RemoveSymbolButton.setText("")
        self.DataLbl.setText(QCoreApplication.translate("AssetDialog", u"Extra data", None))
        self.AddDataButton.setText("")
        self.RemoveDataButton.setText("")
        self.NameLbl.setText(QCoreApplication.translate("AssetDialog", u"Name:", None))
        self.isinLbl.setText(QCoreApplication.translate("AssetDialog", u"ISIN:", None))
        self.CancelButton.setText(QCoreApplication.translate("AssetDialog", u"Cancel", None))
        self.OkButton.setText(QCoreApplication.translate("AssetDialog", u"OK", None))
        self.BaseLbl.setText(QCoreApplication.translate("AssetDialog", u"Base asset:", None))
        self.TypeLbl.setText(QCoreApplication.translate("AssetDialog", u"Type: ", None))
        self.CountryLbl.setText(QCoreApplication.translate("AssetDialog", u"Country: ", None))
コード例 #8
0
ファイル: ui_operations_widget.py プロジェクト: flmnvd/jal
class Ui_OperationsWidget(object):
    def setupUi(self, OperationsWidget):
        if not OperationsWidget.objectName():
            OperationsWidget.setObjectName(u"OperationsWidget")
        OperationsWidget.resize(1232, 552)
        self.verticalLayout_4 = QVBoxLayout(OperationsWidget)
        self.verticalLayout_4.setSpacing(0)
        self.verticalLayout_4.setObjectName(u"verticalLayout_4")
        self.verticalLayout_4.setContentsMargins(0, 0, 0, 0)
        self.BalanceOperationsSplitter = QSplitter(OperationsWidget)
        self.BalanceOperationsSplitter.setObjectName(
            u"BalanceOperationsSplitter")
        sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(
            self.BalanceOperationsSplitter.sizePolicy().hasHeightForWidth())
        self.BalanceOperationsSplitter.setSizePolicy(sizePolicy)
        self.BalanceOperationsSplitter.setOrientation(Qt.Horizontal)
        self.BalanceBox = QGroupBox(self.BalanceOperationsSplitter)
        self.BalanceBox.setObjectName(u"BalanceBox")
        sizePolicy1 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        sizePolicy1.setHorizontalStretch(1)
        sizePolicy1.setVerticalStretch(0)
        sizePolicy1.setHeightForWidth(
            self.BalanceBox.sizePolicy().hasHeightForWidth())
        self.BalanceBox.setSizePolicy(sizePolicy1)
        self.BalanceBox.setMaximumSize(QSize(16777215, 16777215))
        self.verticalLayout = QVBoxLayout(self.BalanceBox)
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.BalanceConfigFrame = QFrame(self.BalanceBox)
        self.BalanceConfigFrame.setObjectName(u"BalanceConfigFrame")
        self.BalanceConfigFrame.setMinimumSize(QSize(408, 0))
        self.BalanceConfigFrame.setMaximumSize(QSize(16777215, 44))
        self.BalanceConfigFrame.setFrameShape(QFrame.Panel)
        self.BalanceConfigFrame.setFrameShadow(QFrame.Plain)
        self.BalanceConfigFrame.setLineWidth(0)
        self.horizontalLayout_2 = QHBoxLayout(self.BalanceConfigFrame)
        self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
        self.horizontalLayout_2.setContentsMargins(2, 2, 2, 2)
        self.BalanceDate = QDateEdit(self.BalanceConfigFrame)
        self.BalanceDate.setObjectName(u"BalanceDate")
        self.BalanceDate.setDateTime(
            QDateTime(QDate(2020, 11, 25), QTime(21, 0, 0)))
        self.BalanceDate.setCalendarPopup(True)
        self.BalanceDate.setTimeSpec(Qt.UTC)

        self.horizontalLayout_2.addWidget(self.BalanceDate)

        self.CurrencyLbl = QLabel(self.BalanceConfigFrame)
        self.CurrencyLbl.setObjectName(u"CurrencyLbl")
        self.CurrencyLbl.setLayoutDirection(Qt.LeftToRight)
        self.CurrencyLbl.setAlignment(Qt.AlignRight | Qt.AlignTrailing
                                      | Qt.AlignVCenter)

        self.horizontalLayout_2.addWidget(self.CurrencyLbl)

        self.BalancesCurrencyCombo = CurrencyComboBox(self.BalanceConfigFrame)
        self.BalancesCurrencyCombo.setObjectName(u"BalancesCurrencyCombo")

        self.horizontalLayout_2.addWidget(self.BalancesCurrencyCombo)

        self.ShowInactiveCheckBox = QCheckBox(self.BalanceConfigFrame)
        self.ShowInactiveCheckBox.setObjectName(u"ShowInactiveCheckBox")

        self.horizontalLayout_2.addWidget(self.ShowInactiveCheckBox)

        self.horizontalSpacer_2 = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                              QSizePolicy.Minimum)

        self.horizontalLayout_2.addItem(self.horizontalSpacer_2)

        self.verticalLayout.addWidget(self.BalanceConfigFrame)

        self.BalancesTableView = QTableView(self.BalanceBox)
        self.BalancesTableView.setObjectName(u"BalancesTableView")
        self.BalancesTableView.setFrameShape(QFrame.Panel)
        self.BalancesTableView.setEditTriggers(
            QAbstractItemView.EditKeyPressed
            | QAbstractItemView.SelectedClicked)
        self.BalancesTableView.setAlternatingRowColors(True)
        self.BalancesTableView.setSelectionMode(QAbstractItemView.NoSelection)
        self.BalancesTableView.setGridStyle(Qt.DotLine)
        self.BalancesTableView.setWordWrap(False)
        self.BalancesTableView.verticalHeader().setVisible(False)
        self.BalancesTableView.verticalHeader().setMinimumSectionSize(20)
        self.BalancesTableView.verticalHeader().setDefaultSectionSize(20)

        self.verticalLayout.addWidget(self.BalancesTableView)

        self.BalanceOperationsSplitter.addWidget(self.BalanceBox)
        self.OperationsBox = QGroupBox(self.BalanceOperationsSplitter)
        self.OperationsBox.setObjectName(u"OperationsBox")
        sizePolicy2 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        sizePolicy2.setHorizontalStretch(4)
        sizePolicy2.setVerticalStretch(0)
        sizePolicy2.setHeightForWidth(
            self.OperationsBox.sizePolicy().hasHeightForWidth())
        self.OperationsBox.setSizePolicy(sizePolicy2)
        self.OperationsBox.setContextMenuPolicy(Qt.DefaultContextMenu)
        self.verticalLayout_2 = QVBoxLayout(self.OperationsBox)
        self.verticalLayout_2.setObjectName(u"verticalLayout_2")
        self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
        self.OperationConfigFrame = QFrame(self.OperationsBox)
        self.OperationConfigFrame.setObjectName(u"OperationConfigFrame")
        self.OperationConfigFrame.setEnabled(True)
        self.OperationConfigFrame.setMinimumSize(QSize(0, 0))
        self.OperationConfigFrame.setFrameShape(QFrame.Panel)
        self.OperationConfigFrame.setFrameShadow(QFrame.Plain)
        self.OperationConfigFrame.setLineWidth(0)
        self.horizontalLayout_3 = QHBoxLayout(self.OperationConfigFrame)
        self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
        self.horizontalLayout_3.setContentsMargins(2, 2, 2, 2)
        self.DateRange = DateRangeSelector(self.OperationConfigFrame)
        self.DateRange.setObjectName(u"DateRange")
        self.DateRange.setProperty("ItemsList", u"week;month;quarter;year;all")

        self.horizontalLayout_3.addWidget(self.DateRange)

        self.AccountLbl = QLabel(self.OperationConfigFrame)
        self.AccountLbl.setObjectName(u"AccountLbl")

        self.horizontalLayout_3.addWidget(self.AccountLbl)

        self.ChooseAccountBtn = AccountButton(self.OperationConfigFrame)
        self.ChooseAccountBtn.setObjectName(u"ChooseAccountBtn")

        self.horizontalLayout_3.addWidget(self.ChooseAccountBtn)

        self.SearchLbl = QLabel(self.OperationConfigFrame)
        self.SearchLbl.setObjectName(u"SearchLbl")

        self.horizontalLayout_3.addWidget(self.SearchLbl)

        self.SearchString = QLineEdit(self.OperationConfigFrame)
        self.SearchString.setObjectName(u"SearchString")

        self.horizontalLayout_3.addWidget(self.SearchString)

        self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Expanding,
                                            QSizePolicy.Minimum)

        self.horizontalLayout_3.addItem(self.horizontalSpacer)

        self.verticalLayout_2.addWidget(self.OperationConfigFrame)

        self.OperationsDetailsSplitter = QSplitter(self.OperationsBox)
        self.OperationsDetailsSplitter.setObjectName(
            u"OperationsDetailsSplitter")
        self.OperationsDetailsSplitter.setOrientation(Qt.Vertical)
        self.OperationsTableView = QTableView(self.OperationsDetailsSplitter)
        self.OperationsTableView.setObjectName(u"OperationsTableView")
        sizePolicy3 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        sizePolicy3.setHorizontalStretch(0)
        sizePolicy3.setVerticalStretch(4)
        sizePolicy3.setHeightForWidth(
            self.OperationsTableView.sizePolicy().hasHeightForWidth())
        self.OperationsTableView.setSizePolicy(sizePolicy3)
        self.OperationsTableView.setAlternatingRowColors(True)
        self.OperationsTableView.setSelectionMode(
            QAbstractItemView.ExtendedSelection)
        self.OperationsTableView.setSelectionBehavior(
            QAbstractItemView.SelectRows)
        self.OperationsTableView.setWordWrap(False)
        self.OperationsDetailsSplitter.addWidget(self.OperationsTableView)
        self.OperationsTableView.verticalHeader().setVisible(False)
        self.OperationsTableView.verticalHeader().setMinimumSectionSize(20)
        self.OperationsTableView.verticalHeader().setDefaultSectionSize(20)
        self.OperationDetails = QFrame(self.OperationsDetailsSplitter)
        self.OperationDetails.setObjectName(u"OperationDetails")
        sizePolicy4 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        sizePolicy4.setHorizontalStretch(0)
        sizePolicy4.setVerticalStretch(1)
        sizePolicy4.setHeightForWidth(
            self.OperationDetails.sizePolicy().hasHeightForWidth())
        self.OperationDetails.setSizePolicy(sizePolicy4)
        self.OperationDetails.setMinimumSize(QSize(0, 100))
        self.OperationDetails.setMaximumSize(QSize(16777215, 300))
        self.OperationDetails.setFrameShape(QFrame.Panel)
        self.OperationDetails.setFrameShadow(QFrame.Sunken)
        self.OperationDetails.setLineWidth(1)
        self.horizontalLayout_4 = QHBoxLayout(self.OperationDetails)
        self.horizontalLayout_4.setObjectName(u"horizontalLayout_4")
        self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
        self.OperationsTabs = QStackedWidget(self.OperationDetails)
        self.OperationsTabs.setObjectName(u"OperationsTabs")
        self.NoOperation = QWidget()
        self.NoOperation.setObjectName(u"NoOperation")
        self.OperationsTabs.addWidget(self.NoOperation)
        self.IncomeSpending = IncomeSpendingWidget()
        self.IncomeSpending.setObjectName(u"IncomeSpending")
        self.OperationsTabs.addWidget(self.IncomeSpending)
        self.Dividend = DividendWidget()
        self.Dividend.setObjectName(u"Dividend")
        self.OperationsTabs.addWidget(self.Dividend)
        self.Trade = TradeWidget()
        self.Trade.setObjectName(u"Trade")
        self.OperationsTabs.addWidget(self.Trade)
        self.Transfer = TransferWidget()
        self.Transfer.setObjectName(u"Transfer")
        self.OperationsTabs.addWidget(self.Transfer)
        self.CorporateAction = CorporateActionWidget()
        self.CorporateAction.setObjectName(u"CorporateAction")
        self.OperationsTabs.addWidget(self.CorporateAction)

        self.horizontalLayout_4.addWidget(self.OperationsTabs)

        self.OperationsButtons = QFrame(self.OperationDetails)
        self.OperationsButtons.setObjectName(u"OperationsButtons")
        self.verticalLayout_3 = QVBoxLayout(self.OperationsButtons)
        self.verticalLayout_3.setSpacing(2)
        self.verticalLayout_3.setObjectName(u"verticalLayout_3")
        self.verticalLayout_3.setContentsMargins(2, 2, 2, 2)
        self.NewOperationBtn = QPushButton(self.OperationsButtons)
        self.NewOperationBtn.setObjectName(u"NewOperationBtn")

        self.verticalLayout_3.addWidget(self.NewOperationBtn)

        self.CopyOperationBtn = QPushButton(self.OperationsButtons)
        self.CopyOperationBtn.setObjectName(u"CopyOperationBtn")

        self.verticalLayout_3.addWidget(self.CopyOperationBtn)

        self.DeleteOperationBtn = QPushButton(self.OperationsButtons)
        self.DeleteOperationBtn.setObjectName(u"DeleteOperationBtn")

        self.verticalLayout_3.addWidget(self.DeleteOperationBtn)

        self.verticalSpacer_4 = QSpacerItem(20, 40, QSizePolicy.Minimum,
                                            QSizePolicy.Expanding)

        self.verticalLayout_3.addItem(self.verticalSpacer_4)

        self.horizontalLayout_4.addWidget(self.OperationsButtons)

        self.OperationsDetailsSplitter.addWidget(self.OperationDetails)

        self.verticalLayout_2.addWidget(self.OperationsDetailsSplitter)

        self.BalanceOperationsSplitter.addWidget(self.OperationsBox)

        self.verticalLayout_4.addWidget(self.BalanceOperationsSplitter)

        self.retranslateUi(OperationsWidget)

        self.OperationsTabs.setCurrentIndex(5)

        QMetaObject.connectSlotsByName(OperationsWidget)

    # setupUi

    def retranslateUi(self, OperationsWidget):
        OperationsWidget.setWindowTitle(
            QCoreApplication.translate("OperationsWidget",
                                       u"Operations & Balances", None))
        self.BalanceBox.setTitle(
            QCoreApplication.translate("OperationsWidget", u"Balances", None))
        self.BalanceDate.setDisplayFormat(
            QCoreApplication.translate("OperationsWidget", u"dd/MM/yyyy",
                                       None))
        self.CurrencyLbl.setText(
            QCoreApplication.translate("OperationsWidget", u"Sum Currency:",
                                       None))
        self.ShowInactiveCheckBox.setText(
            QCoreApplication.translate("OperationsWidget", u"Show &Inactive",
                                       None))
        self.OperationsBox.setTitle(
            QCoreApplication.translate("OperationsWidget", u"Operations",
                                       None))
        self.AccountLbl.setText(
            QCoreApplication.translate("OperationsWidget", u"Account:", None))
        self.SearchLbl.setText(
            QCoreApplication.translate("OperationsWidget", u"Search:", None))
        #if QT_CONFIG(tooltip)
        self.NewOperationBtn.setToolTip(
            QCoreApplication.translate("OperationsWidget", u"New operation",
                                       None))
        #endif // QT_CONFIG(tooltip)
        self.NewOperationBtn.setText("")
        #if QT_CONFIG(tooltip)
        self.CopyOperationBtn.setToolTip(
            QCoreApplication.translate("OperationsWidget", u"Copy operation",
                                       None))
        #endif // QT_CONFIG(tooltip)
        self.CopyOperationBtn.setText("")
        #if QT_CONFIG(tooltip)
        self.DeleteOperationBtn.setToolTip(
            QCoreApplication.translate("OperationsWidget", u"Delete operation",
                                       None))
        #endif // QT_CONFIG(tooltip)
        self.DeleteOperationBtn.setText("")
コード例 #9
0
        """Override method from QAbstractTableModel

        Return dataframe index as vertical header data and columns as horizontal header data.
        """
        if role == Qt.DisplayRole:
            if orientation == Qt.Horizontal:
                return str(self._dataframe.columns[section])

            if orientation == Qt.Vertical:
                return str(self._dataframe.index[section])

        return None


if __name__ == "__main__":

    app = QApplication(sys.argv)

    df = pd.read_csv("iris.csv")

    view = QTableView()
    view.resize(800, 500)
    view.horizontalHeader().setStretchLastSection(True)
    view.setAlternatingRowColors(True)
    view.setSelectionBehavior(QTableView.SelectRows)

    model = PandasModel(df)
    view.setModel(model)
    view.show()
    app.exec_()