Exemplo n.º 1
0
 def saveStagesAsPreset(self, stages):
     from PythonQt import BoolResult
     ok = BoolResult()
     presetName = qt.QInputDialog().getText(qt.QWidget(), 'Save Preset',
                                            'Preset name: ',
                                            qt.QLineEdit.Normal,
                                            'my_preset', ok)
     if not ok:
         return
     if presetName in self.getPresetNames():
         qt.QMessageBox().warning(
             qt.QWidget(), 'Warning',
             presetName + ' already exists. Set another name.')
         self.saveStagesAsPreset(stages)
         return
     outFilePath = os.path.join(self.presetPath, presetName + '.json')
     saveSettings = self.getPresetParametersByName()
     saveSettings['stages'] = self.removeNodesFromStages(stages)
     try:
         with open(outFilePath, 'w') as outfile:
             json.dump(saveSettings, outfile)
     except:
         qt.QMessageBox().warning(qt.QWidget(), 'Warning',
                                  'Unable to write into ' + outFilePath)
         return
     print('Saved preset to ' + outFilePath)
     return presetName
Exemplo n.º 2
0
def inputInt(title="", label="", val=0, min=-2147483647, max=2147483647, step=1):
    x = QDialog()
    x.setAttribute(Qt.WA_DeleteOnClose)
    ok = BoolResult()
    i = QInputDialog.getInt(x, title, label, val, min, max, step, ok)
    if ok: return i
    else: return False
Exemplo n.º 3
0
 def addFunction(self):
     if self.parameterNode.GetParameter("MNIAtlasPath") != ".":
         items = ImportAtlas.ImportAtlasLogic().getValidAtlases(
             self.parameterNode.GetParameter("MNIAtlasPath"))
         result = BoolResult()
         atlasName = qt.QInputDialog.getItem(qt.QWidget(), 'Select Atlas',
                                             '', items, 0, 0, result)
         if result:
             ImportAtlas.ImportAtlasLogic().run(
                 os.path.join(
                     self.parameterNode.GetParameter("MNIAtlasPath"),
                     atlasName))
Exemplo n.º 4
0
def inputBox(parent, title, text, default=""):
    """
    :param default:
    :param title:
    :param text:
    :return:
    """
    x = QWidget(parent)
    x.setAttribute(Qt.WA_DeleteOnClose)
    ok = BoolResult()
    text = QInputDialog.getText(x, title, text, QLineEdit.Normal, default, ok)
    if ok: return text
    else: return False
Exemplo n.º 5
0
def inputBox(title, text, default=""):
    """
    :param default:
    :param title:
    :param text:
    :return:
    """
    x = QWidget()
    x.setAttribute(Qt.WA_DeleteOnClose)
    ok = BoolResult()
    if not default: default = QApplication.clipboard().text()
    text = QInputDialog.getText(x, title, text, QLineEdit.Normal, default, ok) # QDir.Home.dirName()
    if ok: return text
    else: return False
Exemplo n.º 6
0
def inputInt(title="", label="", val=0, min=-2147483647, max=2147483647, step=1):
    """
    :param title:
    :param label:
    :param val:
    :param min:
    :param max:
    :param step:
    :return:
    """
    x = QWidget()
    x.setAttribute(Qt.WA_DeleteOnClose)
    ok = BoolResult()
    i = QInputDialog.getInt(x, title, label, val, min, max, step, ok)
    if ok: return i
    else: return False
Exemplo n.º 7
0
 def addFunction(self):
     if self.parameterNode.GetParameter("MNIAtlasPath") not in [".", ""]:
         directory = self.parameterNode.GetParameter("MNIAtlasPath")
     else:
         with open(
                 os.path.join(
                     os.path.split(ImportAtlas.__file__)[0], 'Resources',
                     'previousDirectory.txt'), 'r') as f:
             directory = f.readlines()[0]
             if directory == ".":
                 return
     # load
     items = ImportAtlas.ImportAtlasLogic().getValidAtlases(directory)
     result = BoolResult()
     atlasName = qt.QInputDialog.getItem(qt.QWidget(), 'Select Atlas', '',
                                         items, 0, 0, result)
     if result:
         ImportAtlas.ImportAtlasLogic().readAtlas(
             os.path.join(directory, atlasName, 'atlas_index.mat'))
