Exemple #1
0
class IdListFilter(QWidget, Control):

    """ Multiple ids filter
    """

    def __init__(self, tree, dataset, master, parent=None):
        QWidget.__init__(self, parent)
        Control.__init__(self, tree, dataset, master)
        self.tree = tree
        self.dataset = dataset
        self.master = master
        self.setObjectName(tree.internalName)

        self.setLayout(QGridLayout())
        self.textWidget = QPlainTextEdit()  # TODO: Subclass to receive drop events from item model views
        self.layout().addWidget(self.textWidget, 0, 0, 1, 1)

    def value(self):
        """ Return filter value for use in a query
        """
        return str(self.textWidget.toPlainText()).split()

    def get_filter(self):
        return self.tree.internalName, self.value()

    def query(self):
        return [("Filter", self.tree, self.value())]

    def setControlValue(self, name, value):
        if type(value) == list:
            value = "\n".join(value)
        self.textWidget.setPlainText(value)
Exemple #2
0
class IdListFilter(QWidget, Control):

    """ Multiple ids filter
    """

    def __init__(self, tree, dataset, master, parent=None):
        QWidget.__init__(self, parent)
        Control.__init__(self, tree, dataset, master)
        self.tree = tree
        self.dataset = dataset
        self.master = master
        self.setObjectName(tree.internalName)

        self.setLayout(QGridLayout())
        self.textWidget = QPlainTextEdit()  # TODO: Subclass to receive drop events from item model views
        self.layout().addWidget(self.textWidget, 0, 0, 1, 1)

    def value(self):
        """ Return filter value for use in a query
        """
        return str(self.textWidget.toPlainText()).split()

    def get_filter(self):
        return self.tree.internalName, self.value()

    def query(self):
        return [("Filter", self.tree, self.value())]

    def setControlValue(self, name, value):
        if type(value) == list:
            value = "\n".join(value)
        self.textWidget.setPlainText(value)
Exemple #3
0
    class APICredentialsDialog(OWWidget):
        name = "Twitter API Credentials"
        want_main_area = False
        resizing_enabled = False

        def __init__(self, parent):
            super().__init__()
            self.cm_key = CredentialManager("Twitter Bearer Token")
            self.parent = parent

            box = gui.vBox(self.controlArea, "Bearer Token")
            self.key_edit = QPlainTextEdit()
            box.layout().addWidget(self.key_edit)

            self.submit_button = gui.button(self.buttonsArea, self, "OK",
                                            self.accept)
            self.load_credentials()

        def load_credentials(self):
            self.key_edit.setPlainText(self.cm_key.key)

        def save_credentials(self):
            self.cm_key.key = self.key_edit.toPlainText()

        def accept(self):
            token = self.key_edit.toPlainText()
            if token:
                self.save_credentials()
                self.parent.update_api(token)
                super().accept()
Exemple #4
0
 def __init__(self, locals=None, parent=None):
     QPlainTextEdit.__init__(self, parent)
     code.InteractiveConsole.__init__(self, locals)
     self.newPromptPos = 0
     self.history, self.historyInd = [""], 0
     self.loop = self.interact()
     next(self.loop)
Exemple #5
0
    def __init__(self, tree, dataset, master, parent=None):
        QWidget.__init__(self, parent)
        Control.__init__(self, tree, dataset, master)
        self.tree = tree
        self.dataset = dataset
        self.master = master
        self.setObjectName(tree.internalName)

        self.setLayout(QGridLayout())
        self.textWidget = QPlainTextEdit()  # TODO: Subclass to receive drop events from item model views
        self.layout().addWidget(self.textWidget, 0, 0, 1, 1)
Exemple #6
0
    def __init__(self, *args, **kwargs):
        QPlainTextEdit.__init__(self, *args, **kwargs)
        self.setFrameStyle(QPlainTextEdit.NoFrame)
        self.setTextInteractionFlags(Qt.TextBrowserInteraction)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)

        font = self.font()
        font.setStyleHint(QFont.Monospace)
        font.setFamily("Monospace")
        self.setFont(font)
    def __init__(self, *args, **kwargs):
        QPlainTextEdit.__init__(self, *args, **kwargs)
        self.setFrameStyle(QPlainTextEdit.NoFrame)
        self.setTextInteractionFlags(Qt.TextBrowserInteraction)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)

        font = self.font()
        font.setStyleHint(QFont.Monospace)
        font.setFamily("Monospace")
        self.setFont(font)
