def __init__(self): uil = QUiLoader() self.settingsDialog = uil.load(QFile(workingDir + "/settings.ui")) self.settingsDialog.group_account.button_authenticate.connect("clicked()", self.startAuthenticationProcess) self.settingsDialog.group_account.widget_loggedIn.button_logout.connect("clicked()", self.logOut) self.settingsDialog.group_name.input_name.connect("textChanged(QString)", self.nameFormatEdited) self.loadSettings()
def __init__(self, uistring, queue, endApplication, controller): self.controller = controller loader = QUiLoader() uifile = QFile(uistring) ui = loader.load(uifile) self.gui = ui width = ui.size.width() height = ui.size.height() uism = naali.ui # uiprops = r.createUiWidgetProperty(1) #1 is ModuleWidget, shown at toolbar # uiprops.SetMenuGroup(2) #2 is server tools group # uiprops.widget_name_ = "Local Scene" #uiprops.my_size_ = QSize(width, height) #not needed anymore, uimodule reads it #self.proxywidget = r.createUiProxyWidget(ui, uiprops) self.proxywidget = r.createUiProxyWidget(ui) #if not uism.AddProxyWidget(self.proxywidget): if not uism.AddWidgetToScene(self.proxywidget): r.logInfo("Adding the ProxyWidget to the bar failed.") # TODO: Due to core UI API refactor AddWidgetToMenu doesn't exist anymore. #uism.AddWidgetToMenu(self.proxywidget, "Local Scene", "Server Tools", "./data/ui/images/menus/edbutton_LSCENE_normal.png") self.inputQueue = queue self.endApplication = endApplication self.tableitems = [] pass
def showSettingsUI(self, parentWidget): self.settingsDialog = QUiLoader().load(QFile(workingDir + "/settings.ui"), parentWidget) # Inject the image title format. self.settingsDialog.group_upload.input_name.connect("textChanged(QString)", self.nameFormatEdited) self.settingsDialog.connect("accepted()", self.saveSettings) # Inject the upload stream self.settingsDialog.group_upload.input_stream.text = self.Stream # Inject default values. self.loadSettings() self.settingsDialog.group_upload.input_name.text = self.Format self.settingsDialog.group_account.input_username.text = self.Username self.settingsDialog.group_account.input_password.text = self.Password self.settingsDialog.group_clipboard.radio_direct.setChecked(not self.copyDirect) self.settingsDialog.group_clipboard.radio_nothing.setChecked(not self.copyNothing) # Wait for login/out button activation. self.settingsDialog.group_account.widget_loggedIn.connect("clicked()", self.Logout) self.settingsDialog.group_account.button_authenticate.connect("clicked()", self.Login) self.updateUi() self.settingsDialog.open()
def __init__(self, uistring, queue, endApplication, controller): self.controller = controller loader = QUiLoader() uifile = QFile(uistring) ui = loader.load(uifile) self.gui = ui width = ui.size.width() height = ui.size.height() uism = r.getUiSceneManager() # uiprops = r.createUiWidgetProperty(1) #1 is ModuleWidget, shown at toolbar # uiprops.SetMenuGroup(2) #2 is server tools group # uiprops.widget_name_ = "Local Scene" #uiprops.my_size_ = QSize(width, height) #not needed anymore, uimodule reads it #self.proxywidget = r.createUiProxyWidget(ui, uiprops) self.proxywidget = r.createUiProxyWidget(ui) #if not uism.AddProxyWidget(self.proxywidget): if not uism.AddWidgetToScene(self.proxywidget): r.logInfo("Adding the ProxyWidget to the bar failed.") uism.AddWidgetToMenu(self.proxywidget, "Local Scene", "Server Tools", "./data/ui/images/menus/edbutton_LSCENE_normal.png") self.inputQueue = queue self.endApplication = endApplication self.tableitems = [] pass
def __init__(self): paramiko.util.log_to_file(QDesktopServices.storageLocation(QDesktopServices.HomeLocation) + "/screencloud-sftp.log") uil = QUiLoader() self.settingsDialog = uil.load(QFile(workingDir + "/settings.ui")) self.settingsDialog.group_server.combo_auth.connect("currentIndexChanged(QString)", self.authMethodChanged) self.settingsDialog.group_server.button_browse.connect("clicked()", self.browseForKeyfile) self.settingsDialog.group_location.input_name.connect("textChanged(QString)", self.nameFormatEdited) self.loadSettings() self.updateUi()
def __init__(self): try: tempLocation = QDesktopServices.storageLocation(QDesktopServices.TempLocation) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tempLocation = QStandardPaths.writableLocation(QStandardPaths.TempLocation) self.uil = QUiLoader() self.loadSettings()
def __init__(self): try: tempLocation = QDesktopServices.storageLocation( QDesktopServices.TempLocation) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tempLocation = QStandardPaths.writableLocation( QStandardPaths.TempLocation) #paramiko.util.log_to_file(tempLocation + "/screencloud-sftp.log") self.uil = QUiLoader() self.loadSettings()
def __init__(self): self.sels = [] Component.__init__(self) self.window = window.ObjectEditWindow(self) self.resetValues() self.worldstream = r.getServerConnection() self.mouse_events = { #r.LeftMouseClickPressed: self.LeftMousePressed, r.InWorldClick: self.LeftMousePressed, r.LeftMouseClickReleased: self.LeftMouseReleased, r.RightMouseClickPressed: self.RightMousePressed, r.RightMouseClickReleased: self.RightMouseReleased } self.shortcuts = { #r.PyObjectEditDeselect: self.deselect, r.PyObjectEditToggleMove: self.window.manipulator_move, #"ALT+M", #move r.PyObjectEditToggleScale: self.window.manipulator_scale, #"ALT+S" #, #scale r.Delete: self.deleteObject, r.Undo: self.undo, r.PyDuplicateDrag: self.duplicateStart, r.ObjectLink: self.linkObjects, r.ObjectUnlink: self.unlinkObjects, } self.resetManipulators() loader = QUiLoader() selectionfile = QFile(self.SELECTIONRECT) self.selection_rect = loader.load(selectionfile) rectprops = r.createUiWidgetProperty(2) #~ print type(rectprops), dir(rectprops) #print rectprops.WidgetType #uiprops.widget_name_ = "Selection Rect" #uiprops.my_size_ = QSize(width, height) #not needed anymore, uimodule reads it proxy = r.createUiProxyWidget(self.selection_rect, rectprops) uism = r.getUiSceneManager() uism.AddProxyWidget(proxy) proxy.setWindowFlags(0) #changing it to Qt::Widget self.selection_rect.setGeometry(0, 0, 0, 0) self.selection_rect_startpos = None r.c = self #this is for using objectedit from command.py
def __init__(self): self.uil = QUiLoader() self.loadSettings() self.clientID, self.clientSecret = '417133363442-dtm48svvid8ntj6locavdvdt3e982n6k.apps.googleusercontent.com', 'UmzBQInps-09e6VNbnsRT0BG' if self.accessToken and self.refreshToken: credentials = client.GoogleCredentials( self.accessToken, self.clientID, self.clientSecret, self.refreshToken, None, "https://accounts.google.com/o/oauth2/token", 'ScreenCloudGoogleDrivePlugin/1.3') self.driveService = build('drive', 'v3', http=credentials.authorize(Http()))
class ShellUploader(): def __init__(self): self.uil = QUiLoader() def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.connect("accepted()", self.saveSettings) self.loadSettings() self.settingsDialog.group_shell.input_command.text = self.commandFormat self.settingsDialog.open() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("shell") self.commandFormat = settings.value("command", "") settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("shell") settings.setValue("command", self.settingsDialog.group_shell.input_command.text) settings.endGroup() settings.endGroup() def isConfigured(self): self.loadSettings() if not self.commandFormat: return False return True def getFilename(self): timestamp = time.time() return ScreenCloud.formatFilename(str(timestamp)) def upload(self, screenshot, name): self.loadSettings() tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + name screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) command = string.Formatter().vformat(self.commandFormat, (), defaultdict(str, s = tmpFilename)) try: command = command.encode(sys.getfilesystemencoding()) except UnicodeEncodeError: ScreenCloud.setError("Invalid characters in command '" + command + "'") return False try: p = subprocess.Popen(command.split()) p.wait() if p.returncode > 0: ScreenCloud.setError("Command " + command + " did not return 0") return False except OSError: ScreenCloud.setError("Failed to run command " + command) return False return True
def __init__(self): self.sels = [] Component.__init__(self) self.window = window.ObjectEditWindow(self) self.resetValues() self.worldstream = r.getServerConnection() self.mouse_events = { #r.LeftMouseClickPressed: self.LeftMousePressed, r.InWorldClick: self.LeftMousePressed, r.LeftMouseClickReleased: self.LeftMouseReleased, r.RightMouseClickPressed: self.RightMousePressed, r.RightMouseClickReleased: self.RightMouseReleased } self.shortcuts = { #r.PyObjectEditDeselect: self.deselect, r.PyObjectEditToggleMove: self.window.manipulator_move,#"ALT+M", #move r.PyObjectEditToggleScale: self.window.manipulator_scale,#"ALT+S" #, #scale r.Delete: self.deleteObject, r.Undo: self.undo, r.PyDuplicateDrag: self.duplicateStart, r.ObjectLink: self.linkObjects, r.ObjectUnlink: self.unlinkObjects, } self.resetManipulators() loader = QUiLoader() selectionfile = QFile(self.SELECTIONRECT) self.selection_rect = loader.load(selectionfile) rectprops = r.createUiWidgetProperty(2) #~ print type(rectprops), dir(rectprops) #print rectprops.WidgetType #uiprops.widget_name_ = "Selection Rect" #uiprops.my_size_ = QSize(width, height) #not needed anymore, uimodule reads it proxy = r.createUiProxyWidget(self.selection_rect, rectprops) uism = r.getUiSceneManager() uism.AddProxyWidget(proxy) proxy.setWindowFlags(0) #changing it to Qt::Widget self.selection_rect.setGeometry(0,0,0,0) self.selection_rect_startpos = None r.c = self #this is for using objectedit from command.py
class SCUploader(): def __init__(self): self.uil = QUiLoader() self.loadSettings() def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.connect("accepted()", self.saveSettings) self.loadSettings() self.settingsDialog.group_url.input_address.text = self.url_address self.settingsDialog.open() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("scuploader") self.url_address = settings.value("url-address", "http://s.876974.ru/upload") settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("scuploader") settings.setValue("url-address", self.settingsDialog.group_url.input_address.text) settings.endGroup() settings.endGroup() def isConfigured(self): self.loadSettings() return not(not self.url_address) def getFilename(self): return time.time() def upload(self, screenshot, name): self.loadSettings() url = self.url_address if not url.startswith('http'): ScreenCloud.setError('Invalid url!') return False timestamp = time.time() tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) reply = requests.post(url, files={'image': open(tmpFilename, 'rb')} ).json() try: ScreenCloud.setUrl(reply['href']) except Exception as e: ScreenCloud.setError("Could not upload to: " + self.url_address + "\nError: " + e.message) return False return True
def __init__(self): Component.__init__(self) loader = QUiLoader() uism = r.getUiSceneManager() uifile = QFile(UIFILELOC) self.widget = loader.load(uifile) uism.SetDemoLoginWidget(self.widget) def make_worldlogin(w): def worldlogin(): self.login(w) return worldlogin for w in self.WORLDS: but = getattr(self.widget, w.butname) but.connect('clicked()', make_worldlogin(w))
def __init__(self): self.uil = QUiLoader() self.loadSettings() http_provider = onedrivesdk.HttpProvider() auth_provider = onedrivesdk.AuthProvider(http_provider=http_provider, client_id=CLIENT_ID, scopes=SCOPES, session_type=QSettingsSession) try: auth_provider.load_session() self.loggedIn = True except: self.loggedIn = False self.client = onedrivesdk.OneDriveClient(API_BASE_URL, auth_provider, http_provider)
class ZapierUploader(): def __init__(self): self.uil = QUiLoader() self.loadSettings() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("zapier") self.zapier_url = settings.value("url", "") settings.endGroup() settings.endGroup() def saveSettings(self): self.zapier_url = self.settingsDialog.group_url.widget_url.input_url.text settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("zapier") settings.setValue("url", self.zapier_url) settings.endGroup() settings.endGroup() def isConfigured(self): return bool(self.zapier_url.strip()) def getFilename(self): return ScreenCloud.formatFilename("screenshot") def showSettingsUI(self, parentWidget): self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.connect("accepted()", self.saveSettings) self.settingsDialog.setWindowTitle("Zapier settings"); self.settingsDialog.group_url.widget_url.input_url.setText(self.zapier_url) self.settingsDialog.adjustSize() self.settingsDialog.open() def upload(self, screenshot, name): ba = QByteArray() buf = QBuffer(ba) buf.open(QIODevice.WriteOnly) screenshot.save( buf, ScreenCloud.getScreenshotFormat() ) #writes image into ba buf.close() json_data = json.dumps({'image': ba.toBase64().data()}) request = urllib2.Request(self.zapier_url, json_data, {"Content-Type": "application/json"}) try: reply = urllib2.urlopen(request) except Exception as e: ScreenCloud.setError("Could not upload to: "+ self.zapier_url + "\n" + e.message) return False try: replyText = reply.read() ScreenCloud.setUrl(json.loads(replyText).link) except Exception as e: ScreenCloud.setError("Could not upload to: "+ self.zapier_url + "\n" + e.message) return False return True
def __init__(self): try: tempLocation = QDesktopServices.storageLocation(QDesktopServices.TempLocation) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tempLocation = QStandardPaths.writableLocation(QStandardPaths.TempLocation) paramiko.util.log_to_file(tempLocation + "/screencloud-sftp.log") self.uil = QUiLoader() self.loadSettings()
def createWidget(self, clsname, parent=None, name=''): if parent is None: return self.main else: if self.extraWidgets: for w in self.extraWidgets: if w.__name__ == clsname: obj = w(parent) obj.setObjectName(name) return obj return QUiLoader.createWidget(self, clsname, parent, name)
class ZapierUploader(): def __init__(self): self.uil = QUiLoader() self.loadSettings() def isConfigured(self): self.loadSettings() return bool(self.zapier_url.strip()) def getFilename(self): return ScreenCloud.formatFilename("screenshot") def showSettingsUI(self, parentWidget): self.parent_widget = parentWidget self.settings_widget = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settings_widget.connect("accepted()", self.saveSettings) self.settings_widget.setWindowTitle("Zapier settings") self.settings_widget.group_url.widget_url.input_url.setText(self.zapier_url) self.settings_widget.adjustSize() self.settings_widget.open() def upload(self, screenshot, name): q_byte_array = QByteArray() q_buffer = QBuffer(q_byte_array) q_buffer.open(QIODevice.WriteOnly) screenshot.save(q_buffer, ScreenCloud.getScreenshotFormat()) # writes image to byte array q_buffer.close() json_data = json.dumps({'image': str(q_byte_array.toBase64())}) #f = open('/tmp/zapier', 'w') #f.write("{}\n{}\n\n".format(self.zapier_url, json_data)) #f.close() response = requests.post(url=self.zapier_url, data=json_data, headers={'Content-Type': 'application/json'}) try: response.raise_for_status() except Exception as e: ScreenCloud.setError("Could not upload to: " + self.zapier_url + "\n" + e.message) return False try: ScreenCloud.setUrl(response.json()['link']) except Exception as e: ScreenCloud.setError("Upload to {} worked, but response was invalid: {}\n{}".format(self.zapier_url, response.content, e.message)) return False return True def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("zapier") self.zapier_url = settings.value("url", "") settings.endGroup() settings.endGroup() def saveSettings(self): self.zapier_url = self.settings_widget.group_url.widget_url.input_url.text settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("zapier") settings.setValue("url", self.zapier_url) settings.endGroup() settings.endGroup()
class GoogleDriveUploader(): def __init__(self): self.uil = QUiLoader() self.loadSettings() self.clientID, self.clientSecret = '417133363442-dtm48svvid8ntj6locavdvdt3e982n6k.apps.googleusercontent.com', 'UmzBQInps-09e6VNbnsRT0BG' if self.accessToken and self.refreshToken: credentials = client.GoogleCredentials( self.accessToken, self.clientID, self.clientSecret, self.refreshToken, None, "https://accounts.google.com/o/oauth2/token", 'ScreenCloudGoogleDrivePlugin/1.3') self.driveService = build('drive', 'v3', http=credentials.authorize(Http())) def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.group_account.widget_authorize.button_authenticate.connect( "clicked()", self.startAuthenticationProcess) self.settingsDialog.group_account.widget_loggedIn.button_logout.connect( "clicked()", self.logout) self.settingsDialog.group_name.input_nameFormat.connect( "textChanged(QString)", self.nameFormatEdited) self.settingsDialog.connect("accepted()", self.saveSettings) self.loadSettings() self.updateUi() self.settingsDialog.open() def updateUi(self): self.loadSettings() if not self.accessToken or not self.refreshToken: self.settingsDialog.group_account.widget_loggedIn.setVisible(False) self.settingsDialog.group_account.widget_authorize.setVisible(True) self.settingsDialog.group_account.widget_authorize.button_authenticate.setEnabled( True) self.settingsDialog.group_name.setEnabled(False) self.settingsDialog.group_folder.setEnabled(False) self.settingsDialog.group_clipboard.setEnabled(False) else: self.settingsDialog.group_account.widget_loggedIn.setVisible(True) self.settingsDialog.group_account.widget_authorize.setVisible( False) self.settingsDialog.group_account.widget_loggedIn.label_user.setText( self.displayName) self.settingsDialog.group_name.setEnabled(True) self.settingsDialog.group_folder.setEnabled(True) self.settingsDialog.group_clipboard.setEnabled(True) self.settingsDialog.group_clipboard.radio_publiclink.setChecked( self.copyLink) self.settingsDialog.group_clipboard.radio_dontcopy.setChecked( not self.copyLink) self.settingsDialog.group_name.input_nameFormat.setText( self.nameFormat) self.settingsDialog.adjustSize() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("googledrive") self.accessToken = settings.value("access-token", "") self.refreshToken = settings.value("refresh-token", "") self.displayName = settings.value("display-name", "") self.copyLink = settings.value("copy-link", "true") in ['true', True] self.nameFormat = settings.value("name-format", "Screenshot at %H-%M-%S") self.folderName = settings.value("folder-name", "ScreenCloud") settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("googledrive") settings.setValue("access-token", self.accessToken) settings.setValue("refresh-token", self.refreshToken) settings.setValue("display-name", self.displayName) settings.setValue( "copy-link", self.settingsDialog.group_clipboard.radio_publiclink.checked) settings.setValue("name-format", self.settingsDialog.group_name.input_nameFormat.text) settings.setValue( "folder-name", self.settingsDialog.group_folder.input_folderName.text) settings.endGroup() settings.endGroup() def isConfigured(self): self.loadSettings() if not self.accessToken or not self.refreshToken: return False return True def getFilename(self): self.loadSettings() return ScreenCloud.formatFilename(self.nameFormat) def upload(self, screenshot, name): self.loadSettings() #Save to memory buffer ba = QByteArray() buf = QBuffer(ba) buf.open(QIODevice.ReadWrite) screenshot.save(buf, ScreenCloud.getScreenshotFormat()) #Create folder if not exists folders = self.driveService.files().list( q="name='%s' and mimeType='application/vnd.google-apps.folder' and trashed=false" % (self.folderName)).execute()["files"] exists = len(folders) > 0 if not exists: folderMetadata = { 'name': self.folderName, 'mimeType': 'application/vnd.google-apps.folder' } folder = self.driveService.files().create(body=folderMetadata, fields='id').execute() else: folder = folders[0] #Upload fileMetadata = {'name': name, 'parents': [folder["id"]]} media = MediaInMemoryUpload(ba.data(), mimetype='image/' + ScreenCloud.getScreenshotFormat()) file = self.driveService.files().create( body=fileMetadata, media_body=media, fields='webViewLink, id').execute() if self.copyLink: webViewLink = file.get('webViewLink') ScreenCloud.setUrl(webViewLink) return True def startAuthenticationProcess(self): self.settingsDialog.group_account.widget_authorize.button_authenticate.setEnabled( False) self.flow = client.OAuth2WebServerFlow( client_id=self.clientID, client_secret=self.clientSecret, scope=SCOPES, redirect_uri="urn:ietf:wg:oauth:2.0:oob") authorize_url = QUrl(self.flow.step1_get_authorize_url()) QDesktopServices.openUrl(authorize_url) try: code = raw_input( "Enter the authorization code from the Google Drive website:") except NameError: code = input( "Enter the authorization code from the Google Drive website:") if code: try: oauth2_result = self.flow.step2_exchange(code) self.accessToken = oauth2_result.access_token self.refreshToken = oauth2_result.refresh_token self.driveService = build('drive', 'v3', http=oauth2_result.authorize(Http())) account = self.driveService.about().get( fields="user").execute() self.displayName = account["user"]["displayName"] except client.Error: if "win" in sys.platform: #Workaround for crash on windows self.parentWidget.hide() self.settingsDialog.hide() QMessageBox.critical( self.settingsDialog, "Failed to authenticate", "Failed to authenticate with Google Drive. Wrong code?") if "win" in sys.platform: self.settingsDialog.show() self.parentWidget.show() self.saveSettings() self.updateUi() def logout(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("googledrive") settings.remove("access-token") settings.remove("refresh-token") settings.remove("user-id") settings.remove("display-name") settings.endGroup() settings.endGroup() self.loadSettings() self.updateUi() def nameFormatEdited(self, nameFormat): self.settingsDialog.group_name.label_example.setText( ScreenCloud.formatFilename(nameFormat))
def __init__(self): uil = QUiLoader() self.settingsDialog = uil.load(QFile(workingDir + "/settings.ui")) self.settingsDialog.group_location.input_name.connect("textChanged(QString)", self.nameFormatEdited)
#print dir(box.treeWidget) if 0: box = r.c.widget #print box, dir(box.treeWidget) text = box.treeWidget.currentItem().text(0) print text print type(text), r.c.widgetList print r.c.widgetList[720010] if 0: #QtUI::UICanvas::External ?! not here... from PythonQt.QtUiTools import QUiLoader from PythonQt.QtCore import QFile, QIODevice #print dir(quil) #print dir(PythonQt.QtCore.QIODevice) loader = QUiLoader() canvas = r.createCanvas(0) file = QFile("pymodules/usr/editobject.ui") iodev = QIODevice(file) widget = loader.load(file) canvas.AddWidget(widget) canvas.Show() if 0: #collada load testing import collada print collada.Collada try: pycollada_test except:
class YASCPUploader(): def __init__(self): self.uil = QUiLoader() self.loadSettings() def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.connect("accepted()", self.saveSettings) self.loadSettings() self.settingsDialog.group_server.combo_type.setCurrentIndex(self.settingsDialog.group_server.combo_type.findText(self.type)) self.settingsDialog.group_server.input_username.text = self.username self.settingsDialog.group_server.input_password.text = self.password self.settingsDialog.group_server.input_host.text = self.host self.settingsDialog.group_server.input_port.text = self.port self.settingsDialog.group_upload.input_url.text = self.url self.settingsDialog.group_upload.input_path.text = self.path self.settingsDialog.open() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("yascp") self.type = settings.value("type", "SFTP") self.username = settings.value("username", "") self.password = settings.value("password", "") self.host = settings.value("host", "") if self.type == "FTP": port = 21 elif self.type == "SFTP": port = 22 self.port = int(settings.value("port", port)) self.url = settings.value("url", "") self.path = settings.value("path", "") settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("yascp") settings.setValue("type", self.settingsDialog.group_server.combo_type.currentText) settings.setValue("username", self.settingsDialog.group_server.input_username.text) settings.setValue("password", self.settingsDialog.group_server.input_password.text) settings.setValue("host", self.settingsDialog.group_server.input_host.text) settings.setValue("port", self.settingsDialog.group_server.input_port.text) settings.setValue("url", self.settingsDialog.group_upload.input_url.text) settings.setValue("path", self.settingsDialog.group_upload.input_path.text) settings.endGroup() settings.endGroup() def isConfigured(self): self.loadSettings() return not(not self.username or not self.password or not self.host or not self.port or not self.url or not self.path or not self.type) def getFilename(self): self.loadSettings() name = uuid.uuid4().hex return ScreenCloud.formatFilename(name[:16]) def upload(self, screenshot, name): self.loadSettings() f = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(name) screenshot.save(QFile(f), ScreenCloud.getScreenshotFormat()) now = datetime.datetime.now() date = "/%s/%02d/%02d" % (now.year, now.month, now.day) path = "/%s/%02d/%02d/%s" % (now.year, now.month, now.day, ScreenCloud.formatFilename(name)) if self.type == "SFTP": transport = paramiko.Transport((self.host, self.port)) transport.connect(username = self.username, password = self.password) sftp = paramiko.SFTPClient.from_transport(transport) try: sftp.chdir(os.path.normpath(self.path) + date) except IOError: sftp.mkdir(os.path.normpath(self.path) + date) try: sftp.put(f, os.path.normpath(self.path) + path) except IOError: ScreenCloud.setError("Failed to write file") sftp.close() transport.close() elif self.type == "FTP": ftp = ftplib.FTP() ftp.connect(self.host, self.port) ftp.login(self.username, self.password) if os.path.normpath(self.path) in ftp.nlst(): try: ftp.cwd(os.path.normpath(self.path)) except ftplib.error_perm as err: ScreenCloud.setError(err.message) return False year = "%02d" % now.year month = "%02d" % now.month day = "%02d" % now.day if year in ftp.nlst(): ftp.cwd(year) else: ftp.mkd(year) ftp.cwd(year) if month in ftp.nlst(): ftp.cwd(month) else: ftp.mkd(month) ftp.cwd(month) if day in ftp.nlst(): ftp.cwd(day) else: ftp.mkd(day) ftp.cwd(day) #borrowed from screencloud ftp plugin fs = open(f, 'rb') try: ftp.storbinary('STOR ' + name, fs) except ftplib.error_perm as err: ScreenCloud.setError(err.message) return False ftp.quit() fs.close() url = "%s%s/%s/%s/%s" % (self.url, now.year, now.month, now.day, ScreenCloud.formatFilename(name)) ScreenCloud.setUrl(self.url.strip("/") + path) return True
class OneDriveUploader(): def __init__(self): self.uil = QUiLoader() self.loadSettings() http_provider = onedrivesdk.HttpProvider() auth_provider = onedrivesdk.AuthProvider(http_provider=http_provider, client_id=CLIENT_ID, scopes=SCOPES, session_type=QSettingsSession) try: auth_provider.load_session() self.loggedIn = True except: self.loggedIn = False self.client = onedrivesdk.OneDriveClient(API_BASE_URL, auth_provider, http_provider) def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.group_account.widget_authorize.button_authenticate.connect( "clicked()", self.startAuthenticationProcess) self.settingsDialog.group_account.widget_loggedIn.button_logout.connect( "clicked()", self.logout) self.settingsDialog.group_name.input_nameFormat.connect( "textChanged(QString)", self.nameFormatEdited) self.settingsDialog.connect("accepted()", self.saveSettings) self.loadSettings() self.updateUi() self.settingsDialog.open() def updateUi(self): self.loadSettings() if not self.loggedIn: self.settingsDialog.group_account.widget_loggedIn.setVisible(False) self.settingsDialog.group_account.widget_authorize.setVisible(True) self.settingsDialog.group_account.widget_authorize.button_authenticate.setEnabled( True) self.settingsDialog.group_name.setEnabled(False) self.settingsDialog.group_clipboard.setEnabled(False) else: self.settingsDialog.group_account.widget_loggedIn.setVisible(True) self.settingsDialog.group_account.widget_authorize.setVisible( False) self.settingsDialog.group_account.widget_loggedIn.label_user.setText( self.displayName) self.settingsDialog.group_name.setEnabled(True) self.settingsDialog.group_clipboard.setEnabled(True) self.settingsDialog.group_clipboard.radio_publiclink.setChecked( self.copyLink) self.settingsDialog.group_clipboard.radio_dontcopy.setChecked( not self.copyLink) self.settingsDialog.group_name.input_nameFormat.setText( self.nameFormat) self.settingsDialog.adjustSize() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("onedrive") self.displayName = settings.value("display-name", "") self.copyLink = settings.value("copy-link", "true") in ['true', True] self.nameFormat = settings.value("name-format", "Screenshot at %H-%M-%S") settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("onedrive") settings.setValue("display-name", self.displayName) settings.setValue( "copy-link", self.settingsDialog.group_clipboard.radio_publiclink.checked) settings.setValue("name-format", self.settingsDialog.group_name.input_nameFormat.text) settings.endGroup() settings.endGroup() self.client.auth_provider.save_session() def isConfigured(self): self.loadSettings() return self.loggedIn def getFilename(self): self.loadSettings() return ScreenCloud.formatFilename(self.nameFormat) def upload(self, screenshot, name): self.loadSettings() if self.loggedIn: self.client.auth_provider.refresh_token() #Save to temporary file timestamp = time.time() try: tmpFilename = QDesktopServices.storageLocation( QDesktopServices.TempLocation ) + "/" + ScreenCloud.formatFilename(str(timestamp)) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation( QStandardPaths.TempLocation ) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) #Workaround to get id of app folder import requests, json endpoint = "https://api.onedrive.com/v1.0/drives/me/special/approot" headers = { "Authorization": "Bearer " + self.client.auth_provider.access_token } response = requests.get(endpoint, headers=headers).json() appfolder_id = response["id"] #Upload uploaded_item = self.client.item(drive='me', id=appfolder_id).children[ ScreenCloud.formatFilename(name)].upload(tmpFilename) print(uploaded_item, " ".join(dir(uploaded_item)), str(uploaded_item), uploaded_item.id, uploaded_item.image) if self.copyLink: permission = self.client.item( id=uploaded_item.id).create_link("view").post() ScreenCloud.setUrl(permission.link.web_url) return True def startAuthenticationProcess(self): self.settingsDialog.group_account.widget_authorize.button_authenticate.setEnabled( False) authorize_url = QUrl( self.client.auth_provider.get_auth_url(REDIRECT_URI)) QDesktopServices.openUrl(authorize_url) try: code = raw_input( "Copy everything in the address bar after \"code=\", and paste it below:" ) except NameError: code = input( "Copy everything in the address bar after \"code=\", and paste it below:" ) if code: try: self.client.auth_provider.authenticate(code, REDIRECT_URI, None) except: if "win" in sys.platform: #Workaround for crash on windows self.parentWidget.hide() self.settingsDialog.hide() QMessageBox.critical( self.settingsDialog, "Failed to authenticate", "Failed to authenticate with OneDrive. Wrong code?") if "win" in sys.platform: self.settingsDialog.show() self.parentWidget.show() #Set display name self.displayName = self.client.drive.get().owner.user.display_name self.loggedIn = True self.saveSettings() self.updateUi() def logout(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("onedrive") settings.beginGroup("session") settings.remove("") settings.endGroup() settings.endGroup() settings.endGroup() self.loggedIn = False self.loadSettings() self.updateUi() def nameFormatEdited(self, nameFormat): self.settingsDialog.group_name.label_example.setText( ScreenCloud.formatFilename(nameFormat))
def __init__(self, controller, queue): loader = QUiLoader() loader.setLanguageChangeEnabled(True) #uifile = QFile("pymodules/estatemanagement/estatemanagement.ui") uifile = QFile(EstateManagementWindow.UIFILE) self.gui = loader.load(uifile) self.controller = controller IncomingMessagesHandler.__init__(self, queue, self.endMethod) uism = r.getUiSceneManager() # uiprops = r.createUiWidgetProperty(1) # 1 = Qt::Dialog # uiprops.SetMenuGroup("Server Tools") # uiprops.name_ = "Estate Management" self.proxywidget = r.createUiProxyWidget(self.gui) self.proxywidget.setWindowTitle("Estate Management") if not uism.AddWidgetToScene(self.proxywidget): r.logInfo("Adding ProxyWidget failed.") uism.AddWidgetToMenu( self.proxywidget, "Estate Management", "Server Tools", "./data/ui/images/menus/edbutton_ESMNG_normal.png") self.btnLoadEstate = self.gui.findChild("QPushButton", "btnLoadEstate") self.listWEI = self.gui.findChild("QListWidget", "listWidgetEstateInfo") self.listWRU = self.gui.findChild("QListWidget", "listWidgetRegionUsers") self.listWEB = self.gui.findChild("QListWidget", "listWidgetBanList") self.listWAL = self.gui.findChild("QListWidget", "listWidgetAccessList") self.listWEM = self.gui.findChild("QListWidget", "listWidgetEstateManagers") self.listWSU = self.gui.findChild("QListWidget", "listWidgetSavedUsers") self.labelEstateInfo = self.gui.findChild("QLabel", "labelEstateInfo") self.tableEstates = self.gui.findChild("QListWidget", "tableWidgetEstates") self.chkEstateAccess = self.gui.findChild("QCheckBox", "checkBoxEstateAccess") self.lineCurrentEstate = self.gui.findChild("QLineEdit", "lineEditCurrentEstate") self.listWidgetEstates = self.gui.findChild("QListWidget", "listWidgetEstates") self.btnSetEstate = self.gui.findChild("QPushButton", "pushButtonSetEstate") self.chkSunFixed = self.gui.findChild("QCheckBox", "checkBoxSunFixed") # PublicAllowed # ExternallyVisible); self.chkAllowVoice = self.gui.findChild("QCheckBox", "checkBoxAllowVoice") self.chkAllowDirectTeleport = self.gui.findChild( "QCheckBox", "checkBoxAllowDirectTeleport") self.chkDenyAnonymous = self.gui.findChild("QCheckBox", "checkBoxDenyAnonymous") self.chkDenyIdentified = self.gui.findChild("QCheckBox", "checkBoxDenyIdentified") self.chkDenyTransacted = self.gui.findChild("QCheckBox", "checkBoxDenyTransacted") self.chkAbuseEmailToEstateOwner = self.gui.findChild( "QCheckBox", "checkBoxAbuseEmailToEstateOwner") self.chkBlockDwell = self.gui.findChild("QCheckBox", "checkBoxBlockDwell") self.chkEstateSkipScripts = self.gui.findChild( "QCheckBox", "checkBoxEstateSkipScripts") self.chkResetHomeOnTeleport = self.gui.findChild( "QCheckBox", "checkBoxResetHomeOnTeleport") self.chkTaxFree = self.gui.findChild("QCheckBox", "checkBoxTaxFree") self.chkDenyAgeUnverified = self.gui.findChild( "QCheckBox", "checkBoxDenyAgeUnverified") self.btnLoadEstate.connect("clicked(bool)", self.btnLoadEstateClicked) self.btnToBan = self.gui.findChild("QPushButton", "pushButtonToBan") self.btnToAccess = self.gui.findChild("QPushButton", "pushButtonToAccess") self.btnToManagers = self.gui.findChild("QPushButton", "pushButtonToManagers") self.btnSaveUserInfo = self.gui.findChild("QPushButton", "pushButtonSaveUserInfo") self.btnRemoveBan = self.gui.findChild("QPushButton", "pushButtonRemoveBan") self.btnRemoveAccess = self.gui.findChild("QPushButton", "pushButtonRemoveAccess") self.btnRemoveManagers = self.gui.findChild("QPushButton", "pushButtonRemoveManager") self.btnRemoveSaved = self.gui.findChild("QPushButton", "pushButtonRemoveSaved") self.btnSavedToAccess = self.gui.findChild("QPushButton", "pushButtonSavedToAccess") self.btnSavedToBan = self.gui.findChild("QPushButton", "pushButtonSavedToBan") self.btnSavedToManagers = self.gui.findChild( "QPushButton", "pushButtonSavedToManagers") self.btnKick = self.gui.findChild("QPushButton", "pushButtonKick") self.btnRequestGodLikePowers = self.gui.findChild( "QPushButton", "pushButtonRequestGodLikePowers") self.lineKickMessage = self.gui.findChild("QLineEdit", "lineEditKickMessage") self.btnToBan.connect("clicked(bool)", self.btnToBanClicked) self.btnToAccess.connect("clicked(bool)", self.btnToAccessClicked) self.btnToManagers.connect("clicked(bool)", self.btnToManagersClicked) self.btnSaveUserInfo.connect("clicked(bool)", self.btnSaveUserInfoClicked) self.btnRemoveBan.connect("clicked(bool)", self.btnRemoveBanClicked) self.btnRemoveAccess.connect("clicked(bool)", self.btnRemoveAccessClicked) self.btnRemoveManagers.connect("clicked(bool)", self.btnRemoveManagersClicked) self.btnRemoveSaved.connect("clicked(bool)", self.btnRemoveSavedClicked) self.btnSavedToAccess.connect("clicked(bool)", self.btnSavedToAccessClicked) self.btnSavedToBan.connect("clicked(bool)", self.btnSavedToBanClicked) self.btnSavedToManagers.connect("clicked(bool)", self.btnSavedToManagersClicked) self.btnRequestGodLikePowers.connect( "clicked(bool)", self.btnRequestGodLikePowersClicked) self.btnKick.connect("clicked(bool)", self.btnKickClicked) self.btnSetEstate.connect("clicked(bool)", self.btnSetEstateClicked) self.chkEstateAccess.connect("toggled(bool)", self.chkEstateAccessToggled) # add incoming event handlers self.addHandler('EstateUpdate', self.setEstateInfo) self.addHandler('setEstateManagers', self.setEstateManagers) self.addHandler('setEstateBans', self.setEstateBans) self.addHandler('setEsteteAccessList', self.setEsteteAccessList) self.addHandler('noCapability', self.noCapabilityInfoMessage) self.addHandler('estateSetting', self.handleEstateAccessSetting) self.addHandler('failedEstateSetting', self.handleEstateAccessFailure) self.addHandler('unknownResponse', self.handleEstateAccessFailure) self.addHandler('malformedResp', self.handleEstateAccessFailure) self.addHandler('currentEstateIdAndName', self.handleCurrentEstateIdAndName) self.addHandler('estates', self.handleEstates) self.addHandler('displayerror', self.handleDisplayError)
def __init__(self): self.uil = QUiLoader() self.loadSettings() if self.access_token: self.client = dropbox.client.DropboxClient(self.access_token)
class SFTPUploader(): def __init__(self): try: tempLocation = QDesktopServices.storageLocation(QDesktopServices.TempLocation) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tempLocation = QStandardPaths.writableLocation(QStandardPaths.TempLocation) self.uil = QUiLoader() self.loadSettings() def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.group_server.combo_auth.connect("currentIndexChanged(QString)", self.authMethodChanged) self.settingsDialog.group_server.button_browse.connect("clicked()", self.browseForKeyfile) self.settingsDialog.group_location.input_name.connect("textChanged(QString)", self.nameFormatEdited) self.settingsDialog.connect("accepted()", self.saveSettings) self.loadSettings() self.updateUi() self.settingsDialog.group_server.input_host.text = self.host self.settingsDialog.group_server.input_port.value = self.port self.settingsDialog.group_server.input_username.text = self.username self.settingsDialog.group_server.input_password.text = self.password self.settingsDialog.group_server.input_keyfile.text = self.keyfile self.settingsDialog.group_server.input_passphrase.text = self.passphrase self.settingsDialog.group_location.input_folder.text = self.folder self.settingsDialog.group_location.input_url.text = self.url self.settingsDialog.group_location.input_name.text = self.nameFormat self.settingsDialog.group_server.combo_auth.setCurrentIndex(self.settingsDialog.group_server.combo_auth.findText(self.authMethod)) self.settingsDialog.open() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("sftp") self.host = settings.value("host", "") self.port = int(settings.value("port", 22)) self.username = settings.value("username", "") self.password = settings.value("password", "") self.keyfile = settings.value("keyfile", "") self.passphrase = settings.value("passphrase", "") self.url = settings.value("url", "") self.folder = settings.value("folder", "") self.nameFormat = settings.value("name-format", "Screenshot at %H-%M-%S") self.authMethod = settings.value("auth-method", "Password") settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("sftp") settings.setValue("host", self.settingsDialog.group_server.input_host.text) settings.setValue("port", int(self.settingsDialog.group_server.input_port.value)) settings.setValue("username", self.settingsDialog.group_server.input_username.text) settings.setValue("password", self.settingsDialog.group_server.input_password.text) settings.setValue("keyfile", self.settingsDialog.group_server.input_keyfile.text) settings.setValue("passphrase", self.settingsDialog.group_server.input_passphrase.text) settings.setValue("url", self.settingsDialog.group_location.input_url.text) settings.setValue("folder", self.settingsDialog.group_location.input_folder.text) settings.setValue("name-format", self.settingsDialog.group_location.input_name.text) settings.setValue("auth-method", self.settingsDialog.group_server.combo_auth.currentText) settings.endGroup() settings.endGroup() def updateUi(self): self.settingsDialog.group_server.label_password.setVisible(self.authMethod == "Password") self.settingsDialog.group_server.input_password.setVisible(self.authMethod == "Password") self.settingsDialog.group_server.label_keyfile.setVisible(self.authMethod == "Key") self.settingsDialog.group_server.input_keyfile.setVisible(self.authMethod == "Key") self.settingsDialog.group_server.button_browse.setVisible(self.authMethod == "Key") self.settingsDialog.group_server.label_passphrase.setVisible(self.authMethod == "Key") self.settingsDialog.group_server.input_passphrase.setVisible(self.authMethod == "Key") self.settingsDialog.adjustSize() def isConfigured(self): self.loadSettings() return not(not self.host or not self.username or not (self.password or self.keyfile) or not self.folder) def getFilename(self): self.loadSettings() return ScreenCloud.formatFilename(self.nameFormat) def upload(self, screenshot, name): self.loadSettings() #Save to a temporary file timestamp = time.time() try: tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) #Connect to server try: sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((self.host, self.port)) session = Session() session.handshake(sock) except Exception as e: ScreenCloud.setError(e.message) return False if self.authMethod == "Password": try: session.userauth_password(self.username, self.password) except ssh2.exceptions.AuthenticationError: ScreenCloud.setError("Authentication failed (password)") return False else: try: session.userauth_publickey_fromfile(self.username, self.keyfile, passphrase=self.passphrase) except ssh2.exceptions.AuthenticationError: ScreenCloud.setError("Authentication failed (key)") return False except Exception as e: ScreenCloud.setError("Unknown error: " + e.message) return False sftp = session.sftp_init() mode = LIBSSH2_SFTP_S_IRUSR | \ LIBSSH2_SFTP_S_IWUSR | \ LIBSSH2_SFTP_S_IRGRP | \ LIBSSH2_SFTP_S_IROTH f_flags = LIBSSH2_FXF_CREAT | LIBSSH2_FXF_WRITE try: try: sftp.opendir(self.folder) except ssh2.exceptions.SFTPError: sftp.mkdir(self.folder, mode | LIBSSH2_SFTP_S_IXUSR) (filepath, filename) = os.path.split(ScreenCloud.formatFilename(name)) if len(filepath): for folder in filepath.split("/"): try: sftp.mkdir(folder) except IOError: pass source = tmpFilename destination = self.folder + "/" + ScreenCloud.formatFilename(filename) with open(source, 'rb') as local_fh, sftp.open(destination, f_flags, mode) as remote_fh: for data in local_fh: remote_fh.write(data) except IOError: ScreenCloud.setError("Failed to write " + self.folder + "/" + ScreenCloud.formatFilename(name) + ". Check permissions.") return False sock.close() if self.url: ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name)) return True def authMethodChanged(self, method): self.authMethod = method self.updateUi() def browseForKeyfile(self): filename = QFileDialog.getOpenFileName(self.settingsDialog, "Select Keyfile...", QDesktopServices.storageLocation(QDesktopServices.HomeLocation), "*") if filename: self.settingsDialog.group_server.input_keyfile.setText(filename) def nameFormatEdited(self, nameFormat): self.settingsDialog.group_location.label_example.setText(ScreenCloud.formatFilename(nameFormat))
class FTPUploader(): def __init__(self): self.uil = QUiLoader() def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.group_location.input_name.connect("textChanged(QString)", self.nameFormatEdited) self.settingsDialog.connect("accepted()", self.saveSettings) self.loadSettings() self.settingsDialog.group_server.input_host.text = self.host self.settingsDialog.group_server.input_port.value = self.port self.settingsDialog.group_server.input_username.text = self.username self.settingsDialog.group_server.input_password.text = self.password self.settingsDialog.group_server.input_url.text = self.url self.settingsDialog.group_location.input_folder.text = self.folder self.settingsDialog.group_location.input_name.text = self.nameFormat self.settingsDialog.open() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("ftp") self.host = settings.value("host", "") self.port = int(settings.value("port", 21)) self.username = settings.value("username", "") self.password = settings.value("password", "") self.url = settings.value("url", "") self.folder = settings.value("folder", "") self.nameFormat = settings.value("name-format", "Screenshot at %H-%M-%S") settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("ftp") settings.setValue("host", self.settingsDialog.group_server.input_host.text) settings.setValue("port", int(self.settingsDialog.group_server.input_port.value)) settings.setValue("username", self.settingsDialog.group_server.input_username.text) settings.setValue("password", self.settingsDialog.group_server.input_password.text) settings.setValue("url", self.settingsDialog.group_server.input_url.text) settings.setValue("folder", self.settingsDialog.group_location.input_folder.text) settings.setValue("name-format", self.settingsDialog.group_location.input_name.text) settings.endGroup() settings.endGroup() def isConfigured(self): self.loadSettings() return not(not self.host or not self.username or not self.password or not self.folder) def getFilename(self): self.loadSettings() return ScreenCloud.formatFilename(self.nameFormat) def upload(self, screenshot, name): self.loadSettings() timestamp = time.time() tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) ftp = ftplib.FTP() ftp.connect(self.host, self.port) ftp.login(self.username, self.password) f = open(tmpFilename, 'rb') try: ftp.cwd(self.folder) except ftplib.error_perm as err: ScreenCloud.setError(err.message) return False try: ftp.storbinary('STOR ' + name, f) except ftplib.error_perm as err: ScreenCloud.setError(err.message) return False ftp.quit() f.close() if self.url: ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name)) return True def nameFormatEdited(self, nameFormat): self.settingsDialog.group_location.label_example.setText(ScreenCloud.formatFilename(nameFormat))
class OwnCloudUploader(): def __init__(self): self.uil = QUiLoader() self.loadSettings() def updateUi(self): self.loadSettings() if self.connectStatus: self.settingsDialog.group_connection.widget_status.label_status.setText("Valid") else: self.settingsDialog.group_connection.widget_status.label_status.setText("Unknown") self.settingsDialog.group_name.input_name.setText(self.nameFormat) self.settingsDialog.adjustSize() def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.group_connection.button_authenticate.connect("clicked()", self.startAuthenticationProcess) self.settingsDialog.group_name.input_name.connect("textChanged(QString)", self.nameFormatEdited) self.settingsDialog.connect("accepted()", self.saveSettings) self.loadSettings() self.settingsDialog.group_account.input_url.text = self.url self.settingsDialog.group_account.input_username.text = self.username self.settingsDialog.group_account.input_password.text = self.password self.settingsDialog.group_name.input_path.text = self.remotePath self.settingsDialog.group_name.input_name.text = self.nameFormat self.settingsDialog.group_clipboard.radio_dontcopy.setChecked(not self.copyLink) self.settingsDialog.group_clipboard.radio_directlink.setChecked(self.copyDirectLink) self.updateUi() self.settingsDialog.open() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("owncloud") self.url = settings.value("url", "") self.username = settings.value("username", "") self.password = settings.value("password", "") self.remotePath = settings.value("remote-path", "") self.connectStatus = settings.value("connect-status", "") self.nameFormat = settings.value("name-format", "Screenshot at %H:%M:%S") self.copyLink = settings.value("copy-link", "true") in ['true', True] self.copyDirectLink = settings.value("copy-direct-link", "false") in ['true', True] settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("owncloud") settings.setValue("url", self.settingsDialog.group_account.input_url.text) settings.setValue("username", self.settingsDialog.group_account.input_username.text) settings.setValue("password", self.settingsDialog.group_account.input_password.text) settings.setValue("remote-path", self.settingsDialog.group_name.input_path.text) settings.setValue("connect-status", self.connectStatus) settings.setValue("name-format", self.settingsDialog.group_name.input_name.text) settings.setValue("copy-link", not self.settingsDialog.group_clipboard.radio_dontcopy.checked) settings.setValue("copy-direct-link", self.settingsDialog.group_clipboard.radio_directlink.checked) settings.endGroup() settings.endGroup() def isConfigured(self): self.loadSettings() return self.connectStatus def getFilename(self): self.loadSettings() return ScreenCloud.formatFilename(self.nameFormat) def upload(self, screenshot, name): return True def startAuthenticationProcess(self): if self.settingsDialog.group_account.input_url.text and self.settingsDialog.group_account.input_username.text and self.settingsDialog.group_account.input_password.text: self.saveSettings() self.loadSettings() if match(self.url, "URI"): try: request = requests.get(self.url, timeout=3); if request.status_code == 200: oc = owncloud.Client(self.url) oc.login(self.username, self.password) self.connectStatus = "true" self.saveSettings() self.updateUi() except requests.exceptions.RequestException as e: QMessageBox.critical(self.settingsDialog, "OwnCloud Connection Error", "The specified Server URL is invalid!") settings = QSettings() settings.remove("connect-status") self.saveSettings() self.updateUi() except Exception as e: errorMessage = self.formatConnectionError(e.message) if errorMessage == "401": self.settingsDialog.group_connection.widget_status.label_status.setText("Invalid") else: QMessageBox.critical(self.settingsDialog, "OwnCloud Connection Error", errorMessage) else: QMessageBox.critical(self.settingsDialog, "OwnCloud Connection Error", "The specified Server URL is invalid!") else: missingFields = "" fieldText = "field" if not self.settingsDialog.group_account.input_url.text: missingFields = "\"Server URL\"" if not self.settingsDialog.group_account.input_username.text: if missingFields == "": missingFields = "\"Username\"" else: missingFields = missingFields + " and \"Username\"" fieldText = "fields" if not self.settingsDialog.group_account.input_password.text: if missingFields == "": missingFields = "\"Password\"" else: missingFields = missingFields.replace(" and", ",") + " and \"Password\"" fieldText = "fields" QMessageBox.critical(self.settingsDialog, "OwnCloud Connection Error", "The " + missingFields + " " + fieldText + " must be filled in!") def upload(self, screenshot, name): self.loadSettings() timestamp = time.time() try: tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) try: oc = owncloud.Client(self.url) oc.login(self.username, self.password) remotePath = "" if self.remotePath: remotePath = self.remotePath try: oc.file_info(remotePath) except Exception: oc.mkdir(remotePath) uploaded_image = oc.put_file(remotePath + "/" + ScreenCloud.formatFilename(name, False), tmpFilename) if self.copyLink: link_info = oc.share_file_with_link(remotePath + "/" + ScreenCloud.formatFilename(name, False)) share_link = link_info.get_link() if self.copyDirectLink: share_link = share_link + "/download" ScreenCloud.setUrl(share_link) return True except Exception as e: ScreenCloud.setError("Failed to upload to OwnCloud. " + e.message) return False def nameFormatEdited(self, nameFormat): self.settingsDialog.group_name.label_example.setText(ScreenCloud.formatFilename(nameFormat, False)) def formatConnectionError(self, e): return { "HTTP error: 400": "OwnCloud was unable to process the request due to a client error!", "HTTP error: 401": "401", "HTTP error: 403": "The specified user is not permitted to access the API!", "HTTP error: 404": "The specified Server URL is invalid!", "HTTP error: 500": "OwnCloud was unable to process the request due to a server error!", "HTTP error: 502": "The specified Server URL appears to be offline!" }.get(e, e.replace("/ocs/v1.php/cloud/capabilities", ""))
class ShellUploader(): def __init__(self): self.uil = QUiLoader() def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.connect("accepted()", self.saveSettings) self.loadSettings() self.settingsDialog.group_shell.input_command.text = self.commandFormat self.settingsDialog.open() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("shell") self.commandFormat = settings.value("command", "") settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("shell") settings.setValue("command", self.settingsDialog.group_shell.input_command.text) settings.endGroup() settings.endGroup() def isConfigured(self): self.loadSettings() if not self.commandFormat: return False return True def getFilename(self): timestamp = time.time() return ScreenCloud.formatFilename(str(timestamp)) def upload(self, screenshot, name): self.loadSettings() tmpFilename = QDesktopServices.storageLocation( QDesktopServices.TempLocation) + "/" + name screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) command = string.Formatter().vformat(self.commandFormat, (), defaultdict(str, s=tmpFilename)) try: command = command.encode(sys.getfilesystemencoding()) except UnicodeEncodeError: ScreenCloud.setError("Invalid characters in command '" + command + "'") return False try: p = subprocess.Popen(command.split()) p.wait() if p.returncode > 0: ScreenCloud.setError("Command " + command + " did not return 0") return False except OSError: ScreenCloud.setError("Failed to run command " + command) return False return True
class ImgurUploader(): def __init__(self): self.uil = QUiLoader() self.loadSettings() def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.group_account.button_authenticate.connect("clicked()", self.startAuthenticationProcess) self.settingsDialog.group_account.widget_loggedIn.button_logout.connect("clicked()", self.logOut) self.settingsDialog.group_name.input_name.connect("textChanged(QString)", self.nameFormatEdited) self.settingsDialog.connect("accepted()", self.saveSettings) self.loadSettings() self.settingsDialog.group_clipboard.radio_dontcopy.setChecked(not self.copyLink) self.settingsDialog.group_clipboard.radio_directlink.setChecked(self.copyDirectLink) self.updateUi() self.settingsDialog.open() def updateUi(self): #self.loadSettings() if self.access_token and self.refresh_token: self.settingsDialog.group_account.widget_loggedIn.show() self.settingsDialog.group_account.button_authenticate.hide() self.settingsDialog.group_account.radio_account.setChecked(True) self.settingsDialog.group_account.widget_loggedIn.label_user.setText(self.username) else: self.settingsDialog.group_account.widget_loggedIn.hide() self.settingsDialog.group_account.button_authenticate.show() if self.uploadAnon and self.settingsDialog.group_clipboard.radio_dontcopy.checked: self.settingsDialog.group_clipboard.radio_imgur.setChecked(True) self.settingsDialog.group_account.radio_anon.setChecked(self.uploadAnon) self.settingsDialog.group_name.input_name.setText(self.nameFormat) self.settingsDialog.adjustSize() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("imgur") self.uploadAnon = settings.value("anonymous", "true") in ['true', True] self.copyLink = settings.value("copy-link", "true") in ['true', True] self.copyDirectLink = settings.value("copy-direct-link", "false") in ['true', True] self.access_token = settings.value("access-token", "") self.refresh_token = settings.value("refresh-token", "") self.nameFormat = settings.value("name-format", "Screenshot at %H:%M:%S") self.username = settings.value("username", "") settings.endGroup() settings.endGroup() if self.uploadAnon: self.imgur = pyimgur.Imgur("7163c05b94dcf99") else: self.imgur = pyimgur.Imgur("7163c05b94dcf99", "5132015d173997bbb52e1d9e093d882abed8d9f1", self.access_token, self.refresh_token) def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("imgur") settings.setValue("anonymous", self.settingsDialog.group_account.radio_anon.checked) settings.setValue("copy-link", not self.settingsDialog.group_clipboard.radio_dontcopy.checked) settings.setValue("copy-direct-link", self.settingsDialog.group_clipboard.radio_directlink.checked) settings.setValue("access-token", self.access_token) settings.setValue("refresh-token", self.refresh_token) settings.setValue("name-format", self.settingsDialog.group_name.input_name.text) settings.setValue("username", self.username) settings.endGroup() settings.endGroup() def isConfigured(self): self.loadSettings() if self.uploadAnon: return True else: return self.access_token and self.refresh_token def getFilename(self): self.loadSettings() return ScreenCloud.formatFilename(self.nameFormat) def upload(self, screenshot, name): self.loadSettings() #Make sure we have a up to date token if not self.uploadAnon: self.imgur.refresh_access_token() #Save to a temporary file timestamp = time.time() tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) #Upload! try: uploaded_image = self.imgur.upload_image(tmpFilename, title=ScreenCloud.formatFilename(name, False)) except Exception as e: ScreenCloud.setError("Failed to upload to imgur. " + e.message) return False if self.copyLink: if self.copyDirectLink: ScreenCloud.setUrl(uploaded_image.link) else: ScreenCloud.setUrl("https://imgur.com/" + uploaded_image.id) return True def startAuthenticationProcess(self): self.saveSettings() self.loadSettings() auth_url = self.imgur.authorization_url('pin') QDesktopServices.openUrl(QUrl(auth_url)) pin = raw_input("Enter PIN from imgur website:") if pin: try: self.access_token, self.refresh_token = self.imgur.exchange_pin(pin) except KeyError as e: QMessageBox.critical(self.settingsDialog, "Imgur key error", "Failed to exchange pin. " + e.message) self.access_token, self.username = self.imgur.refresh_access_token() self.saveSettings() self.updateUi() def logOut(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("imgur") settings.remove("access-token") settings.remove("refresh-token") settings.remove("username") settings.setValue("anonymous", "true") settings.endGroup() settings.endGroup() self.loadSettings() self.updateUi() def nameFormatEdited(self, nameFormat): self.settingsDialog.group_name.label_example.setText(ScreenCloud.formatFilename(nameFormat, False))
class WebDAVUploader(): def __init__(self): self.uil = QUiLoader() self.loadSettings() # self.dav_address = 'myfiles.fastmail.com' def upload(self, screenshot, name): name = fix_filename(name) path = self.save(screenshot, name) if not path: ScreenCloud.setError('Failed to save screenshot') return False dav = WebDAV(self.dav_address) dav.auth(self.username, self.password) if not dav.exists('ScreenCloud'): dav.mkdir('ScreenCloud') print(name) if not dav.upload('ScreenCloud/' + name, path): ScreenCloud.setError('Failed to upload screenshot') return False if self.copy_link: ScreenCloud.setUrl(self.host_address + '/' + name) return True def save(self, screenshot, name, path=None): if self.save_file and len(self.save_path) > 0: if os.path.isdir(self.save_path): path = self.save_path # else: # TODO: warn the user that the file could not be saved locally if not path: path = QStandardPaths.writableLocation(QStandardPaths.TempLocation) path = os.path.join(path, name) try: screenshot.save(QFile(path), ScreenCloud.getScreenshotFormat()) except Exception as e: raise return path def getFilename(self): return fix_filename( ScreenCloud.formatFilename(self.name_format, custom_vars=get_rnd_dict())) def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + '/settings.ui'), parentWidget) self.settingsDialog.group_url.check_copylink.connect( 'stateChanged(int)', self.updateUI) self.settingsDialog.group_screenshot.input_name.connect( 'textChanged(QString)', self.nameFormatEdited) self.settingsDialog.group_screenshot.check_savefile.connect( 'stateChanged(int)', self.updateUI) self.settingsDialog.group_screenshot.button_browse.connect( 'clicked()', self.browseForDirectory) self.settingsDialog.connect('accepted()', self.saveSettings) self.loadSettings() self.settingsDialog.group_url.input_url.text = self.dav_address self.settingsDialog.group_url.input_username.text = self.username self.settingsDialog.group_url.input_password.text = self.password self.settingsDialog.group_url.check_copylink.checked = self.copy_link self.settingsDialog.group_url.input_public.text = self.host_address self.settingsDialog.group_screenshot.input_name.text = self.name_format self.settingsDialog.group_screenshot.check_savefile.checked = self.save_file self.settingsDialog.group_screenshot.input_directory.text = self.save_path self.updateUI() self.settingsDialog.open() def loadSettings(self): settings = QSettings() settings.beginGroup('uploaders') settings.beginGroup('webdav') self.dav_address = settings.value('url', '') self.username = settings.value('username', '') self.password = settings.value('password', '') self.copy_link = settings.value('copy-link', 'True') == 'True' self.host_address = settings.value('host-address', '') self.name_format = settings.value('name-format', '%Y-%m-%d_%H-%M-%S') self.save_file = settings.value('save-file', 'False') == 'True' self.save_path = settings.value('save-path', '') settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup('uploaders') settings.beginGroup('webdav') settings.setValue('url', self.settingsDialog.group_url.input_url.text) settings.setValue('username', self.settingsDialog.group_url.input_username.text) settings.setValue('password', self.settingsDialog.group_url.input_password.text) settings.setValue( 'copy-link', str(self.settingsDialog.group_url.check_copylink.checked)) settings.setValue('host-address', self.settingsDialog.group_url.input_public.text) settings.setValue('name-format', self.settingsDialog.group_screenshot.input_name.text) settings.setValue( 'save-file', str(self.settingsDialog.group_screenshot.check_savefile.checked)) settings.setValue( 'save-path', self.settingsDialog.group_screenshot.input_directory.text) settings.endGroup() settings.endGroup() def isConfigured(self): self.loadSettings() return len(self.dav_address) > 0 and len(self.username) > 0 and len( self.password) > 0 def browseForDirectory(self): path = QFileDialog.getExistingDirectory(self.settingsDialog, 'Select location', self.save_path) if path: self.settingsDialog.group_screenshot.input_directory.setText(path) self.saveSettings() def nameFormatEdited(self, name_format): self.settingsDialog.group_screenshot.label_example.setText( fix_filename( ScreenCloud.formatFilename(name_format, custom_vars=get_rnd_dict()))) def updateUI(self): save_file = self.settingsDialog.group_screenshot.check_savefile.checked self.settingsDialog.group_screenshot.label_directory.setVisible( save_file) self.settingsDialog.group_screenshot.input_directory.setVisible( save_file) self.settingsDialog.group_screenshot.button_browse.setVisible( save_file) copy_link = self.settingsDialog.group_url.check_copylink.checked self.settingsDialog.group_url.label_public.setVisible(copy_link) self.settingsDialog.group_url.input_public.setVisible(copy_link)
def __init__(self): self.uil = QUiLoader() self.loadSettings()
class UguuUploader(): def __init__(self): self.uil = QUiLoader() self.loadSettings() def isConfigured(self): return True def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("uguu.se") self.nameFormat = settings.value("name-format", "screenshot-%H-%M-%S") self.copyLink = settings.value("copy-link", "true") in ["true", True] settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("uguu.se") settings.setValue("name-format", self.settingsDialog.group_name.input_name.text) settings.setValue( "copy-link", self.settingsDialog.group_clipboard.checkbox_copy_link.checked) settings.endGroup() settings.endGroup() def getFilename(self): self.loadSettings() return ScreenCloud.formatFilename(self.nameFormat) def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.group_name.input_name.connect( "textChanged(QString)", self.nameFormatEdited) self.settingsDialog.connect("accepted()", self.saveSettings) self.updateUi() self.settingsDialog.open() def updateUi(self): self.loadSettings() self.settingsDialog.group_name.input_name.setText(self.nameFormat) self.settingsDialog.group_clipboard.checkbox_copy_link.setChecked( self.copyLink) def upload(self, screenshot, name): self.loadSettings() tmpFilename = QStandardPaths.writableLocation( QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename( str(time.time())) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) data = {"name": name} files = {"file": open(tmpFilename, "rb")} try: response = requests.post("https://uguu.se/api.php?d=upload-tool", data=data, files=files) response.raise_for_status() if self.copyLink: ScreenCloud.setUrl(response.text) except RequestException as e: ScreenCloud.setError("Failed to upload to Uguu.se: " + e.message) return False return True def nameFormatEdited(self, nameFormat): self.settingsDialog.group_name.label_example.setText( ScreenCloud.formatFilename(nameFormat, False))
class ZapierUploader(): def __init__(self): self.uil = QUiLoader() self.loadSettings() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("zapier") self.zapier_url = settings.value("url", "") settings.endGroup() settings.endGroup() def saveSettings(self): self.zapier_url = self.settingsDialog.group_url.widget_url.input_url.text settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("zapier") settings.setValue("url", self.zapier_url) settings.endGroup() settings.endGroup() def isConfigured(self): return bool(self.zapier_url.strip()) def getFilename(self): return ScreenCloud.formatFilename("screenshot") def showSettingsUI(self, parentWidget): self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.connect("accepted()", self.saveSettings) self.settingsDialog.setWindowTitle("Zapier settings") self.settingsDialog.group_url.widget_url.input_url.setText( self.zapier_url) self.settingsDialog.adjustSize() self.settingsDialog.open() def upload(self, screenshot, name): ba = QByteArray() buf = QBuffer(ba) buf.open(QIODevice.WriteOnly) screenshot.save( buf, ScreenCloud.getScreenshotFormat()) #writes image into ba buf.close() json_data = json.dumps({'image': ba.toBase64().data()}) request = urllib2.Request(self.zapier_url, json_data, {"Content-Type": "application/json"}) try: reply = urllib2.urlopen(request) except Exception as e: ScreenCloud.setError("Could not upload to: " + self.zapier_url + "\n" + e.message) return False try: replyText = reply.read() ScreenCloud.setUrl(json.loads(replyText).link) except Exception as e: ScreenCloud.setError("Could not upload to: " + self.zapier_url + "\n" + e.message) return False return True
def __init__(self, controller, queue): loader = QUiLoader() loader.setLanguageChangeEnabled(True) # uifile = QFile("pymodules/estatemanagement/estatemanagement.ui") uifile = QFile(EstateManagementWindow.UIFILE) self.gui = loader.load(uifile) self.controller = controller IncomingMessagesHandler.__init__(self, queue, self.endMethod) uism = naali.ui # uiprops = r.createUiWidgetProperty(1) # 1 = Qt::Dialog # uiprops.SetMenuGroup("Server Tools") # uiprops.name_ = "Estate Management" self.proxywidget = r.createUiProxyWidget(self.gui) self.proxywidget.setWindowTitle("Estate Management") if not uism.AddWidgetToScene(self.proxywidget): r.logInfo("Adding ProxyWidget failed.") # TODO: Due to core UI API refactor RemoveWidgetFromMenu doesn't exist anymore. # uism.AddWidgetToMenu(self.proxywidget, "Estate Management", "Server Tools", "./data/ui/images/menus/edbutton_ESMNG_normal.png") self.btnLoadEstate = self.gui.findChild("QPushButton", "btnLoadEstate") self.listWEI = self.gui.findChild("QListWidget", "listWidgetEstateInfo") self.listWRU = self.gui.findChild("QListWidget", "listWidgetRegionUsers") self.listWEB = self.gui.findChild("QListWidget", "listWidgetBanList") self.listWAL = self.gui.findChild("QListWidget", "listWidgetAccessList") self.listWEM = self.gui.findChild("QListWidget", "listWidgetEstateManagers") self.listWSU = self.gui.findChild("QListWidget", "listWidgetSavedUsers") self.labelEstateInfo = self.gui.findChild("QLabel", "labelEstateInfo") self.tableEstates = self.gui.findChild("QListWidget", "tableWidgetEstates") self.chkEstateAccess = self.gui.findChild("QCheckBox", "checkBoxEstateAccess") self.lineCurrentEstate = self.gui.findChild("QLineEdit", "lineEditCurrentEstate") self.listWidgetEstates = self.gui.findChild("QListWidget", "listWidgetEstates") self.btnSetEstate = self.gui.findChild("QPushButton", "pushButtonSetEstate") self.chkSunFixed = self.gui.findChild("QCheckBox", "checkBoxSunFixed") # PublicAllowed # ExternallyVisible); self.chkAllowVoice = self.gui.findChild("QCheckBox", "checkBoxAllowVoice") self.chkAllowDirectTeleport = self.gui.findChild("QCheckBox", "checkBoxAllowDirectTeleport") self.chkDenyAnonymous = self.gui.findChild("QCheckBox", "checkBoxDenyAnonymous") self.chkDenyIdentified = self.gui.findChild("QCheckBox", "checkBoxDenyIdentified") self.chkDenyTransacted = self.gui.findChild("QCheckBox", "checkBoxDenyTransacted") self.chkAbuseEmailToEstateOwner = self.gui.findChild("QCheckBox", "checkBoxAbuseEmailToEstateOwner") self.chkBlockDwell = self.gui.findChild("QCheckBox", "checkBoxBlockDwell") self.chkEstateSkipScripts = self.gui.findChild("QCheckBox", "checkBoxEstateSkipScripts") self.chkResetHomeOnTeleport = self.gui.findChild("QCheckBox", "checkBoxResetHomeOnTeleport") self.chkTaxFree = self.gui.findChild("QCheckBox", "checkBoxTaxFree") self.chkDenyAgeUnverified = self.gui.findChild("QCheckBox", "checkBoxDenyAgeUnverified") self.btnLoadEstate.connect("clicked(bool)", self.btnLoadEstateClicked) self.btnToBan = self.gui.findChild("QPushButton", "pushButtonToBan") self.btnToAccess = self.gui.findChild("QPushButton", "pushButtonToAccess") self.btnToManagers = self.gui.findChild("QPushButton", "pushButtonToManagers") self.btnSaveUserInfo = self.gui.findChild("QPushButton", "pushButtonSaveUserInfo") self.btnRemoveBan = self.gui.findChild("QPushButton", "pushButtonRemoveBan") self.btnRemoveAccess = self.gui.findChild("QPushButton", "pushButtonRemoveAccess") self.btnRemoveManagers = self.gui.findChild("QPushButton", "pushButtonRemoveManager") self.btnRemoveSaved = self.gui.findChild("QPushButton", "pushButtonRemoveSaved") self.btnSavedToAccess = self.gui.findChild("QPushButton", "pushButtonSavedToAccess") self.btnSavedToBan = self.gui.findChild("QPushButton", "pushButtonSavedToBan") self.btnSavedToManagers = self.gui.findChild("QPushButton", "pushButtonSavedToManagers") self.btnKick = self.gui.findChild("QPushButton", "pushButtonKick") self.btnRequestGodLikePowers = self.gui.findChild("QPushButton", "pushButtonRequestGodLikePowers") self.lineKickMessage = self.gui.findChild("QLineEdit", "lineEditKickMessage") self.btnToBan.connect("clicked(bool)", self.btnToBanClicked) self.btnToAccess.connect("clicked(bool)", self.btnToAccessClicked) self.btnToManagers.connect("clicked(bool)", self.btnToManagersClicked) self.btnSaveUserInfo.connect("clicked(bool)", self.btnSaveUserInfoClicked) self.btnRemoveBan.connect("clicked(bool)", self.btnRemoveBanClicked) self.btnRemoveAccess.connect("clicked(bool)", self.btnRemoveAccessClicked) self.btnRemoveManagers.connect("clicked(bool)", self.btnRemoveManagersClicked) self.btnRemoveSaved.connect("clicked(bool)", self.btnRemoveSavedClicked) self.btnSavedToAccess.connect("clicked(bool)", self.btnSavedToAccessClicked) self.btnSavedToBan.connect("clicked(bool)", self.btnSavedToBanClicked) self.btnSavedToManagers.connect("clicked(bool)", self.btnSavedToManagersClicked) self.btnRequestGodLikePowers.connect("clicked(bool)", self.btnRequestGodLikePowersClicked) self.btnKick.connect("clicked(bool)", self.btnKickClicked) self.btnSetEstate.connect("clicked(bool)", self.btnSetEstateClicked) self.chkEstateAccess.connect("toggled(bool)", self.chkEstateAccessToggled) # add incoming event handlers self.addHandler("EstateUpdate", self.setEstateInfo) self.addHandler("setEstateManagers", self.setEstateManagers) self.addHandler("setEstateBans", self.setEstateBans) self.addHandler("setEsteteAccessList", self.setEsteteAccessList) self.addHandler("noCapability", self.noCapabilityInfoMessage) self.addHandler("estateSetting", self.handleEstateAccessSetting) self.addHandler("failedEstateSetting", self.handleEstateAccessFailure) self.addHandler("unknownResponse", self.handleEstateAccessFailure) self.addHandler("malformedResp", self.handleEstateAccessFailure) self.addHandler("currentEstateIdAndName", self.handleCurrentEstateIdAndName) self.addHandler("estates", self.handleEstates) self.addHandler("displayerror", self.handleDisplayError)
class NextCloudUploader(): def __init__(self): self.uil = QUiLoader() self.loadSettings() def updateUi(self): self.loadSettings() if self.connectStatus: self.settingsDialog.group_connection.widget_status.label_status.setText( "Valid") else: self.settingsDialog.group_connection.widget_status.label_status.setText( "Unknown") self.settingsDialog.group_name.input_name.setText(self.nameFormat) self.settingsDialog.adjustSize() def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.group_connection.button_authenticate.connect( "clicked()", self.startAuthenticationProcess) self.settingsDialog.group_name.input_name.connect( "textChanged(QString)", self.nameFormatEdited) self.settingsDialog.connect("accepted()", self.saveSettings) self.loadSettings() self.settingsDialog.group_account.input_url.text = self.url self.settingsDialog.group_account.input_username.text = self.username self.settingsDialog.group_account.input_password.text = self.password self.settingsDialog.group_name.input_path.text = self.remotePath self.settingsDialog.group_name.input_name.text = self.nameFormat self.settingsDialog.group_clipboard.radio_dontcopy.setChecked( not self.copyLink) self.settingsDialog.group_clipboard.radio_directlink.setChecked( self.copyDirectLink) self.updateUi() self.settingsDialog.open() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("nextcloud") self.url = settings.value("url", "") self.username = settings.value("username", "") self.password = settings.value("password", "") self.remotePath = settings.value("remote-path", "") self.connectStatus = settings.value("connect-status", "") self.nameFormat = settings.value("name-format", "Screenshot at %H:%M:%S") self.copyLink = settings.value("copy-link", "true") in ['true', True] self.copyDirectLink = settings.value("copy-direct-link", "false") in ['true', True] settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("nextcloud") settings.setValue("url", self.settingsDialog.group_account.input_url.text) settings.setValue( "username", self.settingsDialog.group_account.input_username.text) settings.setValue( "password", self.settingsDialog.group_account.input_password.text) settings.setValue("remote-path", self.settingsDialog.group_name.input_path.text) settings.setValue("connect-status", self.connectStatus) settings.setValue("name-format", self.settingsDialog.group_name.input_name.text) settings.setValue( "copy-link", not self.settingsDialog.group_clipboard.radio_dontcopy.checked) settings.setValue( "copy-direct-link", self.settingsDialog.group_clipboard.radio_directlink.checked) settings.endGroup() settings.endGroup() def isConfigured(self): self.loadSettings() return self.connectStatus def getFilename(self): self.loadSettings() return ScreenCloud.formatFilename(self.nameFormat) def upload(self, screenshot, name): return True def startAuthenticationProcess(self): if self.settingsDialog.group_account.input_url.text and self.settingsDialog.group_account.input_username.text and self.settingsDialog.group_account.input_password.text: self.saveSettings() self.loadSettings() if match(self.url, "URI"): try: request = requests.get(self.url, timeout=3) if request.status_code == 200: oc = nextcloud.Client(self.url) oc.login(self.username, self.password) self.connectStatus = "true" self.saveSettings() self.updateUi() except requests.exceptions.RequestException as e: QMessageBox.critical( self.settingsDialog, "NextCloud Connection Error", "The specified Server URL is invalid!") settings = QSettings() settings.remove("connect-status") self.saveSettings() self.updateUi() except Exception as e: errorMessage = self.formatConnectionError(e.message) if errorMessage == "401": self.settingsDialog.group_connection.widget_status.label_status.setText( "Invalid") else: QMessageBox.critical(self.settingsDialog, "NextCloud Connection Error", errorMessage) else: QMessageBox.critical(self.settingsDialog, "NextCloud Connection Error", "The specified Server URL is invalid!") else: missingFields = "" fieldText = "field" if not self.settingsDialog.group_account.input_url.text: missingFields = "\"Server URL\"" if not self.settingsDialog.group_account.input_username.text: if missingFields == "": missingFields = "\"Username\"" else: missingFields = missingFields + " and \"Username\"" fieldText = "fields" if not self.settingsDialog.group_account.input_password.text: if missingFields == "": missingFields = "\"Password\"" else: missingFields = missingFields.replace( " and", ",") + " and \"Password\"" fieldText = "fields" QMessageBox.critical( self.settingsDialog, "NextCloud Connection Error", "The " + missingFields + " " + fieldText + " must be filled in!") def upload(self, screenshot, name): self.loadSettings() timestamp = time.time() try: tmpFilename = QDesktopServices.storageLocation( QDesktopServices.TempLocation ) + "/" + ScreenCloud.formatFilename(str(timestamp)) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation( QStandardPaths.TempLocation ) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) try: oc = nextcloud.Client(self.url) oc.login(self.username, self.password) remotePath = "" if self.remotePath: remotePath = self.remotePath try: oc.file_info(remotePath) except Exception: oc.mkdir(remotePath) uploaded_image = oc.put_file( remotePath + "/" + ScreenCloud.formatFilename(name, False), tmpFilename) if self.copyLink: link_info = oc.share_file_with_link( remotePath + "/" + ScreenCloud.formatFilename(name, False)) share_link = link_info.get_link() if self.copyDirectLink: share_link = share_link + "/download" ScreenCloud.setUrl(share_link) return True except Exception as e: ScreenCloud.setError("Failed to upload to NextCloud. " + e.message) return False def nameFormatEdited(self, nameFormat): self.settingsDialog.group_name.label_example.setText( ScreenCloud.formatFilename(nameFormat, False)) def formatConnectionError(self, e): return { "HTTP error: 400": "NextCloud was unable to process the request due to a client error!", "HTTP error: 401": "401", "HTTP error: 403": "The specified user is not permitted to access the API!", "HTTP error: 404": "The specified Server URL is invalid!", "HTTP error: 500": "NextCloud was unable to process the request due to a server error!", "HTTP error: 502": "The specified Server URL appears to be offline!" }.get(e, e.replace("/ocs/v1.php/cloud/capabilities", ""))
class ImgurUploader(): def __init__(self): self.uil = QUiLoader() self.loadSettings() def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.group_account.button_authenticate.connect( "clicked()", self.startAuthenticationProcess) self.settingsDialog.group_account.widget_loggedIn.button_logout.connect( "clicked()", self.logOut) self.settingsDialog.group_name.input_name.connect( "textChanged(QString)", self.nameFormatEdited) self.settingsDialog.connect("accepted()", self.saveSettings) self.updateUi() self.settingsDialog.open() def updateUi(self): self.loadSettings() if self.access_token and self.refresh_token: self.settingsDialog.group_account.widget_loggedIn.show() self.settingsDialog.group_account.button_authenticate.hide() self.settingsDialog.group_account.radio_account.setChecked(True) self.settingsDialog.group_account.widget_loggedIn.label_user.setText( self.username) else: self.settingsDialog.group_account.widget_loggedIn.hide() self.settingsDialog.group_account.button_authenticate.show() if self.uploadAnon and self.settingsDialog.group_clipboard.radio_dontcopy.checked: self.settingsDialog.group_clipboard.radio_imgur.setChecked(True) self.settingsDialog.group_account.radio_anon.setChecked( self.uploadAnon) self.settingsDialog.group_name.input_name.setText(self.nameFormat) self.settingsDialog.adjustSize() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("imgur") self.uploadAnon = settings.value("anonymous", "true") in ['true', True] self.copyLink = settings.value("copy-link", "true") in ['true', True] self.copyDirectLink = settings.value("copy-direct-link", "false") in ['true', True] self.access_token = settings.value("access-token", "") self.refresh_token = settings.value("refresh-token", "") self.nameFormat = settings.value("name-format", "Screenshot at %H:%M:%S") self.username = settings.value("username", "") settings.endGroup() settings.endGroup() if self.uploadAnon: self.imgur = pyimgur.Imgur("7163c05b94dcf99") else: self.imgur = pyimgur.Imgur( "7163c05b94dcf99", "5132015d173997bbb52e1d9e093d882abed8d9f1", self.access_token, self.refresh_token) def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("imgur") settings.setValue("anonymous", self.settingsDialog.group_account.radio_anon.checked) settings.setValue( "copy-link", not self.settingsDialog.group_clipboard.radio_dontcopy.checked) settings.setValue( "copy-direct-link", self.settingsDialog.group_clipboard.radio_directlink.checked) settings.setValue("access-token", self.access_token) settings.setValue("refresh-token", self.refresh_token) settings.setValue("name-format", self.settingsDialog.group_name.input_name.text) settings.setValue("username", self.username) settings.endGroup() settings.endGroup() def isConfigured(self): self.loadSettings() if self.uploadAnon: return True else: return self.access_token and self.refresh_token def getFilename(self): self.loadSettings() return ScreenCloud.formatFilename(self.nameFormat) def upload(self, screenshot, name): self.loadSettings() #Make sure we have a up to date token if not self.uploadAnon: self.imgur.refresh_access_token() #Save to a temporary file timestamp = time.time() tmpFilename = QDesktopServices.storageLocation( QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename( str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) #Upload! try: uploaded_image = self.imgur.upload_image( tmpFilename, title=ScreenCloud.formatFilename(name, False)) except Exception as e: ScreenCloud.setError("Failed to upload to imgur. " + e.message) return False if self.copyLink: if self.copyDirectLink: ScreenCloud.setUrl(uploaded_image.link) else: ScreenCloud.setUrl("https://imgur.com/" + uploaded_image.id) return True def startAuthenticationProcess(self): self.saveSettings() self.loadSettings() auth_url = self.imgur.authorization_url('pin') QDesktopServices.openUrl(QUrl(auth_url)) pin = raw_input("Enter PIN from imgur website:") if pin: try: self.access_token, self.refresh_token = self.imgur.exchange_pin( pin) except KeyError as e: QMessageBox.critical(self.settingsDialog, "Imgur key error", "Failed to exchange pin. " + e.message) self.access_token, self.username = self.imgur.refresh_access_token() self.saveSettings() self.updateUi() def logOut(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("imgur") settings.remove("access-token") settings.remove("refresh-token") settings.remove("username") settings.setValue("anonymous", "true") settings.endGroup() settings.endGroup() self.loadSettings() self.updateUi() def nameFormatEdited(self, nameFormat): self.settingsDialog.group_name.label_example.setText( ScreenCloud.formatFilename(nameFormat, False))
def __init__(self): uil = QUiLoader() self.settingsDialog = uil.load(QFile(workingDir + "/settings.ui"))
def init_ui(self): loader = QUiLoader() # Container widget self.container = ui = loader.load(QFile("pymodules/loadurlhandler/webbrowser.ui")) # Webview self.webview = QWebView(self.container) self.webview.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks) self.webview.connect("loadStarted()", self.on_load_start) self.webview.connect("loadFinished(bool)", self.on_load_stop) self.webview.connect("loadProgress(int)", self.on_load_progress) self.webview.connect("linkClicked(QUrl)", self.link_clicked) layout = ui.findChild("QVBoxLayout", "verticalLayout_Container") layout.insertWidget(2, self.webview) # Buttons ui.findChild("QPushButton", "pushButton_ClearCookie").hide() self.button_back = ui.findChild("QPushButton", "pushButton_Back") self.button_forward = ui.findChild("QPushButton", "pushButton_Forward") self.button_refresh = ui.findChild("QPushButton", "pushButton_Refresh") self.button_stop = ui.findChild("QPushButton", "pushButton_Stop") self.button_go = ui.findChild("QPushButton", "pushButton_Go") self.button_back.setIcon(QIcon("./data/ui/images/arrow_left_48.png")); self.button_back.setIconSize(QSize(20, 20)); self.button_forward.setIcon(QIcon("./data/ui/images/arrow_right_48.png")); self.button_forward.setIconSize(QSize(20, 20)); self.button_refresh.setIcon(QIcon("./data/ui/images/refresh_48.png")); self.button_refresh.setIconSize(QSize(20, 20)); self.button_stop.setIcon(QIcon("./data/ui/images/cross_48.png")); self.button_stop.setIconSize(QSize(20, 20)); self.button_stop.setEnabled(False); self.button_go.setIcon(QIcon("./data/ui/images/arrow_right_green_48.png")); self.button_go.setIconSize(QSize(20, 20)); self.button_back.connect("clicked()", self.on_back) self.button_forward.connect("clicked()", self.on_forward) self.button_refresh.connect("clicked()", self.on_refresh) self.button_stop.connect("clicked()", self.on_stop) self.button_go.connect("clicked()", self.go_to_linedit_url) # Address bar self.lineedit_address = ui.findChild("QComboBox", "comboBox_Address") self.lineedit_address.lineEdit().connect("returnPressed()", self.go_to_linedit_url) # Progress bar and label self.progress_bar = ui.findChild("QProgressBar", "progressBar_Status") self.progress_bar.hide() self.progress_label = ui.findChild("QLabel", "label_Status") # Add to scene #uism = naali.ui #self.proxywidget = r.createUiProxyWidget(self.container) #self.proxywidget.setWindowTitle("Naali Web Browser") #self.proxywidget.connect("Visible(bool)", self.vibibility_changed) #if not uism.AddWidgetToScene(self.proxywidget): # r.logError('LoadURLHandler: Adding the ProxyWidget to the scene failed.') self.container.show()
def __init__(self, controller): self.controller = controller loader = QUiLoader() uifile = QFile(self.UIFILE) ui = loader.load(uifile) width = ui.size.width() height = ui.size.height() #if not DEV: uism = r.getUiSceneManager() uiprops = r.createUiWidgetProperty(1) #1 is ModuleWidget, shown at toolbar uiprops.widget_name_ = "Object Edit" #uiprops.my_size_ = QSize(width, height) #not needed anymore, uimodule reads it self.proxywidget = r.createUiProxyWidget(ui, uiprops) if not uism.AddProxyWidget(self.proxywidget): print "Adding the ProxyWidget to the bar failed." self.widget = ui self.tabwidget = ui.findChild("QTabWidget", "MainTabWidget") self.mainTab = ui.findChild("QWidget", "MainFrame") self.materialTab = ui.findChild("QWidget", "MaterialsTab") self.tabwidget.setTabEnabled(1, False) self.materialTabFormWidget = self.materialTab.formLayoutWidget self.mainTab.label.text = "<none>" self.meshline = lines.MeshAssetidEditline(controller) self.meshline.name = "meshLineEdit" button_ok = self.getButton("Apply", self.ICON_OK, self.meshline, self.meshline.applyAction) button_cancel = self.getButton("Cancel", self.ICON_CANCEL, self.meshline, self.meshline.cancelAction) box = self.mainTab.findChild("QHBoxLayout", "meshLine") box.addWidget(self.meshline) box.addWidget(button_ok) box.addWidget(button_cancel) self.propedit = r.getPropertyEditor() self.tabwidget.addTab(self.propedit, "Properties") self.tabwidget.setTabEnabled(2, False) def poschanger(i): def pos_at_index(v): self.controller.changepos(i, v) return pos_at_index for i, poswidget in enumerate([self.mainTab.xpos, self.mainTab.ypos, self.mainTab.zpos]): poswidget.connect('valueChanged(double)', poschanger(i)) def rotchanger(i): def rot_at_index(v): self.controller.changerot(i, v) return rot_at_index for i, rotwidget in enumerate([self.mainTab.rot_x, self.mainTab.rot_y, self.mainTab.rot_z]): rotwidget.connect('valueChanged(double)', rotchanger(i)) def scalechanger(i): def scale_at_index(v): self.controller.changescale(i, v) return scale_at_index for i, scalewidget in enumerate([self.mainTab.scalex, self.mainTab.scaley, self.mainTab.scalez]): scalewidget.connect('valueChanged(double)', scalechanger(i)) self.mainTab.treeWidget.connect('clicked(QModelIndex)', self.itemActivated) self.mainTab.treeWidget.connect('activated(QModelIndex)', self.itemActivated) self.proxywidget.connect('Visible(bool)', self.controller.on_hide) #self.tabwidget.connect('currentChanged(int)', self.tabChanged) self.meshline.connect('textEdited(QString)', button_ok.lineValueChanged) self.meshline.connect('textEdited(QString)', button_cancel.lineValueChanged) self.mainTab.findChild("QPushButton", "newObject").connect('clicked()', self.controller.createObject) self.mainTab.findChild("QPushButton", "deleteObject").connect('clicked()', self.controller.deleteObject) self.mainTab.findChild("QPushButton", "duplicate").connect('clicked()', self.controller.duplicate) self.mainTab.findChild("QPushButton", "undo").connect('clicked()', self.controller.undo) self.mainTab.findChild("QToolButton", "move_button").connect('clicked()', self.manipulator_move) self.mainTab.findChild("QToolButton", "scale_button").connect('clicked()', self.manipulator_scale) self.mainTab.findChild("QToolButton", "rotate_button").connect('clicked()', self.manipulator_rotate) self.mainTabList = {} self.currentlySelectedTreeWidgetItem = []
def __init__(self): self.uil = QUiLoader()
def __init__(self): self.sels = [] Component.__init__(self) self.window = window.ObjectEditWindow(self) self.resetValues() self.worldstream = r.getServerConnection() self.usingManipulator = False self.useLocalTransform = False self.cpp_python_handler = None self.left_button_down = False self.keypressed = False self.shortcuts = { (Qt.Key_Z, Qt.ControlModifier): self.undo, (Qt.Key_Delete, Qt.NoModifier): self.deleteObject, (Qt.Key_L, Qt.AltModifier): self.linkObjects, (Qt.Key_L, Qt.ControlModifier | Qt.ShiftModifier): self.unlinkObjects, } # Connect to key pressed signal from input context self.edit_inputcontext = naali.createInputContext("object-edit", 100) self.edit_inputcontext.SetTakeMouseEventsOverQt(True) self.edit_inputcontext.connect('KeyPressed(KeyEvent*)', self.on_keypressed) # Connect to mouse events self.edit_inputcontext.connect('MouseScroll(MouseEvent*)', self.on_mousescroll) self.edit_inputcontext.connect('MouseLeftPressed(MouseEvent*)', self.on_mouseleftpressed) self.edit_inputcontext.connect('MouseLeftReleased(MouseEvent*)', self.on_mouseleftreleased) self.edit_inputcontext.connect('MouseMove(MouseEvent*)', self.on_mousemove) self.resetManipulators() loader = QUiLoader() selectionfile = QFile(self.SELECTIONRECT) self.selection_rect = loader.load(selectionfile) #rectprops = r.createUiWidgetProperty(2) #~ print type(rectprops), dir(rectprops) #print rectprops.WidgetType #uiprops.widget_name_ = "Selection Rect" #uiprops.my_size_ = QSize(width, height) #not needed anymore, uimodule reads it proxy = r.createUiProxyWidget(self.selection_rect) uism = naali.ui uism.AddWidgetToScene(proxy) proxy.setWindowFlags(0) #changing it to Qt::Widget self.selection_rect.setGeometry(0, 0, 0, 0) self.selection_rect_startpos = None r.c = self #this is for using objectedit from command.py # Get world building modules python handler self.cpp_python_handler = r.getQWorldBuildingHandler() if self.cpp_python_handler == None: r.logDebug( "Could not aqquire world building service to object edit") else: # Connect signals self.cpp_python_handler.connect('ActivateEditing(bool)', self.on_activate_editing) self.cpp_python_handler.connect('ManipulationMode(int)', self.on_manupulation_mode_change) self.cpp_python_handler.connect('RemoveHightlight()', self.deselect_all) self.cpp_python_handler.connect( 'RotateValuesToNetwork(int, int, int)', self.changerot_cpp) self.cpp_python_handler.connect( 'ScaleValuesToNetwork(double, double, double)', self.changescale_cpp) self.cpp_python_handler.connect( 'PosValuesToNetwork(double, double, double)', self.changepos_cpp) self.cpp_python_handler.connect('CreateObject()', self.createObject) self.cpp_python_handler.connect('DuplicateObject()', self.duplicate) self.cpp_python_handler.connect('DeleteObject()', self.deleteObject) # Pass widgets self.cpp_python_handler.PassWidget("Mesh", self.window.mesh_widget) self.cpp_python_handler.PassWidget("Animation", self.window.animation_widget) self.cpp_python_handler.PassWidget("Sound", self.window.sound_widget) self.cpp_python_handler.PassWidget( "Materials", self.window.materialTabFormWidget) # Check if build mode is active, required on python restarts self.on_activate_editing( self.cpp_python_handler.IsBuildingActive())
class SFTPUploader(): def __init__(self): try: tempLocation = QDesktopServices.storageLocation(QDesktopServices.TempLocation) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tempLocation = QStandardPaths.writableLocation(QStandardPaths.TempLocation) paramiko.util.log_to_file(tempLocation + "/screencloud-sftp.log") self.uil = QUiLoader() self.loadSettings() def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.group_server.combo_auth.connect("currentIndexChanged(QString)", self.authMethodChanged) self.settingsDialog.group_server.button_browse.connect("clicked()", self.browseForKeyfile) self.settingsDialog.group_location.input_name.connect("textChanged(QString)", self.nameFormatEdited) self.settingsDialog.connect("accepted()", self.saveSettings) self.loadSettings() self.updateUi() self.settingsDialog.group_server.input_host.text = self.host self.settingsDialog.group_server.input_port.value = self.port self.settingsDialog.group_server.input_username.text = self.username self.settingsDialog.group_server.input_password.text = self.password self.settingsDialog.group_server.input_keyfile.text = self.keyfile self.settingsDialog.group_server.input_passphrase.text = self.passphrase self.settingsDialog.group_location.input_folder.text = self.folder self.settingsDialog.group_location.input_url.text = self.url self.settingsDialog.group_location.input_name.text = self.nameFormat self.settingsDialog.group_server.combo_auth.setCurrentIndex(self.settingsDialog.group_server.combo_auth.findText(self.authMethod)) self.settingsDialog.open() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("sftp") self.host = settings.value("host", "") self.port = int(settings.value("port", 22)) self.username = settings.value("username", "") self.password = settings.value("password", "") self.keyfile = settings.value("keyfile", "") self.passphrase = settings.value("passphrase", "") self.url = settings.value("url", "") self.folder = settings.value("folder", "") self.nameFormat = settings.value("name-format", "Screenshot at %H-%M-%S") self.authMethod = settings.value("auth-method", "Password") settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("sftp") settings.setValue("host", self.settingsDialog.group_server.input_host.text) settings.setValue("port", int(self.settingsDialog.group_server.input_port.value)) settings.setValue("username", self.settingsDialog.group_server.input_username.text) settings.setValue("password", self.settingsDialog.group_server.input_password.text) settings.setValue("keyfile", self.settingsDialog.group_server.input_keyfile.text) settings.setValue("passphrase", self.settingsDialog.group_server.input_passphrase.text) settings.setValue("url", self.settingsDialog.group_location.input_url.text) settings.setValue("folder", self.settingsDialog.group_location.input_folder.text) settings.setValue("name-format", self.settingsDialog.group_location.input_name.text) settings.setValue("auth-method", self.settingsDialog.group_server.combo_auth.currentText) settings.endGroup() settings.endGroup() def updateUi(self): self.settingsDialog.group_server.label_password.setVisible(self.authMethod == "Password") self.settingsDialog.group_server.input_password.setVisible(self.authMethod == "Password") self.settingsDialog.group_server.label_keyfile.setVisible(self.authMethod == "Key") self.settingsDialog.group_server.input_keyfile.setVisible(self.authMethod == "Key") self.settingsDialog.group_server.button_browse.setVisible(self.authMethod == "Key") self.settingsDialog.group_server.label_passphrase.setVisible(self.authMethod == "Key") self.settingsDialog.group_server.input_passphrase.setVisible(self.authMethod == "Key") self.settingsDialog.adjustSize() def isConfigured(self): self.loadSettings() return not(not self.host or not self.username or not (self.password or self.keyfile) or not self.folder) def getFilename(self): self.loadSettings() return ScreenCloud.formatFilename(self.nameFormat) def upload(self, screenshot, name): self.loadSettings() #Save to a temporary file timestamp = time.time() try: tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) #Connect to server try: transport = paramiko.Transport((self.host, self.port)) except Exception as e: ScreenCloud.setError(e.message) return False if self.authMethod == "Password": try: transport.connect(username = self.username, password = self.password) except paramiko.AuthenticationException: ScreenCloud.setError("Authentication failed (password)") return False else: try: private_key = paramiko.ECDSAKey.from_private_key_file(self.keyfile, password=self.passphrase) transport.connect(username=self.username, pkey=private_key) except paramiko.AuthenticationException: ScreenCloud.setError("Authentication failed (key)") return False except paramiko.SSHException as e: ScreenCloud.setError("Error while connecting to " + self.host + ":" + str(self.port) + ". " + e.message) return False except Exception as e: ScreenCloud.setError("Unknown error: " + e.message) return False sftp = paramiko.SFTPClient.from_transport(transport) try: sftp.put(tmpFilename, self.folder + "/" + ScreenCloud.formatFilename(name)) except IOError: ScreenCloud.setError("Failed to write " + self.folder + "/" + ScreenCloud.formatFilename(name) + ". Check permissions.") return False sftp.close() transport.close() if self.url: ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name)) return True def authMethodChanged(self, method): self.authMethod = method self.updateUi() def browseForKeyfile(self): filename = QFileDialog.getOpenFileName(self.settingsDialog, "Select Keyfile...", QDesktopServices.storageLocation(QDesktopServices.HomeLocation), "*") if filename: self.settingsDialog.group_server.input_keyfile.setText(filename) def nameFormatEdited(self, nameFormat): self.settingsDialog.group_location.label_example.setText(ScreenCloud.formatFilename(nameFormat))
class DropboxUploader(): def __init__(self): self.uil = QUiLoader() self.loadSettings() if self.access_token: self.client = dropbox.client.DropboxClient(self.access_token) def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.group_account.widget_authorize.button_authenticate.connect("clicked()", self.startAuthenticationProcess) self.settingsDialog.group_account.widget_loggedIn.button_logout.connect("clicked()", self.logout) self.settingsDialog.group_name.input_nameFormat.connect("textChanged(QString)", self.nameFormatEdited) self.settingsDialog.connect("accepted()", self.saveSettings) self.loadSettings() self.updateUi() self.settingsDialog.open() def updateUi(self): self.loadSettings() if not self.access_token: self.settingsDialog.group_account.widget_loggedIn.setVisible(False) self.settingsDialog.group_account.widget_authorize.setVisible(True) self.settingsDialog.group_account.widget_authorize.button_authenticate.setEnabled(True) self.settingsDialog.group_name.setEnabled(False) self.settingsDialog.group_clipboard.setEnabled(False) else: self.settingsDialog.group_account.widget_loggedIn.setVisible(True) self.settingsDialog.group_account.widget_authorize.setVisible(False) self.settingsDialog.group_account.widget_loggedIn.label_user.setText(self.display_name) self.settingsDialog.group_name.setEnabled(True) self.settingsDialog.group_clipboard.setEnabled(True) self.settingsDialog.group_clipboard.radio_publiclink.setChecked(self.copy_link) self.settingsDialog.group_clipboard.radio_dontcopy.setChecked(not self.copy_link) self.settingsDialog.group_name.input_nameFormat.setText(self.nameFormat) self.settingsDialog.adjustSize() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("dropbox") self.access_token = settings.value("access-token", "") self.user_id = settings.value("user-id", "") self.display_name = settings.value("display-name", "") self.copy_link = settings.value("copy-link", "true") in ['true', True] self.nameFormat = settings.value("name-format", "Screenshot at %H-%M-%S") settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("dropbox") settings.setValue("access-token", self.access_token) settings.setValue("user-id", self.user_id) settings.setValue("display-name", self.display_name) settings.setValue("copy-link", self.settingsDialog.group_clipboard.radio_publiclink.checked) settings.setValue("name-format", self.settingsDialog.group_name.input_nameFormat.text) settings.endGroup() settings.endGroup() def isConfigured(self): self.loadSettings() if not self.access_token: return False return True def getFilename(self): self.loadSettings() return ScreenCloud.formatFilename(self.nameFormat) def upload(self, screenshot, name): self.loadSettings() timestamp = time.time() try: tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) f = open(tmpFilename, 'rb') response = self.client.put_file('/' + ScreenCloud.formatFilename(name), f) f.close() os.remove(tmpFilename) if self.copy_link: share = self.client.share('/' + ScreenCloud.formatFilename(name), False) ScreenCloud.setUrl(share['url'].replace('dl=0', 'raw=1')) return True def selectFolderClicked(self): self.selectFolderDialog.exec_() def startAuthenticationProcess(self): self.settingsDialog.group_account.widget_authorize.button_authenticate.setEnabled(False) self.flow = dropbox.client.DropboxOAuth2FlowNoRedirect('sfacmqvdb9dn66r', 'hx8meda636xgsox') authorize_url = QUrl(self.flow.start()) QDesktopServices.openUrl(authorize_url) try: code = raw_input("Enter the authorization code from the dropbox website:") except NameError: code = input("Enter the authorization code from the dropbox website:") if code: try: self.access_token, self.user_id = self.flow.finish(code) self.client = dropbox.client.DropboxClient(self.access_token) self.display_name = self.client.account_info()['display_name'] except dropbox.rest.ErrorResponse: if "win" in sys.platform: #Workaround for crash on windows self.parentWidget.hide() self.settingsDialog.hide() QMessageBox.critical(self.settingsDialog, "Failed to authenticate", "Failed to authenticate with Dropbox. Wrong code?") if "win" in sys.platform: self.settingsDialog.show() self.parentWidget.show() self.saveSettings() self.updateUi() def logout(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("dropbox") settings.remove("access-token") settings.remove("user-id") settings.remove("display-name") settings.endGroup() settings.endGroup() self.loadSettings() self.updateUi() def nameFormatEdited(self, nameFormat): self.settingsDialog.group_name.label_example.setText(ScreenCloud.formatFilename(nameFormat))
class FileUploader(): def __init__(self): self.uil = QUiLoader() self.loadSettings() def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.group_name.input_name.connect("textChanged(QString)", self.nameFormatEdited) self.settingsDialog.group_location.button_browse.connect("clicked()", self.browseForFolder) self.settingsDialog.connect("accepted()", self.saveSettings) self.loadSettings() self.settingsDialog.group_name.input_name.setText(self.nameFormat) self.settingsDialog.group_location.input_folder.setText(self.folder) self.settingsDialog.open() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("file") self.nameFormat = settings.value("name-format", "Screenshot at %H-%M-%S") self.folder = settings.value("folder", "") settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("file") settings.setValue("name-format", self.settingsDialog.group_name.input_name.text) settings.setValue("folder", self.settingsDialog.group_location.input_folder.text) settings.endGroup() settings.endGroup() def isConfigured(self): self.loadSettings() return self.folder and self.nameFormat def getFilename(self): self.loadSettings() return ScreenCloud.formatFilename(self.nameFormat) def upload(self, screenshot, name): self.loadSettings() f = QFile(self.folder + "/" + ScreenCloud.formatFilename(name)) f.open(QIODevice.WriteOnly) if not f.isWritable(): ScreenCloud.setError("File " + f.fileName() + " is not writable!") return False screenshot.save(f, ScreenCloud.getScreenshotFormat()) f.close() return True def nameFormatEdited(self, nameFormat): self.settingsDialog.group_name.label_example.setText(ScreenCloud.formatFilename(nameFormat)) def browseForFolder(self): selectedFolder = QFileDialog.getExistingDirectory(self.settingsDialog, "Select Folder...", self.folder) if selectedFolder: self.settingsDialog.group_location.input_folder.setText(selectedFolder) self.saveSettings()
class FileUploader(): def __init__(self): self.uil = QUiLoader() self.loadSettings() def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.group_name.input_name.connect( "textChanged(QString)", self.nameFormatEdited) self.settingsDialog.group_location.button_browse.connect( "clicked()", self.browseForFolder) self.settingsDialog.connect("accepted()", self.saveSettings) self.loadSettings() self.settingsDialog.group_name.input_name.setText(self.nameFormat) self.settingsDialog.group_location.input_folder.setText(self.folder) self.settingsDialog.open() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("file") self.nameFormat = settings.value("name-format", "Screenshot at %H-%M-%S") self.folder = settings.value("folder", "") settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("file") settings.setValue("name-format", self.settingsDialog.group_name.input_name.text) settings.setValue("folder", self.settingsDialog.group_location.input_folder.text) settings.endGroup() settings.endGroup() def isConfigured(self): self.loadSettings() return self.folder and self.nameFormat def getFilename(self): self.loadSettings() return ScreenCloud.formatFilename(self.nameFormat) def upload(self, screenshot, name): self.loadSettings() f = QFile(self.folder + "/" + ScreenCloud.formatFilename(self.nameFormat)) f.open(QIODevice.WriteOnly) if not f.isWritable(): ScreenCloud.setError("File " + f.fileName() + " is not writable!") return False screenshot.save(f, ScreenCloud.getScreenshotFormat()) f.close() return True def nameFormatEdited(self, nameFormat): self.settingsDialog.group_name.label_example.setText( ScreenCloud.formatFilename(nameFormat)) def browseForFolder(self): selectedFolder = QFileDialog.getExistingDirectory( self.settingsDialog, "Select Folder...", self.folder) if selectedFolder: self.settingsDialog.group_location.input_folder.setText( selectedFolder) self.saveSettings()
class ShellUploader(): def __init__(self): self.uil = QUiLoader() def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.connect("accepted()", self.saveSettings) self.loadSettings() self.settingsDialog.group_shell.input_command.text = self.commandFormat self.settingsDialog.group_shell.output_is_url.checked = self.outputIsUrl self.settingsDialog.open() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("shell") self.commandFormat = settings.value("command", "") self.outputIsUrl = settings.value("copyOutput", str(False)) == "True" settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("shell") settings.setValue("command", self.settingsDialog.group_shell.input_command.text) settings.setValue( "copyOutput", str(self.settingsDialog.group_shell.output_is_url.checked)) settings.endGroup() settings.endGroup() def isConfigured(self): self.loadSettings() if not self.commandFormat: return False return True def getFilename(self): timestamp = time.time() return ScreenCloud.formatFilename(str(timestamp)) def upload(self, screenshot, name): self.loadSettings() try: tmpFilename = QDesktopServices.storageLocation( QDesktopServices.TempLocation) + "/" + name except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation( QStandardPaths.TempLocation) + "/" + name screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) command = string.Formatter().vformat(self.commandFormat, (), defaultdict(str, s=tmpFilename)) try: command = command.encode(sys.getfilesystemencoding()) except UnicodeEncodeError: ScreenCloud.setError("Invalid characters in command '" + command + "'") return False try: if self.outputIsUrl: pipe = subprocess.PIPE else: pipe = None p = subprocess.Popen(command, shell=True, stdout=pipe) p.wait() if p.returncode > 0: ScreenCloud.setError("Command " + command + " did not return 0") return False elif self.outputIsUrl: result = p.stdout.read() result = result.strip() ScreenCloud.setUrl(result) except OSError: ScreenCloud.setError("Failed to run command " + command) return False return True
class UguuUploader: def __init__(self): self.uil = QUiLoader() self.loadSettings() def isConfigured(self): return True def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("uguu.se") self.nameFormat = settings.value("name-format", "screenshot-%H-%M-%S") self.copyLink = settings.value("copy-link", "true") in ["true", True] settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("uguu.se") settings.setValue("name-format", self.settingsDialog.group_name.input_name.text) settings.setValue("copy-link", self.settingsDialog.group_clipboard.checkbox_copy_link.checked) settings.endGroup() settings.endGroup() def getFilename(self): self.loadSettings() return ScreenCloud.formatFilename(self.nameFormat) def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.group_name.input_name.connect("textChanged(QString)", self.nameFormatEdited) self.settingsDialog.connect("accepted()", self.saveSettings) self.updateUi() self.settingsDialog.open() def updateUi(self): self.loadSettings() self.settingsDialog.group_name.input_name.setText(self.nameFormat) self.settingsDialog.group_clipboard.checkbox_copy_link.setChecked(self.copyLink) def upload(self, screenshot, name): self.loadSettings() tmpFilename = ( QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename(str(time.time())) ) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) data = {"name": name} files = {"file": open(tmpFilename, "rb")} try: response = requests.post("https://uguu.se/api.php?d=upload-tool", data=data, files=files) response.raise_for_status() if self.copyLink: ScreenCloud.setUrl(response.text) except RequestException as e: ScreenCloud.setError("Failed to upload to Uguu.se: " + e.message) return False return True def nameFormatEdited(self, nameFormat): self.settingsDialog.group_name.label_example.setText(ScreenCloud.formatFilename(nameFormat, False))
class ShellUploader(): def __init__(self): self.uil = QUiLoader() def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.connect("accepted()", self.saveSettings) self.loadSettings() self.settingsDialog.group_shell.input_command.text = self.commandFormat self.settingsDialog.group_shell.output_is_url.checked = self.outputIsUrl self.settingsDialog.open() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("shell") self.commandFormat = settings.value("command", "") self.outputIsUrl = settings.value("copyOutput",str(False)) == "True" settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("shell") settings.setValue("command", self.settingsDialog.group_shell.input_command.text) settings.setValue("copyOutput", str(self.settingsDialog.group_shell.output_is_url.checked)) settings.endGroup() settings.endGroup() def isConfigured(self): self.loadSettings() if not self.commandFormat: return False return True def getFilename(self): timestamp = time.time() return ScreenCloud.formatFilename(str(timestamp)) def upload(self, screenshot, name): self.loadSettings() try: tmpFilename = QDesktopServices.storageLocation(QDesktopServices.TempLocation) + "/" + name except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation(QStandardPaths.TempLocation) + "/" + name screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) command = string.Formatter().vformat(self.commandFormat, (), defaultdict(str, s = tmpFilename)) try: command = command.encode(sys.getfilesystemencoding()) except UnicodeEncodeError: ScreenCloud.setError("Invalid characters in command '" + command + "'") return False try: if self.outputIsUrl: pipe = subprocess.PIPE else: pipe = None p = subprocess.Popen(command, shell=True, stdout=pipe) p.wait() if p.returncode > 0: ScreenCloud.setError("Command %s returned %d, but 0 was expected" % (str(command), int(p.returncode))) return False elif self.outputIsUrl: result = bytes.decode(p.stdout.read()) result = result.strip() ScreenCloud.setUrl(result) except OSError: ScreenCloud.setError("Failed to run command " + command) return False return True
def __init__(self): self.sels = [] Component.__init__(self) self.window = window.ObjectEditWindow(self) self.resetValues() self.worldstream = r.getServerConnection() self.usingManipulator = False self.useLocalTransform = False self.cpp_python_handler = None self.left_button_down = False self.keypressed = False self.shortcuts = { (Qt.Key_Z, Qt.ControlModifier) : self.undo, (Qt.Key_Delete, Qt.NoModifier) : self.deleteObject, (Qt.Key_L, Qt.AltModifier) : self.linkObjects, (Qt.Key_L, Qt.ControlModifier|Qt.ShiftModifier) : self.unlinkObjects, } # Connect to key pressed signal from input context self.edit_inputcontext = naali.createInputContext("object-edit", 100) self.edit_inputcontext.SetTakeMouseEventsOverQt(True) self.edit_inputcontext.connect('KeyPressed(KeyEvent*)', self.on_keypressed) # Connect to mouse events self.edit_inputcontext.connect('MouseScroll(MouseEvent*)', self.on_mousescroll) self.edit_inputcontext.connect('MouseLeftPressed(MouseEvent*)', self.on_mouseleftpressed) self.edit_inputcontext.connect('MouseLeftReleased(MouseEvent*)', self.on_mouseleftreleased) self.edit_inputcontext.connect('MouseMove(MouseEvent*)', self.on_mousemove) self.resetManipulators() loader = QUiLoader() selectionfile = QFile(self.SELECTIONRECT) self.selection_rect = loader.load(selectionfile) #rectprops = r.createUiWidgetProperty(2) #~ print type(rectprops), dir(rectprops) #print rectprops.WidgetType #uiprops.widget_name_ = "Selection Rect" #uiprops.my_size_ = QSize(width, height) #not needed anymore, uimodule reads it proxy = r.createUiProxyWidget(self.selection_rect) uism = r.getUiSceneManager() uism.AddWidgetToScene(proxy) proxy.setWindowFlags(0) #changing it to Qt::Widget self.selection_rect.setGeometry(0,0,0,0) self.selection_rect_startpos = None r.c = self #this is for using objectedit from command.py # Get world building modules python handler self.cpp_python_handler = r.getQWorldBuildingHandler() if self.cpp_python_handler == None: r.logDebug("Could not aqquire world building service to object edit") else: # Connect signals self.cpp_python_handler.connect('ActivateEditing(bool)', self.on_activate_editing) self.cpp_python_handler.connect('ManipulationMode(int)', self.on_manupulation_mode_change) self.cpp_python_handler.connect('RemoveHightlight()', self.deselect_all) self.cpp_python_handler.connect('RotateValuesToNetwork(int, int, int)', self.changerot_cpp) self.cpp_python_handler.connect('ScaleValuesToNetwork(double, double, double)', self.changescale_cpp) self.cpp_python_handler.connect('PosValuesToNetwork(double, double, double)', self.changepos_cpp) self.cpp_python_handler.connect('CreateObject()', self.createObject) self.cpp_python_handler.connect('DuplicateObject()', self.duplicate) self.cpp_python_handler.connect('DeleteObject()', self.deleteObject) # Pass widgets self.cpp_python_handler.PassWidget("Mesh", self.window.mesh_widget) self.cpp_python_handler.PassWidget("Animation", self.window.animation_widget) self.cpp_python_handler.PassWidget("Sound", self.window.sound_widget) self.cpp_python_handler.PassWidget("Materials", self.window.materialTabFormWidget) # Check if build mode is active, required on python restarts self.on_activate_editing(self.cpp_python_handler.IsBuildingActive())
class SFTPUploader(): def __init__(self): try: tempLocation = QDesktopServices.storageLocation( QDesktopServices.TempLocation) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tempLocation = QStandardPaths.writableLocation( QStandardPaths.TempLocation) #paramiko.util.log_to_file(tempLocation + "/screencloud-sftp.log") self.uil = QUiLoader() self.loadSettings() def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.group_server.combo_auth.connect( "currentIndexChanged(QString)", self.authMethodChanged) self.settingsDialog.group_server.button_browse.connect( "clicked()", self.browseForKeyfile) self.settingsDialog.group_location.input_name.connect( "textChanged(QString)", self.nameFormatEdited) self.settingsDialog.connect("accepted()", self.saveSettings) self.loadSettings() self.updateUi() self.settingsDialog.group_server.input_host.text = self.host self.settingsDialog.group_server.input_port.value = self.port self.settingsDialog.group_server.input_username.text = self.username self.settingsDialog.group_server.input_password.text = self.password self.settingsDialog.group_server.input_keyfile.text = self.keyfile self.settingsDialog.group_server.input_passphrase.text = self.passphrase self.settingsDialog.group_location.input_folder.text = self.folder self.settingsDialog.group_location.input_url.text = self.url self.settingsDialog.group_location.input_name.text = self.nameFormat self.settingsDialog.group_server.combo_auth.setCurrentIndex( self.settingsDialog.group_server.combo_auth.findText( self.authMethod)) self.settingsDialog.open() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("sftp") self.host = settings.value("host", "") self.port = int(settings.value("port", 22)) self.username = settings.value("username", "") self.password = settings.value("password", "") self.keyfile = settings.value("keyfile", "") self.passphrase = settings.value("passphrase", "") self.url = settings.value("url", "") self.folder = settings.value("folder", "") self.nameFormat = settings.value("name-format", "Screenshot at %H-%M-%S") self.authMethod = settings.value("auth-method", "Password") settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("sftp") settings.setValue("host", self.settingsDialog.group_server.input_host.text) settings.setValue( "port", int(self.settingsDialog.group_server.input_port.value)) settings.setValue("username", self.settingsDialog.group_server.input_username.text) settings.setValue("password", self.settingsDialog.group_server.input_password.text) settings.setValue("keyfile", self.settingsDialog.group_server.input_keyfile.text) settings.setValue( "passphrase", self.settingsDialog.group_server.input_passphrase.text) settings.setValue("url", self.settingsDialog.group_location.input_url.text) settings.setValue("folder", self.settingsDialog.group_location.input_folder.text) settings.setValue("name-format", self.settingsDialog.group_location.input_name.text) settings.setValue( "auth-method", self.settingsDialog.group_server.combo_auth.currentText) settings.endGroup() settings.endGroup() def updateUi(self): self.settingsDialog.group_server.label_password.setVisible( self.authMethod == "Password") self.settingsDialog.group_server.input_password.setVisible( self.authMethod == "Password") self.settingsDialog.group_server.label_keyfile.setVisible( self.authMethod == "Key") self.settingsDialog.group_server.input_keyfile.setVisible( self.authMethod == "Key") self.settingsDialog.group_server.button_browse.setVisible( self.authMethod == "Key") self.settingsDialog.group_server.label_passphrase.setVisible( self.authMethod == "Key") self.settingsDialog.group_server.input_passphrase.setVisible( self.authMethod == "Key") self.settingsDialog.adjustSize() def isConfigured(self): self.loadSettings() return not (not self.host or not self.username or not (self.password or self.keyfile) or not self.folder) def getFilename(self): self.loadSettings() return ScreenCloud.formatFilename(self.nameFormat) def upload(self, screenshot, name): self.loadSettings() #Save to a temporary file timestamp = time.time() try: tmpFilename = QDesktopServices.storageLocation( QDesktopServices.TempLocation ) + "/" + ScreenCloud.formatFilename(str(timestamp)) except AttributeError: from PythonQt.QtCore import QStandardPaths #fix for Qt5 tmpFilename = QStandardPaths.writableLocation( QStandardPaths.TempLocation ) + "/" + ScreenCloud.formatFilename(str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) #Connect to server try: transport = paramiko.Transport((self.host, self.port)) except Exception as e: ScreenCloud.setError(e.message) return False if self.authMethod == "Password": try: transport.connect(username=self.username, password=self.password) except paramiko.AuthenticationException: ScreenCloud.setError("Authentication failed (password)") return False else: try: private_key = paramiko.RSAKey.from_private_key_file( self.keyfile, password=self.passphrase) transport.connect(username=self.username, pkey=private_key) except paramiko.AuthenticationException: ScreenCloud.setError("Authentication failed (key)") return False except paramiko.SSHException as e: ScreenCloud.setError("Error while connecting to " + self.host + ":" + str(self.port) + ". " + e.message) return False except Exception as e: ScreenCloud.setError("Unknown error: " + e.message) return False sftp = paramiko.SFTPClient.from_transport(transport) try: sftp.put(tmpFilename, self.folder + "/" + ScreenCloud.formatFilename(name)) except IOError: ScreenCloud.setError("Failed to write " + self.folder + "/" + ScreenCloud.formatFilename(name) + ". Check permissions.") return False sftp.close() transport.close() if self.url: ScreenCloud.setUrl(self.url + ScreenCloud.formatFilename(name)) return True def authMethodChanged(self, method): self.authMethod = method self.updateUi() def browseForKeyfile(self): filename = QFileDialog.getOpenFileName( self.settingsDialog, "Select Keyfile...", QDesktopServices.storageLocation(QDesktopServices.HomeLocation), "*") if filename: self.settingsDialog.group_server.input_keyfile.setText(filename) def nameFormatEdited(self, nameFormat): self.settingsDialog.group_location.label_example.setText( ScreenCloud.formatFilename(nameFormat))
class DropboxUploader(): def __init__(self): self.uil = QUiLoader() self.loadSettings() if self.access_token: self.client = dropbox.client.DropboxClient(self.access_token) def showSettingsUI(self, parentWidget): self.parentWidget = parentWidget self.settingsDialog = self.uil.load(QFile(workingDir + "/settings.ui"), parentWidget) self.settingsDialog.group_account.widget_authorize.button_authenticate.connect( "clicked()", self.startAuthenticationProcess) self.settingsDialog.group_account.widget_loggedIn.button_logout.connect( "clicked()", self.logout) self.settingsDialog.group_name.input_nameFormat.connect( "textChanged(QString)", self.nameFormatEdited) self.settingsDialog.connect("accepted()", self.saveSettings) self.loadSettings() self.updateUi() self.settingsDialog.open() def updateUi(self): self.loadSettings() if not self.access_token: self.settingsDialog.group_account.widget_loggedIn.setVisible(False) self.settingsDialog.group_account.widget_authorize.setVisible(True) self.settingsDialog.group_account.widget_authorize.button_authenticate.setEnabled( True) self.settingsDialog.group_name.setEnabled(False) self.settingsDialog.group_clipboard.setEnabled(False) else: self.settingsDialog.group_account.widget_loggedIn.setVisible(True) self.settingsDialog.group_account.widget_authorize.setVisible( False) self.settingsDialog.group_account.widget_loggedIn.label_user.setText( self.display_name) self.settingsDialog.group_name.setEnabled(True) self.settingsDialog.group_clipboard.setEnabled(True) self.settingsDialog.group_clipboard.radio_publiclink.setChecked( self.copy_link) self.settingsDialog.group_clipboard.radio_dontcopy.setChecked( not self.copy_link) self.settingsDialog.group_name.input_nameFormat.setText( self.nameFormat) self.settingsDialog.adjustSize() def loadSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("dropbox") self.access_token = settings.value("access-token", "") self.user_id = settings.value("user-id", "") self.display_name = settings.value("display-name", "") self.copy_link = settings.value("copy-link", "true") in ['true', True] self.nameFormat = settings.value("name-format", "Screenshot at %H-%M-%S") settings.endGroup() settings.endGroup() def saveSettings(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("dropbox") settings.setValue("access-token", self.access_token) settings.setValue("user-id", self.user_id) settings.setValue("display-name", self.display_name) settings.setValue( "copy-link", self.settingsDialog.group_clipboard.radio_publiclink.checked) settings.setValue("name-format", self.settingsDialog.group_name.input_nameFormat.text) settings.endGroup() settings.endGroup() def isConfigured(self): self.loadSettings() if not self.access_token: return False return True def getFilename(self): self.loadSettings() return ScreenCloud.formatFilename(self.nameFormat) def upload(self, screenshot, name): self.loadSettings() timestamp = time.time() tmpFilename = QDesktopServices.storageLocation( QDesktopServices.TempLocation) + "/" + ScreenCloud.formatFilename( str(timestamp)) screenshot.save(QFile(tmpFilename), ScreenCloud.getScreenshotFormat()) f = open(tmpFilename, 'rb') response = self.client.put_file('/' + ScreenCloud.formatFilename(name), f) f.close() os.remove(tmpFilename) if self.copy_link: share = self.client.share('/' + ScreenCloud.formatFilename(name)) ScreenCloud.setUrl(share['url']) return True def selectFolderClicked(self): self.selectFolderDialog.exec_() def startAuthenticationProcess(self): self.settingsDialog.group_account.widget_authorize.button_authenticate.setEnabled( False) self.flow = dropbox.client.DropboxOAuth2FlowNoRedirect( 'sfacmqvdb9dn66r', 'hx8meda636xgsox') authorize_url = QUrl(self.flow.start()) QDesktopServices.openUrl(authorize_url) code = raw_input( "Enter the authorization code from the dropbox website:") if code: try: self.access_token, self.user_id = self.flow.finish(code) self.client = dropbox.client.DropboxClient(self.access_token) self.display_name = self.client.account_info()['display_name'] except dropbox.rest.ErrorResponse: if "win" in sys.platform: #Workaround for crash on windows self.parentWidget.hide() self.settingsDialog.hide() QMessageBox.critical( self.settingsDialog, "Failed to authenticate", "Failed to authenticate with Dropbox. Wrong code?") if "win" in sys.platform: self.settingsDialog.show() self.parentWidget.show() self.saveSettings() self.updateUi() def logout(self): settings = QSettings() settings.beginGroup("uploaders") settings.beginGroup("dropbox") settings.remove("access-token") settings.remove("user-id") settings.remove("display-name") settings.endGroup() settings.endGroup() self.loadSettings() self.updateUi() def nameFormatEdited(self, nameFormat): self.settingsDialog.group_name.label_example.setText( ScreenCloud.formatFilename(nameFormat))
def __init__(self, controller): self.controller = controller loader = QUiLoader() loader.setLanguageChangeEnabled(True) uifile = QFile(self.UIFILE) ui = loader.load(uifile) width = ui.size.width() height = ui.size.height() uism = naali.ui self.widget = ui # Material/Texture widgets self.materialTabFormWidget = ui.findChild("QWidget", "MaterialsTab").formLayoutWidget # Mesh line edit and buttons self.meshline = lines.MeshAssetidEditline(controller) self.meshline.name = "meshLineEdit" button_ok = self.getButton("Apply", self.ICON_OK, self.meshline, self.meshline.applyAction) button_cancel = self.getButton("Cancel", self.ICON_CANCEL, self.meshline, self.meshline.cancelAction) button_browse = self.getButton("Browse", self.ICON_FOLDER, None, None) box = QHBoxLayout() box.setContentsMargins(0,0,0,0) box.addWidget(self.meshline) box.addWidget(button_browse) box.addWidget(button_ok) box.addWidget(button_cancel) self.mesh_widget = QWidget() self.mesh_widget.setLayout(box) # Sound line edit and buttons self.soundline = lines.SoundAssetidEditline(controller) self.soundline.name = "soundLineEdit" soundbutton_ok = self.getButton("Apply", self.ICON_OK, self.soundline, self.soundline.applyAction) soundbutton_cancel = self.getButton("Cancel", self.ICON_CANCEL, self.soundline, self.soundline.cancelAction) soundbutton_browse = self.getButton("Browse", self.ICON_FOLDER, None, None) soundRadius = self.getDoubleSpinBox("soundRadius", "Set sound radius", self.soundline) soundVolume = self.getDoubleSpinBox("soundVolume", "Set sound volume", self.soundline) main_box = QVBoxLayout() main_box.setContentsMargins(0,0,0,0) box_buttons = QHBoxLayout() box_buttons.setContentsMargins(0,0,0,0) # TODO no need for self? # crashed always if didnt put self to second label :P you can try to remove them... # basically the qwidget ptr must stay somewhere in py otherwise will crash when gets to painting -Pforce self.label_radius = QLabel("Radius") self.label_radius.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred) self.label_volume = QLabel("Volume") self.label_volume.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred) box_buttons.addWidget(self.label_radius) box_buttons.addWidget(soundRadius) box_buttons.addWidget(self.label_volume) box_buttons.addWidget(soundVolume) box_buttons.addWidget(soundbutton_browse) box_buttons.addWidget(soundbutton_ok) box_buttons.addWidget(soundbutton_cancel) main_box.addWidget(self.soundline) main_box.addLayout(box_buttons) self.sound_widget = QWidget() self.sound_widget.setLayout(main_box) # Animation line edit and buttons self.animation_title = QLabel("Skeleton Animation") self.animation_title.setStyleSheet("font-size:18px;font-weight:bold;padding-top:5px;") self.animation_title.setIndent(0) self.animationline = lines.AnimationAssetidEditline(controller) self.animationline.name = "animationLineEdit" animation_combobox = self.getCombobox("AnimationName", "Animation Name", self.animationline) animationbutton_ok = self.getButton("Apply", self.ICON_OK, self.animationline, self.animationline.applyAction) animationbutton_cancel = self.getButton("Cancel", self.ICON_CANCEL, self.animationline, self.animationline.cancelAction) animationbutton_browse = self.getButton("Browse", self.ICON_FOLDER, None, None) animationRate = self.getDoubleSpinBox("animationRate", "Set animation rate", self.animationline) animationbox = QVBoxLayout() animationbox.setContentsMargins(0,0,0,0) self.anim_box_buttons = QHBoxLayout() self.anim_box_buttons.name = "AnimBoxButtons" self.anim_box_buttons.setContentsMargins(0,0,0,0) label_rate = QLabel("Rate") label_rate.name = "Animation Rate" label_rate.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred) self.anim_box_buttons.addWidget(animation_combobox) self.anim_box_buttons.addWidget(label_rate) self.anim_box_buttons.addWidget(animationRate) self.anim_box_buttons.addWidget(animationbutton_browse) self.anim_box_buttons.addWidget(animationbutton_ok) self.anim_box_buttons.addWidget(animationbutton_cancel) animationbox.addWidget(self.animation_title) animationbox.addWidget(self.animationline) animationbox.addLayout(self.anim_box_buttons) self.animation_widget = QWidget() self.animation_widget.setLayout(animationbox) self.animation_widget.hide() self.updatingSelection = False # mesh buttons self.meshline.connect('textEdited(QString)', button_ok.lineValueChanged) self.meshline.connect('textEdited(QString)', button_cancel.lineValueChanged) # audio buttons self.soundline.connect('textEdited(QString)', soundbutton_ok.lineValueChanged) self.soundline.connect('textEdited(QString)', soundbutton_cancel.lineValueChanged) soundRadius.connect('valueChanged(double)', soundbutton_ok.lineValueChanged) soundRadius.connect('valueChanged(double)', soundbutton_cancel.lineValueChanged) soundVolume.connect('valueChanged(double)', soundbutton_ok.lineValueChanged) soundVolume.connect('valueChanged(double)', soundbutton_cancel.lineValueChanged) # animation buttons self.animationline.connect('textEdited(QString)', animationbutton_ok.lineValueChanged) self.animationline.connect('textEdited(QString)', animationbutton_cancel.lineValueChanged) animationRate.connect('valueChanged(double)', animationbutton_ok.lineValueChanged) animationRate.connect('valueChanged(double)', animationbutton_cancel.lineValueChanged) animation_combobox.connect('currentIndexChanged(int)', animationbutton_ok.lineValueChanged) animation_combobox.connect('currentIndexChanged(int)', animationbutton_cancel.lineValueChanged) self.mainTabList = {} self.currentlySelectedTreeWidgetItem = []