Exemplo n.º 8
0
    def on_repositoryList_doubleClicked(self, item):
        name = item.data(Qt.UserRole)
        try:
            rep = self.replist[name]
        except:
            QMessageBox.critical(self, self._tr("Internal error"),
                                 self._tr("Can't find repository {name} in "
                                          "list").format(name=name))
            return

        ok = BoolResult()
        newurl = QInputDialog.getText(self,
                                      self._tr("Change url of repository "
                                               "{name}").format(name=name),
                                      self._tr("Url:"), QLineEdit.Normal,
                                      rep["url"], ok)

        if ok:
            rep["url"] = newurl
            rep["origin"] = "local"
Exemplo n.º 9
0
    def createFolder(self):
        if self.readonly:
            return

        ok = BoolResult()
        dirname = QInputDialog.getText(self, self._tr("Create Folder"),
                                       self._tr("Folder name:"),
                                       QLineEdit.Normal, "", ok)

        if not ok or dirname == "":
            return

        self.createretcode = ts3lib.createReturnCode()
        err = ts3lib.requestCreateDirectory(self.schid, self.cid,
                                            self.password,
                                            joinpath(self.path, dirname),
                                            self.createretcode)

        if err != ERROR_ok:
            self.showError(self._tr("Error creating directory"), err)
Exemplo n.º 10
0
 def onAddButton(self):
     leadDBSPath = slicer.util.settingsValue(
         "NetstimPreferences/leadDBSPath", "", converter=str)
     if leadDBSPath == "":
         qt.QMessageBox().warning(
             qt.QWidget(), "", "Add Lead-DBS path to Slicer preferences")
         return
     validAtlasesNames = ImportAtlas.ImportAtlasLogic().getValidAtlases()
     if not validAtlasesNames:
         return
     result = BoolResult()
     atlasName = qt.QInputDialog.getItem(qt.QWidget(), 'Select Atlas', '',
                                         validAtlasesNames, 0, 0, result)
     if result:
         qt.QApplication.setOverrideCursor(qt.Qt.WaitCursor)
         qt.QApplication.processEvents()
         try:
             ImportAtlas.ImportAtlasLogic().readAtlas(
                 os.path.join(
                     ImportAtlas.ImportAtlasLogic().getAtlasesPath(),
                     atlasName, 'atlas_index.mat'))
         finally:
             qt.QApplication.restoreOverrideCursor()
     self.updateTable()
