def __init__(self, bool, name, db):
     self.db = db
     self.fields = PropelDatabase.fields
     super(PropelTabDatabase, self).__init__(bool, name)
     self.widgets["database"] = mforms.newTreeView(1)
     self.colmuns_name()
     self.add_end(self.widgets["database"], True, True)
Exemplo n.º 2
0
    def create_ui(self):
        dprint_ex(3, "Enter")
        self.suspend_layout()

        self.warning = not_running_warning_label()
        self.add(self.warning, False, True)

        self.connection_list = newTreeView(mforms.TreeDefault)
        self.connection_list.add_column(mforms.StringColumnType, "Id", 50,
                                        False)
        self.connection_list.add_column(mforms.StringColumnType, "User", 80,
                                        False)
        self.connection_list.add_column(mforms.StringColumnType, "Host", 120,
                                        False)
        self.connection_list.add_column(mforms.StringColumnType, "DB", 100,
                                        False)
        self.connection_list.add_column(mforms.StringColumnType, "Command", 80,
                                        False)
        self.connection_list.add_column(mforms.IntegerColumnType, "Time", 80,
                                        False)
        self.connection_list.add_column(mforms.StringColumnType, "State", 80,
                                        False)
        self.connection_list.add_column(mforms.StringColumnType, "Info", 300,
                                        False)
        self.connection_list.end_columns()
        self.connection_list.set_allow_sorting(True)

        self.connection_list.add_changed_callback(
            weakcb(self, "connection_selected"))

        #self.set_padding(8)
        self.add(self.connection_list, True, True)

        self.button_box = box = newBox(True)
        self.add(box, False, True)

        box.set_spacing(12)
        box.set_padding(12)

        refresh_button = newButton()
        refresh_button.set_text("Refresh")
        box.add_end(refresh_button, False, True)
        refresh_button.add_clicked_callback(weakcb(self, "refresh"))

        self.kill_button = newButton()
        self.kill_button.set_text("Kill Connection")
        box.add_end(self.kill_button, False, True)
        self.kill_button.add_clicked_callback(weakcb(self, "kill_connection"))

        self.killq_button = newButton()
        self.killq_button.set_text("Kill Query")
        box.add_end(self.killq_button, False, True)
        self.killq_button.add_clicked_callback(weakcb(self, "kill_query"))

        self.add(box, False, True)

        self.resume_layout()

        self.connection_selected()
        dprint_ex(3, "Leave")
 def __init__(self, bool, name, db):
     self.db = db
     self.fields = PropelIndice.fields
     super(PropelTabIndices, self).__init__(bool, name)
     self.widgets["indices"] = mforms.newTreeView(1)
     self.search("indices")
     self.colmuns_name("indices")
     self.add_end(self.widgets["indices"], True, True)
Exemplo n.º 4
0
 def __init__(self, bool, name, db):
   self.db = db
   self.fields = PropelTable.fields
   super(PropelTabTables, self).__init__(bool, name)
   self.widgets['tables'] = mforms.newTreeView(1)
   self.search('tables')
   self.colmuns_name('tables')
   self.add_end(self.widgets['tables'], True, True)
 def __init__(self, bool, name, db):
   self.db = db
   self.fields = PropelExternalSchema.fields
   super(PropelTabExternalSchemas, self).__init__(bool, name)
   self.widgets['external_schemas'] = mforms.newTreeView(1)
   self.browse_schema_box()
   self.colmuns_name()
   self.add_end(self.widgets['external_schemas'], True, True)
 def __init__(self, bool, name, db):
   self.db = db
   self.fields = PropelForeignKey.fields
   super(PropelTabForeignKeys, self).__init__(bool, name)
   self.widgets['foreign_keys'] = mforms.newTreeView(1)
   self.search('foreign_keys')
   self.colmuns_name('foreign_keys')
   self.add_end(self.widgets['foreign_keys'], True, True)
    def __init__(self, results, checksum=False):
        mforms.Form.__init__(self, mforms.Form.main_form(), mforms.FormNormal)

        self.box = mforms.newBox(False)
        self.box.set_padding(12)
        self.box.set_spacing(8)
        self.set_content(self.box)

        self.tree = mforms.newTreeView(mforms.TreeFlatList|mforms.TreeAltRowColors|mforms.TreeShowColumnLines)
        self.tree.set_selection_mode(mforms.TreeSelectMultiple)
        self.box.add(self.tree, True, True)
        self.tree.add_column(mforms.StringColumnType, "Table", 200, False)
        if checksum:
            self.tree.add_column(mforms.StringColumnType, "Checksum", 100, False)
        else:
            self.tree.add_column(mforms.StringColumnType, "Operation", 80, False)
            self.tree.add_column(mforms.IconStringColumnType, "Message", 400, False)
        self.tree.end_columns()

        self._checksum = checksum

        app = mforms.App.get()
        icon_path = {
            'status': app.get_resource_path('mini_ok.png'),
            'error': app.get_resource_path('mini_error.png'),
            'info': '',
            'note': app.get_resource_path('mini_notice.png'),
            'warning': app.get_resource_path('mini_warning.png'),
        }

        ok = results.goToFirstRow()
        while ok:
            node = self.tree.add_node()
            node.set_string(0, results.stringFieldValue(0))
            if not checksum:
                node.set_string(1, results.stringFieldValue(1))
                node.set_icon_path(2, icon_path.get(results.stringFieldValue(2), ''))
                node.set_string(2, results.stringFieldValue(3))
                node.set_tag(results.stringFieldValue(2))
            else:
                node.set_string(1, results.stringFieldValue(1))
            ok = results.nextRow()

        bbox = mforms.newBox(True)
        self.box.add(bbox, False, True)

        copy = mforms.newButton()
        copy.add_clicked_callback(self.copy_to_clipboard)
        copy.set_text("Copy to Clipboard")
        bbox.add(copy, False, True)

        self.ok = mforms.newButton()
        self.ok.set_text("OK")
        self.ok.add_clicked_callback(self.close)
        bbox.add_end(self.ok, False, True)

        self.set_size(500, 400)
 def __init__(self, bool, name, db):
   self.db = db
   self.fields = PropelBehavior.fields
   self.behaviors = PropelBehavior.behaviors
   super(PropelTabBehaviors, self).__init__(bool, name)
   self.widgets['behaviors'] = mforms.newTreeView(1)
   self.search('behaviors')
   self.colmuns_name('behaviors')
   self.add_remove_behavior_button()
   self.add_end(self.widgets['behaviors'], True, True)
    def create_ui(self):
        self.suspend_layout()
        self.set_spacing(16)
        self.content.set_spacing(16)

        colbox = mforms.newBox(False)
        colbox.set_spacing(8)
        colbox.add(mforms.newLabel("Select columns you'd like to export"),
                   False, True)

        self.column_list = newTreeView(mforms.TreeFlatList)
        self.column_list.add_column(mforms.CheckColumnType, "Export", 50, True)
        self.column_list.add_column(mforms.StringColumnType, "Column name",
                                    self.owner.main.get_width(), False)
        self.column_list.end_columns()
        self.column_list.set_allow_sorting(True)
        self.column_list.set_size(200, -1)
        colbox.add(self.column_list, True, True)

        limit_box = mforms.newBox(True)
        limit_box.set_spacing(8)
        limit_box.add(mforms.newLabel("Count: "), False, False)
        self.limit_entry = mforms.newTextEntry()
        self.limit_entry.set_size(50, -1)
        self.limit_entry.add_changed_callback(
            lambda entry=self.limit_entry: self.entry_changed(entry))
        limit_box.add(self.limit_entry, False, False)

        offset_box = mforms.newBox(True)
        offset_box.set_spacing(8)
        offset_box.add(mforms.newLabel("Row Offset: "), False, False)
        self.offset_entry = mforms.newTextEntry()
        self.offset_entry.set_size(50, -1)
        self.offset_entry.add_changed_callback(
            lambda entry=self.offset_entry: self.entry_changed(entry))

        offset_box.add(self.offset_entry, False, False)

        sellall_cb = mforms.newCheckBox()
        sellall_cb.set_text("Select / Deselect all entries")
        sellall_cb.set_active(True)
        sellall_cb.add_clicked_callback(
            lambda cb=sellall_cb: self.sell_all(cb))

        limit_offset = mforms.newBox(True)
        limit_offset.set_spacing(8)
        limit_offset.add(sellall_cb, False, True)
        limit_offset.add_end(limit_box, False, True)
        limit_offset.add_end(offset_box, False, True)

        colbox.add(limit_offset, False, True)
        self.content.add(colbox, True, True)
        self.resume_layout()
Exemplo n.º 10
0
    def __init__(self, owner, explain, server_version):
        mforms.Box.__init__(self, False)
        self.set_managed()
        self.set_release_on_add()

        self.toolbar = mforms.newToolBar(mforms.SecondaryToolBar)
        self.toolbar.set_back_color("#ffffff")

        self.switcher_item = newToolBarItem(mforms.SelectorItem)
        self.toolbar.add_item(self.switcher_item)

        self.add(self.toolbar, False, False)

        self.explain_tree = mforms.newTreeView(mforms.TreeFlatList
                                               | mforms.TreeShowColumnLines
                                               | mforms.TreeShowRowLines
                                               | mforms.TreeAltRowColors)
        self.explain_tree.add_column_resized_callback(self.column_resized)
        c = len(explain.columns)
        rows_column = None

        saved_widths = grt.root.wb.state.get(
            "wb.query.analysis:ExplainTreeColumnWidths", None)
        if saved_widths:
            saved_widths = [int(i) for i in saved_widths.split(",")]

        for i, column in enumerate(explain.columns):
            width = saved_widths[i] if saved_widths and i < len(
                saved_widths) else EXPLAIN_COLUMN_WIDTHS.get(column.name, 100)
            if column.name == "rows":
                rows_column = i
                self.explain_tree.add_column(mforms.LongIntegerColumnType,
                                             column.name, width)
            else:
                self.explain_tree.add_column(mforms.StringColumnType,
                                             column.name, width)
        self.explain_tree.end_columns()

        if explain.goToFirstRow():
            while True:
                node = self.explain_tree.add_node()
                for i in range(c):
                    value = explain.stringFieldValue(i)
                    if i == rows_column:
                        node.set_long(i, int(value) if value else 0)
                    else:
                        node.set_string(i, value)
                if not explain.nextRow():
                    break

        explain.reset_references()
        self.add(self.explain_tree, True, True)
Exemplo n.º 11
0
    def create_ui(self):
        dprint_ex(3, "Enter")
        self.suspend_layout()
        
        self.warning = not_running_warning_label()
        self.add(self.warning, False, True)
    
        self.connection_list = newTreeView(mforms.TreeDefault)
        self.connection_list.add_column(mforms.StringColumnType, "Id", 50, False)
        self.connection_list.add_column(mforms.StringColumnType, "User", 80, False)
        self.connection_list.add_column(mforms.StringColumnType, "Host", 120, False)
        self.connection_list.add_column(mforms.StringColumnType, "DB", 100, False)
        self.connection_list.add_column(mforms.StringColumnType, "Command", 80, False)
        self.connection_list.add_column(mforms.IntegerColumnType, "Time", 80, False)
        self.connection_list.add_column(mforms.StringColumnType, "State", 80, False)
        self.connection_list.add_column(mforms.StringColumnType, "Info", 300, False)        
        self.connection_list.end_columns()
        self.connection_list.set_allow_sorting(True)
        
        self.connection_list.add_changed_callback(weakcb(self, "connection_selected"))

        #self.set_padding(8)
        self.add(self.connection_list, True, True)

        self.button_box = box = newBox(True)
        self.add(box, False, True)
        
        box.set_spacing(12)
        box.set_padding(12)
        
        refresh_button = newButton()
        refresh_button.set_text("Refresh")
        box.add_end(refresh_button, False, True)
        refresh_button.add_clicked_callback(weakcb(self, "refresh"))

        self.kill_button = newButton()
        self.kill_button.set_text("Kill Connection")
        box.add_end(self.kill_button, False, True)
        self.kill_button.add_clicked_callback(weakcb(self, "kill_connection"))

        self.killq_button = newButton()
        self.killq_button.set_text("Kill Query")
        box.add_end(self.killq_button, False, True)
        self.killq_button.add_clicked_callback(weakcb(self, "kill_query"))


        self.add(box, False, True)
        
        self.resume_layout()

        self.connection_selected()
        dprint_ex(3, "Leave")
Exemplo n.º 12
0
    def __init__(self, owner):
        LogBox.__init__(self, owner)

        self.tree = tree = newTreeView(mforms.TreeDefault)
        tree.add_column(mforms.StringColumnType, "Time", 150, False)
        tree.add_column(mforms.StringColumnType, "From", 120, False)
        tree.add_column(mforms.StringColumnType, "Thread", 80, False)
        #tree.add_column(mforms.StringColumnType, "Server", False)
        tree.add_column(mforms.StringColumnType, "Command Type", 80, False)
        tree.add_column(mforms.StringColumnType, "Detail", 500, False)
        tree.end_columns()

        self.add(tree, True, True)
Exemplo n.º 13
0
    def __init__(self, owner):
        LogBox.__init__(self, owner)

        self.tree = tree = newTreeView(mforms.TreeDefault)
        tree.add_column(mforms.StringColumnType, "Time", 150, False)
        tree.add_column(mforms.StringColumnType, "From", 120, False)
        tree.add_column(mforms.StringColumnType, "Thread", 80, False)
        #tree.add_column(mforms.StringColumnType, "Server", False)
        tree.add_column(mforms.StringColumnType, "Command Type", 80, False)
        tree.add_column(mforms.StringColumnType, "Detail", 500, False)
        tree.end_columns()

        self.add(tree, True, True)
    def create_ui(self):
        self.suspend_layout()
        self.set_spacing(16)
        self.content.set_spacing(16)
        
        colbox = mforms.newBox(False)
        colbox.set_spacing(8)
        colbox.add(mforms.newLabel("Select columns you'd like to export"), False, True)
        
        self.column_list = newTreeView(mforms.TreeFlatList)
        self.column_list.add_column(mforms.CheckColumnType, "Export", 50, True)
        self.column_list.add_column(mforms.StringColumnType, "Column name", self.owner.main.get_width(), False)
        self.column_list.end_columns()
        self.column_list.set_allow_sorting(True)
        self.column_list.set_size(200, -1)
        colbox.add(self.column_list, True, True)
        
        limit_box = mforms.newBox(True)
        limit_box.set_spacing(8)
        limit_box.add(mforms.newLabel("Count: "), False, False)
        self.limit_entry = mforms.newTextEntry()
        self.limit_entry.set_size(50, -1)
        self.limit_entry.add_changed_callback(lambda entry=self.limit_entry: self.entry_changed(entry))
        limit_box.add(self.limit_entry, False, False)
        
        offset_box = mforms.newBox(True)
        offset_box.set_spacing(8)
        offset_box.add(mforms.newLabel("Row Offset: "), False, False)
        self.offset_entry = mforms.newTextEntry()
        self.offset_entry.set_size(50, -1)
        self.offset_entry.add_changed_callback(lambda entry=self.offset_entry: self.entry_changed(entry))

        offset_box.add(self.offset_entry, False, False)
        
        
        sellall_cb = mforms.newCheckBox()
        sellall_cb.set_text("Select / Deselect all entries")
        sellall_cb.set_active(True)
        sellall_cb.add_clicked_callback(lambda cb = sellall_cb: self.sell_all(cb))
        
        limit_offset = mforms.newBox(True)
        limit_offset.set_spacing(8)
        limit_offset.add(sellall_cb, False, True)
        limit_offset.add_end(limit_box, False, True)
        limit_offset.add_end(offset_box, False, True)

        colbox.add(limit_offset, False, True)
        self.content.add(colbox, True, True)
        self.resume_layout()
Exemplo n.º 15
0
    def run(self):
        self._updating = False
        self._invalid_text = False
        self.form = Form(None, mforms.FormResizable)
        self.form.set_title(self.title)
        self.flist = newTreeView(mforms.TreeFlatList)
        self.curdir = newTextEntry()

        self.flist.add_column(mforms.IconStringColumnType, "File", 400, False)
        self.flist.end_columns()

        self.curdir.add_changed_callback(self.text_changed)
        self.curdir.add_action_callback(self.text_action)
        self.flist.add_activated_callback(self.on_cd)
        self.flist.add_changed_callback(self.on_change)

        accept = newButton()
        accept.set_text("OK")
        cancel = newButton()
        cancel.set_text("Cancel")
        button_box = newBox(True)
        button_box.set_padding(10)
        button_box.set_spacing(8)
        Utilities.add_end_ok_cancel_buttons(button_box, accept, cancel)

        box = newBox(False)  # Hosts all entries on that dialog.
        box.set_padding(10)
        box.set_spacing(10)
        box.add(self.curdir, False, False)
        box.add(self.flist, True, True)
        box.add(button_box, False, False)

        self.form.set_content(box)
        self.form.set_size(500, 400)

        cancel.add_clicked_callback(self.cancel_action)
        accept.add_clicked_callback(self.accept_action)

        self.form.relayout()
        self.form.center()

        self.on_cd(0, 0)

        # Don't use the accept button in run_modal or you won't be able to press <enter>
        #  to change the path via the top edit control.
        self.form.run_modal(None, cancel)
Exemplo n.º 16
0
    def __init__(self, owner):
        LogBox.__init__(self, owner)

        self.tree = tree = newTreeView(mforms.TreeDefault)
        tree.add_column(mforms.StringColumnType, "Start Time", 150, False)
        tree.add_column(mforms.StringColumnType, "From", 120, False)
        tree.add_column(mforms.StringColumnType, "Query Time", 150, False)
        tree.add_column(mforms.StringColumnType, "Lock Time", 150, False)
        tree.add_column(mforms.StringColumnType, "Rows Sent", 50, False)
        tree.add_column(mforms.StringColumnType, "Rows Examined", 50, False)
        tree.add_column(mforms.StringColumnType, "Db", 80, False)
        tree.add_column(mforms.StringColumnType, "Last Insert ID", 50, False)
        tree.add_column(mforms.StringColumnType, "Insert ID", 50, False)
        tree.add_column(mforms.StringColumnType, "Server ID", 50, False)
        tree.add_column(mforms.StringColumnType, "SQL", 500, False)
        tree.end_columns()

        self.add(tree, True, True)
Exemplo n.º 17
0
  def __init__(self, bool, name, db):
    self.db = db

    if not self.db.wbObject.customData['extra_behaviors_path']:
      self.db.cache['extra_behaviors_path'] = self.defaults['extra_behaviors_path']
    else:
      self.db.cache['extra_behaviors_path'] = self.db.wbObject.customData['extra_behaviors_path']

    self.fields = PropelBehavior.fields
    self.fields['name']['items'] = sorted(PropelBehavior.getBehaviorsDict(self.db.cache['extra_behaviors_path']).keys())
    self.behaviors = PropelBehavior.getBehaviorsDict(self.db.cache['extra_behaviors_path'])
    super(PropelTabBehaviors, self).__init__(bool, name)
    self.widgets['behaviors'] = mforms.newTreeView(1)
    self.search('behaviors')
    self.colmuns_name('behaviors')
    self.browse_extra_behaviors_box()
    self.add_remove_behavior_button()    
    self.add_end(self.widgets['behaviors'], True, True)
Exemplo n.º 18
0
    def __init__(self, owner):
        LogBox.__init__(self, owner)

        self.tree = tree = newTreeView(mforms.TreeDefault)
        tree.add_column(mforms.StringColumnType, "Start Time", 150, False)
        tree.add_column(mforms.StringColumnType, "From", 120, False)
        tree.add_column(mforms.StringColumnType, "Query Time", 150, False)
        tree.add_column(mforms.StringColumnType, "Lock Time", 150, False)
        tree.add_column(mforms.StringColumnType, "Rows Sent", 50, False)
        tree.add_column(mforms.StringColumnType, "Rows Examined", 50, False)
        tree.add_column(mforms.StringColumnType, "Db", 80, False)
        tree.add_column(mforms.StringColumnType, "Last Insert ID", 50, False)
        tree.add_column(mforms.StringColumnType, "Insert ID", 50, False)
        tree.add_column(mforms.StringColumnType, "Server ID", 50, False)
        tree.add_column(mforms.StringColumnType, "SQL", 500, False)
        tree.end_columns()

        self.add(tree, True, True)
    def __init__(self, group_container, vars):
        mforms.Form.__init__(self, None)
        self.pending_changes = False
        self.sel_vars = vars
        self.group_container = group_container
        self.suspend_layout()
        
        self.set_title("Custom Variable Categories")

        content = mforms.newBox(False)
        self.set_content(content)
        content.set_padding(20)
        content.set_spacing(12)
        
        l = mforms.newLabel("Select or create new category for custom variable categories.")
        content.add(l, False, False)
        
        self.groups = newTreeView(mforms.TreeFlatList)
        self.groups.set_selection_mode(mforms.TreeSelectMultiple)
        self.groups.add_column(mforms.StringColumnType, "Category name", 100, False)
        self.groups.end_columns()
        self.groups.set_size(200, 200)
        self.menu = mforms.newContextMenu()
        self.menu.add_item_with_title("Delete Category", self.group_delete, "group_delete")
        self.groups.set_context_menu(self.menu)

        content.add(self.groups, True, True)

        entry_box = mforms.newBox(True)
        entry_box.set_spacing(5)

        l = mforms.newLabel("Category name:")
        entry_box.add(l, False, False)
        self.name = mforms.newTextEntry()
        self.name.add_action_callback(self.group_name_action)
        entry_box.add(self.name, True, True)
        self.add_btn = newButton()
        self.add_btn.set_text("Add")
        self.add_btn.add_clicked_callback(self.group_add)
        entry_box.add_end(self.add_btn, False, False)

        content.add(entry_box, False, True)

        self.cancel = newButton()
        self.cancel.set_text("Cancel")
        self.cancel.add_clicked_callback(self.cancel_click)
        self.ok = newButton()
        self.ok.set_text("OK")
        self.ok.add_clicked_callback(self.ok_click)

        self.delete = newButton()
        self.delete.set_text("Delete")
        self.delete.add_clicked_callback(self.group_delete)
        
        bbox = mforms.newBox(True)
        bbox.set_spacing(12)
        
        okcancel_box = mforms.newBox(True)
        okcancel_box.set_spacing(12)

        bbox.add_end(okcancel_box, False, True)
        bbox.add(self.delete, False, True)

        mforms.Utilities.add_end_ok_cancel_buttons(okcancel_box, self.ok, self.cancel)
        content.add_end(bbox, False, True)

        self.set_size(550, 350)
        self.center()
        self.load_groups()

        self.resume_layout()