Exemple #8
0
        def __init__(self, parent):
            super().__init__()
            self.cm_key = CredentialManager("Twitter Bearer Token")
            self.parent = parent

            box = gui.vBox(self.controlArea, "Bearer Token")
            self.key_edit = QPlainTextEdit()
            box.layout().addWidget(self.key_edit)

            self.submit_button = gui.button(self.buttonsArea, self, "OK",
                                            self.accept)
            self.load_credentials()
Exemple #9
0
    def __init__(self, tree, dataset, master, parent=None):
        QWidget.__init__(self, parent)
        Control.__init__(self, tree, dataset, master)

        self.setLayout(QVBoxLayout())
        self.setContentsMargins(0, 0, 0, 0)
        self.cb = QComboBox()
        self.idsEdit = QPlainTextEdit()

        self.layout().addWidget(self.cb)
        self.layout().addWidget(self.idsEdit)

        self.options = []
        self.setOptions(tree.subelements_top("Option"))
Exemple #10
0
 def keyPressEvent(self, event):
     if event.key() == Qt.Key_Return:
         self.write("\n")
         next(self.loop)
     elif event.key() == Qt.Key_Up:
         self.historyUp()
     elif event.key() == Qt.Key_Down:
         self.historyDown()
     elif event.key() == Qt.Key_Tab:
         self.complete()
     elif event.key() in [Qt.Key_Left, Qt.Key_Backspace]:
         if self.textCursor().position() > self.newPromptPos:
             QPlainTextEdit.keyPressEvent(self, event)
     else:
         QPlainTextEdit.keyPressEvent(self, event)
Exemple #11
0
 def keyPressEvent(self, event):
     if event.key() == Qt.Key_Return:
         self.write("\n")
         next(self.loop)
     elif event.key() == Qt.Key_Up:
         self.historyUp()
     elif event.key() == Qt.Key_Down:
         self.historyDown()
     elif event.key() == Qt.Key_Tab:
         self.complete()
     elif event.key() in [Qt.Key_Left, Qt.Key_Backspace]:
         if self.textCursor().position() > self.newPromptPos:
             QPlainTextEdit.keyPressEvent(self, event)
     else:
         QPlainTextEdit.keyPressEvent(self, event)
Exemple #12
0
class PlainTextField(Field):
    def render(self):
        self.widget = QPlainTextEdit(self.value)
        return self.widget

    def get_value(self):
        return self.widget.toPlainText()
Exemple #13
0
    def __init__(self):
        super().__init__()

        self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
        self.domain = None
        self.data = None
        self.query = ''
        if self.savedQuery is not None:
            self.query = self.savedQuery
        self.username = ''
        if self.savedUsername is not None:
            self.username = self.savedUsername
        self.password = ''
        if self.savedPwd is not None:
            self.password = self.savedPwd
        self.database = ''
        if self.savedDB is not None:
            self.database = self.savedDB

        #Control Area layout
        self.connectBox = gui.widgetBox(self.controlArea,
                                        "Database connection")
        self.connectBox.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)

        #Database
        self.userLabel = gui.label(self.connectBox, self, 'User name')
        self.connectUser = QLineEdit(self.username, self)
        self.connectBox.layout().addWidget(self.connectUser)
        self.passwordLabel = gui.label(self.connectBox, self, 'Password')
        self.connectPassword = QLineEdit(self.password, self)
        self.connectPassword.setEchoMode(QLineEdit.Password)
        self.connectBox.layout().addWidget(self.connectPassword)
        self.dbLabel = gui.label(self.connectBox, self, 'Database')
        self.connectDB = QLineEdit(self.database, self)
        self.connectBox.layout().addWidget(self.connectDB)
        self.runSQL = gui.auto_commit(self.connectBox,
                                      self,
                                      'autocommit',
                                      label='Run SQL',
                                      commit=self.commit)
        # query
        self.sqlBox = gui.widgetBox(self.mainArea, "SQL")
        self.queryTextEdit = QPlainTextEdit(self.query, self)
        self.sqlBox.layout().addWidget(self.queryTextEdit)

        QTimer.singleShot(0, self.commit)