Exemplo n.º 11
0
class massAction(ts3plugin):
    name = "Mass Actions"
    apiVersion = 22
    requestAutoload = False
    version = "1.0"
    author = "Bluscream"
    description = "Gives you the ability to take actions to all users in a channel or the server."
    offersConfigure = False
    commandKeyword = ""
    infoTitle = None
    hotkeys = []
    debug = False
    banned_names = ["BAN", "NOT WELCOME"]
    sbgroup = 0
    menuItems = [
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL, 0, "== {0} ==".format(name), ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL, 1, "Message all Clients", ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL, 2, "OfflineMessage all Clients", ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL, 3, "Message all Channels", ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL, 4, "Poke all Clients", ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL, 5, "ChannelKick all Clients", ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL, 6, "ChannelBan all Clients", ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL, 7, "Kick all Clients", ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL, 8, "Ban all Clients", ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL, 9, "Delete all Channels", ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL, 10, "== {0} ==".format(name), ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_CHANNEL, 11, "== {0} ==".format(name), ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_CHANNEL, 1, "Message all Clients", ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_CHANNEL, 2, "OfflineMessage all Clients", ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_CHANNEL, 3, "Poke all Clients", ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_CHANNEL, 4, "ChannelKick all Clients", ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_CHANNEL, 5, "ChannelBan all Clients", ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_CHANNEL, 6, "Kick all Clients", ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_CHANNEL, 7, "Ban all Clients", ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_CHANNEL, 8, "Give Talk Power", ""),
        (ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_CHANNEL, 12, "== {0} ==".format(name), "")
    ]
    dlg = None
    ok = BoolResult()

    @staticmethod
    def timestamp(): return '[{:%Y-%m-%d %H:%M:%S}] '.format(datetime.now())

    def __init__(self):
        self.requested = True;ts3lib.requestChannelGroupList(ts3lib.getCurrentServerConnectionHandlerID())
        if self.debug: ts3lib.printMessageToCurrentTab("{0}[color=orange]{1}[/color] Plugin for pyTSon by [url=https://github.com/{2}]{2}[/url] loaded.".format(self.timestamp(),self.name,self.author))

    def menuCreated(self):
        if not self.name in PluginHost.active: return
        for id in [0,10,11,12]:
            try: ts3lib.setPluginMenuEnabled(PluginHost.globalMenuID(self, id), False)
            except: pass

    def onMenuItemEvent(self, schid, atype, menuItemID, selectedItemID):
        try:
            if atype == ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_GLOBAL:
                if menuItemID == 1: # Message all Clients
                    (error, clients) = ts3lib.getClientList(schid)
                    msgs = self.getText(multiline=True,title="Message all %s clients on this server"%len(clients),text="Enter Private Message")
                    if bool(self.ok) != True:return
                    (error, ownID) = ts3lib.getClientID(schid)
                    for c in clients:
                        if c == ownID: continue
                        for msg in msgs: ts3lib.requestSendPrivateTextMsg(schid, msg, c)
                elif menuItemID == 2: # OffineMessage all Clients
                    (error, clients) = ts3lib.getClientList(schid)
                    (error, ownID) = ts3lib.getClientID(schid)
                    uids = []
                    for c in clients:
                        if c == ownID: continue
                        (error, uid) = ts3lib.getClientVariableAsString(schid, c, ts3defines.ClientProperties.CLIENT_UNIQUE_IDENTIFIER)
                        uids.append(uid)
                    if not self.dlg: self.dlg = MessageDialog(schid, uids)
                    self.dlg.show();self.dlg.raise_();self.dlg.activateWindow()
                elif menuItemID == 3: # Message all Channels
                    (error, channels) = ts3lib.getChannelList(schid)
                    msgs = self.getText(multiline=True,title="Message all %s channels on this server"%len(channels),text="Enter Channel Message")
                    (error, ownID) = ts3lib.getClientID(schid)
                    for c in channels:
                        error = ts3lib.requestClientMove(schid, ownID, c, "123")
                        if not error == ts3defines.ERROR_ok: continue
                        for msg in msgs: ts3lib.requestSendChannelTextMsg(schid, msg, c)
                elif menuItemID == 4: # Poke all Clients
                    (error, clients) = ts3lib.getClientList(schid)
                    msgs = self.getText(title="Poke all %s clients on this server"%len(clients),text="Enter Poke Message",max=100)
                    if bool(self.ok) != True:return
                    (error, ownID) = ts3lib.getClientID(schid)
                    for c in clients:
                        if c == ownID: continue
                        for msg in msgs: ts3lib.requestClientPoke(schid, c, msg)
                elif menuItemID == 5: # ChannelKick all Clients
                    (error, clients) = ts3lib.getClientList(schid)
                    msg = self.getText(title="Kick all %s clients on this server from their channel"%len(clients),text="Enter Kick Reason",multimsg=False,max=80)
                    if bool(self.ok) != True:return
                    (error, ownID) = ts3lib.getClientID(schid)
                    for c in clients:
                        if c == ownID: continue
                        ts3lib.requestClientKickFromChannel(schid, c, msg)
                elif menuItemID == 6: # ChannelBan all Clients
                    (error, clients) = ts3lib.getClientList(schid)
                    msg = self.getText(title="ChannelBan all %s clients on this server"%len(clients),text="Enter Kick Reason",multimsg=False,max=80)
                    if bool(self.ok) != True:return
                    (error, ownID) = ts3lib.getClientID(schid)
                    for c in clients:
                        if c == ownID: continue
                        (error, chan) = ts3lib.getChannelOfClient(schid, selectedItemID)
                        (error, dbid) = ts3lib.getClientVariableAsUInt64(schid, c, ts3defines.ClientPropertiesRare.CLIENT_DATABASE_ID)
                        ts3lib.requestSetClientChannelGroup(schid, [self.sbgroup], [chan], [dbid])
                        ts3lib.requestClientKickFromChannel(schid, c, msg)
                elif menuItemID == 7: # Kick all Clients
                    (error, clients) = ts3lib.getClientList(schid)
                    msg = self.getText(title="Kick all %s clients from this server"%len(clients),text="Enter Kick Reason",multimsg=False,max=80)
                    if bool(self.ok) != True:return
                    (error, ownID) = ts3lib.getClientID(schid)
                    for c in clients:
                        if c == ownID: continue
                        ts3lib.requestClientKickFromServer(schid, c, msg)
                elif menuItemID == 8: # Ban all Clients
                    (error, clients) = ts3lib.getClientList(schid)
                    msg = self.getText(title="Ban all %s clients from this server"%len(clients),text="Enter Ban Reason",multimsg=False,max=80)
                    if bool(self.ok) != True:return
                    (error, ownID) = ts3lib.getClientID(schid)
                    for c in clients:
                        if c == ownID: continue
                        ts3lib.banclient(schid, c, -1, msg)
                elif menuItemID == 9: # Delete all Channels
                    (error, channels) = ts3lib.getChannelList(schid)
                    confirmation = self.confirm('Delete all Channels', 'Do you really want to delete all {0} channels on this server?'.format(len(channels)))
                    if not confirmation: return
                    for c in channels: ts3lib.requestChannelDelete(schid, c, True)
            elif atype == ts3defines.PluginMenuType.PLUGIN_MENU_TYPE_CHANNEL:
                if menuItemID == 1: # Message all Clients
                    (error, clients) = ts3lib.getChannelClientList(schid, selectedItemID)
                    (err, name) = ts3lib.getChannelVariableAsString(schid, selectedItemID, ts3defines.ChannelProperties.CHANNEL_NAME)
                    msgs = self.getText(multiline=True,title="Message to all %s clients in channel \"%s\""%(len(clients),name),text="Enter Private Message")
                    if bool(self.ok) != True:return
                    (error, ownID) = ts3lib.getClientID(schid)
                    for c in clients:
                        if c == ownID: continue
                        for msg in msgs: ts3lib.requestSendPrivateTextMsg(schid, msg, c)
                if menuItemID == 2: # OfflineMessage all Clients
                    (error, clients) = ts3lib.getChannelClientList(schid, selectedItemID)
                    (error, ownID) = ts3lib.getClientID(schid)
                    uids = []
                    for c in clients:
                        if c == ownID: continue
                        (error, uid) = ts3lib.getClientVariableAsString(schid, c, ts3defines.ClientProperties.CLIENT_UNIQUE_IDENTIFIER)
                        uids.append(uid)
                    if not self.dlg: self.dlg = MessageDialog(schid, uids)
                    self.dlg.show();self.dlg.raise_();self.dlg.activateWindow()
                elif menuItemID == 3: # Poke all Clients
                    (error, clients) = ts3lib.getChannelClientList(schid, selectedItemID)
                    (err, name) = ts3lib.getChannelVariableAsString(schid, selectedItemID, ts3defines.ChannelProperties.CHANNEL_NAME)
                    msgs = self.getText(title="Poke all %s clients in channel \"%s\""%(len(clients),name),text="Enter Poke Message",max=100)
                    if bool(self.ok) != True:return
                    (error, ownID) = ts3lib.getClientID(schid)
                    for c in clients:
                        if c == ownID: continue
                        for msg in msgs: ts3lib.requestClientPoke(schid, c, msg)
                elif menuItemID == 4: # ChannelKick all Clients
                    (error, clients) = ts3lib.getChannelClientList(schid,selectedItemID)
                    (err, name) = ts3lib.getChannelVariableAsString(schid, selectedItemID, ts3defines.ChannelProperties.CHANNEL_NAME)
                    msg = self.getText(title="Kick all %s clients from channel \"%s\""%(len(clients),name),text="Enter Kick Reason",multimsg=False,max=80)
                    if bool(self.ok) != True:return
                    (error, ownID) = ts3lib.getClientID(schid)
                    for c in clients:
                        if c == ownID: continue
                        ts3lib.requestClientKickFromChannel(schid, c, msg)
                elif menuItemID == 5: # ChannelBan all Clients
                    (error, clients) = ts3lib.getChannelClientList(schid,selectedItemID)
                    (err, name) = ts3lib.getChannelVariableAsString(schid, selectedItemID, ts3defines.ChannelProperties.CHANNEL_NAME)
                    msg = self.getText(title="ChannelBan all %s clients from channel \"%s\""%(len(clients),name),text="Enter Kick Reason",multimsg=False,max=80)
                    if bool(self.ok) != True:return
                    (error, ownID) = ts3lib.getClientID(schid)
                    for c in clients:
                        if c == ownID: continue
                        (error, dbid) = ts3lib.getClientVariableAsUInt64(schid, c, ts3defines.ClientPropertiesRare.CLIENT_DATABASE_ID)
                        ts3lib.requestSetClientChannelGroup(schid, [self.sbgroup], [selectedItemID], [dbid])
                        ts3lib.requestClientKickFromChannel(schid, c, msg)
                elif menuItemID == 6: # Kick all Clients
                    (error, clients) = ts3lib.getChannelClientList(schid,selectedItemID)
                    (err, name) = ts3lib.getChannelVariableAsString(schid, selectedItemID, ts3defines.ChannelProperties.CHANNEL_NAME)
                    msg = self.getText(title="Kick all %s clients in channel \"%s\" from this server"%(len(clients),name),text="Enter Kick Reason",multimsg=False,max=80)
                    if bool(self.ok) != True:return
                    (error, ownID) = ts3lib.getClientID(schid)
                    for c in clients:
                        if c == ownID: continue
                        ts3lib.requestClientKickFromServer(schid, c, msg)
                elif menuItemID == 7: # Ban all Clients
                    (error, clients) = ts3lib.getChannelClientList(schid,selectedItemID)
                    (err, name) = ts3lib.getChannelVariableAsString(schid, selectedItemID, ts3defines.ChannelProperties.CHANNEL_NAME)
                    msg = self.getText(title="Ban all %s clients in channel \"%s\""%(len(clients),name),text="Enter Ban Reason",multimsg=False,max=80)
                    if bool(self.ok) != True:return
                    (error, ownID) = ts3lib.getClientID(schid)
                    for c in clients:
                        if c == ownID: continue
                        ts3lib.banclient(schid, c, -1, msg)
        except: from traceback import format_exc;ts3lib.logMessage(format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "pyTSon", 0)

    def getText(self,multimsg=True,multiline=False,title="Enter text here",text="",max=1024):
        try:
            x = QDialog()
            x.setAttribute(Qt.WA_DeleteOnClose)
            if multiline:
                clipboard = QApplication.clipboard().text()
                _message = QInputDialog.getMultiLineText(x, title, text, clipboard)
            else: _message = QInputDialog.getText(x, title, text, QLineEdit.Normal, "", self.ok)
            if multimsg: return [_message[i:i + max] for i in range(0, len(_message), max)]
            else: return _message[:max]
        except: from traceback import format_exc;ts3lib.logMessage(format_exc(), ts3defines.LogLevel.LogLevel_ERROR, "pyTSon", 0)

    def confirm(self, title, message):
        x = QDialog()
        x.setAttribute(Qt.WA_DeleteOnClose)
        _t = QMessageBox.question(x, title, message, QMessageBox.Yes, QMessageBox.No)
        if _t == QMessageBox.Yes: return True
        else: return False

    def onConnectStatusChangeEvent(self, schid, newStatus, errorNumber):
        if newStatus == ts3defines.ConnectStatus.STATUS_CONNECTION_ESTABLISHED:
            self.requested = True;ts3lib.requestChannelGroupList(schid)

    def onChannelGroupListEvent(self, schid, channelGroupID, name, atype, iconID, saveDB):
        if self.requested:
            for _name in self.banned_names:
                if name.upper().__contains__(_name): self.sbgroup = channelGroupID;break

    def onChannelGroupListFinishedEvent(self, schid):
        if self.requested: self.requested = False