Exemplo n.º 20
0
    def update_ui(self):
        if self.error_box:
            self.remove(self.error_box)
            self.error_box = None

        if self.tree:
            self.remove(self.tree)
            self.tree = None

        if self.bbox:
            self.remove(self.bbox)
            self.bbox = None

        if self.warning_box:
            self.remove(self.warning_box)
            self.warning_box = None

        self.set_padding(8)
        self.set_spacing(8)
        
        filter_box = self.create_filter_box()
        if filter_box:
            if filter_box.get_parent():
                self.remove(filter_box)
            self.add(filter_box, False, True)
        
        try:
            self.log_reader = self.BackendLogReaderClass(*self.args)
        except Exception as error:
            import traceback
            log_error("Exception creating log reader: %s\n%s\n" % (error, traceback.format_exc()))
            self._show_error("Error creating log reader: %s\n" % error)
            return

        if self.log_reader.partial_support:
            self.warning_box = newBox(True)
            self.warning_box.set_spacing(8)
            warning_label = newLabel(self.log_reader.partial_support)
            self.warning_box.add(warning_label, False, True)
            self.add(self.warning_box, False, True)

        self.tree = newTreeView(mforms.TreeFlatList)
        self.tree.set_selection_mode(mforms.TreeSelectMultiple)

        for colspec in self.log_reader.column_specs:
            self.tree.add_column(mforms.StringColumnType,
                                 colspec[0],  # column header
                                 colspec[1],  # column width
                                 False)
        self.tree.end_columns()

        self.add(self.tree, True, True)

        table = mforms.newTable()
        table.set_row_spacing(4)
        table.set_column_spacing(4)
        table.set_column_count(4)
        table.set_row_count(2)

        table.add(newLabel("Log File Location:"), 0, 1, 0, 1, mforms.HFillFlag)
        if self.log_reader.log_file:
            if self.log_reader.log_file.path == "stderr":
                self.query = """<QueryList><Query Id = "0" Path = "Application">
                                <Select Path = "Application">*[System[Provider[@Name = 'MySQL'] and TimeCreated[timediff(@SystemTime) &lt;= 604800000]]]</Select>
                                </Query></QueryList>"""
                grt.setEventlogCallback(self.printResults)
                label = newLabel("Windows Event viewer")
            else:
                label = newLabel(self.log_reader.log_file.path)
        else:
            label = newLabel("TABLE")
        label.set_style(mforms.BoldStyle)
        table.add(label, 1, 2, 0, 1, mforms.VFillFlag|mforms.HFillFlag|mforms.HExpandFlag)

        table.add(newLabel("Log File Size:"), 2, 3, 0, 1, mforms.VFillFlag|mforms.HFillFlag)
        self.size_label = newLabel("retrieving..." if self.log_reader.log_file else "-")
        self.size_label.set_style(mforms.BoldStyle)
        table.add(self.size_label, 3, 4, 0, 1, mforms.VFillFlag|mforms.HFillFlag|mforms.HExpandFlag)

        table.add(newLabel("Showing:"), 0, 1, 1, 2, mforms.VFillFlag|mforms.HFillFlag)
        self.range_label = newLabel("retrieving data...")
        self.range_label.set_style(mforms.BoldStyle)
        table.add(self.range_label, 1, 2, 1, 2, mforms.VFillFlag|mforms.HFillFlag)
        self.add(table, False, True)

        self.bbox = newBox(True)
        self.bbox.set_spacing(8)
        self.add_end(self.bbox, False, True)

        self._menu = mforms.newContextMenu()
        self._menu.add_item_with_title("Copy Row", self.copy_record, "Copy Record", "Copy Record")
        self._menu.add_item_with_title("Copy Details", self.copy_details, "Copy Details", "Copy Details")
        self.tree.set_context_menu(self._menu)

        self.bbox.add(newLabel(""), True, True)

        self.bof_button = newButton()
        self.bof_button.set_text("Oldest")
        self.bbox.add(self.bof_button, False, True)
        self.bof_button.add_clicked_callback(self.go_bof)

        self.back_button = newButton()
        self.back_button.set_text("< Previous Page")
        self.bbox.add(self.back_button, False, True)
        self.back_button.add_clicked_callback(self.go_back)

        self.next_button = newButton()
        self.next_button.set_text("Next Page >")
        self.bbox.add(self.next_button, False, True)
        self.next_button.add_clicked_callback(self.go_next)

        self.eof_button = newButton()
        self.eof_button.set_text("Most Recent")
        self.bbox.add(self.eof_button, False, True)
        self.eof_button.add_clicked_callback(self.go_eof)

        self.refresh_button = newButton()
        self.refresh_button.set_text("Refresh")
        self.bbox.add(self.refresh_button, False, True)
        self.refresh_button.add_clicked_callback(self.refresh)

        if self.log_reader.log_file and self.log_reader.log_file.path == "stderr":
            self.actual_position = 0
            grt.getEventLogEntry(0, self.query)
Exemplo n.º 21
0
    def __init__(self, group_container, variables):
        mforms.Form.__init__(self, None)
        self.pending_changes = False
        self.sel_vars = variables
        self.group_container = group_container
        self.suspend_layout()

        self.set_title("Custom Variable Categories")

        content = mforms.newBox(False)
        self.set_content(content)
        content.set_padding(20)
        content.set_spacing(12)

        lbl = mforms.newLabel(
            "Select or create new category for custom variable categories.")
        content.add(lbl, False, False)

        self.groups = newTreeView(mforms.TreeFlatList)
        self.groups.set_selection_mode(mforms.TreeSelectMultiple)
        self.groups.add_column(mforms.StringColumnType, "Category name", 100,
                               False)
        self.groups.end_columns()
        self.groups.set_size(200, 200)
        self.menu = mforms.newContextMenu()
        self.menu.add_item_with_title("Delete Category", self.group_delete,
                                      "group_delete")
        self.groups.set_context_menu(self.menu)

        content.add(self.groups, True, True)

        entry_box = mforms.newBox(True)
        entry_box.set_spacing(5)

        lbl = mforms.newLabel("Category name:")
        entry_box.add(lbl, False, False)
        self.name = mforms.newTextEntry()
        self.name.add_action_callback(self.group_name_action)
        entry_box.add(self.name, True, True)
        self.add_btn = newButton()
        self.add_btn.set_text("Add")
        self.add_btn.add_clicked_callback(self.group_add)
        entry_box.add_end(self.add_btn, False, False)

        content.add(entry_box, False, True)

        self.cancel = newButton()
        self.cancel.set_text("Cancel")
        self.cancel.add_clicked_callback(self.cancel_click)
        self.ok = newButton()
        self.ok.set_text("OK")
        self.ok.add_clicked_callback(self.ok_click)

        self.delete = newButton()
        self.delete.set_text("Delete")
        self.delete.add_clicked_callback(self.group_delete)

        bbox = mforms.newBox(True)
        bbox.set_spacing(12)

        okcancel_box = mforms.newBox(True)
        okcancel_box.set_spacing(12)

        bbox.add_end(okcancel_box, False, True)
        bbox.add(self.delete, False, True)

        mforms.Utilities.add_end_ok_cancel_buttons(okcancel_box, self.ok,
                                                   self.cancel)
        content.add_end(bbox, False, True)

        self.set_size(550, 350)
        self.center()
        self.load_groups()

        self.resume_layout()
  def __init__(self, catalog):
    mforms.Form.__init__(self, None, mforms.FormNone)

    self.catalog = catalog

    self.set_title("Create Relationships for Tables")

    box = mforms.newBox(False)
    self.set_content(box)
    box.set_padding(12)
    box.set_spacing(12)

    label = mforms.newLabel(
"""This will automatically create foreign keys for tables that match
a certain column naming pattern, allowing you to visualize relationships 
between MyISAM tables.

To use, fill the Column Pattern field with the naming convention used for
columns that are meant to be used as foreign keys. The %(table)s and %(pk)s
variable names will be substituted with the referenced table values.""")
    box.add(label, False, True)

    hbox = mforms.newBox(True)
    hbox.set_spacing(12)
    box.add(hbox, False, True)

    label = mforms.newLabel("Column Pattern:")
    hbox.add(label, False, True)
    self.pattern = mforms.newTextEntry()
    hbox.add(self.pattern, True, True)
    self.matchType = mforms.newCheckBox()
    self.matchType.set_text("Match column types")
    hbox.add(self.matchType, False, True)
    self.matchType.set_active(True)
    search = mforms.newButton()
    search.set_text("Preview Matches")
    search.add_clicked_callback(self.findMatches)
    hbox.add(search, False, True)

    self.pattern.set_value("%(table)s_id")

    self.candidateTree = mforms.newTreeView(mforms.TreeShowHeader)
    self.candidateTree.add_column(mforms.StringColumnType, "From Table", 100, False)
    self.candidateTree.add_column(mforms.StringColumnType, "Column", 100, False)
    self.candidateTree.add_column(mforms.StringColumnType, "Type", 100, False)
    self.candidateTree.add_column(mforms.StringColumnType, "To Table", 100, False)
    self.candidateTree.add_column(mforms.StringColumnType, "Column", 100, False)
    self.candidateTree.add_column(mforms.StringColumnType, "Type", 100, False)
    self.candidateTree.end_columns()
    box.add(self.candidateTree, True, True)

    hbox = mforms.newBox(True)
    hbox.set_spacing(12)
    self.matchCount = mforms.newLabel("")
    hbox.add(self.matchCount, False, True)
    self.cancelButton = mforms.newButton()
    self.cancelButton.set_text("Cancel")
    hbox.add_end(self.cancelButton, False, True)
    self.okButton = mforms.newButton()
    self.okButton.set_text("Create FKs")
    hbox.add_end(self.okButton, False, True)
    self.okButton.add_clicked_callback(self.createFKs)
    box.add(hbox, False, True)

    self.set_size(700, 600)
    def __init__(self, owner):
        mforms.Form.__init__(self, None, mforms.FormDialogFrame|mforms.FormResizable|mforms.FormMinimizable)
        self.owner = owner
        self.tables_by_id = {}

        self.set_title("Table Templates")

        box = mforms.newBox(False)
        box.set_padding(12)
        box.set_spacing(12)

        label = mforms.newLabel("Manage templates of tables with pre-defined columns, for frequently used table structures.")
        box.add(label, False, True)

        top = mforms.newBox(True)
        box.add(top, False, True)

        #top.set_padding(12)
        top.set_spacing(12)
        self.template_list = mforms.newTreeView(mforms.TreeFlatList)
        self.template_list.add_column(mforms.IconStringColumnType, "Table Template", 200, True)
        self.template_list.end_columns()
        self.template_list.add_changed_callback(self.table_selected)
        self.template_list.set_cell_edited_callback(self.table_edited)
        top.add(self.template_list, True, True)
        if sys.platform.lower() != "darwin":
            self.template_list.set_size(-1, 150)

        bbox = mforms.newBox(False)
        bbox.set_spacing(8)
        top.add(bbox, False, True)

        self.add = mforms.newButton()
        self.add.set_text("New Template")
        self.add.add_clicked_callback(self.add_templ)
        bbox.add(self.add, False, True)

        self.duplicate = mforms.newButton()
        self.duplicate.set_text("Duplicate")
        self.duplicate.add_clicked_callback(self.dup_templ)
        bbox.add(self.duplicate, False, True)

        self.delete = mforms.newButton()
        self.delete.set_text("Delete")
        self.delete.add_clicked_callback(self.del_templ)
        bbox.add(self.delete, False, True)

        hbox = mforms.newBox(True)
        hbox.set_spacing(12)
      
        self.column_list = mforms.newTreeView(mforms.TreeFlatList)
        self.column_list.add_column(mforms.IconStringColumnType, "Column", 100, True)
        self.column_list.add_column(mforms.StringColumnType, "Datatype", 100, True)
        self.column_list.add_column(mforms.StringColumnType, "Default", 150, True)
        self.column_list.add_column(mforms.CheckColumnType, "PK", 25, True)
        self.column_list.add_column(mforms.CheckColumnType, "NN", 25, True)
        self.column_list.add_column(mforms.CheckColumnType, "UQ", 25, True)
        self.column_list.add_column(mforms.CheckColumnType, "AI", 25, True)
        self.column_list.end_columns()
        self.column_list.set_cell_edited_callback(self.column_edited)
        self.column_list.add_changed_callback(self.column_selected)
        hbox.add(self.column_list, True, True)
      
        vbox = mforms.newBox(False)
        vbox.set_spacing(8)
      
        vbox.add(mforms.newLabel("Column Collation:"), False, True)
        self.charset = mforms.newSelector(mforms.SelectorPopup)
        self.charset.add_changed_callback(self.collation_changed)
        collations = ["Table Default"]
        for ch in grt.root.wb.rdbmsMgmt.rdbms[0].characterSets:
            collations += ch.collations
        self.charset.add_items(collations)
        vbox.add(self.charset, False, True)

        vbox.add(mforms.newLabel("Additional Flags:"), False, True)
        self.flag_checkboxes = []
        hbox.add(vbox, False, True)
        self.column_details = vbox
      
        box.add(hbox, True, True)

        self.column_menu = mforms.newContextMenu()
        self.column_menu.add_item_with_title("Delete", self.delete_column)
        self.column_list.set_context_menu(self.column_menu)

        bbox = mforms.newBox(True)
        self.ok = mforms.newButton()
        self.ok.set_text("Close")
        bbox.add_end(self.ok, False, True)

        box.add(bbox, False, True)

        self.set_content(box)
        self.set_size(800, 500)
        self.center()

        self.refresh_tables()
Exemplo n.º 24
0
    def __init__(self, results, checksum=False):
        mforms.Form.__init__(self, mforms.Form.main_form(), mforms.FormNormal)

        self.box = mforms.newBox(False)
        self.box.set_padding(12)
        self.box.set_spacing(8)
        self.set_content(self.box)

        self.tree = mforms.newTreeView(mforms.TreeFlatList
                                       | mforms.TreeAltRowColors
                                       | mforms.TreeShowColumnLines)
        self.tree.set_selection_mode(mforms.TreeSelectMultiple)
        self.box.add(self.tree, True, True)
        self.tree.add_column(mforms.StringColumnType, "Table", 200, False)
        if checksum:
            self.tree.add_column(mforms.StringColumnType, "Checksum", 100,
                                 False)
        else:
            self.tree.add_column(mforms.StringColumnType, "Operation", 80,
                                 False)
            self.tree.add_column(mforms.IconStringColumnType, "Message", 400,
                                 False)
        self.tree.end_columns()

        self._checksum = checksum

        app = mforms.App.get()
        icon_path = {
            'status': app.get_resource_path('mini_ok.png'),
            'error': app.get_resource_path('mini_error.png'),
            'info': '',
            'note': app.get_resource_path('mini_notice.png'),
            'warning': app.get_resource_path('mini_warning.png'),
        }

        ok = results.goToFirstRow()
        while ok:
            node = self.tree.add_node()
            node.set_string(0, results.stringFieldValue(0))
            if not checksum:
                node.set_string(1, results.stringFieldValue(1))
                node.set_icon_path(
                    2, icon_path.get(results.stringFieldValue(2), ''))
                node.set_string(2, results.stringFieldValue(3))
                node.set_tag(results.stringFieldValue(2))
            else:
                node.set_string(1, results.stringFieldValue(1))
            ok = results.nextRow()

        bbox = mforms.newBox(True)
        self.box.add(bbox, False, True)

        copy = mforms.newButton()
        copy.add_clicked_callback(self.copy_to_clipboard)
        copy.set_text("Copy to Clipboard")
        bbox.add(copy, False, True)

        self.ok = mforms.newButton()
        self.ok.set_text("OK")
        self.ok.add_clicked_callback(self.close)
        bbox.add_end(self.ok, False, True)

        self.set_size(500, 400)
Exemplo n.º 25
0
    def __init__(self, owner):
        mforms.Form.__init__(
            self, None, mforms.FormDialogFrame | mforms.FormResizable
            | mforms.FormMinimizable)
        self.owner = owner

        # We need to have some default catalog and schema so parser is happy
        self.tmpCatalog = grt.classes.db_mysql_Catalog()
        self.tmpCatalog.name = 'tmpCatalog'
        self.tmpCatalog.oldName = self.tmpCatalog.name
        self.tmpCatalog.simpleDatatypes.extend(
            grt.root.wb.rdbmsMgmt.rdbms[0].simpleDatatypes)

        self.tmpSchema = grt.classes.db_mysql_Schema()
        self.tmpSchema.name = "tmpSchema"
        self.tmpSchema.oldName = self.tmpSchema.name
        self.tmpSchema.owner = self.tmpCatalog
        self.tmpCatalog.schemata.append(self.tmpSchema)

        self.tables_by_id = {}

        self.set_title("Table Templates")

        box = mforms.newBox(False)
        box.set_padding(12)
        box.set_spacing(12)

        label = mforms.newLabel(
            "Manage templates of tables with pre-defined columns, for frequently used table structures."
        )
        box.add(label, False, True)

        top = mforms.newBox(True)
        box.add(top, False, True)

        #top.set_padding(12)
        top.set_spacing(12)
        self.template_list = mforms.newTreeView(mforms.TreeFlatList)
        self.template_list.add_column(mforms.IconStringColumnType,
                                      "Table Template", 200, True)
        self.template_list.end_columns()
        self.template_list.add_changed_callback(self.table_selected)
        self.template_list.set_cell_edited_callback(self.table_edited)
        top.add(self.template_list, True, True)
        if sys.platform.lower() != "darwin":
            self.template_list.set_size(-1, 150)

        bbox = mforms.newBox(False)
        bbox.set_spacing(8)
        top.add(bbox, False, True)

        self.add = mforms.newButton()
        self.add.set_text("New Template")
        self.add.add_clicked_callback(self.add_templ)
        bbox.add(self.add, False, True)

        self.duplicate = mforms.newButton()
        self.duplicate.set_text("Duplicate")
        self.duplicate.add_clicked_callback(self.dup_templ)
        self.duplicate.set_enabled(False)
        bbox.add(self.duplicate, False, True)

        self.delete = mforms.newButton()
        self.delete.set_text("Delete")
        self.delete.add_clicked_callback(self.del_templ)
        self.delete.set_enabled(False)
        bbox.add(self.delete, False, True)

        hbox = mforms.newBox(True)
        hbox.set_spacing(12)

        self.column_list = mforms.newTreeView(mforms.TreeFlatList)
        self.column_list.add_column(mforms.IconStringColumnType, "Column", 100,
                                    True)
        self.column_list.add_column(mforms.StringColumnType, "Datatype", 100,
                                    True)
        self.column_list.add_column(mforms.StringColumnType, "Default", 150,
                                    True)
        self.column_list.add_column(mforms.CheckColumnType, "PK", 25, True)
        self.column_list.add_column(mforms.CheckColumnType, "NN", 25, True)
        self.column_list.add_column(mforms.CheckColumnType, "UQ", 25, True)
        self.column_list.add_column(mforms.CheckColumnType, "AI", 25, True)
        self.column_list.end_columns()
        self.column_list.set_cell_edited_callback(self.column_edited)
        self.column_list.add_changed_callback(self.column_selected)
        hbox.add(self.column_list, True, True)

        vbox = mforms.newBox(False)
        vbox.set_spacing(8)

        vbox.add(mforms.newLabel("Column Collation:"), False, True)
        self.charset = mforms.newSelector(mforms.SelectorPopup)
        self.charset.add_changed_callback(self.collation_changed)
        collations = ["Table Default"]
        for ch in grt.root.wb.rdbmsMgmt.rdbms[0].characterSets:
            collations += ch.collations
        self.charset.add_items(collations)
        vbox.add(self.charset, False, True)

        vbox.add(mforms.newLabel("Additional Flags:"), False, True)
        self.flag_checkboxes = []
        hbox.add(vbox, False, True)
        self.column_details = vbox

        box.add(hbox, True, True)

        self.column_menu = mforms.newContextMenu()
        self.column_menu.add_item_with_title("Delete", self.delete_column)
        self.column_list.set_context_menu(self.column_menu)

        bbox = mforms.newBox(True)
        self.ok = mforms.newButton()
        self.ok.set_text("Close")
        bbox.add_end(self.ok, False, True)

        box.add(bbox, False, True)

        self.set_content(box)
        self.set_size(800, 500)
        self.center()

        self.refresh_tables()
    def __init__(self, catalog):
        mforms.Form.__init__(self, None, mforms.FormNormal)

        self.catalog = catalog

        self.set_title("Create Migration for Rails")

        box = mforms.newBox(False)
        self.set_content(box)
        box.set_padding(12)
        box.set_spacing(12)

        label = mforms.newLabel(
            """This is going to create all migration files necessary in Rails application. 
   It also creates a scaffold.txt with scaffold commands to be customized, as you wish my Lord.  
   To use it, you must inform the path where the files will be created and click on Create Files button."""
        )
        box.add(label, False, True)

        hbox = mforms.newBox(True)
        hbox.set_spacing(12)
        box.add(hbox, False, True)

        label = mforms.newLabel("Path to create:")
        hbox.add(label, False, True)
        self.pattern = mforms.newTextEntry()
        hbox.add(self.pattern, True, True)
        self.browser_file_button = mforms.newButton()
        self.browser_file_button.set_text("...")
        hbox.add(self.browser_file_button, False, True)
        self.browser_file_button.add_clicked_callback(self.choose_directory)
        #self.matchType.set_active(True)
        search = mforms.newButton()
        search.set_text("Create Files")
        search.add_clicked_callback(self.export_porra_toda)
        hbox.add(search, False, True)

        self.pattern.set_value("E:\\18")

        self.candidateTree = mforms.newTreeView(mforms.TreeShowHeader)
        self.candidateTree.add_column(mforms.StringColumnType, "Table", 100,
                                      False)
        self.candidateTree.add_column(mforms.StringColumnType, "Column", 100,
                                      False)
        self.candidateTree.add_column(mforms.StringColumnType, "Type", 100,
                                      False)
        self.candidateTree.add_column(mforms.StringColumnType, "Migration",
                                      100, False)
        self.candidateTree.add_column(mforms.StringColumnType, "Column", 100,
                                      False)
        self.candidateTree.add_column(mforms.StringColumnType, "Type", 100,
                                      False)
        self.candidateTree.add_column(mforms.StringColumnType, "File", 100,
                                      False)
        self.candidateTree.end_columns()
        box.add(self.candidateTree, True, True)

        hbox = mforms.newBox(True)
        hbox.set_spacing(12)
        self.matchCount = mforms.newLabel("")
        hbox.add(self.matchCount, False, True)
        self.cancelButton = mforms.newButton()
        self.cancelButton.set_text("Cancel")
        hbox.add_end(self.cancelButton, False, True)

        self.okButton = mforms.newButton()
        self.okButton.set_text("Thanks!")
        hbox.add_end(self.okButton, False, True)
        #self.okButton.add_clicked_callback(self.createFKs)
        box.add(hbox, False, True)
        self.component_id = 0
        self.set_size(700, 600)