Exemple #14
0
class DropDownIdListFilter(QWidget, Control):

    """Container for multiple id list filters
    """

    def __init__(self, tree, dataset, master, parent=None):
        QWidget.__init__(self, parent)
        Control.__init__(self, tree, dataset, master)

        self.setLayout(QVBoxLayout())
        self.setContentsMargins(0, 0, 0, 0)
        self.cb = QComboBox()
        self.idsEdit = QPlainTextEdit()

        self.layout().addWidget(self.cb)
        self.layout().addWidget(self.idsEdit)

        self.options = []
        self.setOptions(tree.subelements_top("Option"))

    def setOptions(self, options):
        self.cb.clear()
        self.options = []
        for option in options:
            self.cb.addItem(option.displayName)
            self.options.append(option)

    def value(self):
        return str(self.idsEdit.toPlainText()).split()

    def query(self):
        filter = self.options[self.cb.currentIndex()]
        filter = biomart.FilterDescription(
            self.tree.registry, "FilterDescription",
            filter.attributes, filter.children)
        return [("Filter", filter, self.value())]

    def setControlValue(self, name, value):
        if isinstance(value, list):
            value = "\n".join(value)

        for i, op in enumerate(self.options):
            if name == op.internalName:
                self.cb.setCurrentIndex(i)
                self.idsEdit.setPlainText(value)
Exemple #15
0
class DropDownIdListFilter(QWidget, Control):

    """Container for multiple id list filters
    """

    def __init__(self, tree, dataset, master, parent=None):
        QWidget.__init__(self, parent)
        Control.__init__(self, tree, dataset, master)

        self.setLayout(QVBoxLayout())
        self.setContentsMargins(0, 0, 0, 0)
        self.cb = QComboBox()
        self.idsEdit = QPlainTextEdit()

        self.layout().addWidget(self.cb)
        self.layout().addWidget(self.idsEdit)

        self.options = []
        self.setOptions(tree.subelements_top("Option"))

    def setOptions(self, options):
        self.cb.clear()
        self.options = []
        for option in options:
            self.cb.addItem(option.displayName)
            self.options.append(option)

    def value(self):
        return str(self.idsEdit.toPlainText()).split()

    def query(self):
        filter = self.options[self.cb.currentIndex()]
        filter = biomart.FilterDescription(
            self.tree.registry, "FilterDescription",
            filter.attributes, filter.children)
        return [("Filter", filter, self.value())]

    def setControlValue(self, name, value):
        if isinstance(value, list):
            value = "\n".join(value)

        for i, op in enumerate(self.options):
            if name == op.internalName:
                self.cb.setCurrentIndex(i)
                self.idsEdit.setPlainText(value)
Exemple #16
0
    def __init__(self, tree, dataset, master, parent=None):
        QWidget.__init__(self, parent)
        Control.__init__(self, tree, dataset, master)
        self.tree = tree
        self.dataset = dataset
        self.master = master
        self.setObjectName(tree.internalName)

        self.setLayout(QGridLayout())
        self.textWidget = QPlainTextEdit()  # TODO: Subclass to receive drop events from item model views
        self.layout().addWidget(self.textWidget, 0, 0, 1, 1)
Exemple #17
0
    def __init__(self, tree, dataset, master, parent=None):
        QWidget.__init__(self, parent)
        Control.__init__(self, tree, dataset, master)

        self.setLayout(QVBoxLayout())
        self.setContentsMargins(0, 0, 0, 0)
        self.cb = QComboBox()
        self.idsEdit = QPlainTextEdit()

        self.layout().addWidget(self.cb)
        self.layout().addWidget(self.idsEdit)

        self.options = []
        self.setOptions(tree.subelements_top("Option"))
