예제 #1
0
파일: widget.py 프로젝트: swavan/oneui
def delete_confirmation(parent, _id: str, action: Callable):
    msg = QMessageBox()
    msg.setText("Are you sure, you want to remove ?")
    msg.setStyleSheet('''
        background-color: #1d251c;
        color: #bdc0bd;
    ''')
    msg.setParent(parent)
    msg.setWindowModality(Qt.WindowModality.WindowModal)

    style = '''
    margin-top: 20px;
    border: none;
    '''
    yes_btn = QPushButton("  Yes")
    yes_btn.setIcon(QIcon(full_path("assets/images/icons/trash-can.ico")))
    yes_btn.setStyleSheet(style)

    no_btn = QPushButton("  Cancel")
    no_btn.setStyleSheet(style)
    no_btn.setIcon(QIcon(full_path("assets/images/icons/cancel.ico")))

    yes_btn.setDefault(True)

    msg.addButton(no_btn, msg.ButtonRole.NoRole)
    msg.addButton(yes_btn, msg.ButtonRole.YesRole)

    msg.buttonClicked.connect(lambda x: action(_id) if x.text().lower().strip() == "yes" else do_nothing())
    msg.exec()
예제 #2
0
파일: helper.py 프로젝트: swavan/oneui
def add_or_button(button: QToolButton):
    if button.text().lower() == "and":
        button.setText("or")
        button.setIcon(QIcon(full_path("assets/images/icons/or.ico")))
    elif button.text().lower() == "or":
        button.setText("and")
        button.setIcon(QIcon(full_path("assets/images/icons/and.ico")))
예제 #3
0
 def init(cls):
     if not cls.is_log_file_exist():
         open(full_path("data/logs/swavan.log"), 'w').close()
     cls.logger.setLevel(logging.INFO)
     fh = logging.FileHandler(full_path(cls.__log_file_name__))
     sh = logging.StreamHandler(sys.stdout)
     formatter = logging.Formatter(
         '[%(asctime)s] %(levelname)s %(message)s',
         datefmt='%a, %d %b %Y %H:%M:%S')
     fh.setFormatter(formatter)
     sh.setFormatter(formatter)
     cls.logger.addHandler(fh)
     cls.logger.addHandler(sh)
예제 #4
0
파일: __init__.py 프로젝트: swavan/oneui
 def __init__(self, *args, **kwargs):
     super(SwaVanMainWindow, self).__init__(*args, **kwargs)
     self.setWindowIcon(QIcon(full_path("assets/images/logo/swavan_one_ui.png")))
     self.setContentsMargins(0, 0, 0, 0)
     _window = SwaVanDashboard()
     self.setCentralWidget(_window)
     self.setWindowTitle("SwaVan")
예제 #5
0
파일: __init__.py 프로젝트: swavan/oneui
 def eventFilter(self, source, event):
     if event.type(
     ) == QEvent.Type.ContextMenu and source is self.mock_env_list:
         menu = QMenu()
         _copy = menu.addAction(
             QIcon(full_path("assets/images/icons/export.ico")), "Export")
         _remove = menu.addAction(
             QIcon(full_path("assets/images/icons/trash-can.ico")),
             "Remove")
         if source.itemAt(event.pos()):
             action = menu.exec(event.globalPos())
             _item = source.itemAt(event.pos())
             _id = _item.whatsThis()
             if action == _remove:
                 delete_confirmation(self, _id, self.delete)
         return True
     return super().eventFilter(source, event)
예제 #6
0
파일: __init__.py 프로젝트: swavan/oneui
 def update_env_list(self):
     mocks = MockEnvironmentService.load()
     self.mock_env_list.clear()
     for _mock_env in mocks:
         item = QListWidgetItem()
         item.setWhatsThis(_mock_env.id)
         item.setIcon(
             QIcon(full_path("assets/images/icons/environment.ico")))
         item.setText(f"{_mock_env.name}:{_mock_env.port}")
         self.mock_env_list.addItem(item)
예제 #7
0
파일: __init__.py 프로젝트: swavan/oneui
 def add_header_row(self, _header: Header = Header()):
     self.mock_env_cors_headers.insertRow(
         self.mock_env_cors_headers.rowCount())
     row_position = self.mock_env_cors_headers.rowCount()
     self.mock_env_cors_headers.setItem(row_position - 1, 0,
                                        QTableWidgetItem(_header.key))
     self.mock_env_cors_headers.setItem(row_position - 1, 1,
                                        QTableWidgetItem(_header.value))
     _delete = QTableWidgetItem()
     _delete_icon = QIcon(full_path("assets/images/icons/close.ico"))
     _delete.setSizeHint(QSize(50, 50))
     _delete.setIcon(_delete_icon)
     self.mock_env_cors_headers.setItem(row_position - 1, 2, _delete)