Exemplo n.º 27
0
    def __init__(self, main):
        WizardPage.__init__(self, main, "Create Target Results", wide=True)

        self.main.add_wizard_page(self, "ObjectMigration",
                                  "Create Target Results")

        text = """Scripts to create the target schema were executed. No data has been migrated yet. Review the creation report below 
for errors or warnings. If there are any errors, you can manually fix the scripts and click [Recreate Objects] to retry 
the schema creation or return to the Manual Editing page to correct them there and retry the target creation."""
        description = mforms.newLabel(text)
        description.set_name("Page Description")
        self.content.add(description, False, True)

        hbox = mforms.newBox(True)
        hbox.set_spacing(12)
        hbox.set_homogeneous(True)
        self._tree = mforms.newTreeView(mforms.TreeFlatList)
        self._tree.set_name("Script Results")
        self._tree.add_column(mforms.IconStringColumnType, "Object", 200,
                              False)
        self._tree.add_column(mforms.IconStringColumnType, "Result", 600,
                              False)
        self._tree.end_columns()
        self._tree.add_changed_callback(self._selection_changed)
        hbox.add(self._tree, True, True)
        #self.content.add(self._tree, True, True)

        self._advbox = mforms.newPanel(mforms.TitledBoxPanel)
        self._advbox.set_title("SQL CREATE Script for Selected Object")
        self._advbox.set_name("SQL IDE")
        box = mforms.newBox(False)
        self._code = mforms.newCodeEditor()
        self._code.set_language(mforms.LanguageMySQL)
        self._code.add_changed_callback(self._code_changed)
        box.add(self._code, True, True)
        vbox = mforms.newBox(True)
        vbox.set_padding(12)
        vbox.set_spacing(8)
        self._comment_check = mforms.newCheckBox()
        self._comment_check.set_text("Comment out")
        self._comment_check.set_name("Comment Out")
        self._comment_check.add_clicked_callback(self._comment_clicked)
        vbox.add(self._comment_check, False, True)

        self._revert_btn = mforms.newButton()
        self._revert_btn.set_text("Discard")
        vbox.add_end(self._revert_btn, False, True)
        self._revert_btn.add_clicked_callback(self._discard_clicked)

        self._apply_btn = mforms.newButton()
        self._apply_btn.set_text("Apply")
        vbox.add_end(self._apply_btn, False, True)
        self._apply_btn.add_clicked_callback(self._apply_clicked)
        box.add(vbox, False, True)

        self._advbox.add(box)
        #self._advbox.set_size(-1, 200)
        #self._advbox_shown = True
        #self.go_advanced() # toggle to hide

        self.advanced_button.set_text("Recreate Objects")

        #self.content.add(self._advbox, False, True)
        hbox.add(self._advbox, True, True)
        self.content.add(hbox, True, True)

        self._msgbox = mforms.newPanel(mforms.TitledBoxPanel)
        self._msgbox.set_title("Output Messages")
        self._msgbox.set_name("Output Messages")
        box = mforms.newBox(False)
        box.set_padding(8)
        self._msgs = mforms.newTextBox(mforms.VerticalScrollBar)
        box.add(self._msgs, True, True)
        self._msgbox.add(box)
        self.content.add(self._msgbox, False, True)
        self._msgbox.set_size(-1, 200)

        self._error_tables = []
Exemplo n.º 28
0
    def __init__(self, owner):
        mforms.Box.__init__(self, False)
        self.set_managed()
        self.owner = owner

        self._selected_user = None
        self._selected_user_original = None
        self.valid = False

        self.suspend_layout()
        self.set_padding(8)
        self.set_spacing(8)

        top_box = newBox(True)
        top_box.set_spacing(8)
        self.add(top_box, True, True)

        bottom_box = newBox(True)
        bottom_box.set_spacing(8)

        self.add_button = newButton()
        self.add_button.set_text("Add Account")
        bottom_box.add(self.add_button, False, True)
        self.add_button.add_clicked_callback(self.add_account)

        self.dup_button = newButton()
        self.dup_button.set_text("Duplicate")
        #bottom_box.add(self.dup_button, False, True)
        self.dup_button.add_clicked_callback(self.dup_account)

        self.del_button = newButton()
        self.del_button.set_text("Remove")
        bottom_box.add(self.del_button, False, True)
        self.del_button.add_clicked_callback(self.del_account)

        self.refresh_button = newButton()
        self.refresh_button.set_text("Refresh")
        self.refresh_button.add_clicked_callback(self.owner.refresh)
        bottom_box.add_end(self.refresh_button, False, True)

        self.save_button = newButton()
        self.save_button.set_text("Apply")
        bottom_box.add_end(self.save_button, False, True)
        self.save_button.add_clicked_callback(self.commit)

        self.revert_button = newButton()
        self.revert_button.set_text("Revert")
        bottom_box.add_end(self.revert_button, False, True)
        self.revert_button.add_clicked_callback(self.revert)

        self.revoke_all_button = newButton()
        self.revoke_all_button.set_text("Revoke All Privileges")
        bottom_box.add_end(self.revoke_all_button, False, True)
        self.revoke_all_button.add_clicked_callback(self.revoke_all)
        self.revoke_all_button.set_tooltip(
            "Immediately remove all privileges from the account, from every object at all levels.\nThe account itself will be left untouched and logins will still be possible."
        )

        self.add(bottom_box, False, True)

        account_list_box = newBox(False)
        account_list_box.set_spacing(8)
        account_list_box.set_size(220, -1)
        top_box.add(account_list_box, False, True)

        label = newLabel("User Accounts")
        account_list_box.add(label, False, True)

        #searchbox = TextEntry(SearchEntry)
        #account_list_box.add(searchbox, False, True)

        self.user_list = newTreeView(mforms.TreeDefault)
        self.user_list.add_column(mforms.StringColumnType, "User", 80, False)
        self.user_list.add_column(mforms.StringColumnType, "From Host", 120,
                                  False)
        self.user_list.end_columns()
        self.user_list.add_changed_callback(self.user_selected)
        self.user_list.set_allow_sorting(True)
        account_list_box.add(self.user_list, True, True)

        self.content_box = abox = newBox(False)
        abox.set_spacing(8)
        top_box.add(abox, True, True)

        self.account_label = newLabel(
            "Select an account to edit or click Add Account to create a new one"
        )
        self.account_label.set_style(mforms.BoldStyle)

        abox.add(self.account_label, False, True)

        tabView = newTabView(False)
        abox.add(tabView, True, True)

        ##
        vbox = newBox(False)
        vbox.set_spacing(12)
        vbox.set_padding(12)
        tabView.add_page(vbox, "Login")

        table = newTable()
        vbox.add(table, False, True)

        table.set_row_count(7)
        table.set_column_count(3)
        table.set_row_spacing(8)
        table.set_column_spacing(8)

        self.username = newTextEntry()
        self.username.set_size(150, -1)
        self.username.add_changed_callback(self.set_dirty)
        self.username.set_max_length(16)  # max username length for mysql
        self.password = newTextEntry(mforms.PasswordEntry)
        self.password.set_size(150, -1)
        self.password.add_changed_callback(self.set_dirty)
        self.confirm = newTextEntry(mforms.PasswordEntry)
        self.confirm.set_size(150, -1)
        self.confirm.add_changed_callback(self.set_dirty)

        self.hostlimithost = newTextEntry()
        self.hostlimithost.add_changed_callback(self.validate_hostlimithost)

        table.add(rLabel("Login Name:"), 0, 1, 0, 1, mforms.HFillFlag)
        table.add(self.username, 1, 2, 0, 1, mforms.HFillFlag)
        table.add(
            dLabel(
                "You may create multiple accounts with the same name\nto connect from different hosts."
            ), 2, 3, 0, 1, mforms.HFillFlag | mforms.HExpandFlag)

        self.has_extra_plugins = len([
            p for p in self.active_plugins
            if p not in ("mysql_native_password", "mysql_old_password")
        ]) > 0

        if self.has_extra_plugins:
            self.auth_type_label = rLabel("Authentication Type:")
            table.add(self.auth_type_label, 0, 1, 1, 2, mforms.HFillFlag)
            self.auth_type_sel = newSelector()
            table.add(self.auth_type_sel, 1, 2, 1, 2,
                      mforms.HFillFlag | mforms.HExpandFlag)
            table.add(
                dLabel(
                    "\nFor the standard password and/or host based authentication,\nselect 'Standard'.\n"
                ), 2, 3, 1, 2, mforms.HFillFlag)
            self.auth_type_sel.add_changed_callback(self.auth_type_changed)
            self.auth_type_list = []
            for plugin in [None] + self.active_plugins:
                if plugin in ("mysql_native_password", "mysql_old_password"):
                    continue
                if AUTHENTICATION_PLUGIN_TYPES.has_key(plugin):
                    self.auth_type_sel.add_item(
                        AUTHENTICATION_PLUGIN_TYPES[plugin]["name"])
                else:
                    self.auth_type_sel.add_item(plugin)
                self.auth_type_list.append(plugin)
        else:
            self.auth_type_list = None
            self.auth_string_param = None

        self.auth_type_password_labels = []

        def add(label, l=self.auth_type_password_labels):
            l.append(label)
            return label

        table.add(add(rLabel("Limit Connectivity to Hosts Matching:")), 0, 1,
                  2, 3, mforms.HFillFlag)
        table.add(self.hostlimithost, 1, 2, 2, 3, mforms.HFillFlag)
        self.hostlimit_box = newBox(True)
        self.hostlimithost_valid_icon = newImageBox()
        self.hostlimit_box.add(self.hostlimithost_valid_icon, False, False)
        self.hostlimit_box.add(add(dLabel("% and _ wildcards may be used")),
                               True, True)
        table.add(self.hostlimit_box, 2, 3, 2, 3,
                  mforms.HFillFlag | mforms.HExpandFlag)

        table.add(add(rLabel("Password:"******"Type a password to reset it.")), 2, 3, 3, 4,
                  mforms.HFillFlag | mforms.HExpandFlag)
        table.add(add(rLabel("Confirm Password:"******"Enter password again to confirm.")), 2, 3, 4, 5,
                  mforms.HFillFlag | mforms.HExpandFlag)

        table.add(newLabel(""), 1, 2, 5, 6, mforms.HFillFlag)

        if self.has_extra_plugins:
            self.auth_string_param = newTextEntry()
            self.auth_string_param.add_changed_callback(self.set_dirty)
            self.auth_string_label = rLabel("Authentication String:")
            table.add(self.auth_string_label, 0, 1, 6, 7, mforms.HFillFlag)
            table.add(self.auth_string_param, 1, 2, 6, 7,
                      mforms.HFillFlag | mforms.HExpandFlag)
            table.add(dLabel("Authentication plugin specific parameters."), 2,
                      3, 6, 7, mforms.HFillFlag)
            self.auth_string_help = newLabel("")
            vbox.add(self.auth_string_help, False, True)

        ####

        box = newBox(False)
        tabView.add_page(box, "Administrative Roles")

        lbox = newBox(True)
        box.add(lbox, True, True)
        lbox.set_spacing(12)
        lbox.set_padding(12)

        self.role_list = newTreeView(mforms.TreeDefault)
        self.role_list.add_column(mforms.CheckColumnType, "", 30, True)
        self.role_list.add_column(mforms.StringColumnType, "Role", 150, False)
        self.role_list.add_column(mforms.StringColumnType, "Description", 300,
                                  False)
        self.role_list.end_columns()
        lbox.add(self.role_list, True, True)
        self.role_list.set_cell_edited_callback(self.role_list_toggled)

        self.role_priv_list = newTreeView(mforms.TreeDefault)
        self.role_priv_list.add_column(mforms.StringColumnType,
                                       "Global Privileges Assigned to User",
                                       200, False)
        self.role_priv_list.end_columns()
        self.role_priv_list.set_size(220, -1)
        self.role_priv_list.set_allow_sorting(True)
        lbox.add(self.role_priv_list, False, True)

        self.role_list.clear_rows()
        for name, desc, privs in SecurityAdminRoles:
            row = self.role_list.add_row()
            self.role_list.set_bool(row, 0, False)
            self.role_list.set_string(row, 1, name)
            self.role_list.set_string(row, 2, desc)

        ###
        table = newTable()
        tabView.add_page(table, "Account Limits")

        table.set_padding(12)
        table.set_column_spacing(8)
        table.set_row_spacing(8)
        table.set_row_count(4)
        table.set_column_count(3)

        table.add(rLabel("Max. Queries:"), 0, 1, 0, 1, 0)
        self.max_questions = newTextEntry()
        self.max_questions.set_size(60, -1)
        self.max_questions.add_changed_callback(self.set_dirty)
        table.add(self.max_questions, 1, 2, 0, 1, mforms.HFillFlag)
        table.add(
            dLabel(
                "Number of queries the account can execute within one hour."),
            2, 3, 0, 1, mforms.HFillFlag | mforms.HExpandFlag)

        table.add(rLabel("Max. Updates:"), 0, 1, 1, 2, 0)
        self.max_updates = newTextEntry()
        self.max_updates.set_size(60, -1)
        self.max_updates.add_changed_callback(self.set_dirty)
        table.add(self.max_updates, 1, 2, 1, 2, mforms.HFillFlag)
        table.add(
            dLabel(
                "Number of updates the account can execute within one hour."),
            2, 3, 1, 2, mforms.HFillFlag | mforms.HExpandFlag)

        table.add(rLabel("Max. Connections:"), 0, 1, 2, 3, 0)
        self.max_connections = newTextEntry()
        self.max_connections.set_size(60, -1)
        self.max_connections.add_changed_callback(self.set_dirty)
        table.add(self.max_connections, 1, 2, 2, 3, mforms.HFillFlag)
        table.add(
            dLabel(
                "The number of times the account can connect to the server per hour."
            ), 2, 3, 2, 3, mforms.HFillFlag | mforms.HExpandFlag)

        table.add(rLabel("Concurrent Connections:"), 0, 1, 3, 4, 0)
        self.max_uconnections = newTextEntry()
        self.max_uconnections.set_size(60, -1)
        self.max_uconnections.add_changed_callback(self.set_dirty)
        table.add(self.max_uconnections, 1, 2, 3, 4, mforms.HFillFlag)
        table.add(
            dLabel(
                "The number of simultaneous connections to the server the account can have."
            ), 2, 3, 3, 4, mforms.HFillFlag | mforms.HExpandFlag)

        self.resume_layout()

        self.user_selected()
Exemplo n.º 29
0
class LogView(mforms.Box):
    '''
    Main front end view class for displaying log entries.

    Each page in the Tab View is an instance of this class.
    '''
    def __init__(self, owner, BackendLogReaderClass, *args):
        '''
        The arguments following BackendLogReaderClass will be passed to
        BackendLogReaderClass to instantiate it in order to get a log
        reader object.
        '''

        super(LogView, self).__init__(False)
        self.set_managed()
        self.owner = owner

        self.BackendLogReaderClass = BackendLogReaderClass
        self.args = args

        self.log_reader = None
        self.error_box = None
        self.tree = None
        self.bbox = None
        self.warning_box = None
        self.update_ui()

    @log_error_decorator
    def _show_error(self, error):
        if self.error_box:
            self.remove(self.error_box)
            self.error_box = None
        self.error_box = newBox(True)
        self.error_box.set_spacing(8)
        error_label = newLabel(str(error))
        self.error_box.add(error_label, False, False)
        try_again_button = newButton()
        try_again_button.set_text('Try again')
        self.error_box.add(try_again_button, False, False)
        try_again_button.add_clicked_callback(self.update_ui)
        self.add(self.error_box, False, True)

    def update_ui(self):
        # Clean up:
        if self.error_box:
            self.remove(self.error_box)
            self.error_box = None

        if self.tree:
            self.remove(self.tree)
            self.tree = None

        if self.bbox:
            self.remove(self.bbox)
            self.bbox = None

        if self.warning_box:
            self.remove(self.warning_box)
            self.warning_box = None

        self.set_padding(8)
        self.set_spacing(8)

        try:
            self.log_reader = self.BackendLogReaderClass(*self.args)
        except (ServerIOError, LogFileAccessError, OperationCancelledError,
                IOError, ValueError), error:
            self._show_error(error)
            return

        if self.log_reader.partial_support:
            self.warning_box = newBox(True)
            self.warning_box.set_spacing(8)
            warning_label = newLabel(self.log_reader.partial_support)
            self.warning_box.add(warning_label, False, False)
            self.add(self.warning_box, False, True)

        self.tree = newTreeView(mforms.TreeDefault)

        for colspec in self.log_reader.column_specs:
            self.tree.add_column(
                mforms.StringColumnType,
                colspec[0],  # column header
                colspec[1],  # column width
                False)
        self.tree.end_columns()

        self.add(self.tree, True, True)

        self.bbox = newBox(True)
        self.bbox.set_spacing(8)
        self.add_end(self.bbox, False, True)

        self.range_label = newLabel("")
        self.bbox.add(self.range_label, True, True)

        self.view_button = newButton()
        self.view_button.set_text("Copy Selected")
        self.bbox.add(self.view_button, False, True)
        self.view_button.add_clicked_callback(self.copy_details)

        self.bof_button = newButton()
        self.bof_button.set_text("<<")
        self.bbox.add(self.bof_button, False, True)
        self.bof_button.add_clicked_callback(self.go_bof)

        self.back_button = newButton()
        self.back_button.set_text("<")
        self.bbox.add(self.back_button, False, True)
        self.back_button.add_clicked_callback(self.go_back)

        self.next_button = newButton()
        self.next_button.set_text(">")
        self.bbox.add(self.next_button, False, True)
        self.next_button.add_clicked_callback(self.go_next)

        self.eof_button = newButton()
        self.eof_button.set_text(">>")
        self.bbox.add(self.eof_button, False, True)
        self.eof_button.add_clicked_callback(self.go_eof)

        self.refresh_button = newButton()
        self.refresh_button.set_text("Refresh")
        self.bbox.add(self.refresh_button, False, True)
        self.refresh_button.add_clicked_callback(self.refresh)

        try:
            self.refresh(self.log_reader.last())
        except (ServerIOError, LogFileAccessError, OperationCancelledError,
                IOError, ValueError), error:
            self._show_error(error)
Exemplo n.º 30
0
  def __init__(self, ctrl_be, variables, command):
    mforms.Box.__init__(self, False)
    self.set_managed()

    self.suspend_layout()

    self.command = command
    self.ctrl_be = ctrl_be

    box = newBox(True)
    box.set_spacing(12)
    self.add(box, True, True)
    self.tree = newTreeView(mforms.TreeDefault)
    self.tree.set_size(180, -1)
    
    sidebox = newBox(False)
    
    box.add(sidebox, False, True)
    
    self.searchEntry = newTextEntry(mforms.SearchEntry)
    
    sidebox.set_spacing(12)
    sidebox.add(self.searchEntry, False, True)
    sidebox.add(self.tree, True, True)
    
    self.searchEntry.add_changed_callback(self.filterOutput)

    self.tree.add_column(mforms.StringColumnType, "", 160, False)
    self.tree.end_columns()
    self.tree.add_changed_callback(weakcb(self, "refresh"))

    self.values = newTreeView(mforms.TreeDefault)
    box.add(self.values, True, True)

    self.values.add_column(mforms.StringColumnType, "Name", 200, False)
    self.values.add_column(mforms.StringColumnType, "Value", 120, False)
    self.values.add_column(mforms.StringColumnType, "Description", 1000, False)
    self.values.end_columns()
    self.values.set_allow_sorting(True)

    box = newBox(True)
    box.set_spacing(8)
    copy_all_button = newButton()
    copy_all_button.set_text('Copy Global Status and Variables to Clipboard')
    copy_all_button.add_clicked_callback(self.copy_status_to_clipboard)
    box.add(copy_all_button, False, False)
    copy_shown_button = newButton()
    copy_shown_button.set_text('Copy Shown Variables to Clipboard')
    copy_shown_button.add_clicked_callback(self.copy_visible_vars_to_clipboard)
    box.add(copy_shown_button, False, False)
    button = newButton()
    box.add_end(button, False, True)
    button.set_text("Refresh")
    box.set_padding(12)

    button.add_clicked_callback(weakcb(self, "refresh"))

    self.add(box, False, True)

    self.groups = {}
    self.descriptions = {}
    def analyze(tree, level, d, groupd, version, vars, existing_vars):
      groups = {}
      variables = []
      for group_name, group_variables in vars.iteritems():
        vars_added_to_the_group = []
        groups[group_name] = vars_added_to_the_group
        for v in group_variables:
          if v.var in existing_vars:
            name = v.var
            variables.append(name)
            vars_added_to_the_group.append(v.var)
            d[name] = v.description
            existing_vars.remove(name)
        if vars_added_to_the_group:
            row = tree.add_row()
            tree.set_string(row, 0, group_name)
            tree.set_row_tag(row, group_name)
      return groups, variables

    row = self.tree.add_row()
    self.tree.set_string(row, 0, "All")
    row = self.tree.add_row()
    self.tree.set_string(row, 0, "Search Results")
    self.resume_layout()

    
    variables_in_server = []
    result = self.ctrl_be.exec_query(self.command)
    if result is not None:
      while result.nextRow():
        name = result.stringByName("Variable_name")
        variables_in_server.append(name)

    allgroups, allvars = analyze(self.tree, 0, self.descriptions, self.groups, self.ctrl_be.get_server_version(), variables, variables_in_server)
    if variables_in_server:
      allvars += variables_in_server
      group_name = "Other"
      allgroups[group_name] = variables_in_server
      row = self.tree.add_row()
      self.tree.set_string(row, 0, group_name)
      self.tree.set_row_tag(row, group_name)

    self.groups = allgroups
    self.known_variables = allvars