Exemple #18
0
class ORACLESQL(OWWidget):

    name = "Oracle SQL"
    icon = "icons/OracleSQL.svg"
    want_main_area = True
    want_message_bar = True
    #inputs = []
    outputs = [("Data", Table)]
    description = "Select data from oracle databases"
    settingsHandler = settings.DomainContextHandler()
    autocommit = settings.Setting(False, schema_only=True)
    savedQuery = settings.Setting(None, schema_only=True)
    savedUsername = settings.Setting(None, schema_only=True)
    savedPwd = settings.Setting(None, schema_only=True)
    savedDB = settings.Setting(None, schema_only=True)
    
    class Error(OWWidget.Error):
        no_backends = Msg("Please install cx_Oracle package. It is either missing or not working properly")
   
    class Outputs:
        data = Output("Data", Table)       

    def __init__(self):
        super().__init__()

        #Defaults
        self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
        self.domain = None
        self.data = None
        self.query = ''
        if self.savedQuery is not None:
            self.query = self.savedQuery
        self.username = ''
        if self.savedUsername is not None:
            self.username = self.savedUsername
        self.password = ''
        if self.savedPwd is not None:
            self.password = self.savedPwd
        self.database = ''
        if self.savedDB is not None:
            self.database = self.savedDB
        #Control Area layout
        sip.delete(self.controlArea.layout())
        self.controlArea.setLayout(QHBoxLayout())
        self.connectBox = gui.widgetBox(self.controlArea, "Database connection")
        self.connectBox.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
        self.sqlBox = gui.widgetBox(self.controlArea, "SQL")
        #Database
        self.userLabel = gui.label(self.connectBox, self, 'User name')
        self.connectUser = QLineEdit(self.username, self)
        self.connectBox.layout().addWidget(self.connectUser)
        self.passwordLabel = gui.label(self.connectBox, self, 'Password')
        self.connectPassword = QLineEdit(self.password, self)
        self.connectPassword.setEchoMode(QLineEdit.Password)
        self.connectBox.layout().addWidget(self.connectPassword)
        self.dbLabel = gui.label(self.connectBox, self, 'Database')
        self.connectDB = QLineEdit(self.database, self)
        self.connectBox.layout().addWidget(self.connectDB)
        self.runSQL = gui.auto_commit(self.connectBox, self, 'autocommit',
                                      label='Run SQL', commit=self.commit)
        # query
        self.queryTextEdit = QPlainTextEdit(self.query, self)
        self.sqlBox.layout().addWidget(self.queryTextEdit)
        if self.autocommit:
            self.commit()

    def handleNewSignals(self):
        self._invalidate()
        
    def countUniques(self,lst):
        return len(set([x for x in lst if x is not None]))

    def setOfUniques(self,lst):
        return sorted(set([x for x in lst if x is not None]))

    def dateToStr(self,lst):
        return([str(x) if x is not None else x for x in lst ])
    

    def commit(self):
        if cx_Oracle is None:
            data = []
            columns = []
            self.Error.no_backends()
            username = None
            password = None
            database = None
            query = None            
        else:   
            username = self.connectUser.text()
            password = self.connectPassword.text()
            database = self.connectDB.text()
            con = cx_Oracle.connect(username+"/"+password+"@"+database)
            query = self.queryTextEdit.toPlainText()
            
            cur = con.cursor()
            cur.execute(query)
            data = cur.fetchall()
            columns = [i[0] for i in cur.description]      
        
        data_tr=list(zip(*data))
        n=len(columns)     
        featurelist=[ContinuousVariable(str(columns[col])) if all(type(x)==int or type(x)==float
                                or type(x)==type(None) for x in data_tr[col]) else 
            TimeVariable(str(columns[col])) if all(type(x)==type(datetime.datetime(9999,12,31,0,0)) or type(x)==type(None) for x in data_tr[col])  else  DiscreteVariable(str(columns[col]),self.setOfUniques(data_tr[col]))
            if self.countUniques(data_tr[col]) < 101 else DiscreteVariable(str(columns[col]),self.setOfUniques(data_tr[col])) for col in range (0,n)]

        data_tr = [self.dateToStr(data_tr[col]) if all(type(x)==type(datetime.datetime(9999,12,31,0,0)) or type(x)==type(None) for x in data_tr[col])  else  data_tr[col] for col in range (0,n)]
        data=list(zip(*data_tr))

        orangedomain=Domain(featurelist)
        orangetable=Table(orangedomain,data)
        
        self.Outputs.data.send(orangetable)
        self.savedQuery = query
        self.savedUsername = username
        self.savedPwd = password
        self.savedDB = database

    def _invalidate(self):
        self.commit()
Exemple #19
0
 def render(self):
     self.widget = QPlainTextEdit(self.value)
     return self.widget
Exemple #20
0
 def __init__(self, locals=None, parent=None):
     QPlainTextEdit.__init__(self, parent)
     code.InteractiveConsole.__init__(self, locals)
     self.history, self.historyInd = [""], 0
     self.loop = self.interact()
     next(self.loop)
