def __init__(self, url, background_color, foreground_color): QWidget.__init__(self) self.setStyleSheet("background-color: transparent;") url = os.path.expanduser(url) self.file_name_font = QFont() self.file_name_font.setPointSize(24) self.file_name_label = QLabel() self.file_name_label.setText( "Your smartphone file will be shared at\n{0}".format(url)) self.file_name_label.setFont(self.file_name_font) self.file_name_label.setAlignment(Qt.AlignCenter) self.file_name_label.setStyleSheet( "color: {}".format(foreground_color)) self.qrcode_label = QLabel() self.notify_font = QFont() self.notify_font.setPointSize(12) self.notify_label = QLabel() self.notify_label.setText( "Scan the QR code above to upload a file from your smartphone.\nMake sure the smartphone is connected to the same WiFi network as this computer." ) self.notify_label.setFont(self.notify_font) self.notify_label.setAlignment(Qt.AlignCenter) self.notify_label.setStyleSheet("color: {}".format(foreground_color)) layout = QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.addStretch() layout.addWidget(self.qrcode_label, 0, Qt.AlignCenter) layout.addSpacing(20) layout.addWidget(self.file_name_label, 0, Qt.AlignCenter) layout.addSpacing(40) layout.addWidget(self.notify_label, 0, Qt.AlignCenter) layout.addStretch() self.port = get_free_port() self.local_ip = get_local_ip() self.address = "http://{0}:{1}".format(self.local_ip, self.port) self.qrcode_label.setPixmap( qrcode.make(self.address, image_factory=Image).pixmap()) tmp_db_file = os.path.join(tempfile.gettempdir(), "filebrowser.db") self.background_process = subprocess.Popen( "filebrowser --noauth -d {0} --address {1} -p {2}".format( tmp_db_file, self.local_ip, self.port), cwd=url, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
def start_server(self, filename): global local_file_path local_file_path = filename self.port = get_free_port() self.local_ip = get_local_ip() self.set_address("http://{0}:{1}/{2}".format(self.local_ip, self.port, filename)) self.sender_thread = threading.Thread(target=self.run_http_server, name='LoopThread') self.sender_thread.start()