def __add_scroll_area__(self, username): sub_frame = QFrame() sub_frame.setContentsMargins(0, 0, 0, 0) sub_frame.setAccessibleName(sub_qframe_styles[0]) sub_frame.setStyleSheet(sub_qframe_styles[1]) user_profile_layout = QHBoxLayout() user_profile_layout.setContentsMargins(0, 0, 0, 0) self.username_icon = QPushButton() self.username_icon.setContentsMargins(0, 0, 0, 0) self.username_icon.setAccessibleName(username_icon_styles[0]) self.username_icon.setStyleSheet(username_icon_styles[1]) icon = QIcon('./assets/user.png') self.username_icon.setIcon(icon) self.username_icon.setIconSize(QSize(40, 40)) self.username_label = QLabel(username) self.username_label.setContentsMargins(0, 0, 0, 0) self.username_label.setAccessibleName(username_label_styles[0]) self.username_label.setStyleSheet(username_label_styles[1]) user_profile_layout.addWidget(self.username_icon) user_profile_layout.addWidget(self.username_label) sub_frame.setLayout(user_profile_layout) self.scroll_layout.addRow(sub_frame)
def __add_widget__(self): """ this function return a q-frame to use in main layout """ main_frame = QFrame() main_frame.setContentsMargins(0, 10, 0, 0) main_frame.setAccessibleName(main_frame_styles[0]) main_frame.setStyleSheet(main_frame_styles[1]) frame_layout = QVBoxLayout() frame_layout.setContentsMargins(0, 0, 0, 0) frame_layout.setStretch(0, 0) frame_layout.setSpacing(0) self.table_widget = QTableWidget() self.table_widget.setAccessibleName(table_widget_styles[0]) self.table_widget.setStyleSheet(table_widget_styles[1]) self.table_widget.verticalHeader().hide() self.table_widget.setRowCount(0) self.table_widget.setColumnCount(4) self.table_widget.setHorizontalHeaderLabels(["IP Client", "Name", "Port", "System"]) header = self.table_widget.horizontalHeader() header.setAccessibleName(table_header_styles[0]) header.setStyleSheet(table_header_styles[1]) header.setSectionResizeMode(0, QHeaderView.Stretch) header.setSectionResizeMode(1, QHeaderView.Stretch) header.setSectionResizeMode(2, QHeaderView.Stretch) header.setSectionResizeMode(3, QHeaderView.Stretch) frame_layout.addWidget(self.table_widget) main_frame.setLayout(frame_layout) return main_frame
def __add_languages_layout__(self): frame = QFrame() frame.setAccessibleName(inclued_paths_section_style[0]) frame.setStyleSheet(inclued_paths_section_style[1]) frame.setContentsMargins(10, 0, 10, 45) layout = QHBoxLayout() layout.addStretch() button_groups = QButtonGroup() radio_button_php = QRadioButton() radio_button_php.setText("PHP") radio_button_php.setChecked(True) radio_button_php.setAccessibleName(radio_buttons_style[0]) radio_button_php.setStyleSheet(radio_buttons_style[1]) button_groups.addButton(radio_button_php) layout.addWidget(radio_button_php) label = QLabel("Languages") label.setAccessibleName(db_label_style[0]) label.setStyleSheet(db_label_style[1]) label.setContentsMargins(0, 0, 0, 40) layout.addWidget(label) frame.setLayout(layout) self.v_main_layout.addWidget(frame)
def __add_inclued_paths_layout__(self): frame = QFrame() frame.setAccessibleName(inclued_paths_section_style[0]) frame.setStyleSheet(inclued_paths_section_style[1]) frame.setContentsMargins(10, 0, 10, 45) layout = QHBoxLayout() layout.addStretch() frame.setLayout(layout) radio_group = QButtonGroup() radio_button_login_finder = QRadioButton() radio_button_login_finder.setText("Login finder") radio_button_login_finder.setAccessibleName(radio_buttons_style[0]) radio_button_login_finder.setStyleSheet(radio_buttons_style[1]) radio_button_login_finder.setChecked(True) radio_group.addButton(radio_button_login_finder) layout.addWidget(radio_button_login_finder) label = QLabel("Paths") label.setAccessibleName(db_label_style[0]) label.setStyleSheet(db_label_style[1]) label.setContentsMargins(0, 0, 0, 40) layout.addWidget(label) self.v_main_layout.addWidget(frame)
def __add_widget__(self): main_frame = QFrame() main_frame.setContentsMargins(0, 0, 0, 0) main_frame.setAccessibleName(main_frame_styles[0]) main_frame.setStyleSheet(main_frame_styles[1]) frame_layout = QHBoxLayout() frame_layout.setContentsMargins(0, 0, 0, 0) frame_layout.setStretch(0, 0) frame_layout.setSpacing(0) main_frame.setLayout(frame_layout) return main_frame
def __add_widget__(self): main_frame = QFrame() main_frame.setContentsMargins(0, 0, 0, 0) main_frame.setAccessibleName(main_frame_styles[0]) main_frame.setStyleSheet(main_frame_styles[1]) frame_layout = QHBoxLayout() frame_layout.setContentsMargins(0, 0, 0, 0) frame_layout.setStretch(0, 0) frame_layout.setSpacing(0) text_input = QTextEdit() text_input.setPlaceholderText("Type something...") # text_input.setAlignment(Qt.AlignCenter) text_input.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff) text_input.setAlignment(Qt.AlignVCenter) text_input.setAccessibleName(input_text_styles[0]) text_input.setStyleSheet(input_text_styles[1]) attach_icon = QPushButton() attach_icon.setAccessibleName(attach_icon_styles[0]) attach_icon.setStyleSheet(attach_icon_styles[1]) icon_attach = QIcon('./assets/clip.png') attach_icon.setIcon(icon_attach) attach_icon.setIconSize(QSize(25, 25)) sticker_icon = QPushButton() sticker_icon.setAccessibleName(sticker_icon_styles[0]) sticker_icon.setStyleSheet(sticker_icon_styles[1]) icon_sticker = QIcon('./assets/smile.png') sticker_icon.setIcon(icon_sticker) sticker_icon.setIconSize(QSize(25, 25)) send_icon = QPushButton() send_icon.setAccessibleName(send_icon_styles[0]) send_icon.setStyleSheet(send_icon_styles[1]) icon_send = QIcon('./assets/paper-plane.png') send_icon.setIcon(icon_send) send_icon.setIconSize(QSize(25, 25)) frame_layout.addWidget(text_input) frame_layout.addWidget(attach_icon) frame_layout.addWidget(sticker_icon) frame_layout.addWidget(send_icon) main_frame.setLayout(frame_layout) return main_frame
def __add_widget__(self): main_frame = QFrame() main_frame.setContentsMargins(0, 0, 0, 0) main_frame.setAccessibleName(main_frame_styles[0]) main_frame.setStyleSheet(main_frame_styles[1]) frame_layout = QHBoxLayout() frame_layout.setContentsMargins(0, 0, 0, 0) frame_layout.setStretch(0, 0) frame_layout.setSpacing(0) user_icon = QPushButton() user_icon.setAccessibleName(user_icon_styles[0]) user_icon.setStyleSheet(user_icon_styles[1]) icon = QIcon('./assets/user.png') user_icon.setIcon(icon) user_icon.setIconSize(QSize(60, 60)) user_label = QLabel('Username') user_label.setFrameShape(QFrame.NoFrame) user_label.setAccessibleName(user_label_styles[0]) user_label.setStyleSheet(user_label_styles[1]) call_icon = QPushButton() call_icon.setAccessibleName(call_icon_styles[0]) call_icon.setStyleSheet(call_icon_styles[1]) icon_call = QIcon('./assets/Phone-icon.png') call_icon.setIcon(icon_call) call_icon.setIconSize(QSize(25, 25)) video_icon = QPushButton() video_icon.setAccessibleName(video_icon_styles[0]) video_icon.setStyleSheet(video_icon_styles[1]) icon_video = QIcon('./assets/communications.png') video_icon.setIcon(icon_video) video_icon.setIconSize(QSize(25, 25)) frame_layout.addWidget(user_icon) frame_layout.addWidget(user_label) frame_layout.addWidget(call_icon) frame_layout.addWidget(video_icon) main_frame.setLayout(frame_layout) return main_frame
def __add_widget__(self): """ this function return a q-frame to use in main layout """ main_frame = QFrame() main_frame.setContentsMargins(0, 0, 0, 0) main_frame.setAccessibleName(main_frame_styles[0]) main_frame.setStyleSheet(main_frame_styles[1]) frame_layout = QHBoxLayout() frame_layout.setContentsMargins(0, 0, 0, 0) frame_layout.setStretch(0, 0) frame_layout.setSpacing(0) self.q_text_edit = QTextEdit() self.q_text_edit.setAccessibleName(q_text_edit_styles[0]) self.q_text_edit.setReadOnly(True) self.q_text_edit.setStyleSheet(q_text_edit_styles[1]) frame_layout.addWidget(self.q_text_edit) main_frame.setLayout(frame_layout) return main_frame
def __init__(self, engine): super().__init__() self.setupUi(self) self._engine = engine machines = { plugin.name: _(plugin.name) for plugin in registry.list_plugins('machine') } mappings = ( # i18n: Widget: “ConfigWindow”. (_('Interface'), ( ConfigOption(_('Start minimized:'), 'start_minimized', BooleanOption, _('Minimize the main window to systray on startup.')), ConfigOption(_('Show paper tape:'), 'show_stroke_display', BooleanOption, _('Open the paper tape on startup.')), ConfigOption(_('Show suggestions:'), 'show_suggestions_display', BooleanOption, _('Open the suggestions dialog on startup.')), ConfigOption(_('Add translation dialog opacity:'), 'translation_frame_opacity', partial(IntOption, maximum=100, minimum=0), _('Set the translation dialog opacity:\n' '- 0 makes the dialog invisible\n' '- 100 is fully opaque')), ConfigOption(_('Dictionaries display order:'), 'classic_dictionaries_display_order', partial(BooleanAsDualChoiceOption, _('top-down'), _('bottom-up')), _('Set the display order for dictionaries:\n' '- top-down: match the search order; highest priority first\n' '- bottom-up: reverse search order; lowest priority first\n')), )), # i18n: Widget: “ConfigWindow”. (_('Logging'), ( ConfigOption(_('Log file:'), 'log_file_name', partial(FileOption, _('Select a log file'), _('Log files (*.log)')), _('File to use for logging strokes/translations.')), ConfigOption(_('Log strokes:'), 'enable_stroke_logging', BooleanOption, _('Save strokes to the logfile.')), ConfigOption(_('Log translations:'), 'enable_translation_logging', BooleanOption, _('Save translations to the logfile.')), )), # i18n: Widget: “ConfigWindow”. (_('Machine'), ( ConfigOption(_('Machine:'), 'machine_type', partial(ChoiceOption, choices=machines), dependents=( ('machine_specific_options', self._update_machine_options), ('system_keymap', lambda v: self._update_keymap(machine_type=v)), )), ConfigOption(_('Options:'), 'machine_specific_options', self._machine_option), ConfigOption(_('Keymap:'), 'system_keymap', KeymapOption), )), # i18n: Widget: “ConfigWindow”. (_('Output'), ( ConfigOption(_('Enable at start:'), 'auto_start', BooleanOption, _('Enable output on startup.')), ConfigOption(_('Start attached:'), 'start_attached', BooleanOption, _('Disable preceding space on first output.\n' '\n' 'This option is only applicable when spaces are placed before.')), ConfigOption(_('Start capitalized:'), 'start_capitalized', BooleanOption, _('Capitalize the first word.')), ConfigOption(_('Space placement:'), 'space_placement', partial(ChoiceOption, choices={ 'Before Output': _('Before Output'), 'After Output': _('After Output'), }), _('Set automatic space placement: before or after each word.')), ConfigOption(_('Undo levels:'), 'undo_levels', partial(IntOption, maximum=10000, minimum=MINIMUM_UNDO_LEVELS), _('Set how many preceding strokes can be undone.\n' '\n' 'Note: the effective value will take into account the\n' 'dictionaries entry with the maximum number of strokes.')), )), # i18n: Widget: “ConfigWindow”. (_('Plugins'), ( ConfigOption(_('Extension:'), 'enabled_extensions', partial(MultipleChoicesOption, choices={ plugin.name: plugin.name for plugin in registry.list_plugins('extension') }, labels=(_('Name'), _('Enabled'))), _('Configure enabled plugin extensions.')), )), # i18n: Widget: “ConfigWindow”. (_('System'), ( ConfigOption(_('System:'), 'system_name', partial(ChoiceOption, choices={ plugin.name: plugin.name for plugin in registry.list_plugins('system') }), dependents=( ('system_keymap', lambda v: self._update_keymap(system_name=v)), )), )), ) # Only keep supported options, to avoid messing with things like # dictionaries, that are handled by another (possibly concurrent) # dialog. self._supported_options = set() for section, option_list in mappings: self._supported_options.update(option.option_name for option in option_list) self._update_config() # Create and fill tabs. option_by_name = {} for section, option_list in mappings: layout = QFormLayout() for option in option_list: option_by_name[option.option_name] = option option.layout = layout option.widget = self._create_option_widget(option) option.label = QLabel(option.display_name) option.label.setToolTip(option.help_text) option.label.setBuddy(option.widget) layout.addRow(option.label, option.widget) frame = QFrame() frame.setLayout(layout) frame.setAccessibleName(section) frame.setFocusProxy(option_list[0].widget) scroll_area = QScrollArea() scroll_area.setWidgetResizable(True) scroll_area.setWidget(frame) scroll_area.setFocusProxy(frame) self.tabs.addTab(scroll_area, section) # Update dependents. for option in option_by_name.values(): option.dependents = [ (option_by_name[option_name], update_fn) for option_name, update_fn in option.dependents ] self.buttons.button(QDialogButtonBox.Ok).clicked.connect(self.on_apply) self.buttons.button(QDialogButtonBox.Apply).clicked.connect(self.on_apply) self.tabs.currentWidget().setFocus() self.restore_state() self.finished.connect(self.save_state)
class SignIn(Observer, QWidget): def __init__(self, parent=None, socket_server=None): super(SignIn, self).__init__(parent=parent) self.concentrate_subject = ConcentrateSubject() self.concentrate_subject.attach(self) self.socket_server = socket_server self.check_user_pass() self.setContentsMargins(0, 0, 0, 0) self.parent = parent self.main_layout = QVBoxLayout() self.main_layout.setContentsMargins(0, 0, 0, 0) self.main_layout.setStretch(0, 0) self.main_layout.setAlignment(Qt.AlignHCenter) self.__init_ui__() self.main_layout.addWidget(self.main_frame) self.setLayout(self.main_layout) def check_user_pass(self): last_user = User.select() if len(last_user) > 0: last_user = last_user[len(last_user) - 1] if last_user is not None: data = json_dumps({ "message": { "username": last_user.username, "password": last_user.password }, "command": "[LOGIN]", "session": None, "option": None, "route": { "group": "", "to": "server" }, }) self.socket_server.get_socket.sendall(data.encode("utf-8")) @property def class_name(self): return "SIGN_IN" def __init_ui__(self): self.main_frame = QFrame() self.main_frame.setContentsMargins(0, 0, 0, 0) self.main_frame.setAccessibleName(main_frame_styles[0]) self.main_frame.setStyleSheet(main_frame_styles[1]) self.frame_layout = QVBoxLayout() self.frame_layout.setContentsMargins(0, 0, 0, 0) self.frame_layout.setStretch(0, 0) self.frame_layout.setSpacing(0) self._add_textboxs_() self._add_forgot_password_() self._add_btn_login_() self._add_btn_create_account_() self.main_frame.setLayout(self.frame_layout) def _add_textboxs_(self): self.username_edit_text = QLineEdit() self.username_edit_text.setPlaceholderText("Enter UserName") self.username_edit_text.setAccessibleName(q_edit_text_style[0]) self.username_edit_text.setStyleSheet(q_edit_text_style[1]) self.frame_layout.addWidget(self.username_edit_text) self.password_edit_text = QLineEdit() self.password_edit_text.setPlaceholderText("Enter Password") self.password_edit_text.setAccessibleName(q_edit_text_style[0]) self.password_edit_text.setStyleSheet(q_edit_text_style[1]) self.frame_layout.addWidget(self.password_edit_text) def _add_forgot_password_(self): btn_forgot_password = QPushButton("Forgot password?") btn_forgot_password.setAccessibleName(btn_forgot_password_style[0]) btn_forgot_password.setStyleSheet(btn_forgot_password_style[1]) # self.main_layout.addWidget(btn_forgot_password) self.frame_layout.addWidget(btn_forgot_password) def _add_btn_login_(self): btn_login = QPushButton("SingIn") btn_login.setAccessibleName(btn_login_style[0]) btn_login.setStyleSheet(btn_login_style[1]) def btn_login_clicked(): username: str = self.username_edit_text.text() password: str = self.password_edit_text.text() try: if username != "" and password != "": user = User.select().where((User.username == username) & (User.password == password)) if len(user) > 0: data = json_dumps({ "message": "", "command": "[LOGIN_INF]", "session": "", "option": { "sys_info": str(uname().system), "username": username }, "route": { "group": "", "to": "server" }, }) self.socket_server.get_socket.sendall( data.encode("utf-8")) from gui.windows.window_handler.main_window_handler.mainwindow import MainWindow main_window = MainWindow(self.parent, self.socket_server) self.parent.hide() main_window.execute_app() else: MessageBox(title="Not Success", message="UnAuthorized").show() else: MessageBox( title="Error", message=str("Please fill both of password and username" )).show() except Exception as error: MessageBox(title="Error", message=str(error)).show() btn_login.clicked.connect(btn_login_clicked) self.frame_layout.addWidget(btn_login) def _add_btn_create_account_(self): btn_create_account = QPushButton("Create new account ?") btn_create_account.setAccessibleName(btn_create_account_style[0]) btn_create_account.setStyleSheet(btn_create_account_style[1]) btn_create_account.setContentsMargins(0, 0, 0, 0) def clicked_create_account(): self.set_visibility(False) self.signup_page.set_visibility(True) btn_create_account.clicked.connect(clicked_create_account) # self.main_layout.addWidget(btn_create_account) self.frame_layout.addWidget(btn_create_account) def set_visibility(self, visible: bool): if visible: self.show() else: self.hide() def set_sign_up_page(self, signup: object): self.signup_page = signup def notification(self, message): incoming_message = json_loads(message) last_user = User.select() last_user = last_user[len(last_user) - 1] if incoming_message["message"]["code"] == 200: data = json_dumps({ "message": "", "command": "[LOGIN_INF]", "session": "", "option": { "sys_info": str(uname().system), "username": last_user.username }, "route": { "group": "", "to": "server" }, }) self.socket_server.get_socket.sendall(data.encode("utf-8")) self.concentrate_subject.notify(incoming_message, to="USER_LIST") from gui.windows.window_handler.main_window_handler.mainwindow import MainWindow main_window = MainWindow(self.parent, socket_server=self.socket_server) self.parent.hide() main_window.execute_app() else: return @property def signal(self): return self._signal
class SignUp(Observer, QWidget): def __init__(self, parent=None, socket_server=None): super(SignUp, self).__init__(parent=parent) self.concentrate_subject = ConcentrateSubject() self.concentrate_subject.attach(self) self.socket_server = socket_server self.parent = parent self.setContentsMargins(0, 0, 0, 0) self.main_layout = QVBoxLayout() self.main_layout.setContentsMargins(0, 0, 0, 0) self.main_layout.setStretch(0, 0) self.main_layout.setAlignment(Qt.AlignHCenter) self.__init_ui__() self.main_layout.addWidget(self.main_frame) self.setLayout(self.main_layout) @property def class_name(self): return "SIGN_UP" def __init_ui__(self): self.main_frame = QFrame() self.main_frame.setContentsMargins(0, 0, 0, 0) self.main_frame.setAccessibleName(main_frame_styles[0]) self.main_frame.setStyleSheet(main_frame_styles[1]) self.frame_layout = QVBoxLayout() self.frame_layout.setContentsMargins(0, 0, 0, 0) self.frame_layout.setStretch(0, 0) self.frame_layout.setSpacing(0) self._add_textboxs_() self._add_btn_signup_() self._add_btn_register_account_() self.main_frame.setLayout(self.frame_layout) def _add_textboxs_(self): self.username_edit_text = QLineEdit() self.username_edit_text.setPlaceholderText("UserName") self.username_edit_text.setAccessibleName(q_edit_text_style[0]) self.username_edit_text.setStyleSheet(q_edit_text_style[1]) self.frame_layout.addWidget(self.username_edit_text) self.password_edit_text = QLineEdit() self.password_edit_text.setPlaceholderText("Password") self.password_edit_text.setAccessibleName(q_edit_text_style[0]) self.password_edit_text.setStyleSheet(q_edit_text_style[1]) self.frame_layout.addWidget(self.password_edit_text) def _add_btn_signup_(self): btn_signup = QPushButton("SignUp") btn_signup.setAccessibleName(btn_signup_style[0]) btn_signup.setStyleSheet(btn_signup_style[1]) def btn_register_clicked(): username: str = self.username_edit_text.text() password: str = self.password_edit_text.text() try: if username != "" and password != "": self.socket_server.get_socket.sendall(json_dumps({ "message": { "USERNAME": username, "PASSWORD": password }, "params": { "USERNAME": username }, "command": "[REGISTER]", "session": None, "route": { "group": "", "to": "server" }, "option": None }).encode("utf-8")) else: MessageBox( title="Error", message=str("Please fill both of password and username") ).show() except Exception as error: MessageBox( title="Error", message=str(error) ).show() btn_signup.clicked.connect(btn_register_clicked) self.frame_layout.addWidget(btn_signup) def _add_btn_register_account_(self): btn_goto_register_page = QPushButton("SignIn?") btn_goto_register_page.setAccessibleName(btn_goto_register_page_style[0]) btn_goto_register_page.setStyleSheet(btn_goto_register_page_style[1]) btn_goto_register_page.setContentsMargins(0, 0, 0, 0) def change_page_to_register(): self.set_visibility(False) self.signin_page.set_visibility(True) btn_goto_register_page.clicked.connect(change_page_to_register) self.frame_layout.addWidget(btn_goto_register_page) def set_visibility(self, visible: bool): if visible: self.show() else: self.hide() def set_sign_in_page(self, signin: object): self.signin_page = signin def notification(self, message): incoming_message = json_loads(message) if incoming_message["message"]["code"] == 200: User.create( username=self.username_edit_text.text(), password=self.password_edit_text.text() ) data = json_dumps({ "message": "", "command": "[LOGIN_INF]", "session": "", "option": { "sys_info": str(uname().system), "username": self.username_edit_text.text() }, "route": { "group": "", "to": "server" }, }) self.signal.emit(data) self.socket_server.get_socket.sendall(data.encode("utf-8")) from gui.windows.window_handler.main_window_handler.mainwindow import MainWindow main_window = MainWindow(self.parent, socket_server=self.socket_server) self.parent.hide() main_window.execute_app() @property def signal(self): return self._signal