Exemple #21
0
class OWOracleSQL(OWWidget):
    name = "Oracle SQL"
    description = "Select data from oracle databases"
    icon = "icons/OracleSQL.svg"

    class Error(OWWidget.Error):
        no_backends = Msg(
            "Please install cx_Oracle package. It is either missing or not working properly"
        )

    class Outputs:
        data = Output("Data", Table)

    autocommit = settings.Setting(False, schema_only=True)
    savedQuery = settings.Setting(None, schema_only=True)
    savedUsername = settings.Setting(None, schema_only=True)
    savedPwd = settings.Setting(None, schema_only=True)
    savedDB = settings.Setting(None, schema_only=True)

    def __init__(self):
        super().__init__()

        self.setSizePolicy(QSizePolicy.Maximum, QSizePolicy.Maximum)
        self.domain = None
        self.data = None
        self.query = ''
        if self.savedQuery is not None:
            self.query = self.savedQuery
        self.username = ''
        if self.savedUsername is not None:
            self.username = self.savedUsername
        self.password = ''
        if self.savedPwd is not None:
            self.password = self.savedPwd
        self.database = ''
        if self.savedDB is not None:
            self.database = self.savedDB

        #Control Area layout
        self.connectBox = gui.widgetBox(self.controlArea,
                                        "Database connection")
        self.connectBox.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)

        #Database
        self.userLabel = gui.label(self.connectBox, self, 'User name')
        self.connectUser = QLineEdit(self.username, self)
        self.connectBox.layout().addWidget(self.connectUser)
        self.passwordLabel = gui.label(self.connectBox, self, 'Password')
        self.connectPassword = QLineEdit(self.password, self)
        self.connectPassword.setEchoMode(QLineEdit.Password)
        self.connectBox.layout().addWidget(self.connectPassword)
        self.dbLabel = gui.label(self.connectBox, self, 'Database')
        self.connectDB = QLineEdit(self.database, self)
        self.connectBox.layout().addWidget(self.connectDB)
        self.runSQL = gui.auto_commit(self.connectBox,
                                      self,
                                      'autocommit',
                                      label='Run SQL',
                                      commit=self.commit)
        # query
        self.sqlBox = gui.widgetBox(self.mainArea, "SQL")
        self.queryTextEdit = QPlainTextEdit(self.query, self)
        self.sqlBox.layout().addWidget(self.queryTextEdit)

        QTimer.singleShot(0, self.commit)

    def handleNewSignals(self):
        self._invalidate()

    def countUniques(self, lst):
        return len(set([x for x in lst if x is not None]))

    def setOfUniques(self, lst):
        return sorted(set([x for x in lst if x is not None]))

    def dateToStr(self, lst):
        return [str(x) if x is not None else x for x in lst]

    def commit(self):
        if cx_Oracle is None:
            data = []
            columns = []
            self.Error.no_backends()
            username = None
            password = None
            database = None
            query = None
        else:
            username = self.connectUser.text()
            password = self.connectPassword.text()
            database = self.connectDB.text()
            con = cx_Oracle.connect(username + "/" + password + "@" + database)
            query = self.queryTextEdit.toPlainText()

            cur = con.cursor()
            cur.execute(query)
            data = cur.fetchall()
            columns = [i[0] for i in cur.description]

        data_tr = list(zip(*data))

        def create_variable(column_name, column_data):
            continuous_types = (int, float, type(None))
            datetime_types = (datetime.datetime, type(None))
            column_name = str(column_name)

            if all(isinstance(x, continuous_types) for x in column_data):
                return ContinuousVariable(column_name)

            if all(isinstance(x, datetime_types) for x in column_data):
                return TimeVariable(column_name)

            if self.countUniques(column_data) < 101:
                return DiscreteVariable(str(column_name),
                                        self.setOfUniques(column_data))

            return DiscreteVariable(str(column_name),
                                    self.setOfUniques(column_data))

        featurelist = [
            create_variable(column_name, column_data)
            for column_name, column_data in zip(columns, data_tr)
        ]

        data_tr = [
            self.dateToStr(data) if isinstance(var, TimeVariable) else data
            for (var, data) in zip(featurelist, data_tr)
        ]
        data = list(zip(*data_tr))

        orangedomain = Domain(featurelist)
        orangetable = Table(orangedomain, data)

        self.Outputs.data.send(orangetable)
        self.savedQuery = query
        self.savedUsername = username
        self.savedPwd = password
        self.savedDB = database

    def _invalidate(self):
        self.commit()