Exemplo n.º 31
0
    def __init__(self, owner):
        mforms.Box.__init__(self, True)
        self.set_managed()
        self.owner = owner

        self._selected_user = None
        self._selected_user_original = None

        self.suspend_layout()
        self.set_spacing(8)
        self.set_padding(8)

        schema_list_box = newBox(False)
        schema_list_box.set_spacing(8)
        schema_list_box.set_size(150, -1)
        self.add(schema_list_box, False, True)

        #searchbox = TextEntry(SearchEntry)
        #schema_list_box.add(searchbox, False, True)

        self.user_list = newTreeView(mforms.TreeDefault)
        self.user_list.add_column(mforms.StringColumnType, "Users", 140, False)
        self.user_list.end_columns()
        self.user_list.add_changed_callback(self.user_selected)
        self.user_list.set_allow_sorting(True)
        schema_list_box.add(self.user_list, True, True)

        self.schema_rights_checks = {}

        self.content_box = priv_vbox = newBox(False)
        priv_vbox.set_spacing(8)
        self.add(priv_vbox, True, True)

        priv_vbox.add(
            newLabel(
                "Select a user and pick the privileges it has for a given Schema and Host combination."
            ), False, True)

        self.privs_list = newTreeView(mforms.TreeDefault)
        self.privs_list.add_column(mforms.StringColumnType, "Host", 100, True)
        self.privs_list.add_column(mforms.StringColumnType, "Schema", 100,
                                   True)
        self.privs_list.add_column(mforms.StringColumnType, "Privileges", 800,
                                   False)
        self.privs_list.end_columns()
        self.privs_list.add_changed_callback(self.schema_priv_selected)

        priv_vbox.add(self.privs_list, True, True)

        bbox = newBox(True)
        bbox.set_spacing(8)

        bbox.add(
            dLabel(
                "Schema and Host fields may use % and _ wildcards. The server will match specific entries before wildcarded ones."
            ), False, True)

        self.add_entry_button = newButton()
        self.add_entry_button.set_text("Add Entry...")
        bbox.add_end(self.add_entry_button, False, True)
        self.add_entry_button.add_clicked_callback(self.add_entry)

        self.del_entry_button = newButton()
        self.del_entry_button.set_text("Delete Entry")
        bbox.add_end(self.del_entry_button, False, True)
        self.del_entry_button.add_clicked_callback(self.del_entry)

        priv_vbox.add(bbox, False, True)

        self.schema_priv_label = newLabel("")
        priv_vbox.add(self.schema_priv_label, False, True)

        hbox = newBox(True)
        hbox.set_homogeneous(True)
        hbox.set_spacing(8)
        priv_vbox.add(hbox, False, True)

        self.schema_object_privs_panel = panel = newPanel(
            mforms.TitledBoxPanel)
        panel.set_title("Object Rights")
        box = newBox(False)
        box.set_padding(8)
        for name in SCHEMA_OBJECT_RIGHTS:
            cb = newCheckBox()
            label, desc = PrivilegeInfo.get(name, ("", None))
            cb.set_text(label)
            if desc:
                cb.set_tooltip(desc)
            cb.add_clicked_callback(self.schema_priv_checked)
            box.add(cb, False, False)
            self.schema_rights_checks[name] = cb
        panel.add(box)
        hbox.add(panel, False, True)

        self.schema_ddl_privs_panel = panel = newPanel(mforms.TitledBoxPanel)
        panel.set_title("DDL Rights")
        box = newBox(False)
        box.set_padding(8)
        for name in SCHEMA_DDL_RIGHTS:
            cb = newCheckBox()
            label, desc = PrivilegeInfo.get(name, ("", None))
            cb.set_text(label)
            if desc:
                cb.set_tooltip(desc)
            cb.add_clicked_callback(self.schema_priv_checked)
            box.add(cb, False, False)
            self.schema_rights_checks[name] = cb
        panel.add(box)
        hbox.add(panel, False, True)

        self.schema_other_privs_panel = panel = newPanel(mforms.TitledBoxPanel)
        panel.set_title("Other Rights")
        box = newBox(False)
        box.set_padding(8)
        for name in SCHEMA_OTHER_RIGHTS:
            cb = newCheckBox()
            label, desc = PrivilegeInfo.get(name, ("", None))
            cb.set_text(label)
            if desc:
                cb.set_tooltip(desc)
            cb.add_clicked_callback(self.schema_priv_checked)
            box.add(cb, False, False)
            self.schema_rights_checks[name] = cb
        panel.add(box)
        hbox.add(panel, False, True)

        bottom_box = newBox(True)
        bottom_box.set_spacing(8)

        if 0:
            img = newImageBox()
            if App.get().get_resource_path("task_warning_mac.png"):
                img.set_image("task_warning_mac.png")
            else:
                img.set_image("task_warning.png")
            bottom_box.add(img, False, True)
            bottom_box.add(
                dLabel(
                    "There are %i schema privilege entries for accounts that don't exist"
                ), False, True)
            purge = newButton()
            purge.set_text("Purge")
            bottom_box.add(purge, False, True)

        self.grant_all = newButton()
        self.grant_all.set_text('Select "ALL"')
        bottom_box.add(self.grant_all, False, True)
        self.grant_all.add_clicked_callback(self.grant_all_schema_privs)

        self.revoke_all = newButton()
        self.revoke_all.set_text("Unselect All")
        bottom_box.add(self.revoke_all, False, True)
        self.revoke_all.add_clicked_callback(self.revoke_all_schema_privs)

        self.save_button = newButton()
        self.save_button.set_text("Save Changes")
        bottom_box.add_end(self.save_button, False, True)
        self.save_button.add_clicked_callback(self.commit)

        self.revert_button = newButton()
        self.revert_button.set_text("Revert")
        bottom_box.add_end(self.revert_button, False, True)
        self.revert_button.add_clicked_callback(self.revert)

        priv_vbox.add(bottom_box, False, True)

        self.resume_layout()
    def create_ui(self):
        self.set_spacing(16)        
        layer_box = mforms.newBox(True)
        layer_box.set_spacing(8)
        layer_heading = mforms.newLabel("Layer name:")
        layer_box.add(layer_heading, False, False)
        self.layer_name_lbl = mforms.newLabel("")
        layer_box.add(self.layer_name_lbl, False, False)
        self.content.add(layer_box, False, False)

        epsg_box = mforms.newBox(True)
        epsg_box.set_spacing(8)
        epsg_box_heading = mforms.newLabel("EPSG:")
        epsg_box.add(epsg_box_heading, False, False)
        self.epsg_lbl = mforms.newLabel("")
        epsg_box.add(self.epsg_lbl, False, False)
        self.content.add(epsg_box, False, False)
        
        entry_box = mforms.newBox(True)
        entry_box.set_spacing(12)

        entry_box.add(mforms.newLabel("Destination table:"), False, True)

        self.table_name = mforms.newTextEntry()
        entry_box.add(self.table_name, True, True)
        
        self.content.add(entry_box, False, True)
        entry_box.show(True)

        cbox = mforms.newBox(False)

        self.column_list = newTreeView(mforms.TreeFlatList)
        self.column_list.add_column(mforms.CheckColumnType, "", 40, True)
        self.column_list.add_column(mforms.StringColumnType, "Column name", 300, False)
        self.column_list.end_columns()
        self.column_list.set_size(-1, 150)

        cbox.add(small_label("Please select the columns you want to import:"), False, True)
        cbox.add(self.column_list, False, True)

        self.content.add(cbox, False, True)
        cbox.show(True)
        
        options_layer = mforms.newPanel(mforms.TitledBoxPanel)
        options_layer.set_title("Additional options")
        
        options_box = mforms.newBox(False)
        options_box.set_spacing(12)
        options_box.set_padding(12)
        
        boxfailures = mforms.newBox(False)
        
        self.skipfailures_chb = newCheckBox()
        self.skipfailures_chb.set_text("Skip failures");
        self.skipfailures_chb.set_active(False)
        
        boxfailures.add(self.skipfailures_chb, False, False)
        boxfailures.add(small_label("If an error occurs ignore it and continue processing data."), False, False)
        options_box.add(boxfailures, False, False)
        
        boxappend = mforms.newBox(False)
        
        self.append_chb = newCheckBox()
        self.append_chb.set_text("Append to existing data");
        self.append_chb.set_active(False)
        boxappend.add(self.append_chb, False, False)
        boxappend.add(small_label("Append to existing table instead of creating a new one."), False, False)
        options_box.add(boxappend, False, False)
        
        boxoverwrite = mforms.newBox(False)
        
        self.overwrite_chb = newCheckBox()
        self.overwrite_chb.set_text("Overwrite existing data");
        self.overwrite_chb.set_active(False)
        
        self.append_chb.add_clicked_callback(lambda checkbox1 = self.append_chb, checkbox2 = self.overwrite_chb: self.one_check_only(checkbox1, checkbox2))
        self.overwrite_chb.add_clicked_callback(lambda checkbox2 = self.append_chb, checkbox1 = self.overwrite_chb: self.one_check_only(checkbox1, checkbox2))
        boxoverwrite.add(self.overwrite_chb, False, False)
        boxoverwrite.add(small_label("Drop the selected table and recreate it."), False, False)
        options_box.add(boxoverwrite, False, False)
        
        if self.support_spatial_index:
            boxspatial = mforms.newBox(False)
            self.spatial_index_chb = newCheckBox()
            self.spatial_index_chb.set_text("Create spatial index")
            self.spatial_index_chb.set_active(False)
            boxspatial.add(self.spatial_index_chb, False, False)
            boxspatial.add(small_label("import will make spatial index around geometry column"), False, False)
            options_box.add(boxspatial, False, False)
        
        options_layer.add(options_box)
        options_layer.show(True)
        
        self.content.add(options_layer, False, False)

        boxconvert = mforms.newBox(False)
        entry_box = mforms.newBox(True)
        entry_box.set_spacing(8)
        entry_box.add(mforms.newLabel("Convert data to the following EPSG:"), False, True)
        self.convert_to_epsg = mforms.newTextEntry()
        entry_box.add(self.convert_to_epsg, False, False)
        boxconvert.add(entry_box, True, True)
        boxconvert.add(small_label("leave empty to import the data with no conversion"), False, False)
        
        self.content.add(boxconvert, False, True)
        self.get_info()
    def __init__(self, model):
        mforms.Form.__init__(self, mforms.Form.main_form(), mforms.FormNormal)
        self.set_title("Print Model to File")

        self.model = model

        box = mforms.newBox(False)
        box.set_spacing(8)
        box.set_padding(20)

        self.tree = mforms.newTreeView(mforms.TreeFlatList)
        self.tree.add_column(mforms.CheckColumnType, "Print", 50, True)
        self.tree.add_column(mforms.StringColumnType, "Diagram", 300, False)
        self.tree.end_columns()
        box.add(self.tree, True, True)

        for d in model.diagrams:
            node = self.tree.add_node()
            node.set_bool(0, True)
            node.set_string(1, d.name)

        help_text = """The following variables will be substituted:
$document, $doc_version, $doc_author, $doc_project, $doc_date_changed, $doc_date_created, $diagram, $timestamp, $page, $total_pages, $doc_page, $doc_total_pages
            """
        hbox = mforms.newBox(True)
        hbox.set_spacing(8)
        label = mforms.newLabel("Header Text:", True)
        label.set_size(100, -1)
        hbox.add(label, False, True)
        self.header = mforms.newTextEntry()
        self.header.set_tooltip(help_text)
        hbox.add(self.header, True, True)
        box.add(hbox, False, True)
        self.header.set_value(self.model.options.get("wb.PrintModel:HeaderText", "$timestamp, $document - $diagram (part $page of $total_pages)"))

        hbox = mforms.newBox(True)
        hbox.set_spacing(8)
        label = mforms.newLabel("Footer Text:", True)
        label.set_size(100, -1)
        hbox.add(label, False, True)
        self.footer = mforms.newTextEntry()
        self.footer.set_tooltip(help_text)
        hbox.add(self.footer, True, True)
        box.add(hbox, False, True)
        self.footer.set_value(self.model.options.get("wb.PrintModel:FooterText", "$doc_page of $doc_total_pages"))

        hbox = mforms.newBox(True)
        hbox.set_spacing(8)
        label = mforms.newLabel("File:", True)
        label.set_size(100, -1)
        hbox.add(label, False, True)
        self.file = mforms.newTextEntry()
        hbox.add(self.file, True, True)
        self.browse = mforms.newButton()
        self.browse.set_text("...")
        self.browse.add_clicked_callback(self.do_browse)
        self.browse.enable_internal_padding(False)
        hbox.add(self.browse, False, True)
        box.add(hbox, False, True)

        self.file.set_value(self.model.options.get("wb.PrintModel:Path", os.path.join(mforms.Utilities.get_special_folder(mforms.Desktop), "model.pdf")))

        hbox = mforms.newBox(True)
        hbox.set_spacing(8)
        label = mforms.newLabel("Format:", True)
        label.set_size(100, -1)
        hbox.add(label, False, True)
        self.format = mforms.newSelector()
        self.format.add_item("PDF")
        self.format.add_item("PostScript File")
        self.format.add_changed_callback(self.format_changed)
        hbox.add(self.format, True, True)
        box.add(hbox, False, True)

        hbox = mforms.newBox(True)
        hbox.set_spacing(8)
        self.ok = mforms.newButton()
        self.ok.set_text("OK")
        self.cancel = mforms.newButton()
        self.cancel.set_text("Cancel")
        mforms.Utilities.add_end_ok_cancel_buttons(hbox, self.ok, self.cancel)
        box.add_end(hbox, False, True)

        self.set_content(box)
        self.set_size(500, 400)
Exemplo n.º 34
0
    def __init__(self, model):
        mforms.Form.__init__(self, mforms.Form.main_form(), mforms.FormNormal)
        self.set_title("Print Model to File")

        self.model = model

        box = mforms.newBox(False)
        box.set_spacing(8)
        box.set_padding(20)

        self.tree = mforms.newTreeView(mforms.TreeFlatList)
        self.tree.add_column(mforms.CheckColumnType, "Print", 50, True)
        self.tree.add_column(mforms.StringColumnType, "Diagram", 300, False)
        self.tree.end_columns()
        box.add(self.tree, True, True)

        for d in model.diagrams:
            node = self.tree.add_node()
            node.set_bool(0, True)
            node.set_string(1, d.name)

        help_text = """The following variables will be substituted:
$document, $doc_version, $doc_author, $doc_project, $doc_date_changed, $doc_date_created, $diagram, $timestamp, $page, $total_pages, $doc_page, $doc_total_pages
            """
        hbox = mforms.newBox(True)
        hbox.set_spacing(8)
        label = mforms.newLabel("Header Text:", True)
        label.set_size(100, -1)
        hbox.add(label, False, True)
        self.header = mforms.newTextEntry()
        self.header.set_tooltip(help_text)
        hbox.add(self.header, True, True)
        box.add(hbox, False, True)
        self.header.set_value(
            self.model.options.get(
                "wb.PrintModel:HeaderText",
                "$timestamp, $document - $diagram (part $page of $total_pages)"
            ))

        hbox = mforms.newBox(True)
        hbox.set_spacing(8)
        label = mforms.newLabel("Footer Text:", True)
        label.set_size(100, -1)
        hbox.add(label, False, True)
        self.footer = mforms.newTextEntry()
        self.footer.set_tooltip(help_text)
        hbox.add(self.footer, True, True)
        box.add(hbox, False, True)
        self.footer.set_value(
            self.model.options.get("wb.PrintModel:FooterText",
                                   "$doc_page of $doc_total_pages"))

        hbox = mforms.newBox(True)
        hbox.set_spacing(8)
        label = mforms.newLabel("File:", True)
        label.set_size(100, -1)
        hbox.add(label, False, True)
        self.file = mforms.newTextEntry()
        hbox.add(self.file, True, True)
        self.browse = mforms.newButton()
        self.browse.set_text("...")
        self.browse.add_clicked_callback(self.do_browse)
        self.browse.enable_internal_padding(False)
        hbox.add(self.browse, False, True)
        box.add(hbox, False, True)

        self.file.set_value(
            self.model.options.get(
                "wb.PrintModel:Path",
                os.path.join(
                    mforms.Utilities.get_special_folder(mforms.Desktop),
                    "model.pdf")))

        hbox = mforms.newBox(True)
        hbox.set_spacing(8)
        label = mforms.newLabel("Format:", True)
        label.set_size(100, -1)
        hbox.add(label, False, True)
        self.format = mforms.newSelector()
        self.format.add_item("PDF")
        self.format.add_item("PostScript File")
        self.format.add_changed_callback(self.format_changed)
        hbox.add(self.format, True, True)
        box.add(hbox, False, True)

        hbox = mforms.newBox(True)
        hbox.set_spacing(8)
        self.ok = mforms.newButton()
        self.ok.set_text("OK")
        self.cancel = mforms.newButton()
        self.cancel.set_text("Cancel")
        mforms.Utilities.add_end_ok_cancel_buttons(hbox, self.ok, self.cancel)
        box.add_end(hbox, False, True)

        self.set_content(box)
        self.set_size(500, 400)