예제 #8
0
파일: service.py 프로젝트: swavan/oneui
 def __init__(self, _mock: Mock):
     self._id = _mock.id
     self._mock = _mock
     _headers = [('server', 'swavan')]
     _config = Config(app=SwaVanHttp(_mock).app,
                      host="localhost",
                      headers=_headers,
                      port=int(_mock.port),
                      access_log=False)
     if _mock.enable_https:
         _key = full_path("data/__certs__/swavan.key")
         _crt = full_path("data/__certs__/swavan.crt")
         if _mock.use_default_cert:
             if os.path.isfile(_key) and os.path.isfile(_crt):
                 _config.ssl_keyfile = _key
                 _config.ssl_certfile = _crt
                 SwaVanLogRecorder.send_log(f"Using default cert")
         else:
             if os.path.isfile(_mock.ssl_key_file_url) and os.path.isfile(
                     _mock.ssl_cert_file_url):
                 _config.ssl_keyfile = _mock.ssl_key_file_url
                 _config.ssl_certfile = _mock.ssl_cert_file_url
                 SwaVanLogRecorder.send_log(f"Using custom cert")
     self._core_server = Server(config=_config)
예제 #9
0
파일: __init__.py 프로젝트: swavan/oneui
    def eventFilter(self, source, event):
        if event.type(
        ) == QEvent.Type.ContextMenu and source is self.mock_endpoints:
            menu = QMenu()
            _copy = menu.addAction(
                QIcon(full_path("assets/images/icons/copy.ico")), "Copy")
            _toggle = menu.addAction(
                QIcon(full_path("assets/images/icons/toggle.ico")), "Toggle")
            _remove = menu.addAction(
                QIcon(full_path("assets/images/icons/trash-can.ico")),
                "Remove")

            if source.itemAt(event.pos()):
                action = menu.exec(event.globalPos())
                _item = source.itemAt(event.pos())
                _id = _item.whatsThis()
                if action == _copy:
                    copy_endpoint(endpoint_ids=[_id])
                elif action == _toggle:
                    self.toggle_endpoint(_id)
                elif action == _remove:
                    delete_confirmation(self, _id, self.delete)
            return True
        return super().eventFilter(source, event)
예제 #10
0
파일: __init__.py 프로젝트: swavan/oneui
 def update_view(self):
     self.mock_endpoints.clear()
     _endpoints = EndpointService.load_by_parent(
         SwaVanCache.get_selected_env())
     _endpoints.sort(key=lambda x: x.created_at)
     if SwaVanCache.get_selected_env():
         for row in _endpoints:
             item = QListWidgetItem(row.url)
             item.setWhatsThis(row.id)
             icon = QIcon(
                 full_path(
                     f"assets/images/icons/{'sad' if not row.is_active else row.http_method.lower()}.ico"
                 ))
             item.setToolTip(
                 f"""<b>{row.http_method.title()}</b> {row.url} { 'is disabled' if not row.is_active else ''}"""
             )
             item.setIcon(icon)
             self.mock_endpoints.addItem(item)
예제 #11
0
 def is_log_file_exist(cls) -> bool:
     return os.path.exists(full_path(cls.__log_file_name__))
예제 #12
0
 def reading_log(cls):
     return (row for row in open(full_path(cls.__log_file_name__)))
예제 #13
0
파일: page.py 프로젝트: swavan/oneui
 def play_icon_update(self, is_running: bool):
     _icon = QIcon(
         full_path(
             f"assets/images/icons/{'play' if not is_running else 'stop'}.ico"
         ))
     self.server_status_btn.setIcon(_icon)
예제 #14
0
파일: main.py 프로젝트: swavan/oneui
import os
import sys
from PyQt6.QtGui import QIcon
from PyQt6.QtWidgets import QApplication

from dashboad import SwaVanMainWindow
from shared.recorder import SwaVanLogRecorder
from shared.widgets.builder import full_path

if __name__ == "__main__":
    app = QApplication(sys.argv)
    app.setApplicationDisplayName("SwaVan")
    app.setApplicationName("SwaVan")
    app.setDesktopFileName("SwaVan")

    app.setWindowIcon(QIcon(full_path("assets/images/logo/swavan_one_ui.icns")))
    with open(full_path("assets/style/dark.qss"), 'r') as file:
        qss = file.read()
        app.setStyleSheet(qss)
        if os.path.exists(full_path("data/logs/swavan.log")):
            open(full_path("data/logs/swavan.log"), 'w').close()

    widget = SwaVanMainWindow()
    widget.show()
    SwaVanLogRecorder.init()
    sys.exit(app.exec())