Best Python code snippet using pyatom_python
main.py
Source:main.py
1import converter2import os3import sys4from filetype import FileType as FT5from PyQt5.QtCore import QSize6from PyQt5.QtWidgets import QFileDialog, QPlainTextEdit, QCheckBox, QMessageBox, QComboBox, QPushButton, QApplication, QMainWindow, QLabel, QWidget, QLineEdit7class MainWindow(QMainWindow):8 def __init__(self):9 QMainWindow.__init__(self)10 windowSize = QSize(320, 280)11 self.setMinimumSize(windowSize)12 self.setWindowTitle("Webp Converter")13 self.setFixedSize(windowSize)14 self.verifyCheck = False15 self.UiComponents()16 self.show()17 def UiComponents(self):18 self.directoryLabel = QLabel(self)19 self.directoryLabel.setText('Folder Directory:')20 self.directoryLabel.move(20, 10)21 # self.directorySelection = QFileDialog().getExistingDirectory(self, "Choose Directory")22 self.directoryLine = QLineEdit(self)23 self.directoryLine.textChanged.connect(24 self.verifyDirectory)25 self.directoryLine.move(20, 35)26 self.directoryLine.resize(220, 25)27 self.directoryButton = QPushButton('Folder...', self)28 self.directoryButton.move(240, 35)29 self.directoryButton.resize(60, 25)30 self.directoryButton.pressed.connect(self.dirButton)31 self.directoryStatusLabel = QLabel(self)32 self.directoryStatusLabel.move(20, 60)33 self.directoryStatusLabel.resize(280, 20)34 self.fileTypeSelection = QComboBox(self)35 self.fileTypeSelection.move(20, 85)36 self.fileTypeSelection.resize(280, 25)37 self.populateComboBox()38 self.deleteOption = QCheckBox("Delete after convert?", self)39 self.deleteOption.move(20, 107)40 self.deleteOption.resize(280, 32)41 self.convertLog = QPlainTextEdit(self)42 self.convertLog.setReadOnly(True)43 self.convertLog.move(20, 135)44 self.convertLog.resize(280, 100)45 self.startButton = QPushButton('Start', self)46 self.startButton.clicked.connect(self.startConversion)47 self.startButton.move(200, 240)48 self.startButton.resize(100, 32)49 self.startButton.setDisabled(True)50 def dirButton(self):51 dir = QFileDialog().getExistingDirectory(self, "Choose Directory")52 print(dir)53 self.directoryLine.setText(dir)54 def populateComboBox(self):55 for item in FT:56 self.fileTypeSelection.addItem(item.name)57 def toggleButton(self, value):58 self.startButton.setDisabled(not value)59 def verifyDirectory(self, text):60 if len(text) == 0:61 self.directoryStatusLabel.setText('')62 self.verifyCheck = False63 return64 try:65 files = converter.scanFiles(text)66 if len(files) > 0:67 self.verifyCheck = True68 self.directoryStatusLabel.setStyleSheet("color: black")69 self.directoryStatusLabel.setText(70 "Files Found: " + str(len(files)))71 else:72 self.verifyCheck = False73 self.directoryStatusLabel.setStyleSheet("color: red")74 self.directoryStatusLabel.setText("No files found")75 except Exception as e:76 self.verifyCheck = False77 self.directoryStatusLabel.setStyleSheet("color: red")78 self.directoryStatusLabel.setText("Error: Directory not found")79 self.toggleButton(self.verifyCheck)80 def startConversion(self):81 files = []82 if self.verifyCheck:83 files = self.findFiles()84 self.convertLog.insertPlainText(85 "Begining Conversion on " + self.directoryLine.text() + "\n")86 if self.deleteOption.isChecked():87 confirmBox = QMessageBox.question(self,88 'Delete Files?',89 'Do you want to delete files?',90 QMessageBox.Yes | QMessageBox.No,91 QMessageBox.No)92 if confirmBox == QMessageBox.Yes:93 for item in files:94 converter.convert(self.directoryLine.text(),95 item, FT[self.fileTypeSelection.currentText()])96 self.convertLog.insertPlainText(97 "Deleting " + item + "\n")98 converter.deleteFile(99 self.directoryLine.text(), item)100 self.convertLog.insertPlainText("Conversions Finished!\n")101 else:102 self.convertLog.insertPlainText(103 "Conversion cancelled...\n")104 else:105 newFolderMessage = QMessageBox()106 newFolderMessage.setWindowTitle("Files will be moved")107 newFolderMessage.setText(108 "Converted files will move to folder named WEBP within the directory.\nFolder will be made if none exist")109 newFolderMessage.exec_()110 files = self.findFiles()111 for item in files:112 self.convertLog.insertPlainText("Moving " + item + "\n")113 converter.convert(self.directoryLine.text(),114 item, FT[self.fileTypeSelection.currentText()])115 converter.moveFile(self.directoryLine.text(), item)116 self.convertLog.insertPlainText("Files Moved to " +117 self.directoryLine.text() + '/WEBP\n')118 self.convertLog.insertPlainText("Conversions Finished!\n")119 self.convertLog.verticalScrollBar().setValue(120 self.convertLog.verticalScrollBar().maximum())121 self.verifyCheck = False122 def findFiles(self):123 temp = []124 for filename in os.listdir(self.directoryLine.text()):125 if filename.endswith(".webp"):126 temp.append(filename)127 return temp128if __name__ == "__main__":129 app = QApplication(sys.argv)130 mainWin = MainWindow()...
client_side.py
Source:client_side.py
1from PyQt5.QtWidgets import QApplication, QMessageBox,QLabel2from PyQt5.uic import loadUi3import sys4import rpyc5from socket import socket6import json7import re8def register():9 username_checker = register_ui.username_field.text()10 email_checker = register_ui.email_field.text()11 pattern_user = '^[\w0-9]{4,}'12 pattern_email = '([a-zA-Z0-9][\w-.]{2,}@\w{2,}\.[a-zA-Z0-9-.]+$)'13 match_user = re.match(pattern_user, username_checker)14 match_email = re.match(pattern_email, email_checker)15 try:16 if match_user is None:17 label_username = QLabel18 error= "Username Invalid"19 register_ui.label_username.settext(error)20 register_ui.label_username.setStyleSheet('color:red')21 except:22 label_username = QLabel23 error = str('use another username')24 register_ui.label_username.settext(error)25 register_ui.label_username.setStyleSheet('color:red')26 try:27 if match_email is None:28 label_email = QLabel29 error='Email Invalid'30 register_ui.label_email.settext('Email Invalid')31 except:32 label_email = QLabel33 error = 'use Correct Email'34 register_ui.label_email.settext('use Correct Email')35 pass1 = register_ui.password1_field.text()36 pass2 = register_ui.password2_field.text()37 if pass1 == pass2 and match_user and match_email:38 username = username_checker39 email = email_checker40 result = services.register(username, email, pass1)41 if result:42 message = QMessageBox()43 message.setText('Registered successfully')44 message.setIcon(QMessageBox.Information)45 message.exec()46 register_ui.username_field.clear()47 register_ui.email_field.clear()48 register_ui.password1_field.clear()49 register_ui.password2_field.clear()50 register_ui.close()51 else:52 message = QMessageBox()53 message.setText('Error in registration, please try later')54 message.setIcon(QMessageBox.Warning)55 message.exec()56 else:57 message = QMessageBox()58 message.setText('passwords do not match')59 message.setIcon(QMessageBox.Warning)60 message.exec()61def login():62 username = login_ui.username_field.text()63 password = login_ui.password_field.text()64 result = services.login(username, password)65 if result:66 chat()67 login_ui.close()68 if result is None:69 message = QMessageBox()70 message.setText('user or pass is incorrect')71 message.setIcon(QMessageBox.Warning)72 message.exec()73 if result is False:74 verifycheck_ui.show()75 login_ui.password_field.clear()76def verify():77 username = login_ui.username_field.text()78 verify_code = verifycheck_ui.verify_check.text()79 result_check = services.verify(username , verify_code)80 if result_check:81 message = QMessageBox()82 message.setText('Verify Successfully Please Login Again')83 message.setIcon(QMessageBox.Information)84 message.exec()85 verifycheck_ui.close()86 else:87 message = QMessageBox()88 message.setText('verify code is not valid')89 message.setIcon(QMessageBox.Warning)90 message.exec()91 verifycheck_ui.verify_check.clear()92def chat():93 chat_ui.show()94 chat_ui.userlist_view.clear()95 lists = services.list_users()96 if lists:97 for row in lists:98 chat_ui.userlist_view.addItem(row[0])99 chat_ui.actionsign_out.triggered.connect(lambda: login_ui.show())100 chat_ui.actionsign_out.triggered.connect(lambda: chat_ui.close())101def message():102 message_sender = chat_ui.message_field.text()103 username_sender = login_ui.username_field.text()104 data = json.dumps({"username": username_sender, "message": message_sender})105 client_socket.send(data.encode())106 lists = services.message()107 if lists:108 data = client_socket.recv(4096)109 data = json.loads(data.decode())110 username_sender = data.get("username")111 message_sender = data.get("message")112 list = "%s : %s".format(username_sender,message_sender)113 chat_ui.chat_view.addItem(list)114 if lists is False:115 error = "Error"116 chat_ui.chat_view.clear()117 chat_ui.chat_view.addItem(error)118if __name__ == '__main__':119 app = QApplication(sys.argv)120 login_ui = loadUi('views/login.ui')121 register_ui = loadUi('views/register.ui')122 chat_ui = loadUi('views/chat-room.ui')123 verifycheck_ui = loadUi('views/verifycheck.ui')124 login_ui.register_btn.clicked.connect(lambda: register_ui.show())125 login_ui.login_btn.clicked.connect(login)126 register_ui.pushButton.clicked.connect(register)127 verifycheck_ui.verifycheck_btn.clicked.connect(verify)128 chat_ui.send_btn.clicked.connect(message)129 login_ui.show()130 client_socket = socket()131 client_socket.bind(('localhost', 1234))132 services = rpyc.connect('localhost', port=1234).root...
urls.py
Source:urls.py
1"""djangotaurus URL Configuration2The `urlpatterns` list routes URLs to views. For more information please see:3 https://docs.djangoproject.com/en/3.1/topics/http/urls/4Examples:5Function views6 1. Add an import: from my_app import views7 2. Add a URL to urlpatterns: path('', views.home, name='home')8Class-based views9 1. Add an import: from other_app.views import Home10 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')11Including another URLconf12 1. Import the include() function: from django.urls import include, path13 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))14"""15from django.contrib import admin16from django.urls import path,include17from django.contrib.staticfiles.urls import staticfiles_urlpatterns18from . import views19urlpatterns = [20 path('admin/', admin.site.urls),21 path('', views.home, name='index'),22 path('login/', views.login, name='login'),23 path('register/', views.register, name='register'),24 path('portfolio/', views.portfolio, name='portfolio'),25 path('portfolio/<int:user_id>', views.portfolio, name='portfolio-staff'),26 path('history/', views.history, name='history'),27 path('history/<int:user_id>', views.history, name='history-staff'),28 path('favourites/', views.favourites, name='favourites'),29 path('profile/', views.profile, name='profile'),30 path('changePassword/', views.changePassword, name='changePassword'),31 path('users/', views.users, name='users'),32 path('staffUserProfile/<int:user_id>', views.staffUserProfile, name='staffUserProfile'),33 path('logout/', views.logout, name='logout'),34 path('forgotPassword/', views.forgotPassword, name='forgotPassword'),35 path('verifyEmail/', views.verifyEmail, name='verifyEmail'),36 path('verifyCheck/<str:access_token>', views.verifyCheck, name='verifyCheck'),37 path('stockDetails/<int:stock_id>', views.stockDetails, name='stockDetails'),38 path('buyStock/', views.buyStock, name='buyStock'),39 path('sellStock/', views.sellStock, name='sellStock'),40 path('resetPassword/<str:access_token>', views.resetPassword, name='resetPassword'),41 path('otp/<str:next>', views.otp, name='otp'),42 path('error', views.error, name='error'),43 path('error<str:error_code>', views.error, name='error'),44 path('', include('pwa.urls'))45 46]...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!