Exemplo n.º 35
0
    def create_preview_table(self, clean_up = False):
        
        def create_chkbox(row):
            chk =  mforms.newCheckBox()
            chk.set_active(True)
            chk.add_clicked_callback(lambda checkbox = chk, output = row: operator.setitem(output, 'active', True if checkbox.get_active() else False))
            return chk
        
        type_items = {'is_string':'text','is_bignumber':'bigint', "is_geometry":'geometry', 'is_number':'int', 'is_float':'double', 'is_bin':'binary', 'is_date_or_time': 'datetime', 'is_json':'json'}
        def create_select_type(row):
            def sel_changed(sel, output):
                selection = sel.get_string_value()
                for v in type_items:
                    if selection in type_items[v]:
                        if output['type'] == 'double' and type_items[v] != 'double':
                            self.show_ds_box(False)
                        
                        if output['type'] == 'datetime' and type_items[v] != 'datetime':
                            self.show_df_box(False)
                            
                        if type_items[v] == 'double':
                            self.show_ds_box(True)
                        if type_items[v] == 'datetime':
                            self.show_df_box(True)
                            
                        output['type'] = type_items[v]
                        
                        break  
                
            sel = mforms.newSelector()
            sel.set_size(120, -1)

            items = [type for type in type_items.values() if not ((type == "geometry" or type == "json") and self.input_file_type == "json" and not self.is_server_5_7) ]
            sel.add_items(items)
            if not self.is_server_5_7 and (row['type'] == "geometry" or row["type"] == "json") and self.input_file_type == "json":
                row['type'] = "text" # If it's server older than 5.7 we don't have support for geojson so we can't properly import this file, instead we fallback to text
                log_info("Column %s is of type GeoJso but server doesn't support this, importing as text instead." % row['name'])
                
            for i, v in enumerate(items):
                if row['type'] == v:
                    sel.set_selected(i)
                    break
            
            sel.add_changed_callback(lambda: sel_changed(sel, row))
            return sel
        
        if self.preview_table is not None:
            self.column_scroll.remove()
            self.table_preview_box.set_spacing(16)
            if self.treeview_preview is not None:
                self.table_preview_box.remove(self.treeview_preview)
                self.treeview_preview = None
            self.preview_table = None
            self.dest_column_table_col = []
            self.field_type_table_col = []
            
        def create_select_dest_col(row, cols):
            sel = mforms.newSelector()
            sel.set_size(120, -1)
            sel.add_items(cols)
            for i, c in enumerate(cols):
                if c == row['dest_col']:
                    sel.set_selected(cols.index(c))
                    break
            sel.add_changed_callback(lambda output = row: operator.setitem(output, 'dest_col', sel.get_string_value()))
            return sel

        self.preview_table = mforms.newTable()
        self.preview_table.suspend_layout()
        self.column_scroll.add(self.preview_table)

        self.preview_table.set_column_count(5)
        self.preview_table.set_row_count(len(self.active_module._columns) + 1)
        self.preview_table.set_row_spacing(8)
        self.preview_table.set_column_spacing(8)
        
        if len(self.active_module._columns) >= 3:
            self.column_caption.set_size(-1, 200)
        else:
            self.column_caption.set_size(-1, 100)
        
        self.checkbox_list = []

        def sell_all(cols, active):
            for checkbox in self.checkbox_list:
                checkbox.set_active(bool(active))
            for row in self.column_mapping:
                row['active'] = active
        
        def find_column(col_name, index):
            if col_name in self.dest_cols:
                return col_name
            else:
                return self.dest_cols[index] if i < len(self.dest_cols) else None
        
        chk = mforms.newCheckBox()
        chk.set_active(True)
        chk.add_clicked_callback(lambda checkbox = chk, columns = self.active_module._columns: sell_all(columns, checkbox.get_active()))
        
        self.preview_table.add(chk, 0, 1, 0, 1, mforms.HFillFlag)
        self.preview_table.add(mforms.newLabel("Source Column"), 1, 2, 0, 1, mforms.HFillFlag)
        if not self.main.destination_page.new_table_radio.get_active():
            self.preview_table.add(mforms.newLabel("Dest Column"), 2, 3, 0, 1, mforms.HFillFlag)
        else:
            self.preview_table.add(mforms.newLabel("Field Type"), 3, 4, 0, 1, mforms.HFillFlag)
        self.column_mapping = []
        for i, col in enumerate(self.active_module._columns):
            row = {'active': True, 'name': col['name'], 'type' : None, 'col_no': i, 'dest_col': find_column(col['name'], i)}
            for c in col:
                if c.startswith('is_') and col[c]:
                    row['type'] = type_items[c]
                    break
            chk_box = create_chkbox(row)
            self.checkbox_list.append(chk_box)
            self.preview_table.add(chk_box, 0, 1, i+1, i+2, mforms.HFillFlag)
            self.preview_table.add(mforms.newLabel(str(col['name'].encode('utf8'))), 1, 2, i+1, i+2, mforms.HFillFlag)
            if not self.main.destination_page.new_table_radio.get_active():
                self.preview_table.add(create_select_dest_col(row, self.dest_cols), 2, 3, i+1, i+2, mforms.HFillFlag)
            else:
                self.preview_table.add(create_select_type(row), 3, 4, i+1, i+2, mforms.HFillFlag)
            self.column_mapping.append(row)
            
        self.treeview_preview = newTreeView(mforms.TreeFlatList)
        for i, col in enumerate(self.active_module._columns):
            self.treeview_preview.add_column(mforms.StringColumnType, str(col['name'].encode('utf8')), 75, True)
        self.treeview_preview.end_columns()
        
        
        if len(self.active_module._columns):
            col_values = []
            val_len = 0
            for col in self.active_module._columns:
                val_len = len(col['value']) if len(col['value']) > val_len else val_len

            col_len = len(self.active_module._columns)
            for i in range(0, val_len):
                row = []
                for j in range(0, col_len):
                    
                    if len(self.active_module._columns[j]['value']) > i:
                        row.append(self.active_module._columns[j]['value'][i])
                    else:
                        row.append("")
                col_values.append(row)

            for row in col_values:
                node = self.treeview_preview.add_node()
                for i, col in enumerate(row):
                    if hasattr(col, 'encode'):
                        node.set_string(i, str(col.encode('utf8')))
                    else:
                        node.set_string(i, str(col))

        self.treeview_preview.set_allow_sorting(True)
        self.treeview_preview.set_size(200, 100)
        self.table_preview_box.add(self.treeview_preview, False, True)
        self.preview_table.resume_layout()
    def __init__(self):
        mforms.Form.__init__(
            self, None, mforms.FormDialogFrame | mforms.FormResizable
            | mforms.FormMinimizable)

        self.set_title("Data Type Mapping for Generic Migration")

        content = mforms.newBox(False)
        self.set_content(content)
        content.set_padding(12)
        content.set_spacing(12)

        hbox = mforms.newBox(True)
        content.add(hbox, True, True)
        hbox.set_spacing(12)

        self._type_list = mforms.newTreeView(
            mforms.TreeFlatList)  #|mforms.TreeAllowReorderRows)
        self._type_list.set_size(200, -1)
        self._type_list.add_column(mforms.StringColumnType, "Type", 100, False)
        self._type_list.add_column(mforms.StringColumnType, "Target Type", 100,
                                   False)
        self._type_list.end_columns()
        self._type_list.add_changed_callback(self.selection_changed)
        hbox.add(self._type_list, False, True)

        detail_box = mforms.newBox(False)
        self.detail_box = detail_box
        hbox.add(detail_box, True, True)
        detail_box.set_spacing(12)

        ##

        spanel = mforms.newPanel(mforms.TitledBoxPanel)
        spanel.set_title("Source Data Type")

        stable = mforms.newTable()
        stable.set_padding(12)
        spanel.add(stable)
        stable.set_row_count(5)
        stable.set_column_count(2)
        stable.set_row_spacing(8)
        stable.set_column_spacing(4)

        stable.add(mforms.newLabel("Type Name:", True), 0, 1, 0, 1,
                   mforms.HFillFlag)
        self._stype_entry = mforms.newTextEntry()
        self._stype_entry.add_changed_callback(self.save_changes)
        stable.add(self._stype_entry, 1, 2, 0, 1,
                   mforms.HFillFlag | mforms.HExpandFlag)

        #self._stype_user_check = mforms.newCheckBox()
        #self._stype_user_check.set_text("Is user datatype")
        #stable.add(self._stype_user_check, 1, 2, 1, 2, mforms.HFillFlag|mforms.HExpandFlag)

        stable.add(mforms.newLabel("Type Category:", True), 0, 1, 2, 3,
                   mforms.HFillFlag)
        self._sgroup_selector = mforms.newSelector()
        stable.add(self._sgroup_selector, 1, 2, 2, 3,
                   mforms.HFillFlag | mforms.HExpandFlag)
        self._sgroup_selector.add_changed_callback(self.source_group_selected)

        stable.add(mforms.newLabel("Min. Length:", True), 0, 1, 3, 4,
                   mforms.HFillFlag)
        self._sminlen_entry = mforms.newTextEntry()
        self._sminlen_entry.add_changed_callback(self.save_changes)
        stable.add(self._sminlen_entry, 1, 2, 3, 4,
                   mforms.HFillFlag | mforms.HExpandFlag)
        stable.add(mforms.newLabel("Max. Length:", True), 0, 1, 4, 5,
                   mforms.HFillFlag)
        self._smaxlen_entry = mforms.newTextEntry()
        self._smaxlen_entry.add_changed_callback(self.save_changes)
        stable.add(self._smaxlen_entry, 1, 2, 4, 5,
                   mforms.HFillFlag | mforms.HExpandFlag)

        detail_box.add(spanel, False, True)

        ##

        tpanel = mforms.newPanel(mforms.TitledBoxPanel)
        tpanel.set_title("Target MySQL Data Type")

        ttable = mforms.newTable()
        ttable.set_padding(12)
        tpanel.add(ttable)
        ttable.set_row_count(4)
        ttable.set_column_count(2)
        ttable.set_row_spacing(8)
        ttable.set_column_spacing(4)

        ttable.add(mforms.newLabel("Target Type:", True), 0, 1, 0, 1,
                   mforms.HFillFlag)
        self._ttype_selector = mforms.newSelector()
        self._ttype_selector.add_changed_callback(self.save_changes)
        ttable.add(self._ttype_selector, 1, 2, 0, 1,
                   mforms.HFillFlag | mforms.HExpandFlag)

        def add_check_entry_row(table, row, label, name):
            check = mforms.newCheckBox()
            check.set_text(label)
            table.add(check, 0, 1, row, row + 1, mforms.HFillFlag)
            entry = mforms.newTextEntry()
            entry.add_changed_callback(self.save_changes)
            table.add(entry, 1, 2, row, row + 1,
                      mforms.HFillFlag | mforms.HExpandFlag)
            setattr(self, name + "_check", check)
            setattr(self, name + "_entry", entry)
            entry.set_enabled(False)

            def callback(entry, check):
                if not check.get_active():
                    entry.set_value("-2")
                entry.set_enabled(check.get_active())
                self.save_changes()

            check.add_clicked_callback(lambda: callback(entry, check))

        add_check_entry_row(ttable, 1, "Override Length:", "_target_length")
        add_check_entry_row(ttable, 2, "Override Precision:",
                            "_target_precision")
        add_check_entry_row(ttable, 3, "Override Scale:", "_target_scale")

        detail_box.add(tpanel, False, True)

        ##

        bbox = mforms.newBox(True)

        self._add_button = mforms.newButton()
        self._add_button.set_text("Add")
        bbox.add(self._add_button, False, True)
        self._add_button.add_clicked_callback(self.add_clicked)
        self._del_button = mforms.newButton()
        self._del_button.set_text("Delete")
        self._del_button.add_clicked_callback(self.del_clicked)
        bbox.add(self._del_button, False, True)

        self._ok_button = mforms.newButton()
        self._ok_button.set_text("OK")
        self._ok_button.add_clicked_callback(self.ok_clicked)
        self._cancel_button = mforms.newButton()
        self._cancel_button.set_text("Cancel")
        self._ok_button.add_clicked_callback(self.cancel_clicked)
        mforms.Utilities.add_end_ok_cancel_buttons(bbox, self._ok_button,
                                                   self._cancel_button)
        content.add_end(bbox, False, True)
        bbox.set_spacing(12)
        self._del_button.set_enabled(False)

        self.set_size(700, 500)
Exemplo n.º 37
0
    def __init__(self, editor, schema):
        mforms.Box.__init__(self, False)
        self.set_managed()
        self.set_release_on_add()

        self.schema = schema
        self.editor = editor

        self.target_version = Version.fromgrt(editor.serverVersion)

        self.main = mforms.newBox(False)
        self.add(self.main, True, True)

        self.error_heading = mforms.newLabel("")
        self.error_heading.set_style(mforms.BoldStyle)
        self.error_body = mforms.newLabel("")
        self.error_box = mforms.newBox(False)
        self.error_box.set_spacing(8)
        self.error_box.set_padding(8)
        self.error_box.add(self.error_heading, True, False)
        self.error_box.add(self.error_body, True, False)
        self.add(self.error_box, True, False)
        self.error_box.show(False)

        self.main.set_padding(8)
        self.main.set_spacing(8)

        self.tree = mforms.newTreeView(mforms.TreeFlatList
                                       | mforms.TreeAltRowColors
                                       | mforms.TreeShowColumnLines)
        self.tree.set_selection_mode(mforms.TreeSelectMultiple)

        #Check if there is method to load the columns, if not, skip.
        if hasattr(self, "preload_columns") and callable(
                getattr(self, "preload_columns")):
            self.preload_columns()

        for field, type, caption, width, min_version in self.columns:
            if min_version and not self.target_version.is_supported_mysql_version_at_least(
                    Version.fromstr(min_version)):
                continue
            self.tree.add_column(type, caption, width, False)
        self.tree.end_columns()
        self.tree.set_allow_sorting(True)
        self.main.add(self.tree, True, True)

        self.menu = mforms.newContextMenu()
        self.menu.add_will_show_callback(self.menu_will_show)
        self.tree.add_activated_callback(self.on_activate)
        self.tree.set_context_menu(self.menu)

        self.icon_path = mforms.App.get().get_resource_path(self.klass +
                                                            ".16x16.png")
        self.bad_icon_path = mforms.App.get().get_resource_path(
            self.bad_icon_path)

        self.row_count = mforms.newLabel("")
        self.row_count.set_text("")

        self.refresh_btn = mforms.newButton()
        self.refresh_btn.set_text("Refresh")
        self.refresh_btn.add_clicked_callback(self.refresh)

        self.bbox = mforms.newBox(True)
        self.bbox.set_spacing(8)
        self.main.add(self.bbox, False, True)

        self.bbox.add(self.row_count, False, True)
        self.bbox.add_end(self.refresh_btn, False, True)

        for caption, callback_name in self.actions:
            if not caption:
                self.bbox.add(mforms.newLabel(" "), False, True)
                continue
            btn = mforms.newButton()
            btn.set_text(caption)
            btn.add_clicked_callback(getattr(self, callback_name))
            self.bbox.add(btn, False, True)
    def create_ui(self):
        self.set_spacing(16)
        layer_box = mforms.newBox(True)
        layer_box.set_spacing(8)
        layer_heading = mforms.newLabel("Layer name:")
        layer_box.add(layer_heading, False, False)
        self.layer_name_lbl = mforms.newLabel("")
        layer_box.add(self.layer_name_lbl, False, False)
        self.content.add(layer_box, False, False)

        epsg_box = mforms.newBox(True)
        epsg_box.set_spacing(8)
        epsg_box_heading = mforms.newLabel("EPSG:")
        epsg_box.add(epsg_box_heading, False, False)
        self.epsg_lbl = mforms.newLabel("")
        epsg_box.add(self.epsg_lbl, False, False)
        self.content.add(epsg_box, False, False)

        entry_box = mforms.newBox(True)
        entry_box.set_spacing(12)

        entry_box.add(mforms.newLabel("Destination table:"), False, True)

        self.table_name = mforms.newTextEntry()
        entry_box.add(self.table_name, True, True)

        self.content.add(entry_box, False, True)
        entry_box.show(True)

        cbox = mforms.newBox(False)

        self.column_list = newTreeView(mforms.TreeFlatList)
        self.column_list.add_column(mforms.CheckColumnType, "", 40, True)
        self.column_list.add_column(mforms.StringColumnType, "Column name",
                                    300, False)
        self.column_list.end_columns()
        self.column_list.set_size(-1, 150)

        cbox.add(small_label("Please select the columns you want to import:"),
                 False, True)
        cbox.add(self.column_list, False, True)

        self.content.add(cbox, False, True)
        cbox.show(True)

        options_layer = mforms.newPanel(mforms.TitledBoxPanel)
        options_layer.set_title("Additional options")

        options_box = mforms.newBox(False)
        options_box.set_spacing(12)
        options_box.set_padding(12)

        boxfailures = mforms.newBox(False)

        self.skipfailures_chb = newCheckBox()
        self.skipfailures_chb.set_text("Skip failures")
        self.skipfailures_chb.set_active(False)

        boxfailures.add(self.skipfailures_chb, False, False)
        boxfailures.add(
            small_label(
                "If an error occurs ignore it and continue processing data."),
            False, False)
        options_box.add(boxfailures, False, False)

        boxappend = mforms.newBox(False)

        self.append_chb = newCheckBox()
        self.append_chb.set_text("Append to existing data")
        self.append_chb.set_active(False)
        boxappend.add(self.append_chb, False, False)
        boxappend.add(
            small_label(
                "Append to existing table instead of creating a new one."),
            False, False)
        options_box.add(boxappend, False, False)

        boxoverwrite = mforms.newBox(False)

        self.overwrite_chb = newCheckBox()
        self.overwrite_chb.set_text("Overwrite existing data")
        self.overwrite_chb.set_active(False)

        self.append_chb.add_clicked_callback(
            lambda checkbox1=self.append_chb, checkbox2=self.overwrite_chb:
            self.one_check_only(checkbox1, checkbox2))
        self.overwrite_chb.add_clicked_callback(
            lambda checkbox2=self.append_chb, checkbox1=self.overwrite_chb:
            self.one_check_only(checkbox1, checkbox2))
        boxoverwrite.add(self.overwrite_chb, False, False)
        boxoverwrite.add(
            small_label("Drop the selected table and recreate it."), False,
            False)
        options_box.add(boxoverwrite, False, False)

        if self.support_spatial_index:
            boxspatial = mforms.newBox(False)
            self.spatial_index_chb = newCheckBox()
            self.spatial_index_chb.set_text("Create spatial index")
            self.spatial_index_chb.set_active(False)
            boxspatial.add(self.spatial_index_chb, False, False)
            boxspatial.add(
                small_label(
                    "import will make spatial index around geometry column"),
                False, False)
            options_box.add(boxspatial, False, False)

        options_layer.add(options_box)
        options_layer.show(True)

        self.content.add(options_layer, False, False)

        boxconvert = mforms.newBox(False)
        entry_box = mforms.newBox(True)
        entry_box.set_spacing(8)
        entry_box.add(mforms.newLabel("Convert data to the following EPSG:"),
                      False, True)
        self.convert_to_epsg = mforms.newTextEntry()
        entry_box.add(self.convert_to_epsg, False, False)
        boxconvert.add(entry_box, True, True)
        boxconvert.add(
            small_label("leave empty to import the data with no conversion"),
            False, False)

        self.content.add(boxconvert, False, True)
        self.get_info()
Exemplo n.º 39
0
    def __init__(self, types_to_display, database_objects, ui_settings={}):
        super(DatabaseObjectSelector, self).__init__(False)
        self.database_objects = database_objects
        self.supported_object_types = types_to_display

        self.ui_settings = {
            'tables': {
                'icon': 'db.Table.many.32x32.png',
                'small_icon': 'db.Table.16x16.png',
                'group_label': 'Migrate Table objects',
                'group_selected': True,
                'status_text': '%(total)d total, %(selected)d selected',
                'show_details': False,
            },
            'views': {
                'icon': 'db.View.many.32x32.png',
                'small_icon': 'db.View.16x16.png',
                'group_label': 'Migrate View objects',
                'group_selected': True,
                'status_text': '%(total)d total, %(selected)d selected',
                'show_details': False,
            },
            'routines': {
                'icon': 'db.Routine.many.32x32.png',
                'small_icon': 'db.Routine.16x16.png',
                'group_label': 'Migrate Routine objects',
                'group_selected': True,
                'status_text': '%(total)d total, %(selected)d selected',
                'show_details': False,
            },
            'routineGroups': {
                'icon': 'db.RoutineGroup.48x48.png',
                'small_icon': 'db.RoutineGroup.16x16.png',
                'group_label': 'Migrate Routine Group/Package objects',
                'group_selected': True,
                'status_text': '%(total)d total, %(selected)d selected',
                'show_details': False,
            },
            'synonyms': {
                'icon': 'grt_object.png',
                'small_icon': 'grt_object.png',
                'group_label': 'Migrate Synonym objects',
                'group_selected': True,
                'status_text': '%(total)d total, %(selected)d selected',
                'show_details': False,
            },
            'structuredTypes': {
                'icon': 'grt_object.png',
                'small_icon': 'grt_object.png',
                'group_label': 'Migrate Structured Type objects',
                'group_selected': True,
                'status_text': '%(total)d total, %(selected)d selected',
                'show_details': False,
            },
            'sequences': {
                'icon': 'grt_object.png',
                'small_icon': 'grt_object.png',
                'group_label': 'Migrate Sequence objects',
                'group_selected': True,
                'status_text': '%(total)d total, %(selected)d selected',
                'show_details': False,
            },
        }

        # Update the ui settings dict with the custom settings supplied by the user (if any):
        if isinstance(ui_settings, dict):
            for key, value in list(ui_settings.items()):
                if key not in self.ui_settings or not isinstance(value, dict):
                    continue
                self.ui_settings[key].update(value)

        # Create UI:
        self.set_padding(8)
        self.set_spacing(8)

        self.ui = {}
        for group in self.supported_object_types:
            if group not in self.database_objects or group not in self.ui_settings:
                continue
            self.ui[group] = {}
            group_objects = self.database_objects[group]

            group_panel = mforms.newPanel(mforms.BorderedPanel)
            group_box = mforms.newBox(False)
            group_box.set_padding(8)
            group_box.set_spacing(8)

            header_box = mforms.Box(True)
            header_box.set_spacing(8)

            icon = mforms.newImageBox()
            icon.set_image(self.ui_settings[group]['icon'])
            header_box.add(icon, False, True)

            text_box = mforms.Box(False)
            group_selector = mforms.newCheckBox()
            group_selector.set_text(self.ui_settings[group]['group_label'])
            group_selector.set_active(
                bool(self.ui_settings[group]['group_selected']))
            group_selector.add_clicked_callback(
                functools.partial(self.group_checkbox_clicked, group=group))
            text_box.add(group_selector, False, True)
            info_label = mforms.newLabel(
                self.ui_settings[group]['status_text'] % {
                    'total':
                    len(group_objects),
                    'selected':
                    len(group_objects)
                    if self.ui_settings[group]['group_selected'] else 0
                })
            info_label.set_style(mforms.SmallHelpTextStyle)
            text_box.add(info_label, False, True)
            header_box.add(text_box, False, True)

            show_details = self.ui_settings[group]['show_details']
            self.ui_settings[group]['_showing_details'] = show_details
            filter_button = mforms.newButton()
            filter_button.set_text(
                'Hide Selection' if show_details else 'Show Selection')
            filter_button.set_enabled(
                bool(self.ui_settings[group]['group_selected']))
            filter_button.add_clicked_callback(
                functools.partial(self.filter_button_clicked, group=group))
            header_box.add_end(filter_button, False, True)

            group_box.add(header_box, False, True)

            # The invisible stuff:
            if len(group_objects) > 0:
                box = mforms.newBox(True)
                search_entry = mforms.newTextEntry(mforms.SearchEntry)
                search_entry.set_name("Search Entry")
                search_entry.set_placeholder_text(
                    "Filter objects (wildcards chars * and ? are allowed)")
                search_entry.add_changed_callback(
                    functools.partial(self.search_entry_changed, group=group))
                box.add(search_entry, False, True)
                group_box.add(box, True, True)
                search_entry.set_size(350, -1)

                filter_container = mforms.newBox(True)
                filter_container.set_spacing(8)

                available_list = mforms.newTreeView(mforms.TreeFlatList)
                available_list.set_name("Available List")
                available_list.add_column(mforms.IconColumnType,
                                          'Available Objects', 300, False)
                available_list.end_columns()
                available_list.set_selection_mode(mforms.TreeSelectMultiple)
                available_list.set_allow_sorting(False)
                filter_container.add(available_list, True, True)

                control_box = mforms.newBox(False)
                control_box.set_padding(0, 30, 0, 30)
                control_box.set_spacing(4)
                add_button = mforms.newButton()
                add_button.set_text('>')
                add_button.enable_internal_padding(False)
                add_button.add_clicked_callback(
                    functools.partial(self.move_button_clicked,
                                      group=group,
                                      operation='add'))
                add_button.set_size(90, 30)
                control_box.add(add_button, False)
                remove_button = mforms.newButton()
                remove_button.set_text('<')
                remove_button.enable_internal_padding(False)
                remove_button.add_clicked_callback(
                    functools.partial(self.move_button_clicked,
                                      group=group,
                                      operation='remove'))
                remove_button.set_size(90, 30)
                control_box.add(remove_button, False, True)
                add_all_button = mforms.newButton()
                add_all_button.set_text('>>')
                add_all_button.enable_internal_padding(False)
                add_all_button.add_clicked_callback(
                    functools.partial(self.move_button_clicked,
                                      group=group,
                                      operation='add_all'))
                add_all_button.set_size(90, 30)
                control_box.add(add_all_button, False, True)
                remove_all_button = mforms.newButton()
                remove_all_button.set_text('<<')
                remove_all_button.enable_internal_padding(False)
                remove_all_button.add_clicked_callback(
                    functools.partial(self.move_button_clicked,
                                      group=group,
                                      operation='remove_all'))
                remove_all_button.set_size(90, 30)
                control_box.add(remove_all_button, False)
                filter_container.add(control_box, False, True)

                selected_list = mforms.newTreeView(mforms.TreeFlatList)
                selected_list.set_name("Selected List")
                selected_list.add_column(mforms.IconColumnType,
                                         'Objects to Migrate', 300, False)
                selected_list.end_columns()
                selected_list.set_selection_mode(mforms.TreeSelectMultiple)
                selected_list.set_allow_sorting(False)
                for item in sorted(group_objects):
                    node = selected_list.add_node()
                    node.set_icon_path(0,
                                       self.ui_settings[group]['small_icon'])
                    node.set_string(0, item)
                filter_container.add(selected_list, True, True)

                group_box.add(filter_container, True, True)

                filter_container.show(bool(show_details))

                self.ui[group].update({
                    'filter_container': filter_container,
                    'available_list': available_list,
                    'selected_list': selected_list,
                    'search_entry': search_entry,
                })
            else:  # Empty object list
                filter_button.set_enabled(False)

            self.ui[group].update({
                'icon': icon,
                'group_selector': group_selector,
                'group_panel': group_panel,
                'info_label': info_label,
                'filter_button': filter_button,
                'all_objects': set(group_objects),
                'has_elements': bool(len(group_objects)),
                'available': set(),
                'selected': set(group_objects),
                'objects_passing_filter': set(group_objects),
            })
            group_panel.add(group_box)
            self.add(group_panel, False, True)
    def __init__(self, ctrl_be, variables, command, type):
        mforms.Box.__init__(self, False)
        self.set_managed()
        self.set_release_on_add()

        self.user_groups = VariablesGroupContainer(type)
        self.user_groups.load()
        
        self.variables = variables

        self.suspend_layout()

        self.command = command
        self.ctrl_be = ctrl_be

        box = newBox(True)
        box.set_spacing(12)
        self.add(box, True, True)
        self.tree = newTreeView(mforms.TreeFlatList)
        self.tree.set_selection_mode(mforms.TreeSelectMultiple)

        sidebox = newBox(False)
        box.add(sidebox, False, True)

        self.searchEntry = newTextEntry(mforms.SearchEntry)

        sidebox.set_spacing(12)
        sidebox.add(self.searchEntry, False, True)
        sidebox.add(self.tree, True, True)
        self.tree.set_size(210, -1)

        self.searchEntry.add_changed_callback(self.filterOutput)

        self.tree.add_column(mforms.StringColumnType, "Category", 200, False)
        self.tree.end_columns()
        self.tree.add_changed_callback(weakcb(self, "refresh"))
        self.cat_menu = mforms.newContextMenu()
        self.cat_menu.add_will_show_callback(self.cat_menu_will_show)
        self.cat_menu.add_item_with_title("Delete Category", self.delete_category, "delete")
        self.tree.set_context_menu(self.cat_menu)

        self.values = newTreeView(mforms.TreeFlatList)
        self.values.set_selection_mode(mforms.TreeSelectMultiple)
        box.add(self.values, True, True)

        self.values.add_column(mforms.StringColumnType, "Name", 200, False)
        self.values.add_column(mforms.StringColumnType, "Value", 120, True)
        self.values.add_column(mforms.StringColumnType, "Description", 1000, False)
        self.values.end_columns()
        self.values.set_allow_sorting(True)
        self.values.set_cell_edited_callback(self.edit_variable)
        self.values.add_changed_callback(weakcb(self, "value_selection_changed"))
        self.menu = mforms.newContextMenu()
        self.menu.add_will_show_callback(self.menu_will_show)
        self.values.set_context_menu(self.menu)

        box = newBox(True)
        box.set_spacing(8)
        copy_all_button = newButton()
        copy_all_button.set_text('Copy Global Status and Variables to Clipboard')
        copy_all_button.add_clicked_callback(self.copy_status_to_clipboard)
        box.add(copy_all_button, False, False)
        copy_shown_button = newButton()
        copy_shown_button.set_text('Copy Selected to Clipboard')
        copy_shown_button.add_clicked_callback(self.copy_selected_to_clipboard)
        box.add(copy_shown_button, False, False)
        self.copy_selected_to_clipboard_button = copy_shown_button
        button = newButton()
        box.add_end(button, False, True)
        button.set_text("Refresh")
        box.set_padding(12)

        button.add_clicked_callback(weakcb(self, "refresh"))

        self.add(box, False, True)

        row = self.tree.add_node()
        row.set_string(0, "All")
        row = self.tree.add_node()
        row.set_string(0, "Filtered")

        self.resume_layout()

        self.variable_info = {}
        self.variables_in_group = {"Other":[]}

        self._delayed_init_tm = mforms.Utilities.add_timeout(0.1, lambda: self.delayed_init(self.variables))
    def __init__(self, variables, all_opts, output_path):
        mforms.Box.__init__(self, False)

        self.set_managed()
        self.set_release_on_add()

        self.suspend_layout()
        self.output_path = output_path
        self.all_options = all_opts

        self.filter = newTextEntry()
        self.filter.add_changed_callback(self.show_filtered_options)
        self.add(self.filter, False, True)

        box = newBox(True)
        box.set_spacing(12)

        sidebox = newBox(False)
        sidebox.set_spacing(12)

        self.groups_tree = newTreeView(mforms.TreeFlatList)
        self.groups_tree.set_size(220, -1)
        self.groups_tree.add_column(mforms.CheckColumnType, "", 20, True)
        self.groups_tree.add_column(mforms.StringColumnType, "", 160, False)
        self.groups_tree.end_columns()
        self.groups_tree.set_cell_edited_callback(self.toggled_group)

        sidebox.add(self.groups_tree, True, True)
        box.add_end(sidebox, False, True)

        self.values_tree = newTreeView(mforms.TreeFlatList)
        self.values_tree.add_column(mforms.StringColumnType, "Name", 200, False)
        self.values_tree.add_column(mforms.StringColumnType, "Groups", 1000, False)
        self.values_tree.set_selection_mode(mforms.TreeSelectMultiple)
        self.values_tree.end_columns()
        self.values_tree.set_allow_sorting(True)
        self.values_tree.add_changed_callback(self.value_selected)
        box.add(self.values_tree, True, True)

        self.add(box, True, True)

        box = newBox(True)
        box.set_spacing(8)
        box.set_padding(12)

        self.button_save = newButton()
        self.button_save.set_text("Save")
        self.button_save.add_clicked_callback(self.save)
        box.add_end(self.button_save, False, True)

        self.button_add_group = newButton()
        self.button_add_group.set_text("Add Group")
        self.button_add_group.add_clicked_callback(self.add_group)
        self.button_add_group.set_enabled(False)
        box.add_end(self.button_add_group, False, True)

        self.group_entry = newTextEntry()
        self.group_entry.set_size(300, -1)
        self.group_entry.set_enabled(False)
        box.add_end(self.group_entry, False, True)

        self.add(box, False, True)

        self.resume_layout()

        self.all_groups = set()
        self.value_group_pair = dict()

        for name, groups in variables:
            self.all_groups = self.all_groups.union(set(groups))
            self.value_group_pair[name] = groups

        for g in sorted(self.all_groups):
            node = self.groups_tree.add_node()
            node.set_string(1, g)

        self.groups = self.all_groups

        self.show_filtered_options()
Exemplo n.º 42
0
    def __init__(self, main):
        WizardPage.__init__(self, main, "Data Transfer Setup")

        self.main.add_wizard_page(self, "DataMigration", "Data Transfer Setup")

        label = mforms.newLabel("Select options for the copy of the migrated schema tables in the target MySQL server and click [Next >] to execute.")
        label.set_name("Page Description")
        self.content.add(label, False, True)

        panel = mforms.newPanel(mforms.TitledBoxPanel)
        panel.set_title("Data Copy")
        self.content.add(panel, False, True)

        box = mforms.newBox(False)
        panel.add(box)
        box.set_padding(16)
        box.set_spacing(16)

        rid = mforms.RadioButton.new_id()

        self._copy_db = mforms.newRadioButton(rid)
        self._copy_db.set_text("Online copy of table data to target RDBMS")
        self._copy_db.set_name("Online Copy")
        self._copy_db.add_clicked_callback(self._script_radio_option_callback)
        box.add(self._copy_db, False, True)

        # XXX TODO
        #box.add(mforms.newLabel(""), False, True)
        #self._add_script_checkbox_option(box, "dump_to_file", "Create a dump file with the data", "Dump File:", "Save As")

        if sys.platform == "win32":
            self._add_script_radiobutton_option(box, "Copy Script", "Create a batch file to copy the data at another time", "Batch File:", "Save As", "You should edit this file to add the source and target server passwords before running it.", rid)
        else:
            self._add_script_radiobutton_option(box, "Copy Script", "Create a shell script to copy the data from outside Workbench", "Shell Script File:", "Save As", "You should edit this file to add the source and target server passwords before running it.", rid)

        self._add_script_radiobutton_option(box, "Bulk Copy Script", "Create a shell script to use native server dump and load abilities for fast migration", "Bulk Data Copy Script:", "Save As", "Edit the generated file and change passwords at the top of the generated script.\nRun it on the source server to create a zip package containing a data dump as well as a load script.\nCopy this to the target server, extract it, and run the import script. See the script output for further details.", rid)

        panel = mforms.newPanel(mforms.TitledBoxPanel)
        panel.set_title("Options")
        self.content.add(panel, False, True)

        self.options_box = mforms.newBox(False)
        self.options_box.set_padding(12)
        self.options_box.set_spacing(8)
        panel.add(self.options_box)

        self._truncate_db = mforms.newCheckBox()
        self._truncate_db.set_text("Truncate target tables (i.e. delete contents) before copying data")
        self._truncate_db.set_name("Truncate")
        self.options_box.add(self._truncate_db, False, True)

        hbox = mforms.newBox(True)
        hbox.set_spacing(16)
        worker_label = mforms.newLabel("Worker tasks")
        worker_label.set_name("Worker Tasks")
        hbox.add(worker_label, False, True)
        self._worker_count = mforms.newTextEntry()
        self._worker_count.set_name("Worker Tasks Count")
        self._worker_count.set_value("2")
        self._worker_count.set_size(30, -1)
        hbox.add(self._worker_count, False, True)
        l = mforms.newImageBox()
        l.set_image(mforms.App.get().get_resource_path("mini_notice.png"))
        l.set_tooltip("Number of tasks to use for data transfer. Each task will open a "+
          "connection to both source and target RDBMSes to copy table rows.\nDefault value 2.")
        hbox.add(l, False, True)
        self.options_box.add(hbox, False, True)

        self._debug_copy = mforms.newCheckBox()
        self._debug_copy.set_text("Enable debug output for table copy")
        self._debug_copy.set_name("Enable Debug Output")
        self.options_box.add(self._debug_copy, False, True)
        
        self._driver_sends_utf8 = mforms.newCheckBox()
        self._driver_sends_utf8.set_text("Driver sends data already encoded as UTF-8.")
        self._driver_sends_utf8.set_name("Send UTF8 Data")
        self.options_box.add(self._driver_sends_utf8, False, True)


        ###

        self._advanced_panel = mforms.newPanel(mforms.TitledBoxPanel)
        self._advanced_panel.set_title("Tables to Copy")
        self.content.add(self._advanced_panel, True, True)

        box = mforms.newBox(False)
        box.set_padding(12)
        box.set_spacing(8)

        l = mforms.newLabel("""You can limit the number of rows to be copied for certain tables. Tables that are referenced by
foreign keys from other tables cannot be limited, unless data copy from the referencing tables is also disabled.
All tables are copied by default.""")
        l.set_name("Description")
        l.set_style(mforms.SmallHelpTextStyle)
        box.add(l, False, True)

        self._tree = mforms.newTreeView(mforms.TreeDefault)
        self._tree.add_column(mforms.IconStringColumnType, "Table", 200, False)
        self._tree.add_column(mforms.StringColumnType, "Limit Copy", 100, True)
        self._tree.add_column(mforms.StringColumnType, "Referencing Tables", 500, False)
        self._tree.end_columns()
        box.add(self._tree, True, True)
        self._advanced_panel.add(box)
        self._tree.set_cell_edited_callback(self._cell_edited)
        self._advbox_shown = False
        self._advanced_panel.show(False)
Exemplo n.º 43
0
    def __init__(self, ctrl_be, variables, command, viewer_type):
        mforms.Box.__init__(self, False)
        self.set_managed()
        self.set_release_on_add()

        self.user_groups = VariablesGroupContainer(viewer_type)
        self.user_groups.load()
        self.viewer_type = viewer_type
        self.variables = variables

        self.suspend_layout()

        self.command = command
        self.ctrl_be = ctrl_be
        self.support_variable_persistence = self.viewer_type == "system" and self.ctrl_be.target_version.is_supported_mysql_version_at_least(
            8, 0, 0)

        box = newBox(True)
        box.set_spacing(12)
        self.add(box, True, True)
        self.tree = newTreeView(mforms.TreeFlatList)
        self.tree.set_selection_mode(mforms.TreeSelectMultiple)

        sidebox = newBox(False)
        box.add(sidebox, False, True)

        self.searchEntry = newTextEntry(mforms.SearchEntry)

        sidebox.set_spacing(12)
        sidebox.add(self.searchEntry, False, True)
        sidebox.add(self.tree, True, True)
        self.tree.set_size(210, -1)

        self.searchEntry.add_changed_callback(self.filterOutput)

        self.tree.add_column(mforms.StringColumnType, "Category", 200, False)
        self.tree.end_columns()
        self.tree.add_changed_callback(weakcb(self, "refresh"))
        self.cat_menu = mforms.newContextMenu()
        self.cat_menu.add_will_show_callback(self.cat_menu_will_show)
        self.cat_menu.add_item_with_title("Delete Category",
                                          self.delete_category, "delete")
        self.tree.set_context_menu(self.cat_menu)

        self.values = newTreeView(mforms.TreeFlatList)
        self.values.set_selection_mode(mforms.TreeSelectMultiple)
        box.add(self.values, True, True)
        if self.support_variable_persistence:
            self.values.add_column(mforms.CheckColumnType, "Persist", 50, True)
        self.values.add_column(mforms.StringColumnType, "Name", 200, False)
        self.values.add_column(mforms.StringColumnType, "Value", 120, True)
        if self.support_variable_persistence:
            self.values.add_column(mforms.StringColumnType, "Persist Value",
                                   120, True)
        self.values.add_column(mforms.StringColumnType, "Description", 1000,
                               False)
        self.values.end_columns()
        self.values.set_allow_sorting(True)
        self.values.set_cell_edited_callback(self.edit_variable)
        self.values.add_changed_callback(
            weakcb(self, "value_selection_changed"))
        self.menu = mforms.newContextMenu()
        self.menu.add_will_show_callback(self.menu_will_show)
        self.values.set_context_menu(self.menu)

        box = newBox(True)
        box.set_spacing(8)
        copy_all_button = newButton()
        copy_all_button.set_text(
            'Copy Global Status and Variables to Clipboard')
        copy_all_button.add_clicked_callback(self.copy_status_to_clipboard)
        box.add(copy_all_button, False, False)
        copy_shown_button = newButton()
        copy_shown_button.set_text('Copy Selected to Clipboard')
        copy_shown_button.add_clicked_callback(self.copy_selected_to_clipboard)
        box.add(copy_shown_button, False, False)

        if self.support_variable_persistence:
            reset_persist = newButton()
            reset_persist.set_text('Reset persist values')
            reset_persist.add_clicked_callback(weakcb(self,
                                                      "reset_persist_cb"))
            box.add(reset_persist, False, False)

        self.copy_selected_to_clipboard_button = copy_shown_button
        button = newButton()
        box.add_end(button, False, True)
        button.set_text("Refresh")
        box.set_padding(0, 8, 0, 8)

        button.add_clicked_callback(weakcb(self, "refresh"))

        self.add(box, False, True)

        row = self.tree.add_node()
        row.set_string(0, "All")
        row = self.tree.add_node()
        row.set_string(0, "Filtered")

        self.resume_layout()

        self.variable_info = {}
        self.variables_in_group = {"Other": [], "Persisted": []}

        self._delayed_init_tm = mforms.Utilities.add_timeout(
            0.1, lambda: self.delayed_init(self.variables))
    def create_uix(self):
        container = mforms.newBox(True)
        container.set_spacing(30)

        left_side_box = mforms.newBox(False)
        left_side_box.set_padding(8)
        logo_image = mforms.newImageBox()
        logo_image.set_image('migration_logo.png')
        left_side_box.add(logo_image, False, True)
        container.add(left_side_box, False, True)

        # Main layout structure
        content = mforms.newBox(False)
        content.set_padding(8)
        content.set_spacing(12)
        title_image = mforms.newImageBox()
        title_image.set_image('migration_title.png')
        content.add(title_image, False, True)

        help_label = mforms.newLabel('''To perform a new migration click the [Start New Migration] button below. To re-run
a previous migration or to perform a new migration based on a previous
migration please double click one of the migration projects below.''')
        content.add(help_label, False, True)

        wrapper_button_box = mforms.newBox(True)
        wrapper_button_box.set_padding(8)
        button_new_migration = mforms.newButton()
        button_new_migration.set_text('Start New Migration')
        #button_new_migration.add_clicked_callback(lambda x: x)
        wrapper_button_box.add(button_new_migration, False, True)
        content.add(wrapper_button_box, False, True)

        project_box = mforms.newBox(False)
        project_box.set_spacing(8)
        project_label = mforms.newLabel('Project Overview')
        project_label.set_style(mforms.BoldStyle)
        project_box.add(project_label, False, True)
        project_tree = mforms.newTreeView(mforms.TreeDefault)
        project_box.add(project_tree, True, True)
        project_button_box = mforms.newBox(True)
        project_button_box.set_spacing(8)
        button_rerun_migration = mforms.newButton()
        button_rerun_migration.set_text('Re-Run Migration')
        button_edit_migration = mforms.newButton()
        button_edit_migration.set_text('Edit Migration Project')
        project_button_box.add(button_rerun_migration, False, True)
        project_button_box.add(button_edit_migration, False, True)
        project_box.add(project_button_box, False, True)
        content.add(project_box, False, True)

        container.add(content, False, True)

        # Right side layout structure
        right_side_box = mforms.newBox(False)
        right_side_image = mforms.newImageBox()
        right_side_image.set_image('migration_background.png')
        right_side_image.set_image_align(mforms.TopRight)
        right_side_box.add(right_side_image, False, True)
        container.add(right_side_box, True, True)

        self.add(container, True, True)
    def init_ui(self):
        if self._title:
            return

        if self._wait_table:
            self._pbar.stop()
            self._pbar = None
            self.remove(self._wait_table)
            self._wait_table = None

        self._title = mforms.newLabel(to_unicode(self.caption))
        self._title.set_style(mforms.BigBoldStyle)
        self.add(self._title, False, True)

        self._column_file = None

        if self.description:
            self._description = mforms.newLabel(to_unicode(self.description))
            self.add(self._description, False, True)

        self._tree = mforms.newTreeView(mforms.TreeFlatList
                                        | mforms.TreeAltRowColors
                                        | mforms.TreeShowColumnLines)
        self._tree.set_selection_mode(mforms.TreeSelectMultiple)
        self._tree.add_column_resized_callback(self._tree_column_resized)
        c = 0

        self._hmenu = mforms.newContextMenu()
        self._hmenu.add_will_show_callback(self._header_menu_will_show)
        self._tree.set_header_menu(self._hmenu)

        self._column_types = []
        self._column_units = []
        self._column_names = []
        self._column_titles = []
        for i, (column, cname, ctype,
                length) in enumerate(self.get_view_columns()):
            unit = None
            if type(ctype) is tuple:
                ctype, unit = ctype
            unit = grt.root.wb.state.get(
                "wb.admin.psreport:unit:%s:%i" % (self.view, i), unit)

            width = min(max(length, 40), 300)
            width = grt.root.wb.state.get(
                "wb.admin.psreport:width:%s:%i" % (self.view, i), width)

            label = to_unicode(self.column_label(column))
            self._column_units.append(unit)
            self._column_names.append(cname)
            self._column_titles.append(label)
            self._column_types.append(ctype)

            if unit:
                self._tree.add_column(ctype, label + " (%s)" % unit, width,
                                      False)
            else:
                self._tree.add_column(ctype, label, width, False)
            c += 1
        self._tree.end_columns()
        self._tree.set_allow_sorting(True)
        self.add(self._tree, True, True)

        bbox = mforms.newBox(True)
        bbox.set_spacing(12)

        btn = mforms.newButton()
        btn.set_text("Export...")
        btn.add_clicked_callback(self.do_export)
        bbox.add(btn, False, True)

        btn = mforms.newButton()
        btn.set_text("Copy Selected")
        btn.add_clicked_callback(self.do_copy)
        bbox.add(btn, False, True)

        btn = mforms.newButton()
        btn.set_text("Copy Query")
        btn.add_clicked_callback(self.do_copy_query)
        bbox.add(btn, False, True)

        self._refresh = mforms.newButton()
        self._refresh.set_text("Refresh")
        self._refresh.add_clicked_callback(self.do_refresh)
        bbox.add_end(self._refresh, False, True)
        self.add(bbox, False, True)
Exemplo n.º 46
0
 def fill_costs_tree(self, json):
     tree = mforms.newTreeView(mforms.TreeFlatList
                               | mforms.TreeShowColumnLines
                               | mforms.TreeShowRowLines
                               | mforms.TreeAltRowColors)
     return tree
    def __init__(self, main):
        WizardPage.__init__(self, main, "Data Transfer Setup")

        self.main.add_wizard_page(self, "DataMigration", "Data Transfer Setup")

        label = mforms.newLabel("Select options for the copy of the migrated schema tables in the target MySQL server and click [Next >] to execute.")
        self.content.add(label, False, True)

        panel = mforms.newPanel(mforms.TitledBoxPanel)
        panel.set_title("Data Copy")
        self.content.add(panel, False, True)

        box = mforms.newBox(False)
        panel.add(box)
        box.set_padding(16)
        box.set_spacing(16)

        rid = mforms.RadioButton.new_id()

        self._copy_db = mforms.newRadioButton(rid)
        self._copy_db.set_text("Online copy of table data to target RDBMS")
        self._copy_db.add_clicked_callback(self._script_radio_option_callback)
        box.add(self._copy_db, False, True)

        # XXX TODO
        #box.add(mforms.newLabel(""), False, True)
        #self._add_script_checkbox_option(box, "dump_to_file", "Create a dump file with the data", "Dump File:", "Save As")

        if sys.platform == "win32":
            self._add_script_radiobutton_option(box, "copy_script", "Create a batch file to copy the data at another time", "Batch File:", "Save As", "You should edit this file to add the source and target server passwords before running it.", rid)
        else:
            self._add_script_radiobutton_option(box, "copy_script", "Create a shell script to copy the data from outside Workbench", "Shell Script File:", "Save As", "You should edit this file to add the source and target server passwords before running it.", rid)

        self._add_script_radiobutton_option(box, "bulk_copy_script", "Create a shell script to use native server dump and load abilities for fast migration", "Bulk Data Copy Script:", "Save As", "Edit the generated file and change passwords at the top of the generated script.\nRun it on the source server to create a zip package containing a data dump as well as a load script.\nCopy this to the target server, extract it, and run the import script. See the script output for further details.", rid)

        panel = mforms.newPanel(mforms.TitledBoxPanel)
        panel.set_title("Options")
        self.content.add(panel, False, True)

        self.options_box = mforms.newBox(False)
        self.options_box.set_padding(12)
        self.options_box.set_spacing(8)
        panel.add(self.options_box)

        self._truncate_db = mforms.newCheckBox()
        self._truncate_db.set_text("Truncate target tables (i.e. delete contents) before copying data")
        self.options_box.add(self._truncate_db, False, True)

        hbox = mforms.newBox(True)
        hbox.set_spacing(16)
        hbox.add(mforms.newLabel("Worker tasks"), False, True)
        self._worker_count = mforms.newTextEntry()
        self._worker_count.set_value("2")
        self._worker_count.set_size(30, -1)
        hbox.add(self._worker_count, False, True)
        l = mforms.newImageBox()
        l.set_image(mforms.App.get().get_resource_path("mini_notice.png"))
        l.set_tooltip("Number of tasks to use for data transfer. Each task will open a "+
          "connection to both source and target RDBMSes to copy table rows.\nDefault value 2.")
        hbox.add(l, False, True)
        self.options_box.add(hbox, False, True)

        self._debug_copy = mforms.newCheckBox()
        self._debug_copy.set_text("Enable debug output for table copy")
        self.options_box.add(self._debug_copy, False, True)
        
        self._driver_sends_utf8 = mforms.newCheckBox()
        self._driver_sends_utf8.set_text("Driver sends data already encoded as UTF-8.")
        self.options_box.add(self._driver_sends_utf8, False, True)


        ###

        self._advanced_panel = mforms.newPanel(mforms.TitledBoxPanel)
        self._advanced_panel.set_title("Tables to Copy")
        self.content.add(self._advanced_panel, True, True)

        box = mforms.newBox(False)
        box.set_padding(12)
        box.set_spacing(8)

        l = mforms.newLabel("""You can limit the number of rows to be copied for certain tables. Tables that are referenced by
foreign keys from other tables cannot be limited, unless data copy from the referencing tables is also disabled.
All tables are copied by default.""")
        l.set_style(mforms.SmallHelpTextStyle)
        box.add(l, False, True)

        self._tree = mforms.newTreeView(mforms.TreeDefault)
        self._tree.add_column(mforms.IconStringColumnType, "Table", 200, False)
        self._tree.add_column(mforms.StringColumnType, "Limit Copy", 100, True)
        self._tree.add_column(mforms.StringColumnType, "Referencing Tables", 500, False)
        self._tree.end_columns()
        box.add(self._tree, True, True)
        self._advanced_panel.add(box)
        self._tree.set_cell_edited_callback(self._cell_edited)
        self._advbox_shown = False
        self._advanced_panel.show(False)
Exemplo n.º 48
0
    def __init__(self, variables, all_opts, output_path):
        mforms.Box.__init__(self, False)

        self.set_managed()
        self.set_release_on_add()

        self.suspend_layout()
        self.output_path = output_path
        self.all_options = all_opts

        self.filter = newTextEntry()
        self.filter.add_changed_callback(self.show_filtered_options)
        self.add(self.filter, False, True)

        box = newBox(True)
        box.set_spacing(12)

        sidebox = newBox(False)
        sidebox.set_spacing(12)

        self.groups_tree = newTreeView(mforms.TreeFlatList)
        self.groups_tree.set_size(220, -1)
        self.groups_tree.add_column(mforms.CheckColumnType, "", 20, True)
        self.groups_tree.add_column(mforms.StringColumnType, "", 160, False)
        self.groups_tree.end_columns()
        self.groups_tree.set_cell_edited_callback(self.toggled_group)

        sidebox.add(self.groups_tree, True, True)
        box.add_end(sidebox, False, True)

        self.values_tree = newTreeView(mforms.TreeFlatList)
        self.values_tree.add_column(mforms.StringColumnType, "Name", 200,
                                    False)
        self.values_tree.add_column(mforms.StringColumnType, "Groups", 1000,
                                    False)
        self.values_tree.set_selection_mode(mforms.TreeSelectMultiple)
        self.values_tree.end_columns()
        self.values_tree.set_allow_sorting(True)
        self.values_tree.add_changed_callback(self.value_selected)
        box.add(self.values_tree, True, True)

        self.add(box, True, True)

        box = newBox(True)
        box.set_spacing(8)
        box.set_padding(12)

        self.button_save = newButton()
        self.button_save.set_text("Save")
        self.button_save.add_clicked_callback(self.save)
        box.add_end(self.button_save, False, True)

        self.button_add_group = newButton()
        self.button_add_group.set_text("Add Group")
        self.button_add_group.add_clicked_callback(self.add_group)
        self.button_add_group.set_enabled(False)
        box.add_end(self.button_add_group, False, True)

        self.group_entry = newTextEntry()
        self.group_entry.set_size(300, -1)
        self.group_entry.set_enabled(False)
        box.add_end(self.group_entry, False, True)

        self.add(box, False, True)

        self.resume_layout()

        self.all_groups = set()
        self.value_group_pair = dict()

        for name, groups in variables:
            self.all_groups = self.all_groups.union(set(groups))
            self.value_group_pair[name] = groups

        for g in sorted(self.all_groups):
            node = self.groups_tree.add_node()
            node.set_string(1, g)

        self.groups = self.all_groups

        self.show_filtered_options()
Exemplo n.º 49
0
    def create_uix(self):
        container = mforms.newBox(True)
        container.set_spacing(30)

        left_side_box = mforms.newBox(False)
        left_side_box.set_padding(8)
        logo_image = mforms.newImageBox()
        logo_image.set_image('migration_logo.png')
        left_side_box.add(logo_image, False, True)
        container.add(left_side_box, False, True)

        # Main layout structure
        content = mforms.newBox(False)
        content.set_padding(8)
        content.set_spacing(12)
        title_image = mforms.newImageBox()
        title_image.set_image('migration_title.png')
        content.add(title_image, False, True)

        help_label = mforms.newLabel(
            '''To perform a new migration click the [Start New Migration] button below. To re-run
a previous migration or to perform a new migration based on a previous
migration please double click one of the migration projects below.''')
        content.add(help_label, False, True)

        wrapper_button_box = mforms.newBox(True)
        wrapper_button_box.set_padding(8)
        button_new_migration = mforms.newButton()
        button_new_migration.set_text('Start New Migration')
        #button_new_migration.add_clicked_callback(lambda x: x)
        wrapper_button_box.add(button_new_migration, False, True)
        content.add(wrapper_button_box, False, True)

        project_box = mforms.newBox(False)
        project_box.set_spacing(8)
        project_label = mforms.newLabel('Project Overview')
        project_label.set_style(mforms.BoldStyle)
        project_box.add(project_label, False, True)
        project_tree = mforms.newTreeView(mforms.TreeDefault)
        project_box.add(project_tree, True, True)
        project_button_box = mforms.newBox(True)
        project_button_box.set_spacing(8)
        button_rerun_migration = mforms.newButton()
        button_rerun_migration.set_text('Re-Run Migration')
        button_edit_migration = mforms.newButton()
        button_edit_migration.set_text('Edit Migration Project')
        project_button_box.add(button_rerun_migration, False, True)
        project_button_box.add(button_edit_migration, False, True)
        project_box.add(project_button_box, False, True)
        content.add(project_box, False, True)

        container.add(content, False, True)

        # Right side layout structure
        right_side_box = mforms.newBox(False)
        right_side_image = mforms.newImageBox()
        right_side_image.set_image('migration_background.png')
        right_side_image.set_image_align(mforms.TopRight)
        right_side_box.add(right_side_image, False, True)
        container.add(right_side_box, True, True)

        self.add(container, True, True)
    def __init__(self, editor, schema):
        mforms.Box.__init__(self, False)
        self.set_managed()
        self.set_release_on_add()

        self.schema = schema
        self.editor = editor
        
        self.target_version = Version.fromgrt(editor.serverVersion)

        self.main = mforms.newBox(False)
        self.add(self.main, True, True)

        self.error_heading = mforms.newLabel("")
        self.error_heading.set_style(mforms.BoldStyle)
        self.error_body = mforms.newLabel("")
        self.error_box = mforms.newBox(False)
        self.error_box.set_spacing(8)
        self.error_box.set_padding(8)
        self.error_box.add(self.error_heading, True, False)
        self.error_box.add(self.error_body, True, False)
        self.add(self.error_box, True, False)
        self.error_box.show(False)

        self.main.set_padding(8)
        self.main.set_spacing(8)

        self.tree = mforms.newTreeView(mforms.TreeFlatList|mforms.TreeAltRowColors|mforms.TreeShowColumnLines)
        self.tree.set_selection_mode(mforms.TreeSelectMultiple)
        
        #Check if there is method to load the columns, if not, skip.
        if hasattr(self, "preload_columns") and callable(getattr(self, "preload_columns")):
            self.preload_columns()
        
        for field, type, caption, width, min_version in self.columns:
            if min_version and not self.target_version.is_supported_mysql_version_at_least(Version.fromstr(min_version)):
                continue
            self.tree.add_column(type, caption, width, False)
        self.tree.end_columns()
        self.tree.set_allow_sorting(True)
        self.main.add(self.tree, True, True)

        self.menu = mforms.newContextMenu()
        self.menu.add_will_show_callback(self.menu_will_show)
        self.tree.add_activated_callback(self.on_activate)
        self.tree.set_context_menu(self.menu)

        self.icon_path = mforms.App.get().get_resource_path(self.klass+".16x16.png")
        self.bad_icon_path = mforms.App.get().get_resource_path(self.bad_icon_path)

        self.row_count = mforms.newLabel("")
        self.row_count.set_text("");
        
        self.refresh_btn = mforms.newButton()
        self.refresh_btn.set_text("Refresh")
        self.refresh_btn.add_clicked_callback(self.refresh)

        self.bbox = mforms.newBox(True)
        self.bbox.set_spacing(8)
        self.main.add(self.bbox, False, True)

        self.bbox.add(self.row_count, False, True)
        self.bbox.add_end(self.refresh_btn, False, True)

        for caption, callback_name in self.actions:
            if not caption:
                self.bbox.add(mforms.newLabel(" "), False, True)
                continue
            btn = mforms.newButton()
            btn.set_text(caption)
            btn.add_clicked_callback(getattr(self, callback_name))
            self.bbox.add(btn, False, True)
Exemplo n.º 51
0
    def create_ui(self):
        self.content.set_spacing(4)
        description = mforms.newLabel(
            "Review and edit migrated objects. You can manually edit the generated SQL before applying them to the target database."
        )
        description.set_name('Page Description')
        self.content.add(description, False, True)

        hbox = mforms.newBox(True)
        self.tree_head_label = mforms.newLabel("Migrated Objects")
        self.tree_head_label.set_name('Header')
        hbox.add(self.tree_head_label, False, True)
        self._filter = mforms.newSelector()
        self._filter.set_name('Change View')
        self._filter.add_items(
            ["Migration Problems", "All Objects", "Column Mappings"])
        self._filter.add_changed_callback(self._filter_changed)
        hbox.add_end(self._filter, False, True)
        hbox.add_end(mforms.newLabel("View:"), False, True)
        self.content.add(hbox, False, True)

        self._no_errors_text = "No migration problems found. %d warning(s).\nUse the View pulldown menu to review all objects."
        self._no_errors = mforms.newLabel(
            ''
        )  # Label text will be set later when the warning count is calculated
        self._no_errors.set_name('Problems Found')
        self._no_errors.set_style(mforms.BigStyle)
        self._no_errors.set_text_align(mforms.MiddleLeft)
        self.content.add(self._no_errors, True, True)

        self._tree = mforms.newTreeView(mforms.TreeDefault)
        self._tree.set_name('All Objects')
        self._tree.add_column(mforms.IconStringColumnType, "Source Object",
                              200, False)
        self._tree.add_column(mforms.IconStringColumnType, "Target Object",
                              200, True)
        self._tree.add_column(mforms.IconStringColumnType, "Migration Message",
                              300, False)
        self._tree.end_columns()
        self._tree.add_changed_callback(self._selection_changed)
        self.content.add(self._tree, True, True)
        self._tree.set_cell_edited_callback(self._cell_edited)

        self._all_menu = mforms.newContextMenu()
        self._all_menu.add_will_show_callback(self.all_menu_will_show)
        self._all_menu.add_check_item_with_title("Skip Object",
                                                 self.skip_object,
                                                 "Skip Object", "skip_object")

        self._tree.set_context_menu(self._all_menu)

        self._columns = mforms.newTreeView(mforms.TreeShowColumnLines
                                           | mforms.TreeShowRowLines
                                           | mforms.TreeFlatList)
        self._columns.set_name('Column Mappings')
        self.COL_SOURCE_SCHEMA = self._columns.add_column(
            mforms.StringColumnType, "Source Schema", 100, False)
        self.COL_SOURCE_TABLE = self._columns.add_column(
            mforms.IconStringColumnType, "Source Table", 100, False)
        self.COL_SOURCE_COLUMN = self._columns.add_column(
            mforms.IconStringColumnType, "Source Column", 100, False)
        self.COL_SOURCE_TYPE = self._columns.add_column(
            mforms.StringColumnType, "Source Type", 100, False)
        self.COL_SOURCE_FLAGS = self._columns.add_column(
            mforms.StringColumnType, "Source Flags", 100, False)
        self.COL_SOURCE_NOTNULL = self._columns.add_column(
            mforms.CheckColumnType, "NN", 25, False)
        self.COL_SOURCE_DEFAULT = self._columns.add_column(
            mforms.StringColumnType, "Source Default Value", 100, False)
        self.COL_SOURCE_COLLATION = self._columns.add_column(
            mforms.StringColumnType, "Source Collation", 100, False)
        self.COL_TARGET_SCHEMA = self._columns.add_column(
            mforms.StringColumnType, "Target Schema", 100, False)
        self.COL_TARGET_TABLE = self._columns.add_column(
            mforms.IconStringColumnType, "Target Table", 100, False)
        self.COL_TARGET_COLUMN = self._columns.add_column(
            mforms.IconStringColumnType, "Target Column", 100, True)
        self.COL_TARGET_TYPE = self._columns.add_column(
            mforms.StringColumnType, "Target Type", 100, True)
        self.COL_TARGET_FLAGS = self._columns.add_column(
            mforms.StringColumnType, "Target Flags", 100, True)
        self.COL_TARGET_AI = self._columns.add_column(mforms.CheckColumnType,
                                                      "AI", 25, True)
        self.COL_TARGET_NOTNULL = self._columns.add_column(
            mforms.CheckColumnType, "NN", 25, True)
        self.COL_TARGET_DEFAULT = self._columns.add_column(
            mforms.StringColumnType, "Target Default Value", 100, True)
        self.COL_TARGET_COLLATION = self._columns.add_column(
            mforms.StringColumnType, "Target Collation", 100, True)
        self.COL_MESSAGE = self._columns.add_column(
            mforms.IconStringColumnType, "Migration Message", 300, False)
        self._columns.end_columns()
        self._columns.set_allow_sorting(True)
        self._columns.set_selection_mode(mforms.TreeSelectMultiple)
        self._columns.add_changed_callback(self._selection_changed)
        self.content.add(self._columns, True, True)
        self._columns.set_cell_edited_callback(self._columns_cell_edited)
        self._columns.show(False)

        self._menu = mforms.newContextMenu()
        self._menu.add_will_show_callback(self.menu_will_show)
        self._menu.add_item_with_title(
            "Set Target Type of Selected Columns...", self.set_target_type,
            "Set Target Type", "set_target_type")
        self._menu.add_item_with_title("Find and Replace Target Type...",
                                       self.replace_target_type,
                                       "Replace Target Type",
                                       "replace_target_type")
        self._menu.add_item_with_title("Find and Replace Target Flags...",
                                       self.replace_target_flags,
                                       "Replace Target Flags",
                                       "replace_target_flags")
        self._menu.add_item_with_title(
            "Find and Replace Target Default Value...",
            self.replace_target_default_value, "Replace Target Default Value",
            "replace_target_default_value")
        self._menu.add_item_with_title("Find and Replace Target Collation...",
                                       self.replace_target_collation,
                                       "Replace Target Collation",
                                       "replace_target_collation")
        self._columns.set_context_menu(self._menu)

        self.help_label = mforms.newLabel(
            "You can rename target schemas and tables, and change column definitions by clicking them once selected."
        )
        self.help_label.set_name('Help Message')
        self.help_label.set_style(mforms.SmallStyle)
        self.content.add(self.help_label, False, True)

        self._advbox = mforms.newPanel(mforms.TitledBoxPanel)
        self._advbox.set_title("SQL CREATE Script for Selected Object")
        self._advbox.set_name('SQL Editor')
        box = mforms.newBox(True)
        self._code = mforms.newCodeEditor()
        self._code.set_language(mforms.LanguageMySQL)
        self._code.add_changed_callback(self._code_changed)
        box.add(self._code, True, True)
        vbox = mforms.newBox(False)
        vbox.set_padding(12)
        vbox.set_spacing(8)

        self._lock_check = mforms.newCheckBox()
        self._lock_check.set_text("Lock edited SQL")
        self._lock_check.set_name("Lock Edited SQL")
        self._lock_check.set_tooltip(
            "Lock the SQL code to the edited one, preventing automatic regenerations from discarding changes made directly to the SQL script."
        )
        self._lock_check.add_clicked_callback(self._lock_clicked)
        vbox.add(self._lock_check, False, True)

        self._comment_check = mforms.newCheckBox()
        self._comment_check.set_text("Comment out")
        self._comment_check.set_name("Comment Out")
        self._comment_check.set_tooltip(
            "Mark the object to be commented out on the generated script, making it not get created in the target server."
        )
        self._comment_check.add_clicked_callback(self._comment_clicked)
        vbox.add(self._comment_check, False, True)

        self._sql_outdated_label = mforms.newLabel("Code is outdated")
        self._sql_outdated_label.show(False)
        self._sql_outdated_label.set_tooltip(
            "The locked SQL code seems to be outdated compared to a newer, automatically generated one. Unlocking the object will update it, but your changes will be lost."
        )
        vbox.add(self._sql_outdated_label, False, True)

        self._revert_btn = mforms.newButton()
        self._revert_btn.set_text("Discard Changes")
        self._revert_btn.set_name("Discard Changes")
        vbox.add_end(self._revert_btn, False, True)
        self._revert_btn.add_clicked_callback(self._discard_clicked)

        self._apply_btn = mforms.newButton()
        self._apply_btn.set_text("Apply Changes")
        self._apply_btn.set_name("Apply Changes")
        vbox.add_end(self._apply_btn, False, True)
        self._apply_btn.add_clicked_callback(self._apply_clicked)
        box.add(vbox, False, True)

        self._advbox.add(box)
        self._advbox.set_size(-1, 200)
        self._advbox_shown = True
        self.go_advanced()  # toggle to hide

        self.content.add(self._advbox, False, True)

        self._filter_errors = False
        self._filter_changed()
    def __init__(self, types_to_display, database_objects, ui_settings={}):
        super(DatabaseObjectSelector, self).__init__(False)
        self.database_objects = database_objects
        self.supported_object_types = types_to_display
        
        self.ui_settings = {
            'tables' : { 'icon': 'db.Table.many.32x32.png',
                        'small_icon': 'db.Table.16x16.png',
                        'group_label': 'Migrate Table objects',
                        'group_selected': True,
                        'status_text': '%(total)d total, %(selected)d selected',
                        'show_details': False,
                      },
            'views'  : { 'icon': 'db.View.many.32x32.png',
                        'small_icon': 'db.View.16x16.png',
                        'group_label': 'Migrate View objects',
                        'group_selected': True,
                        'status_text': '%(total)d total, %(selected)d selected',
                        'show_details': False,
                      },
            'routines':{ 'icon': 'db.Routine.many.32x32.png',
                        'small_icon': 'db.Routine.16x16.png',
                        'group_label': 'Migrate Routine objects',
                        'group_selected': True,
                        'status_text': '%(total)d total, %(selected)d selected',
                        'show_details': False,
                      },
            'routineGroups':{ 'icon': 'db.RoutineGroup.48x48.png',
                        'small_icon': 'db.RoutineGroup.16x16.png',
                        'group_label': 'Migrate Routine Group/Package objects',
                        'group_selected': True,
                        'status_text': '%(total)d total, %(selected)d selected',
                        'show_details': False,
                      },
            'synonyms':{ 'icon': 'grt_object.png',
                        'small_icon': 'grt_object.png',
                        'group_label': 'Migrate Synonym objects',
                        'group_selected': True,
                        'status_text': '%(total)d total, %(selected)d selected',
                        'show_details': False,
                      },
            'structuredTypes':{ 'icon': 'grt_object.png',
                        'small_icon': 'grt_object.png',
                        'group_label': 'Migrate Structured Type objects',
                        'group_selected': True,
                        'status_text': '%(total)d total, %(selected)d selected',
                        'show_details': False,
                      },
            'sequences':{ 'icon': 'grt_object.png',
                        'small_icon': 'grt_object.png',
                        'group_label': 'Migrate Sequence objects',
                        'group_selected': True,
                        'status_text': '%(total)d total, %(selected)d selected',
                        'show_details': False,
                      },
        }
        
        # Update the ui settings dict with the custom settings supplied by the user (if any):
        if isinstance(ui_settings, dict):
            for key, value in ui_settings.iteritems():
                if key not in self.ui_settings or not isinstance(value, dict):
                    continue
                self.ui_settings[key].update(value)
        
        # Create UI:
        self.set_padding(8)
        self.set_spacing(8)
        
        self.ui = {}
        for group in self.supported_object_types:
            if group not in self.database_objects or group not in self.ui_settings:
                continue
            self.ui[group] = {}
            group_objects = self.database_objects[group]
            
            group_panel = mforms.newPanel(mforms.BorderedPanel)
            group_box = mforms.newBox(False)
            group_box.set_padding(8)
            group_box.set_spacing(8)
            
            header_box = mforms.Box(True)
            header_box.set_spacing(8)

            icon = mforms.newImageBox()
            icon.set_image(self.ui_settings[group]['icon'])
            header_box.add(icon, False, True)
            
            text_box = mforms.Box(False)
            group_selector = mforms.newCheckBox()
            group_selector.set_text(self.ui_settings[group]['group_label'])
            group_selector.set_active(bool(self.ui_settings[group]['group_selected']))
            group_selector.add_clicked_callback(functools.partial(self.group_checkbox_clicked, group=group))
            text_box.add(group_selector, False, True)
            info_label = mforms.newLabel(self.ui_settings[group]['status_text'] % {'total': len(group_objects), 
                                       'selected': len(group_objects) if self.ui_settings[group]['group_selected'] else 0 })
            info_label.set_style(mforms.SmallHelpTextStyle)
            text_box.add(info_label, False, True)
            header_box.add(text_box, False, True)
            
            show_details = self.ui_settings[group]['show_details']
            self.ui_settings[group]['_showing_details'] = show_details
            filter_button = mforms.newButton()
            filter_button.set_text('Hide Selection' if show_details else 'Show Selection')
            filter_button.set_enabled(bool(self.ui_settings[group]['group_selected']))
            filter_button.add_clicked_callback(functools.partial(self.filter_button_clicked, group=group))
            header_box.add_end(filter_button, False, True)
            
            group_box.add(header_box, False, True)
            
            # The invisible stuff:
            if len(group_objects) > 0:
                box = mforms.newBox(True)
                search_entry = mforms.newTextEntry(mforms.SearchEntry)
                search_entry.set_placeholder_text("Filter objects (wildcards chars * and ? are allowed)")
                search_entry.add_changed_callback(functools.partial(self.search_entry_changed, group=group))
                box.add(search_entry, False, True)
                group_box.add(box, False, True)
                search_entry.set_size(350, -1)

                filter_container = mforms.newBox(True)
                filter_container.set_spacing(8)

                available_list = mforms.newTreeView(mforms.TreeFlatList)
                available_list.add_column(mforms.IconColumnType, 'Available Objects', 300, False)
                available_list.end_columns()
                available_list.set_selection_mode(mforms.TreeSelectMultiple)
                available_list.set_allow_sorting(False)
                filter_container.add(available_list, True, True)

                control_box = mforms.newBox(False)
                control_box.set_padding(0, 30, 0, 30)
                control_box.set_spacing(4)
                add_button = mforms.newButton()
                add_button.set_text('>')
                add_button.enable_internal_padding(False)
                add_button.add_clicked_callback(functools.partial(self.move_button_clicked, group=group, operation='add'))
                control_box.add(add_button, False)
                remove_button = mforms.newButton()
                remove_button.set_text('<')
                remove_button.enable_internal_padding(False)
                remove_button.add_clicked_callback(functools.partial(self.move_button_clicked, group=group, operation='remove'))
                control_box.add(remove_button, False, True)
                add_all_button = mforms.newButton()
                add_all_button.set_text('>>')
                add_all_button.enable_internal_padding(False)
                add_all_button.add_clicked_callback(functools.partial(self.move_button_clicked, group=group, operation='add_all'))
                control_box.add(add_all_button, False, True)
                remove_all_button = mforms.newButton()
                remove_all_button.set_text('<<')
                remove_all_button.enable_internal_padding(False)
                remove_all_button.add_clicked_callback(functools.partial(self.move_button_clicked, group=group, operation='remove_all'))
                control_box.add(remove_all_button, False)
                filter_container.add(control_box, False, False)


                selected_list = mforms.newTreeView(mforms.TreeFlatList)
                selected_list.add_column(mforms.IconColumnType, 'Objects to Migrate', 300, False)
                selected_list.end_columns()
                selected_list.set_selection_mode(mforms.TreeSelectMultiple)
                selected_list.set_allow_sorting(False)
                for item in sorted(group_objects):
                    node = selected_list.add_node()
                    node.set_icon_path(0, self.ui_settings[group]['small_icon'])
                    node.set_string(0, item)
                filter_container.add(selected_list, True, True)
                
                group_box.add(filter_container, True, True)
                
                filter_container.show(bool(show_details))
            
                self.ui[group].update( {
                    'filter_container': filter_container,
                    'available_list': available_list,
                    'selected_list': selected_list,
                    'search_entry': search_entry,
                    } )
            else:  # Empty object list
                filter_button.set_enabled(False)

            self.ui[group].update ( {
                'icon': icon,
                'group_selector': group_selector,
                'group_panel': group_panel,
                'info_label': info_label,
                'filter_button': filter_button,
                'all_objects': set(group_objects),
                'has_elements': bool(len(group_objects)),
                'available': set(),
                'selected': set(group_objects),
                'objects_passing_filter': set(group_objects),
                }  )
            group_panel.add(group_box)
            self.add(group_panel, False, True)
Exemplo n.º 53
0
    def __init__(self, ctrl_be, variables, command):
        mforms.Box.__init__(self, False)
        self.set_managed()

        self.suspend_layout()

        self.command = command
        self.ctrl_be = ctrl_be

        box = newBox(True)
        box.set_spacing(12)
        self.add(box, True, True)
        self.tree = newTreeView(mforms.TreeDefault)
        self.tree.set_size(180, -1)

        sidebox = newBox(False)

        box.add(sidebox, False, True)

        self.searchEntry = newTextEntry(mforms.SearchEntry)

        sidebox.set_spacing(12)
        sidebox.add(self.searchEntry, False, True)
        sidebox.add(self.tree, True, True)

        self.searchEntry.add_changed_callback(self.filterOutput)

        self.tree.add_column(mforms.StringColumnType, "", 160, False)
        self.tree.end_columns()
        self.tree.add_changed_callback(weakcb(self, "refresh"))

        self.values = newTreeView(mforms.TreeDefault)
        box.add(self.values, True, True)

        self.values.add_column(mforms.StringColumnType, "Name", 200, False)
        self.values.add_column(mforms.StringColumnType, "Value", 120, False)
        self.values.add_column(mforms.StringColumnType, "Description", 1000, False)
        self.values.end_columns()
        self.values.set_allow_sorting(True)

        box = newBox(True)
        box.set_spacing(8)
        copy_all_button = newButton()
        copy_all_button.set_text("Copy Global Status and Variables to Clipboard")
        copy_all_button.add_clicked_callback(self.copy_status_to_clipboard)
        box.add(copy_all_button, False, False)
        copy_shown_button = newButton()
        copy_shown_button.set_text("Copy Shown Variables to Clipboard")
        copy_shown_button.add_clicked_callback(self.copy_visible_vars_to_clipboard)
        box.add(copy_shown_button, False, False)
        button = newButton()
        box.add_end(button, False, True)
        button.set_text("Refresh")
        box.set_padding(12)

        button.add_clicked_callback(weakcb(self, "refresh"))

        self.add(box, False, True)

        self.groups = {}
        self.descriptions = {}

        def analyze(tree, level, d, groupd, version, vars, existing_vars):
            groups = {}
            variables = []
            for group_name, group_variables in vars.iteritems():
                vars_added_to_the_group = []
                groups[group_name] = vars_added_to_the_group
                for v in group_variables:
                    if v.var in existing_vars:
                        name = v.var
                        variables.append(name)
                        vars_added_to_the_group.append(v.var)
                        d[name] = v.description
                        existing_vars.remove(name)
                if vars_added_to_the_group:
                    row = tree.add_row()
                    tree.set_string(row, 0, group_name)
                    tree.set_row_tag(row, group_name)
            return groups, variables

        row = self.tree.add_row()
        self.tree.set_string(row, 0, "All")
        row = self.tree.add_row()
        self.tree.set_string(row, 0, "Search Results")
        self.resume_layout()

        variables_in_server = []
        result = self.ctrl_be.exec_query(self.command)
        if result is not None:
            while result.nextRow():
                name = result.stringByName("Variable_name")
                variables_in_server.append(name)

        allgroups, allvars = analyze(
            self.tree,
            0,
            self.descriptions,
            self.groups,
            self.ctrl_be.get_server_version(),
            variables,
            variables_in_server,
        )
        if variables_in_server:
            allvars += variables_in_server
            group_name = "Other"
            allgroups[group_name] = variables_in_server
            row = self.tree.add_row()
            self.tree.set_string(row, 0, group_name)
            self.tree.set_row_tag(row, group_name)

        self.groups = allgroups
        self.known_variables = allvars
    def __init__(self, database_objects, tree_checked_callback=lambda n:None, ui_settings={}):
        '''Constructor.
        '''
        super(DatabaseSchemaSelector, self).__init__(False)
        self.database_objects = database_objects
        self.tree_checked_callback = tree_checked_callback
      
        # Check if we should use catalogs:
        self.use_catalogs = ( isinstance(database_objects, (list, tuple)) and
                           len(database_objects) > 0 and
                           all( isinstance(item, (list, tuple)) and
                               len(item) == 2 and
                               isinstance(item[0], (str, unicode)) and
                               isinstance(item[1], (list, tuple))
                               for item in database_objects
                               )
                           )
      
      
        self.ui_settings = {
            'catalogs' : { 'icon': 'workbench.physical.Layer.16x16.png',
                           'should_expand': True,
                         },
            'schemas'  : { 'icon': 'db.Schema.16x16.png',
                         },
            'general'  : { 'summary_text': '%(nSchemata)d schemas selected',
                           'show_select_all_button': not self.use_catalogs,
                           'show_unselect_all_button': True,
                         },
        }
        
        # Update the ui settings dict with the custom settings supplied by the user (if any):
        if isinstance(ui_settings, dict):
            for key, value in ui_settings.iteritems():
                if key not in self.ui_settings or not isinstance(value, dict):
                    continue
                self.ui_settings[key].update(value)
        

        if self.use_catalogs:
            self._catalogs = tuple(item[0] for item in database_objects)
            self._schemata = dict(database_objects)
        else:
            self._catalogs = None
            self._schemata = database_objects

        self._schema_nodes = []
        self._catalog_nodes = []

        # Create UI:
        self.set_spacing(8)
        
        self.schema_list_tree = mforms.newTreeView(mforms.TreeDefault)
        self.schema_list_tree.set_name('Schema List')
        self.schema_list_tree.add_column(mforms.CheckColumnType, 'Include', 60, True)
        self.schema_list_tree.add_column(mforms.IconColumnType, 'Catalog/Schema' if self.use_catalogs else 'Schema', 300, False)
        self.schema_list_tree.end_columns()
        self.schema_list_tree.set_cell_edited_callback(self._schema_tree_checked)
        self.schema_list_tree.set_allow_sorting(False)
        self.add(self.schema_list_tree, True, True)

        helper_buttons_box = mforms.newBox(True)
        helper_buttons_box.set_spacing(12)

        self.select_summary_label = mforms.newLabel('')
        self.select_summary_label.set_name('Summary')
        helper_buttons_box.add(self.select_summary_label, False, True)

        if self.ui_settings['general']['show_unselect_all_button']:
            self.unselect_all_btn = mforms.newButton()
            self.unselect_all_btn.set_text('Unselect All')
            self.unselect_all_btn.add_clicked_callback(functools.partial(self._mark_all_schemata, checked=False))
            helper_buttons_box.add_end(self.unselect_all_btn, False)

        if self.ui_settings['general']['show_select_all_button']:
            self.select_all_btn = mforms.newButton()
            self.select_all_btn.set_text('Select All')
            self.select_all_btn.add_clicked_callback(functools.partial(self._mark_all_schemata, checked=True))
            helper_buttons_box.add_end(self.select_all_btn, False)


        self.add(helper_buttons_box, False, True)
        
        self._fill_schema_tree()
    def create_ui(self):
        self.content.set_spacing(4)
        self.content.add(mforms.newLabel("Review and edit migrated objects. You can manually edit the generated SQL before applying them to the target database."), False, True)
        
        hbox = mforms.newBox(True)
        self.tree_head_label = mforms.newLabel("Migrated Objects")
        hbox.add(self.tree_head_label, False, False)
        self._filter = mforms.newSelector()
        self._filter.add_items(["Migration Problems", "All Objects", "Column Mappings"])
        self._filter.add_changed_callback(self._filter_changed)
        hbox.add_end(self._filter, False, True)
        hbox.add_end(mforms.newLabel("View:"), False, False)
        self.content.add(hbox, False, True)
        
        self._no_errors_text = "No migration problems found. %d warning(s).\nUse the View pulldown menu to review all objects."
        self._no_errors = mforms.newLabel('')  # Label text will be set later when the warning count is calculated
        self._no_errors.set_style(mforms.BigStyle)
        self._no_errors.set_text_align(mforms.MiddleLeft)
        self.content.add(self._no_errors, True, True)
        
        self._tree = mforms.newTreeView(mforms.TreeDefault)
        self._tree.add_column(mforms.IconStringColumnType, "Source Object", 200, False)
        self._tree.add_column(mforms.IconStringColumnType, "Target Object", 200, True)
        self._tree.add_column(mforms.IconStringColumnType, "Migration Message", 300, False)
        self._tree.end_columns()
        self._tree.add_changed_callback(self._selection_changed)
        self.content.add(self._tree, True, True)
        self._tree.set_cell_edited_callback(self._cell_edited)

        self._all_menu = mforms.newContextMenu()
        self._all_menu.add_will_show_callback(self.all_menu_will_show)
        self._all_menu.add_check_item_with_title("Skip Object", self.skip_object, "skip_object")

        self._tree.set_context_menu(self._all_menu)

        
        self._columns = mforms.newTreeView(mforms.TreeShowColumnLines|mforms.TreeShowRowLines|mforms.TreeFlatList)
        self.COL_SOURCE_SCHEMA = self._columns.add_column(mforms.StringColumnType, "Source Schema", 100, False)
        self.COL_SOURCE_TABLE = self._columns.add_column(mforms.IconStringColumnType, "Source Table", 100, False)
        self.COL_SOURCE_COLUMN = self._columns.add_column(mforms.IconStringColumnType, "Source Column", 100, False)
        self.COL_SOURCE_TYPE = self._columns.add_column(mforms.StringColumnType, "Source Type", 100, False)
        self.COL_SOURCE_FLAGS = self._columns.add_column(mforms.StringColumnType, "Source Flags", 100, False)
        self.COL_SOURCE_NOTNULL = self._columns.add_column(mforms.CheckColumnType, "NN", 25, False)
        self.COL_SOURCE_DEFAULT = self._columns.add_column(mforms.StringColumnType, "Source Default Value", 100, False)
        self.COL_SOURCE_COLLATION = self._columns.add_column(mforms.StringColumnType, "Source Collation", 100, False)
        self.COL_TARGET_SCHEMA = self._columns.add_column(mforms.StringColumnType, "Target Schema", 100, False)
        self.COL_TARGET_TABLE = self._columns.add_column(mforms.IconStringColumnType, "Target Table", 100, False)
        self.COL_TARGET_COLUMN = self._columns.add_column(mforms.IconStringColumnType, "Target Column", 100, True)
        self.COL_TARGET_TYPE = self._columns.add_column(mforms.StringColumnType, "Target Type", 100, True)
        self.COL_TARGET_FLAGS = self._columns.add_column(mforms.StringColumnType, "Target Flags", 100, True)
        self.COL_TARGET_AI = self._columns.add_column(mforms.CheckColumnType, "AI", 25, True)
        self.COL_TARGET_NOTNULL = self._columns.add_column(mforms.CheckColumnType, "NN", 25, True)
        self.COL_TARGET_DEFAULT = self._columns.add_column(mforms.StringColumnType, "Target Default Value", 100, True)
        self.COL_TARGET_COLLATION = self._columns.add_column(mforms.StringColumnType, "Target Collation", 100, True)
        self.COL_MESSAGE = self._columns.add_column(mforms.IconStringColumnType, "Migration Message", 300, False)
        self._columns.end_columns()
        self._columns.set_allow_sorting(True)
        self._columns.set_selection_mode(mforms.TreeSelectMultiple)
        self._columns.add_changed_callback(self._selection_changed)
        self.content.add(self._columns, True, True)
        self._columns.set_cell_edited_callback(self._columns_cell_edited)
        self._columns.show(False)
        
        self._menu = mforms.newContextMenu()
        self._menu.add_will_show_callback(self.menu_will_show)
        self._menu.add_item_with_title("Set Target Type of Selected Columns...", self.set_target_type, "set_target_type")
        self._menu.add_item_with_title("Find and Replace Target Type...", self.replace_target_type, "replace_target_type")
        self._menu.add_item_with_title("Find and Replace Target Flags...", self.replace_target_flags, "replace_target_flags")
        self._menu.add_item_with_title("Find and Replace Target Default Value...", self.replace_target_default_value, "replace_target_default_value")
        self._menu.add_item_with_title("Find and Replace Target Collation...", self.replace_target_collation, "replace_target_collation")
        self._columns.set_context_menu(self._menu)
        
        self.help_label = mforms.newLabel("You can rename target schemas and tables, and change column definitions by clicking them once selected.")
        self.help_label.set_style(mforms.SmallStyle)
        self.content.add(self.help_label, False, True)
        
        self._advbox = mforms.newPanel(mforms.TitledBoxPanel)
        self._advbox.set_title("SQL CREATE Script for Selected Object")
        box = mforms.newBox(True)
        self._code = mforms.newCodeEditor()
        self._code.set_language(mforms.LanguageMySQL)
        self._code.add_changed_callback(self._code_changed)
        box.add(self._code, True, True)
        vbox = mforms.newBox(False)
        vbox.set_padding(12)
        vbox.set_spacing(8)

        self._lock_check = mforms.newCheckBox()
        self._lock_check.set_text("Lock edited SQL")
        self._lock_check.set_tooltip("Lock the SQL code to the edited one, preventing automatic regenerations from discarding changes made directly to the SQL script.")
        self._lock_check.add_clicked_callback(self._lock_clicked)
        vbox.add(self._lock_check, False, True)

        self._comment_check = mforms.newCheckBox()
        self._comment_check.set_text("Comment out")
        self._comment_check.set_tooltip("Mark the object to be commented out on the generated script, making it not get created in the target server.")
        self._comment_check.add_clicked_callback(self._comment_clicked)
        vbox.add(self._comment_check, False, True)
        
        self._sql_outdated_label = mforms.newLabel("Code is outdated")
        self._sql_outdated_label.show(False)
        self._sql_outdated_label.set_tooltip("The locked SQL code seems to be outdated compared to a newer, automatically generated one. Unlocking the object will update it, but your changes will be lost.")
        vbox.add(self._sql_outdated_label, False, True)

        self._revert_btn = mforms.newButton()
        self._revert_btn.set_text("Discard Changes")
        vbox.add_end(self._revert_btn, False, True)
        self._revert_btn.add_clicked_callback(self._discard_clicked)

        self._apply_btn = mforms.newButton()
        self._apply_btn.set_text("Apply Changes")
        vbox.add_end(self._apply_btn, False, True)
        self._apply_btn.add_clicked_callback(self._apply_clicked)
        box.add(vbox, False, True)

        self._advbox.add(box)
        self._advbox.set_size(-1, 200)
        self._advbox_shown = True
        self.go_advanced() # toggle to hide
                
        self.content.add(self._advbox, False, True)
        
        self._filter_errors = False
        self._filter_changed()
    def __init__(self, database_objects, tree_checked_callback=lambda n:None, ui_settings={}):
        '''Constructor.
        '''
        super(DatabaseSchemaSelector, self).__init__(False)
        self.database_objects = database_objects
        self.tree_checked_callback = tree_checked_callback
      
        # Check if we should use catalogs:
        self.use_catalogs = ( isinstance(database_objects, (list, tuple)) and
                           len(database_objects) > 0 and
                           all( isinstance(item, (list, tuple)) and
                               len(item) == 2 and
                               isinstance(item[0], (str, unicode)) and
                               isinstance(item[1], (list, tuple))
                               for item in database_objects
                               )
                           )
      
      
        self.ui_settings = {
            'catalogs' : { 'icon': 'workbench.physical.Layer.16x16.png',
                           'should_expand': True,
                         },
            'schemas'  : { 'icon': 'db.Schema.16x16.png',
                         },
            'general'  : { 'summary_text': '%(nSchemata)d schemata selected',
                           'show_select_all_button': not self.use_catalogs,
                           'show_unselect_all_button': True,
                         },
        }
        
        # Update the ui settings dict with the custom settings supplied by the user (if any):
        if isinstance(ui_settings, dict):
            for key, value in ui_settings.iteritems():
                if key not in self.ui_settings or not isinstance(value, dict):
                    continue
                self.ui_settings[key].update(value)
        

        if self.use_catalogs:
            self._catalogs = tuple(item[0] for item in database_objects)
            self._schemata = dict(database_objects)
        else:
            self._catalogs = None
            self._schemata = database_objects

        self._schema_nodes = []
        self._catalog_nodes = []

        # Create UI:
        self.set_spacing(8)
        
        self.schema_list_tree = mforms.newTreeView(mforms.TreeDefault)
        self.schema_list_tree.add_column(mforms.CheckColumnType, 'Include', 60, True)
        self.schema_list_tree.add_column(mforms.IconColumnType, 'Catalog/Schema' if self.use_catalogs else 'Schema', 300, False)
        self.schema_list_tree.end_columns()
        self.schema_list_tree.set_cell_edited_callback(self._schema_tree_checked)
        self.schema_list_tree.set_allow_sorting(False)
        self.add(self.schema_list_tree, True, True)

        helper_buttons_box = mforms.newBox(True)
        helper_buttons_box.set_spacing(12)

        self.select_summary_label = mforms.newLabel('')
        helper_buttons_box.add(self.select_summary_label, False, True)

        if self.ui_settings['general']['show_unselect_all_button']:
            self.unselect_all_btn = mforms.newButton()
            self.unselect_all_btn.set_text('Unselect All')
            self.unselect_all_btn.add_clicked_callback(functools.partial(self._mark_all_schemata, checked=False))
            helper_buttons_box.add_end(self.unselect_all_btn, False)

        if self.ui_settings['general']['show_select_all_button']:
            self.select_all_btn = mforms.newButton()
            self.select_all_btn.set_text('Select All')
            self.select_all_btn.add_clicked_callback(functools.partial(self._mark_all_schemata, checked=True))
            helper_buttons_box.add_end(self.select_all_btn, False)


        self.add(helper_buttons_box, False, True)
        
        self._fill_schema_tree()