def create_ui(self):
        self.content.set_padding(20)

        self.content.add(mforms.newLabel('''Select the connection for the source MySQL server where databases will be copied from
and the destination server where they should be copied to.'''), False, True)

        source_panel = mforms.newPanel(mforms.TitledBoxPanel)
        source_panel.set_title('Source MySQL Server')

        box = mforms.newBox(False)
        box.set_spacing(12)
        box.set_padding(8)
        box.add(mforms.newLabel('Select the connection for the source MySQL server instance'), False, True)
        
        source_hbox = mforms.newBox(True)
        source_hbox.set_spacing(8)
        source_hbox.add(mforms.newLabel('Source Connection:'), False, True)
        self.source_selector = mforms.newSelector()
        source_hbox.add(self.source_selector, True, True)
        box.add(source_hbox, False, True)

        self.source_connection_status = mforms.newLabel('')
        self.source_connection_status.set_color('#aa3333')
        box.add(self.source_connection_status, True, True)
        self.source_selector.add_changed_callback(functools.partial(self.selector_changed, label=self.source_connection_status, selector=self.source_selector))

        source_panel.add(box)
        self.content.add(source_panel, False, True)

        target_panel = mforms.newPanel(mforms.TitledBoxPanel)
        target_panel.set_title('Destination MySQL Server')

        tbox = mforms.newBox(False)
        tbox.set_spacing(12)
        tbox.set_padding(8)
        tbox.add(mforms.newLabel('Select the connection object for the destination MySQL server instance'), False, True)
        
        target_hbox = mforms.newBox(True)
        target_hbox.set_spacing(8)
        target_hbox.add(mforms.newLabel('Target Connection:'), False, True)
        self.target_selector = mforms.newSelector()
        target_hbox.add(self.target_selector, True, True)
        tbox.add(target_hbox, False, True)

        self.target_connection_status = mforms.newLabel('')
        self.target_connection_status.set_color('#aa3333')
        tbox.add(self.target_connection_status, True, True)
        self.target_selector.add_changed_callback(functools.partial(self.selector_changed, label=self.target_connection_status, selector=self.target_selector))
        
        target_panel.add(tbox)
        self.content.add(target_panel, False, True)

        self.advanced_button.set_text('Test Connections')

        self.back_button.set_enabled(False)

        self.load_connections()
 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)
     
     sel.add_items(type_items.values())
     for i, v in enumerate(type_items.values()):
         if row['type'] in v:
             sel.set_selected(i)
             break
     
     sel.add_changed_callback(lambda: sel_changed(sel, row))
     return sel
Esempio n. 3
0
    def create_dropdownbox(self, name, ctrl_def, ctype):
      items = None
      if 'choice' in ctrl_def:
        items = ctrl_def['choice']

      style = SelectorPopup
      if ctype == 'dropdownboxentry':
        style = SelectorCombobox
      dropbox = newSelector(style)

      if type(items) is str:
        if items in wb_admin_config_file_be.pysource:
          code = wb_admin_config_file_be.pysource[items]
          result = eval(code)
          items = []
          for item in result.split(','):
            item = item.strip(" \t")
            items.append(item)

      for i in items:
        dropbox.add_item(i)
      dropbox.set_enabled(False)

      if ctrl_def.has_key('default'):
        default = ctrl_def['default']
        idx = 0
        for i in items:
          if i == default:
            dropbox.set_selected(idx)
          idx += 1

      dropbox.add_changed_callback(lambda: self.control_action(name))

      return (dropbox, items)
 def create_ui(self):
     self.suspend_layout()
     self.set_spacing(16)
     
     self.simple_export_box = mforms.newBox(False)
     self.simple_export_box.set_spacing(16)
     
     label = mforms.newLabel("Select source table for export.")
     label.set_style(mforms.BoldInfoCaptionStyle)
     self.simple_export_box.add(label, False, True)
     
     self.source_table_sel = mforms.newSelector()
     self.source_table_sel.set_size(self.get_width(), -1)
     self.preload_existing_tables()
     sorted_keys = self.table_list.keys()
     sorted_keys.sort()
     self.source_table_sel.add_items(sorted_keys)
     table_name = "%s.%s" % (self.main.source_table['schema'], self.main.source_table['table'])
     if table_name in self.table_list.keys():
         self.source_table_sel.set_selected(sorted_keys.index(table_name))
     self.source_table_sel.add_changed_callback(lambda selector = self.source_table_sel: self.source_table_changed(selector.get_string_value()))
     self.simple_export_box.add(self.source_table_sel, False, True)
     
     self.simple_export = SimpleTabExport(self.main.editor, self)
     self.simple_export_box.add(self.simple_export, True, True)
     self.content.add(self.simple_export_box, True, True)
     
     self.advanced_export = AdvancedTabExport(self.main.editor, self)
     self.advanced_export.show(False)
     self.content.add(self.advanced_export, True, True)
     self.resume_layout()
     
     self.preload_table_info()
 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
 def add_remove_behavior_button(self):
   tBox = PropelForm.spaced_box(True)
   self.widgets['selectBehaviors'] = mforms.newSelector(mforms.SelectorPopup)
   self.widgets['selectBehaviors'].add_items(sorted(PropelBehavior.getBehaviorsDict(self.widgets['extra_behaviors_path'].get_string_value()).keys()))
   tBox.add(self.widgets['selectBehaviors'], False, True)
   addBehavior = mforms.newButton()
   addBehavior.set_text("add selected behavior to selected table")
   addBehavior.add_clicked_callback(lambda: self.add_behavior())
   tBox.add(addBehavior, False, True)
   removeBehavior = mforms.newButton()
   removeBehavior.set_text("remove this behavior")
   removeBehavior.add_clicked_callback(lambda: self.remove_behavior())
   tBox.add(removeBehavior, False, True)
   self.add_end(tBox, False, True)
 def add_remove_behavior_button(self):
   tBox = PropelForm.spaced_box(True)
   self.widgets['selectBehaviors'] = mforms.newSelector(mforms.SelectorPopup)
   self.widgets['selectBehaviors'].add_items(PropelBehavior.fields['name']['items'])
   tBox.add(self.widgets['selectBehaviors'], False, True)
   addBehavior = mforms.newButton()
   addBehavior.set_text("add selected behavior to selected table")
   addBehavior.add_clicked_callback(lambda: self.add_behavior())
   tBox.add(addBehavior, False, True)
   removeBehavior = mforms.newButton()
   removeBehavior.set_text("remove this behavior")
   removeBehavior.add_clicked_callback(lambda: self.remove_behavior())
   tBox.add(removeBehavior, False, True)
   self.add_end(tBox, False, True)
Esempio n. 8
0
 def select_box(self, grid_name, edited_row, edited_col, fieldName):
   tBox = mforms.Form(None, mforms.FormResizable)
   tBox.set_title("Propel Choice")
   tBox.set_size(self.defaults['popup_width'], self.defaults['popup_height'])
   tBox.set_position(self.defaults['popup_x'], self.defaults['popup_y'])
   box = mforms.newBox(False)
   list = mforms.newSelector(mforms.SelectorPopup)
   list.add_items(self.fields[fieldName]['items'])
   list.set_selected(list.index_of_item_with_title(self.widgets[grid_name].get_string(edited_row, edited_col)))
   box.add(list, False, True)
   ok = mforms.newButton()
   ok.set_text("select this value")
   ok.add_clicked_callback(lambda: self.edit_field(edited_row, edited_col, list.get_string_value()))
   box.add_end(ok, False, True)
   tBox.set_content(box)
   tBox.run_modal(ok, None)
    def load_module_options(self):
        self.suspend_layout()
        
        self.optpanel.show(False)
        if self.optbox:
            self.optpanel.remove(self.optbox)
        if self.active_module and len(self.active_module.options) != 0:
            def set_text_entry(field, output):
                txt = field.get_string_value().encode('utf-8').strip()
                if len(txt) == 0:
                    operator.setitem(output, 'value', None)
                elif len(txt) == 1:
                    operator.setitem(output, 'value', txt)
                else:
                    field.set_value("")
                    mforms.Utilities.show_error(self.main.title, "Due to the nature of this wizard, you can't use unicode characters in this place, as also only one character is allowed.","Ok","","")
                    

            def set_selector_entry(selector, output):
                operator.setitem(output, 'value', output['opts'][str(selector.get_string_value())])
            
            self.optbox = mforms.newBox(False)
            self.optbox.set_spacing(8)
            self.optbox.set_padding(8)
            for name, opts in self.active_module.options.iteritems():
                label_box = mforms.newBox(True)
                label_box.set_spacing(8)
                label_box.add(mforms.newLabel(opts['description']), False, False)
                if opts['type'] == 'text':
                    opt_val = mforms.newTextEntry()
                    opt_val.set_size(35, -1)
                    opt_val.set_value(opts['value'])
                    opt_val.add_changed_callback(lambda field = opt_val, output = opts: set_text_entry(field, output))
                    label_box.add_end(opt_val, False, False)
                if opts['type'] == 'select':
                    opt_val = mforms.newSelector()
                    opt_val.set_size(75, -1)
                    opt_val.add_items([v for v in opts['opts']])
                    opt_val.set_selected(opts['opts'].values().index(opts['value']))
                    opt_val.add_changed_callback(lambda selector = opt_val, output = opts: set_selector_entry(selector, output))
                    label_box.add_end(opt_val, False, False)
                self.optbox.add(label_box, False, False)
            self.optpanel.add(self.optbox)
            self.optpanel.show(True)        
        self.resume_layout()
Esempio n. 10
0
 def addSelectInput (self,label,options,saveObject,objectKey,callback):      
     curBox=self.createBaseInput(label)
     input=mforms.newSelector()
     curBox.add(input,False,False)
     #input.set_size(300,20)
     input.add_items(options)
     if saveObject != None:      
       if saveObject.has_key(objectKey):
            if type(saveObject[objectKey]) is dict or type(saveObject[objectKey]) is grt.Dict:
               val=saveObject[objectKey].values()[0]
            else:
               val=saveObject[objectKey]
            input.set_value(val)
           
     if callback==None:          
         input.add_changed_callback(lambda:self.changeTextValue(input,saveObject,objectKey))      
     else:
         input.add_changed_callback(lambda: callback(input,saveObject,objectKey))
    def pack_to_top(self):
      self.suspend_layout()
      self.main_view.ui_profile.apply_style(self, 'page')

      #if self.server_profile.admin_enabled:
      self.file_name_ctrl = newTextEntry()
      sys_config_path = self.server_profile.config_file_path
      if sys_config_path is None:
        sys_config_path = ""
      self.file_name_ctrl.set_value(sys_config_path)
      self.file_name_ctrl.set_size(300, -1)
      self.file_name_ctrl.set_read_only(True)

      self.section_ctrl = newSelector()
      self.section_ctrl.set_size(150, -1)

      #spacer = newPanel(mforms.TransparentPanel)
      #spacer.set_size(100, 10)

      self.bottom_box = newBox(True)

      accept_btn = newButton()
      accept_btn.set_text("Apply ...")

      discard_btn = newButton()
      discard_btn.set_text("Discard")

      #self.add(self.search_panel, False, True)
      self.add(self.tab_view, True, True)
      self.add(self.bottom_box, False, False)

      self.bottom_box.add(newLabel("Configuration File:"), False, True)
      self.bottom_box.add(self.file_name_ctrl, True, True)
      self.bottom_box.add(self.section_ctrl, False, True)

      Utilities.add_end_ok_cancel_buttons(self.bottom_box, accept_btn, discard_btn)

      self.bottom_box.set_spacing(8)
      self.bottom_box.set_padding(12)

      accept_btn.add_clicked_callback(self.config_apply_changes_clicked)
      discard_btn.add_clicked_callback(self.config_discard_changes_clicked)

      self.resume_layout()
    def setup_info_table(self, info_table, info, params):
        info_table.set_row_count(len(info)+1)
        for i, item in enumerate(info):
            (label, value_source) = item
            if callable(value_source):
                value = value_source(*params)
            else:
                value = value_source

            if self.controls.has_key(label):
                info_table.remove(self.controls[label][0])
            else:
                info_table.add(mforms.newLabel(label), 0, 1, i, i+1, mforms.VFillFlag|mforms.HFillFlag)
            is_gtid_mode_setable = label == 'GTID Mode:' and self.ctrl_be.target_version >= Version(5, 7, 6)
            if type(value) is bool or value is None:
                b = StateIcon()
                b.set_state(value)
                info_table.add(b, 1, 2, i, i+1, mforms.HFillFlag | mforms.HExpandFlag | mforms.VFillFlag)
                self.controls[label] = (b, value_source)
            elif type(value) is tuple:
                b = StateIcon()
                b.set_state(value[0])
                if value[0] and value[1]:
                    b.set_text(value[1])
                info_table.add(b, 1, 2, i, i+1, mforms.HFillFlag | mforms.HExpandFlag | mforms.VFillFlag)
                self.controls[label] = (b, value_source)
            else:
                if is_gtid_mode_setable:
                    self.gtid_mode_selector = mforms.newSelector()
                    self.gtid_mode_selector.add_items(["OFF", "UPGRADE_STEP_1", "UPGRADE_STEP_1", "ON"])
                    self.gtid_mode_selector.set_selected(self.gtid_mode_selector.index_of_item_with_title(value_source))
                    self.gtid_mode_selector.add_changed_callback(self._gtid_mode_changed)
                    info_table.add(self.gtid_mode_selector, 1, 2, i, i + 1, mforms.HFillFlag | mforms.HExpandFlag | mforms.VFillFlag)
                    self.controls[label] = (self.gtid_mode_selector, value_source)
                else:
                    l2 = mforms.newLabel(value or "")
                    l2.set_style(mforms.BoldStyle)
                    l2.set_color("#1c1c1c")
                    info_table.add(l2, 1, 2, i, i + 1, mforms.HFillFlag | mforms.HExpandFlag | mforms.VFillFlag)
                    self.controls[label] = (l2, value_source)
        info_table.add(mforms.newLabel(""), 0, 1, len(info), len(info)+1, mforms.HFillFlag) # blank space
        return info_table
Esempio n. 13
0
 def addTableSelector(self,label,saveObject,objectKey,callback):
   curBox=self.createBaseInput(label)
   input=mforms.newSelector()
   l=[]
   for x in grt.root.wb.doc.physicalModels[0].catalog.schemata[0].tables:
       if x.customData!=None and x.customData['MODULE']!=None:            
           l.append(x.customData['MODULE']+'\\'+x.name)
       else: 
           l.append(x.name)
   l.sort()
   
   l=['None']+l
   input.add_items(l)    
       
   if saveObject!=None:
       if saveObject.has_key(objectKey)==True and saveObject[objectKey] in l:            
           input.set_value(saveObject[objectKey])
   if callback==None :
     callback=self.changeTextValue
   input.add_changed_callback(lambda:callback(input,saveObject,objectKey));
   curBox.add(input,False,False)
Esempio n. 14
0
 def __init__(self,c,l,v,o,k):
   self.c=c
   self.l=l
   self.v=v
   self.o=o
   self.k=k
   self.container=mforms.newBox(False)
   self.buttonContainer=mforms.newBox(True)
   self.container.add(self.buttonContainer, False, True)
   self.buttons={}
   for k in v:
     self.buttons[k]=CustomMultipleSelectorButton(self.buttonContainer,self,k)
   selContainer=mforms.newBox(True)
   self.container.add(selContainer,False,True)
   
   self.selector=mforms.newSelector()
   selContainer.add(self.selector,False,True)
   selectButton=mforms.newButton();
   selectButton.add_clicked_callback(lambda:self.selectCurrent())
   selectButton.set_text('Add');
   selContainer.add(selectButton,False,False)
   self.loadSelector()    
   self.c.add(self.container,False,True)
        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
Esempio n. 16
0
    def create_ui(self):
        self.set_spacing(16)
        format_box = mforms.newBox(True)
        format_box.set_spacing(8)
        format_box.add(
            mforms.newLabel("Detected file format: %s" % self.input_file_type),
            False, True)
        if len(self.active_module.options) != 0:
            advanced_opts_btn = mforms.newButton(mforms.ToolButton)
            advanced_opts_btn.set_size(-1, 16)
            advanced_opts_btn.set_icon(
                mforms.App.get().get_resource_path("admin_option_file.png"))
            advanced_opts_btn.add_clicked_callback(
                lambda: self.optpanel.show(False)
                if self.optpanel.is_shown() else self.optpanel.show(True))
            format_box.add(advanced_opts_btn, False, True)

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

        if len(self.active_module.options) != 0:
            self.optpanel = mforms.newPanel(mforms.TitledBoxPanel)
            self.optpanel.set_title("Options:")

            def set_text_entry(field, output):
                txt = field.get_string_value().encode('utf-8').strip()
                if len(txt) == 0:
                    operator.setitem(output, 'value', None)
                    mforms.Utilities.add_timeout(
                        0.1, self.call_create_preview_table)
                elif len(txt) == 1:
                    operator.setitem(output, 'value', txt)
                    mforms.Utilities.add_timeout(
                        0.1, self.call_create_preview_table)
                else:
                    field.set_value("")
                    mforms.Utilities.show_error(
                        "Import Wizard",
                        "Due to the nature of this wizard, you can't use unicode characters in this place, as only one character is allowed.",
                        "Ok", "", "")

            def set_selector_entry(selector, output):
                operator.setitem(
                    output, 'value',
                    output['opts'][str(selector.get_string_value())])
                mforms.Utilities.add_timeout(0.1,
                                             self.call_create_preview_table)

            box = mforms.newBox(False)
            box.set_spacing(8)
            box.set_padding(8)
            for name, opts in self.active_module.options.iteritems():
                label_box = mforms.newBox(True)
                label_box.set_spacing(8)
                label_box.add(mforms.newLabel(opts['description']), False,
                              True)
                if opts['type'] == 'text':
                    opt_val = mforms.newTextEntry()
                    opt_val.set_size(35, -1)
                    opt_val.set_value(opts['value'])
                    opt_val.add_changed_callback(
                        lambda field=opt_val, output=opts: set_text_entry(
                            field, output))
                    label_box.add_end(opt_val, False, True)
                    self.opts_mapping[name] = lambda val: opt_val.set_value(val
                                                                            )
                if opts['type'] == 'select':
                    opt_val = mforms.newSelector()
                    opt_val.set_size(75, -1)
                    opt_val.add_items([v for v in opts['opts']])
                    opt_val.set_selected(opts['opts'].values().index(
                        opts['value']))
                    opt_val.add_changed_callback(
                        lambda selector=opt_val, output=opts:
                        set_selector_entry(selector, output))
                    self.opts_mapping[name] = lambda input, values=opts[
                        'opts'].values(): opt_val.set_selected(
                            values.index(input) if input in values else 0)
                    label_box.add_end(opt_val, False, True)
                box.add(label_box, False, True)
            self.optpanel.add(box)
            self.content.add(self.optpanel, False, True)
            self.optpanel.show(False)

        if self.input_file_type == 'csv':
            # We show encoding box only for csv as json can be only utf-8, utf-16 according to rfc
            self.encoding_box = mforms.newBox(True)
            self.encoding_box.set_spacing(16)
            self.encoding_box.add(mforms.newLabel("Encoding: "), False, True)
            self.encoding_sel = mforms.newSelector()
            self.encoding_sel.set_size(250, -1)
            self.encoding_box.add(self.encoding_sel, False, True)

            for i, e in enumerate(self.encoding_list):
                self.encoding_sel.add_item(e)
                if self.encoding_list[e] == 'utf-8':
                    self.encoding_sel.set_selected(i)
            self.encoding_sel.add_changed_callback(self.encoding_changed)
            self.content.add(self.encoding_box, False, True)

        self.table_preview_box = mforms.newBox(False)
        self.table_preview_box.set_spacing(16)
        self.preview_table = None
        self.content.add(self.table_preview_box, True, True)

        self.column_caption = mforms.newPanel(mforms.BorderedPanel)
        self.column_caption.set_title("Columns:")
        self.column_caption.set_size(-1, 100)
        self.column_scroll = mforms.newScrollPanel(0)
        self.column_caption.add(self.column_scroll)
        self.table_preview_box.add(self.column_caption, True, True)

        extra_opts = mforms.newBox(False)
        extra_opts.set_spacing(16)

        self.ds_box = mforms.newBox(True)
        self.ds_box.set_spacing(8)
        extra_opts.add(self.ds_box, False, True)

        self.df_box = mforms.newBox(True)
        self.df_box.set_spacing(8)
        extra_opts.add_end(self.df_box, False, True)

        self.ds_box.add(mforms.newLabel("Decimal Separator:"), False, True)
        self.ds_entry = mforms.newTextEntry()
        self.ds_entry.set_value('.')
        self.ds_entry.set_size(30, -1)
        self.ds_box.add(self.ds_entry, False, True)
        self.ds_box.show(False)

        self.df_box.add(
            self.make_label_with_tooltip(
                "Date format: ",
                "Expects string pattern with the date format.\n"
                "Default format is: %Y-%m-%d %H:%M:%S\n"
                "\nCommon used options:\n"
                "\t%d is the day number\n"
                "\t%m is the month number\n"
                "\t%y is the four digits year number\n"
                "\t%H is the hour number\n"
                "\t%M is the minute number\n"
                "\t%S is the second number\n\n"
                "More formats can be found under the following location:\n"
                "https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior"
            ), False, True)
        self.df_entry = mforms.newTextEntry()
        self.df_entry.set_value("%Y-%m-%d %H:%M:%S")
        self.df_entry.set_size(200, -1)
        self.df_box.add(self.df_entry, False, True)
        self.df_box.show(False)

        self.content.add_end(extra_opts, False, True)
Esempio n. 17
0
    def create_ui(self):
        self.set_spacing(16)

        label = mforms.newLabel(
            "Select destination table and additional options.")
        label.set_style(mforms.BoldInfoCaptionStyle)
        self.content.add(label, False, True)

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

        existing_table_box = mforms.newBox(True)
        existing_table_box.set_spacing(8)
        self.existing_table_radio = mforms.newRadioButton(1)
        self.existing_table_radio.set_text("Use existing table:")
        self.existing_table_radio.add_clicked_callback(self.radio_click)
        if 'table' in self.main.destination_table and self.main.destination_table[
                'table'] is not None:
            self.existing_table_radio.set_active(True)
        existing_table_box.add(self.existing_table_radio, False, True)

        self.destination_table_sel = mforms.newSelector()
        self.destination_table_sel.set_size(75, -1)
        existing_table_box.add(self.destination_table_sel, True, True)
        table_destination_box.add(existing_table_box, False, True)

        new_table_box = mforms.newBox(True)
        new_table_box.set_spacing(8)
        self.new_table_radio = mforms.newRadioButton(1)
        self.new_table_radio.set_text("Create new table: ")
        self.new_table_radio.add_clicked_callback(self.radio_click)
        if 'table' not in self.main.destination_table or self.main.destination_table[
                'table'] is None:
            self.new_table_radio.set_active(True)

        new_table_box.add(self.new_table_radio, False, True)
        self.destination_database_sel = mforms.newSelector()
        self.destination_database_sel.set_size(120, -1)
        new_table_box.add(self.destination_database_sel, False, True)
        new_table_box.add(mforms.newLabel("."), False, True)
        self.new_table_name = mforms.newTextEntry()
        new_table_box.add_end(self.new_table_name, True, True)
        table_destination_box.add(new_table_box, True, True)

        def set_trunc(sender):
            global truncate_table
            truncate_table = sender.get_active()

        self.truncate_table_cb = mforms.newCheckBox()
        self.truncate_table_cb.set_text("Truncate table before import")
        self.truncate_table_cb.set_active(truncate_table)
        self.truncate_table_cb.add_clicked_callback(
            lambda sender=self.truncate_table_cb: set_trunc(sender))
        table_destination_box.add(self.truncate_table_cb, False, True)

        def set_drop(sender):
            global drop_table
            drop_table = sender.get_active()

        self.drop_table_cb = mforms.newCheckBox()
        self.drop_table_cb.set_text("Drop table if exists")
        self.drop_table_cb.set_active(drop_table)
        self.drop_table_cb.add_clicked_callback(
            lambda sender=self.drop_table_cb: set_drop(sender))
        if self.existing_table_radio.get_active():
            self.drop_table_cb.show(False)
            self.truncate_table_cb.show(True)
        else:
            self.drop_table_cb.show(True)
            self.truncate_table_cb.show(False)
        table_destination_box.add(self.drop_table_cb, False, True)

        self.content.add(table_destination_box, False, True)
    def setup_info_table(self, info_table, info, params):
        info_table.set_row_count(len(info) + 1)
        for i, item in enumerate(info):
            (label, value_source) = item
            if callable(value_source):
                value = value_source(*params)
            else:
                value = value_source

            if self.controls.has_key(label):
                info_table.remove(self.controls[label][0])
            else:
                l = mforms.newLabel(label + ":")
                l.set_name(label)
                info_table.add(l, 0, 1, i, i + 1,
                               mforms.VFillFlag | mforms.HFillFlag)
            is_gtid_mode_setable = label == 'GTID Mode:' and self.ctrl_be.target_version >= Version(
                5, 7, 6)
            if type(value) is bool or value is None:
                b = StateIcon()
                b.set_name(label + " Value")
                b.set_state(value)
                info_table.add(
                    b, 1, 2, i, i + 1,
                    mforms.HFillFlag | mforms.HExpandFlag | mforms.VFillFlag)
                self.controls[label] = (b, value_source)
            elif type(value) is tuple:
                b = StateIcon()
                b.set_name(label + " Value")
                b.set_state(value[0])
                if value[0] and value[1]:
                    b.set_text(value[1])
                info_table.add(
                    b, 1, 2, i, i + 1,
                    mforms.HFillFlag | mforms.HExpandFlag | mforms.VFillFlag)
                self.controls[label] = (b, value_source)
            else:
                if is_gtid_mode_setable:
                    self.gtid_mode_selector = mforms.newSelector()
                    self.gtid_mode_selector.set_name(label + " Value")
                    self.gtid_mode_selector.add_items(
                        ["OFF", "UPGRADE_STEP_1", "UPGRADE_STEP_1", "ON"])
                    self.gtid_mode_selector.set_selected(
                        self.gtid_mode_selector.index_of_item_with_title(
                            value_source))
                    self.gtid_mode_selector.add_changed_callback(
                        self._gtid_mode_changed)
                    info_table.add(
                        self.gtid_mode_selector, 1, 2, i, i + 1,
                        mforms.HFillFlag | mforms.HExpandFlag
                        | mforms.VFillFlag)
                    self.controls[label] = (self.gtid_mode_selector,
                                            value_source)
                else:
                    l2 = mforms.newLabel(value or "")
                    l2.set_name(label + " Value")
                    l2.set_style(mforms.BoldStyle)
                    l2.set_color("#1c1c1c")
                    info_table.add(
                        l2, 1, 2, i, i + 1, mforms.HFillFlag
                        | mforms.HExpandFlag | mforms.VFillFlag)
                    self.controls[label] = (l2, value_source)
        info_table.add(mforms.newLabel(""), 0, 1, len(info),
                       len(info) + 1, mforms.HFillFlag)  # blank space
        return info_table
Esempio n. 19
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)
    def create_ui(self):
        dprint_ex(4, "Enter")
        self.suspend_layout()

        self.heading = make_panel_header("title_connections.png", self.instance_info.name, "Client Connections")
        self.add(self.heading, False, False)

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

        self.connection_list = newTreeNodeView(mforms.TreeDefault|mforms.TreeFlatList|mforms.TreeAltRowColors)
        self.connection_list.add_column(mforms.LongIntegerColumnType, "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.LongIntegerColumnType, "Time", 60, False)
        self.connection_list.add_column(mforms.StringColumnType, "State", 80, False)
        self.info_column = 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)
        
        box.set_spacing(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"))
        
        refresh_label = newLabel("Refresh Rate:")
        box.add(refresh_label, False, True)

        self._menu = mforms.newContextMenu()
        self._menu.add_item_with_title("Copy Info", self.copy_selected, "copy_selected")
        self._menu.add_item_with_title("Show in Editor", self.edit_selected, "edit_selected")
        self.connection_list.set_context_menu(self._menu)

        
        self.refresh_values = [0.5, 1, 2, 3, 4, 5, 10, 15, 30]
        self.refresh_values_size = len(self.refresh_values)
        
        self.refresh_selector = newSelector()
        self.refresh_selector.set_size(100,-1)
        
        for s in self.refresh_values:
            self.refresh_selector.add_item(str(s) + " seconds")
        
        self.refresh_selector.add_item("Don't Refresh")
        
        refresh_rate_index = grt.root.wb.options.options.get('Administrator:refresh_connections_rate_index', 9)
        self.refresh_selector.set_selected(refresh_rate_index)
        self.update_refresh_rate()
        self.refresh_selector.add_changed_callback(weakcb(self, "update_refresh_rate"))
        box.add(self.refresh_selector, False, True)

        self.hide_sleep_connections = newCheckBox()
        self.hide_sleep_connections.set_text('Hide sleeping connections')
        self.hide_sleep_connections.add_clicked_callback(self.refresh)
        box.add(self.hide_sleep_connections, False, True)
        
        self.add(box, False, True)
        
        self.resume_layout()
        
        self.connection_selected()
        dprint_ex(4, "Leave")
    def create_ui(self):
        dprint_ex(4, "Enter")
        self.suspend_layout()

        self.create_basic_ui("title_connections.png", "Client Connections")

        if self.new_processlist():
            widths = grt.root.wb.state.get("wb.admin:ConnectionListColumnWidthsPS", None)
        else:
            widths = grt.root.wb.state.get("wb.admin:ConnectionListColumnWidths", None)
        if widths:
            column_widths = [int(i) for i in widths.split(",")]
        else:
            column_widths = None

        self.connection_box = mforms.newBox(True)
        self.connection_box.set_spacing(8)
        self.connection_list = newTreeNodeView(mforms.TreeDefault|mforms.TreeFlatList|mforms.TreeAltRowColors)
        self.connection_list.set_selection_mode(mforms.TreeSelectMultiple)
        self.connection_list.add_column_resized_callback(self.column_resized)
        for i, (field, type, caption, width) in enumerate(self.columns):
            if column_widths and i < len(column_widths):
                width = column_widths[i]
            self.connection_list.add_column(type, caption, width, False)

        self.connection_list.end_columns()
        self.connection_list.set_allow_sorting(True)
        
        self.connection_list.add_changed_callback(weakcb(self, "connection_selected"))

        self.connection_box.add(self.connection_list, True, True)

        info_table = mforms.newTable()
        info_table.set_row_count(2)
        info_table.set_column_count(5)
        info_table.set_row_spacing(4)
        info_table.set_column_spacing(20)

        info_table.add(self.create_labeled_info("Threads Connected:", "lbl_Threads_connected"),                     0, 1, 0, 1, mforms.HFillFlag)
        info_table.add(self.create_labeled_info("Threads Running:", "lbl_Threads_running"),                          1, 2, 0, 1, mforms.HFillFlag)
        info_table.add(self.create_labeled_info("Threads Created:", "lbl_Threads_created"),                         2, 3, 0, 1, mforms.HFillFlag)
        info_table.add(self.create_labeled_info("Threads Cached:", "lbl_Threads_cached"),                           3, 4, 0, 1, mforms.HFillFlag)
        info_table.add(self.create_labeled_info("Rejected (over limit):", "lbl_Connection_errors_max_connections"), 4, 5, 0, 1, mforms.HFillFlag)

        info_table.add(self.create_labeled_info("Total Connections:", "lbl_Connections"),                           0, 1, 1, 2, mforms.HFillFlag)
        info_table.add(self.create_labeled_info("Connection Limit:", "lbl_max_connections"),                        1, 2, 1, 2, mforms.HFillFlag)
        info_table.add(self.create_labeled_info("Aborted Clients:", "lbl_Aborted_clients"),                         2, 3, 1, 2, mforms.HFillFlag)
        info_table.add(self.create_labeled_info("Aborted Connections:", "lbl_Aborted_connects"),                    3, 4, 1, 2, mforms.HFillFlag)
        info_table.add(self.create_labeled_info("Errors:", "lbl_errors", "tooltip_errors"),                         4, 5, 1, 2, mforms.HFillFlag)

        self.info_table = info_table
        self.add(info_table, False, True)

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


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

        box.set_spacing(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(s)")
        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(s)")
        box.add_end(self.killq_button, False, True)
        self.killq_button.add_clicked_callback(weakcb(self, "kill_query"))
        
        refresh_label = newLabel("Refresh Rate:")
        box.add(refresh_label, False, True)

        self._menu = mforms.newContextMenu()
        self._menu.add_will_show_callback(self.menu_will_show)
        self.connection_list.set_context_menu(self._menu)

        
        self.refresh_values = [0.5, 1, 2, 3, 4, 5, 10, 15, 30]
        self.refresh_values_size = len(self.refresh_values)
        
        self.refresh_selector = newSelector()
        self.refresh_selector.set_size(100,-1)
        
        for s in self.refresh_values:
            self.refresh_selector.add_item(str(s) + " seconds")
        
        self.refresh_selector.add_item("Don't Refresh")
        
        refresh_rate_index = grt.root.wb.options.options.get('Administrator:refresh_connections_rate_index', 9)
        self.refresh_selector.set_selected(refresh_rate_index)
        self.update_refresh_rate()
        self.refresh_selector.add_changed_callback(weakcb(self, "update_refresh_rate"))
        box.add(self.refresh_selector, False, True)

        self.check_box = newBox(True)
        self.check_box.set_spacing(12)

        self.hide_sleep_connections = newCheckBox()
        self.hide_sleep_connections.set_text('Hide sleeping connections')
        self.hide_sleep_connections.add_clicked_callback(self.refresh)
        self.hide_sleep_connections.set_tooltip('Remove connections in the Sleeping state from the connection list.')
        self.check_box.add(self.hide_sleep_connections, False, True)

        self.mdl_locks_page = None
        self._showing_extras = False
        if self.new_processlist():
            self.hide_background_threads = newCheckBox()
            self.hide_background_threads.set_active(True)
            self.hide_background_threads.set_text('Hide background threads')
            self.hide_background_threads.set_tooltip('Remove background threads (internal server threads) from the connection list.')
            self.hide_background_threads.add_clicked_callback(self.refresh)
            self.check_box.add(self.hide_background_threads, False, True)
            
            self.truncate_info = newCheckBox()
            self.truncate_info.set_active(True)
            self.truncate_info.set_text('Don\'t load full thread info')
            self.truncate_info.set_tooltip('Toggle whether to load the entire query information for all connections or just the first 255 characters.\nEnabling this can have a large impact in busy servers or server executing large INSERTs.')
            self.truncate_info.add_clicked_callback(self.refresh)
            self.check_box.add(self.truncate_info, False, True)

            # tab with some extra info, only available if PS exists
            self.extra_info_tab = mforms.newTabView(mforms.TabViewSystemStandard)
            self.extra_info_tab.set_size(350, -1)
            self.extra_info_tab.add_tab_changed_callback(self.extra_tab_changed)

            self.connection_details_scrollarea = mforms.newScrollPanel()
            self.connection_details = ConnectionDetailsPanel(self)
            self.connection_details_scrollarea.add(self.connection_details)
            self.details_page = self.extra_info_tab.add_page(self.connection_details_scrollarea, "Details")

            self.mdl_list_box = None
            if self.ctrl_be.target_version.is_supported_mysql_version_at_least(5, 7, 3):
                self.mdl_list_box_scrollarea = mforms.newScrollPanel()
                self.mdl_list_box = mforms.newBox(False)
                self.mdl_list_box_scrollarea.add(self.mdl_list_box)

                self.mdl_label = mforms.newLabel('Metadata locks (MDL) protect concurrent access to\nobject metadata (not table row/data locks)')
                self.mdl_list_box.add(self.mdl_label, False, True)

                label = mforms.newLabel("\nGranted Locks (and threads waiting on them)")
                label.set_style(mforms.BoldStyle)
                self.mdl_list_box.add(label, False, True)
                label = mforms.newLabel("Locks this connection currently owns and\nconnections that are waiting for them.")
                label.set_style(mforms.SmallHelpTextStyle)
                self.mdl_list_box.add(label, False, True)

                self.mdl_list_held = mforms.newTreeNodeView(mforms.TreeAltRowColors)
                self.mdl_list_held.add_column(mforms.IconStringColumnType, "Object", 130, False)
                self.mdl_list_held.add_column(mforms.StringColumnType, "Type", 100, False)
                self.mdl_list_held.add_column(mforms.StringColumnType, "Duration", 100, False)
                self.mdl_list_held.end_columns()
                self.mdl_list_held.set_size(0, 100)
                self.mdl_list_box.add(self.mdl_list_held, True, True)

                label = mforms.newLabel("\nPending Locks")
                label.set_style(mforms.BoldStyle)
                self.mdl_list_box.add(label, False, True)
                hbox = mforms.newBox(True)
                hbox.set_spacing(4)
                self.mdl_blocked_icon = mforms.newImageBox()
                self.mdl_blocked_icon.set_image(mforms.App.get().get_resource_path("message_warning.png"))
                hbox.add(self.mdl_blocked_icon, False, True)
                self.mdl_waiting_label = mforms.newLabel("Locks this connection is currently waiting for.")
                hbox.add(self.mdl_waiting_label, True, True)
                self.mdl_list_box.add(hbox, False, True)
                self.mdl_locks_page = self.extra_info_tab.add_page(self.mdl_list_box_scrollarea, "Locks")

            if self.ctrl_be.target_version.is_supported_mysql_version_at_least(5, 6, 0):
                self.attributes_list = mforms.newTreeNodeView(mforms.TreeFlatList|mforms.TreeAltRowColors)
                self.attributes_list.add_column(mforms.StringColumnType, "Attribute", 150, False)
                self.attributes_list.add_column(mforms.StringColumnType, "Value", 200, False)
                self.attributes_list.end_columns()
                self.attributes_page = self.extra_info_tab.add_page(self.attributes_list, "Attributes")

            self.connection_box.add(self.extra_info_tab, False, True)
            self.extra_info_tab.show(False)

            self.show_extras = newButton()
            self.show_extras.set_text('Show Details')
            self.show_extras.add_clicked_callback(self.toggle_extras)
            self.check_box.add_end(self.show_extras, False, True)

        self.add(self.check_box, False, True)
        
        self.resume_layout()
        
        self.connection_selected()
        
        dprint_ex(4, "Leave")
Esempio n. 22
0
    def create_ui(self):
        dprint_ex(4, "Enter")
        self.suspend_layout()

        self.create_basic_ui("title_connections.png", "Client Connections")

        if self.new_processlist():
            widths = grt.root.wb.state.get("wb.admin:ConnectionListColumnWidthsPS", None)
        else:
            widths = grt.root.wb.state.get("wb.admin:ConnectionListColumnWidths", None)
        if widths:
            column_widths = [int(i) for i in widths.split(",")]
        else:
            column_widths = None

        self.connection_box = mforms.newBox(True)
        self.connection_box.set_spacing(8)
        self.connection_list = newTreeNodeView(mforms.TreeDefault|mforms.TreeFlatList|mforms.TreeAltRowColors)
        self.connection_list.set_selection_mode(mforms.TreeSelectMultiple)
        self.connection_list.add_column_resized_callback(self.column_resized)
        for i, (field, type, caption, width) in enumerate(self.columns):
            if column_widths and i < len(column_widths):
                width = column_widths[i]
            self.connection_list.add_column(type, caption, width, False)

        self.connection_list.end_columns()
        self.connection_list.set_allow_sorting(True)
        
        self.connection_list.add_changed_callback(weakcb(self, "connection_selected"))

        self.connection_box.add(self.connection_list, True, True)

        info_table = mforms.newTable()
        info_table.set_row_count(2)
        info_table.set_column_count(5)
        info_table.set_row_spacing(4)
        info_table.set_column_spacing(20)

        info_table.add(self.create_labeled_info("Threads Connected:", "lbl_Threads_connected"),                     0, 1, 0, 1, mforms.HFillFlag)
        info_table.add(self.create_labeled_info("Threads Running:", "lbl_Threads_running"),                          1, 2, 0, 1, mforms.HFillFlag)
        info_table.add(self.create_labeled_info("Threads Created:", "lbl_Threads_created"),                         2, 3, 0, 1, mforms.HFillFlag)
        info_table.add(self.create_labeled_info("Threads Cached:", "lbl_Threads_cached"),                           3, 4, 0, 1, mforms.HFillFlag)
        info_table.add(self.create_labeled_info("Rejected (over limit):", "lbl_Connection_errors_max_connections"), 4, 5, 0, 1, mforms.HFillFlag)

        info_table.add(self.create_labeled_info("Total Connections:", "lbl_Connections"),                           0, 1, 1, 2, mforms.HFillFlag)
        info_table.add(self.create_labeled_info("Connection Limit:", "lbl_max_connections"),                        1, 2, 1, 2, mforms.HFillFlag)
        info_table.add(self.create_labeled_info("Aborted Clients:", "lbl_Aborted_clients"),                         2, 3, 1, 2, mforms.HFillFlag)
        info_table.add(self.create_labeled_info("Aborted Connections:", "lbl_Aborted_connects"),                    3, 4, 1, 2, mforms.HFillFlag)
        info_table.add(self.create_labeled_info("Errors:", "lbl_errors", "tooltip_errors"),                         4, 5, 1, 2, mforms.HFillFlag)

        self.info_table = info_table
        self.add(info_table, False, True)

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


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

        box.set_spacing(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(s)")
        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(s)")
        box.add_end(self.killq_button, False, True)
        self.killq_button.add_clicked_callback(weakcb(self, "kill_query"))
        
        refresh_label = newLabel("Refresh Rate:")
        box.add(refresh_label, False, True)

        self._menu = mforms.newContextMenu()
        self._menu.add_will_show_callback(self.menu_will_show)
        self.connection_list.set_context_menu(self._menu)

        
        self.refresh_values = [0.5, 1, 2, 3, 4, 5, 10, 15, 30]
        self.refresh_values_size = len(self.refresh_values)
        
        self.refresh_selector = newSelector()
        self.refresh_selector.set_size(100,-1)
        
        for s in self.refresh_values:
            self.refresh_selector.add_item(str(s) + " seconds")
        
        self.refresh_selector.add_item("Don't Refresh")
        
        refresh_rate_index = grt.root.wb.options.options.get('Administrator:refresh_connections_rate_index', 9)
        self.refresh_selector.set_selected(refresh_rate_index)
        self.update_refresh_rate()
        self.refresh_selector.add_changed_callback(weakcb(self, "update_refresh_rate"))
        box.add(self.refresh_selector, False, True)

        self.check_box = newBox(True)
        self.check_box.set_spacing(12)

        self.hide_sleep_connections = newCheckBox()
        self.hide_sleep_connections.set_text('Hide sleeping connections')
        self.hide_sleep_connections.add_clicked_callback(self.refresh)
        self.hide_sleep_connections.set_tooltip('Remove connections in the Sleeping state from the connection list.')
        self.check_box.add(self.hide_sleep_connections, False, True)

        self.mdl_locks_page = None
        self._showing_extras = False
        if self.new_processlist():
            self.hide_background_threads = newCheckBox()
            self.hide_background_threads.set_active(True)
            self.hide_background_threads.set_text('Hide background threads')
            self.hide_background_threads.set_tooltip('Remove background threads (internal server threads) from the connection list.')
            self.hide_background_threads.add_clicked_callback(self.refresh)
            self.check_box.add(self.hide_background_threads, False, True)
            
            self.truncate_info = newCheckBox()
            self.truncate_info.set_active(True)
            self.truncate_info.set_text('Don\'t load full thread info')
            self.truncate_info.set_tooltip('Toggle whether to load the entire query information for all connections or just the first 255 characters.\nEnabling this can have a large impact in busy servers or server executing large INSERTs.')
            self.truncate_info.add_clicked_callback(self.refresh)
            self.check_box.add(self.truncate_info, False, True)

            # tab with some extra info, only available if PS exists
            self.extra_info_tab = mforms.newTabView(mforms.TabViewSystemStandard)
            self.extra_info_tab.set_size(350, -1)
            self.extra_info_tab.add_tab_changed_callback(self.extra_tab_changed)

            self.connection_details_scrollarea = mforms.newScrollPanel()
            self.connection_details = ConnectionDetailsPanel(self)
            self.connection_details_scrollarea.add(self.connection_details)
            self.details_page = self.extra_info_tab.add_page(self.connection_details_scrollarea, "Details")

            self.mdl_list_box = None
            if self.ctrl_be.target_version.is_supported_mysql_version_at_least(5, 7, 3):
                self.mdl_list_box_scrollarea = mforms.newScrollPanel()
                self.mdl_list_box = mforms.newBox(False)
                self.mdl_list_box_scrollarea.add(self.mdl_list_box)

                self.mdl_label = mforms.newLabel('Metadata locks (MDL) protect concurrent access to\nobject metadata (not table row/data locks)')
                self.mdl_list_box.add(self.mdl_label, False, True)

                label = mforms.newLabel("\nGranted Locks (and threads waiting on them)")
                label.set_style(mforms.BoldStyle)
                self.mdl_list_box.add(label, False, True)
                label = mforms.newLabel("Locks this connection currently owns and\nconnections that are waiting for them.")
                label.set_style(mforms.SmallHelpTextStyle)
                self.mdl_list_box.add(label, False, True)

                self.mdl_list_held = mforms.newTreeNodeView(mforms.TreeAltRowColors)
                self.mdl_list_held.add_column(mforms.IconStringColumnType, "Object", 130, False)
                self.mdl_list_held.add_column(mforms.StringColumnType, "Type", 100, False)
                self.mdl_list_held.add_column(mforms.StringColumnType, "Duration", 100, False)
                self.mdl_list_held.end_columns()
                self.mdl_list_held.set_size(0, 100)
                self.mdl_list_box.add(self.mdl_list_held, True, True)

                label = mforms.newLabel("\nPending Locks")
                label.set_style(mforms.BoldStyle)
                self.mdl_list_box.add(label, False, True)
                hbox = mforms.newBox(True)
                hbox.set_spacing(4)
                self.mdl_blocked_icon = mforms.newImageBox()
                self.mdl_blocked_icon.set_image(mforms.App.get().get_resource_path("message_warning.png"))
                hbox.add(self.mdl_blocked_icon, False, True)
                self.mdl_waiting_label = mforms.newLabel("Locks this connection is currently waiting for.")
                hbox.add(self.mdl_waiting_label, True, True)
                self.mdl_list_box.add(hbox, False, True)
                self.mdl_locks_page = self.extra_info_tab.add_page(self.mdl_list_box_scrollarea, "Locks")

            if self.ctrl_be.target_version.is_supported_mysql_version_at_least(5, 6, 0):
                self.attributes_list = mforms.newTreeNodeView(mforms.TreeFlatList|mforms.TreeAltRowColors)
                self.attributes_list.add_column(mforms.StringColumnType, "Attribute", 150, False)
                self.attributes_list.add_column(mforms.StringColumnType, "Value", 200, False)
                self.attributes_list.end_columns()
                self.attributes_page = self.extra_info_tab.add_page(self.attributes_list, "Attributes")

            self.connection_box.add(self.extra_info_tab, False, True)
            self.extra_info_tab.show(False)

            self.show_extras = newButton()
            self.show_extras.set_text('Show Details')
            self.show_extras.add_clicked_callback(self.toggle_extras)
            self.check_box.add_end(self.show_extras, False, True)

        self.add(self.check_box, False, True)
        
        self.resume_layout()
        
        self.connection_selected()
        
        dprint_ex(4, "Leave")
    def __init__(self, owner, editor, schema, table, columns):
        mforms.Form.__init__(self, mforms.Form.main_form(), mforms.FormNormal)

        self._owner = owner
        self._editor = editor
        self._schema = schema
        self._table = table
        self._columns = columns

        self.set_title("Create Index for Table %s.%s" % (schema, table))

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

        table = mforms.newTable()
        table.set_row_count(7)
        table.set_column_count(2)
        table.set_row_spacing(8)
        table.set_column_spacing(8)
        content.add(table, False, True)

        table.add(mforms.newLabel("Index Name:", True), 0, 1, 0, 1, mforms.HFillFlag)
        hbox = mforms.newBox(True)
        hbox.set_spacing(12)
        self.name = mforms.newTextEntry()
        hbox.add(self.name, True, True)
        self.kind = mforms.newSelector()
        self.kind.add_items(["Non-Unique", "Unique", "FullText", "Spatial"])
        hbox.add(self.kind, False, True)
        table.add(hbox, 1, 2, 0, 1, mforms.HFillFlag|mforms.HExpandFlag)

        table.add(mforms.newLabel("Type:", True), 0, 1, 1, 2, mforms.HFillFlag)
        self.type = mforms.newSelector()
        self.type.add_items(["BTREE", "HASH"])
        table.add(self.type, 1, 2, 1, 2, mforms.HFillFlag)

        l = mforms.newLabel("Columns:")
        l.set_text_align(mforms.TopRight)
        table.add(l, 0, 1, 2, 3, mforms.HFillFlag|mforms.VFillFlag)
        self.columns = mforms.newTreeNodeView(mforms.TreeFlatList)
        self.columns.add_column(mforms.StringColumnType, "Column", 200, False)
        self.columns.add_column(mforms.StringColumnType, "Length", 60, True)
        #        self.columns.add_column(mforms.CheckColumnType, "Order", 50, False) # ignored by server
        self.columns.end_columns()
        self.columns.set_size(-1, 80)
        tbl = mforms.newTable()
        tbl.set_row_count(3)
        tbl.set_column_count(2)
        tbl.set_row_spacing(2)
        tbl.set_column_spacing(4)
        tbl.add(self.columns, 0, 1, 0, 3, mforms.HFillFlag|mforms.VFillFlag|mforms.HExpandFlag)
        self.move_up = mforms.newButton()
        self.move_up.set_text("\xe2\x96\xb2")
        self.move_up.add_clicked_callback(self.move_row_up)
        self.move_up.enable_internal_padding(False)
        self.move_down = mforms.newButton()
        self.move_down.set_text("\xe2\x96\xbc")
        self.move_down.add_clicked_callback(self.move_row_down)
        self.move_down.enable_internal_padding(False)
        tbl.add(self.move_up, 1, 2, 0, 1, mforms.HFillFlag)
        tbl.add(self.move_down, 1, 2, 1, 2, mforms.HFillFlag)
        tbl.add(mforms.newLabel(""), 1, 2, 2, 3, mforms.HFillFlag|mforms.VExpandFlag)
        table.add(tbl, 1, 2, 2, 3, mforms.HFillFlag)

        l = mforms.newLabel("Comments:")
        l.set_text_align(mforms.TopRight)
        table.add(l, 0, 1, 3, 4, mforms.HFillFlag|mforms.VFillFlag)
        self.comments = mforms.newTextBox(0)
        self.comments.set_size(-1, 60)
        if self._editor.serverVersion.majorNumber > 5 or (self._editor.serverVersion.majorNumber == 5 and self._editor.serverVersion.minorNumber >= 5):
            pass
        else:
            self.comments.set_enabled(False)
        table.add(self.comments, 1, 2, 3, 4, mforms.HFillFlag|mforms.VFillFlag)

        online_ddl_ok = self._editor.serverVersion.majorNumber > 5 or (self._editor.serverVersion.majorNumber == 5 and self._editor.serverVersion.minorNumber >= 6)

        if online_ddl_ok:
            l = mforms.newLabel("\nCreate/Online Options")
        else:
            l = mforms.newLabel("\nCreate/Online Options (requires MySQL 5.6+)")
            l.set_enabled(False)
        l.set_style(mforms.BoldStyle)
        table.add(l, 1, 2, 4, 5, mforms.HFillFlag)
        table.add(mforms.newLabel("Algorithm:", True), 0, 1, 5, 6, mforms.HFillFlag)
        self.algorithm = mforms.newSelector()
        self.algorithm.add_items(["Default", "Copy", "InPlace"])
        self.algorithm.set_enabled(online_ddl_ok)
        table.add(self.algorithm, 1, 2, 5, 6, mforms.HFillFlag)

        table.add(mforms.newLabel("Locking:", True), 0, 1, 6, 7, mforms.HFillFlag)
        self.lock = mforms.newSelector()
        self.lock.add_items(["Default (allow as much concurrency as possible)", "Exclusive (totally block access to table)", "Shared (allow queries but not DML)", "None (allow queries and DML)"])
        self.lock.set_enabled(online_ddl_ok)
        table.add(self.lock, 1, 2, 6, 7, mforms.HFillFlag)

        bbox = mforms.newBox(True)
        bbox.set_spacing(12)
        self.ok = mforms.newButton()
        self.ok.set_text("Create")

        self.cancel = mforms.newButton()
        self.cancel.set_text("Cancel")

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

        self.set_size(550, -1)
        self.center()
Esempio n. 24
0
    try:
        version_maj = int(version[0]) + int(version[1]) / 10.0
    except (ValueError, IndexError), e:
        version_maj = 5.1

    guessed_version = 5.1

    versions = copy.copy(supported_versions)

    for v in versions:
        if version_maj >= v:
            guessed_version = v
        else:
            break

    version_selector = newSelector(SelectorCombobox)
    versions.reverse()
    version_selector.add_items(map(lambda x: str(x), versions))
    version_selector.set_value(str(guessed_version))
    right_vbox.add(version_selector, False, False)
    version_selector.add_changed_callback(
        lambda: verify_selected_version(version_selector, True))

    info_hbox.add(img_box, False, False)
    info_hbox.add(right_vbox, True, True)
    top_vbox.add(info_hbox, True, True)

    ok = newButton()
    ok.set_text("Ok")

    button_box = newBox(True)
Esempio n. 25
0
    def __init__(self, editor):
        mforms.Form.__init__(self, mforms.Form.main_form(),
                             mforms.FormDialogFrame)

        self.editor = editor
        box = mforms.Box(False)
        box.set_padding(12)
        box.set_spacing(8)

        box.add(
            mforms.newLabel(
                "Preview the first lines of the script below and click [Run] to start executing.\nNote: the preview below may display non-ASCII characters incorrectly, even if the MySQL server can treat them correctly."
            ), False, True)
        self.file_info = mforms.newLabel("")
        box.add(self.file_info, False, True)
        self.text = mforms.newCodeEditor(None)
        self.text.set_language(mforms.LanguageMySQL)

        box.add(self.text, True, True)

        table = mforms.newTable()
        table.set_padding(20)
        table.set_row_count(2)
        table.set_column_count(3)
        table.set_row_spacing(8)
        table.set_column_spacing(4)
        table.add(mforms.newLabel("Default Schema Name:"), 0, 1, 0, 1, 0)
        self.schema = mforms.newSelector(mforms.SelectorCombobox)
        table.add(self.schema, 1, 2, 0, 1,
                  mforms.HFillFlag | mforms.HExpandFlag)

        help = mforms.newLabel(
            "Schema to be used unless explicitly specified in the script.\nLeave blank if the script already specified it,\npick a schema from the drop down or type a name to\ncreate a new one."
        )
        help.set_style(mforms.SmallHelpTextStyle)
        table.add(help, 2, 3, 0, 1, mforms.HFillFlag)

        table.add(mforms.newLabel("Default Character Set:"), 0, 1, 1, 2, 0)
        self.charset = mforms.newSelector()
        self.charset.add_changed_callback(self.update_preview)
        l = [""]
        for ch in grt.root.wb.rdbmsMgmt.rdbms[0].characterSets:
            l.append(ch.name)
        self.charset.add_items(sorted(l))
        table.add(self.charset, 1, 2, 1, 2,
                  mforms.HFillFlag | mforms.HExpandFlag)

        help = mforms.newLabel(
            "Default character set to use when executing the script,\nunless specified in the script."
        )
        help.set_style(mforms.SmallHelpTextStyle)
        table.add(help, 2, 3, 1, 2, mforms.HFillFlag)

        box.add(table, False, True)

        self.ok = mforms.newButton()
        self.ok.set_text("Run")

        self.cancel = mforms.newButton()
        self.cancel.set_text("Cancel")

        hbox = mforms.Box(True)
        hbox.set_spacing(8)
        mforms.Utilities.add_end_ok_cancel_buttons(hbox, self.ok, self.cancel)
        box.add_end(hbox, False, True)

        self.set_content(box)
Esempio n. 26
0
    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.newTreeNodeView(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)
        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.newTreeNodeView(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()
Esempio n. 27
0
    def place_control(self, ctrl_def, table, row):
      ctrl = None
      ctype = ctrl_def['type']
      name = ctrl_def['name']

      enabled = newCheckBox()
      enabled.set_text(ctrl_def['caption'])
      enabled.set_size(200, -1) # Use a fixed fix to make all tables align their columns properly. Must be larger than the largest text, to make it work.
      enabled.set_tooltip(ctrl_def['name'])

      # place_control creates control as ctrl_def describes. Reference to a created control is placed 
      # to map of controls. That is done in order to access controls via option name
      if ctype == "checkbox" or ctype == "boolean":
        ctrl = ('chk', (enabled, enabled), ctrl_def)
        self.opt2ctrl_map[name] = ctrl
        enabled.set_active(False)
        #label = newLabel(" ")
        #table.add(label, 1, 2, row, row+1, HExpandFlag | HFillFlag)
      elif ctype == 'textedit' or ctype == 'string' or ctype == 'set':
        te = self.create_textedit(name, ctrl_def)
        table.add(te, 1, 2, row, row+1, HExpandFlag | HFillFlag)
        ctrl = ('txt', (enabled, te), ctrl_def)
        self.opt2ctrl_map[name] = ctrl
      elif ctype == "directory" or ctype == "filename" or ctype == "dirname":
        (dir_box, te, btn) = self.create_dir_file_edit(name, ctrl_def)
        table.add(dir_box, 1, 2, row, row + 1, HExpandFlag | HFillFlag)
        te.add_changed_callback(lambda: self.control_action(name))
        ctrl = ('dir', (enabled, te, btn), ctrl_def)
        self.opt2ctrl_map[name] = ctrl
      elif ctype == "numeric" or ctype == "spinedit":
        #(spin_box, te, unitcontrol, unit_items) = self.create_numeric(name, ctrl_def)
        #ctrl = ('spn', (enabled, te, unitcontrol, unit_items), ctrl_def)
        te = self.create_numeric(name, ctrl_def)
        #ctrl = ('spn', (enabled, te), ctrl_def)
        ctrl = ('txt', (enabled, te), ctrl_def)
        self.opt2ctrl_map[name] = ctrl
        #table.add(spin_box, 1, 2, row, row + 1, HExpandFlag | HFillFlag)
        table.add(te, 1, 2, row, row + 1, HExpandFlag | HFillFlag)
      elif ctype == "dropdownbox" or ctype == 'dropdownboxentry':
        if 'choice' not in ctrl_def:
          te = newTextEntry()
          te.set_enabled(False)
          te.add_changed_callback(lambda: self.control_action(name))
          table.add(te, 1, 2, row, row+1, HExpandFlag | HFillFlag)
          ctrl = ('txt', (enabled, te), ctrl_def)
          self.opt2ctrl_map[name] = ctrl
        else:
          (dropbox, items) = self.create_dropdownbox(name, ctrl_def, ctype)
          table.add(dropbox, 1, 2, row, row + 1, HExpandFlag | HFillFlag)
          ctrl = ('drp', (enabled, dropbox, items), ctrl_def)
          self.opt2ctrl_map[name] = ctrl

      if CATOPTS is None:
        table.add(enabled, 0, 1, row, row + 1, HFillFlag)
        enabled.add_clicked_callback(lambda: self.enabled_checkbox_click(name))
      else:
        catbox = newBox(True)
        cat = newSelector(mforms.SelectorCombobox)
        for item in cat_sec:
          cat.add_item(item)
        grp = newSelector(mforms.SelectorCombobox)
        for item in cat_grp:
          grp.add_item(item)
        cat.add_changed_callback(lambda : handle_cat_opt(cat, grp, ctrl_def['name']))
        grp.add_changed_callback(lambda : handle_cat_opt(cat, grp, ctrl_def['name']))
        catbox.add(cat, True, True)
        catbox.add(grp, True, True)
        catbox.add(enabled, True, True)
        table.add(catbox, 0, 1, row, row + 1, HExpandFlag | HFillFlag)

      return ctrl
Esempio 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()
Esempio n. 29
0
    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 create_ui(self):
        self.set_spacing(16)
        
        label = mforms.newLabel("Select destination table and additional options.")
        label.set_style(mforms.BoldInfoCaptionStyle)
        self.content.add(label, False, True)

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

        existing_table_box = mforms.newBox(True)
        existing_table_box.set_spacing(8)
        self.existing_table_radio = mforms.newRadioButton(1)
        self.existing_table_radio.set_text("Use existing table:")
        self.existing_table_radio.add_clicked_callback(self.radio_click)
        if 'table' in self.main.destination_table and self.main.destination_table['table'] is not None:
            self.existing_table_radio.set_active(True)
        existing_table_box.add(self.existing_table_radio, False, True)
        
        self.destination_table_sel = mforms.newSelector()
        self.destination_table_sel.set_size(75, -1)
        existing_table_box.add(self.destination_table_sel, True, True)
        table_destination_box.add(existing_table_box, False, True)
            
        new_table_box = mforms.newBox(True)
        new_table_box.set_spacing(8)
        self.new_table_radio = mforms.newRadioButton(1)
        self.new_table_radio.set_text("Create new table: ")
        self.new_table_radio.add_clicked_callback(self.radio_click)
        if 'table' not in self.main.destination_table or self.main.destination_table['table'] is None:
            self.new_table_radio.set_active(True)
            
        new_table_box.add(self.new_table_radio, False, True)
        self.destination_database_sel = mforms.newSelector()
        self.destination_database_sel.set_size(120, -1)
        new_table_box.add(self.destination_database_sel, False, True)
        new_table_box.add(mforms.newLabel("."), False, True)
        self.new_table_name = mforms.newTextEntry()
        new_table_box.add_end(self.new_table_name, True, True)
        table_destination_box.add(new_table_box, True, True)
        
        def set_trunc(sender):
            global truncate_table
            truncate_table = sender.get_active()
 
        self.truncate_table_cb = mforms.newCheckBox()
        self.truncate_table_cb.set_text("Truncate table before import")
        self.truncate_table_cb.set_active(truncate_table)
        self.truncate_table_cb.add_clicked_callback(lambda sender = self.truncate_table_cb: set_trunc(sender))
        table_destination_box.add(self.truncate_table_cb, False, True)
        
        def set_drop(sender):
            global drop_table
            drop_table = sender.get_active()
            
        self.drop_table_cb = mforms.newCheckBox()
        self.drop_table_cb.set_text("Drop table if exists")
        self.drop_table_cb.set_active(drop_table)
        self.drop_table_cb.add_clicked_callback(lambda sender = self.drop_table_cb: set_drop(sender))
        if self.existing_table_radio.get_active():
            self.drop_table_cb.show(False)
            self.truncate_table_cb.show(True)
        else:
            self.drop_table_cb.show(True)
            self.truncate_table_cb.show(False)
        table_destination_box.add(self.drop_table_cb, False, True)
        
        self.content.add(table_destination_box, False, True)
    def __init__(self, editor):
        mforms.Box.__init__(self, False)
        self.set_managed()
        self.set_release_on_add()

        self.editor = editor

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

        heading = mforms.newLabel("Table Maintenance Operations")
        heading.set_style(mforms.BigStyle)
        self.add(heading, False, True)

        help = mforms.newLabel("Select tables and click the operation you want to perform.\nNOTE: Some commands may require locking tables until completion,\nwhich may take a long time for large tables.")
        self.add(help, False, True)

        self.scroll = mforms.newScrollPanel(0)
        self.add(self.scroll, True, True)
        self.content = mforms.newBox(False)
        self.content.set_spacing(8)
        self.content.set_padding(12)
        self.scroll.add(self.content)

        self._buttons = []

        def make_command_box(callable, title, desc, tooltip, options = None, extra_options = None):
            l = mforms.newLabel(title)
            l.set_style(mforms.BoldStyle)
            self.content.add(l, False, True)

            l = mforms.newLabel(desc)
            self.content.add(l, False, True)

            if extra_options:
                self.content.add(extra_options, False, True)

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

            l = mforms.newImageBox()
            l.set_image(mforms.App.get().get_resource_path("mini_notice.png"))
            l.set_tooltip(tooltip)
            hb.add(l, False, True)

            for o in options:
                hb.add(o, False, True)

            btn = mforms.newButton()
            btn.add_clicked_callback(callable)
            btn.set_text(title.strip())
            hb.add_end(btn, False, True)

            self._buttons.append(btn)

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

        self.analyze_local = mforms.newCheckBox()
        self.analyze_local.set_text("Don't write to BINLOG (local)")

        make_command_box(self.analyze_table, "Analyze Table",
                         """Analyzes and stores the key distribution for a table.
During the analysis, the table is locked with a read lock for InnoDB and MyISAM.""",
                         """With InnoDB tables, when you enable the innodb_stats_persistent option, you must run ANALYZE TABLE after loading substantial data into an InnoDB table, or creating a new index for one.

MySQL uses the stored key distribution to decide the order in which tables should be joined when you perform a join on something other than a constant. In addition, key distributions can be used when deciding which indexes to use for a specific table within a query.""",
                         [self.analyze_local])


        if editor.serverVersion.majorNumber > 5 or (editor.serverVersion.majorNumber == 5 and editor.serverVersion.minorNumber >= 6):
            extra_options = mforms.newBox(True)
            extra_options.set_spacing(4)

            self.optimize_ft_only = mforms.newCheckBox()
            self.optimize_ft_only.set_text("Optimize FULLTEXT only")
            self.optimize_ft_only.add_clicked_callback(self.optimize_ft_only_toggled)
            extra_options.add(self.optimize_ft_only, False, True)

            l = mforms.newLabel("")
            l.set_size(20, -1)
            extra_options.add(l, False, True)

            extra_options.add(mforms.newLabel("Number of words to optimize per run:"), False, True)
            self.optimize_ft_numwords = mforms.newTextEntry()
            self.optimize_ft_numwords.set_size(50, -1)
            self.optimize_ft_numwords.set_enabled(False)
            extra_options.add(self.optimize_ft_numwords, False, True)

            result = editor.executeManagementQuery("SHOW VARIABLES LIKE 'innodb_ft_num_word_optimize'", 0)
            if result and result.goToFirstRow():
                self.optimize_ft_numwords.set_value(result.stringFieldValue(1))
        else:
            extra_options = None
            self.optimize_ft_only = None

        self.optimize_local = mforms.newCheckBox()
        self.optimize_local.set_text("Don't write to BINLOG (local)")

        make_command_box(self.optimize_table, "\n\n"+"Optimize Table",
                         """Reorganizes the physical storage of table data and associated index data, 
to reduce storage space and improve I/O efficiency when accessing the table.""",
                         """The exact changes made to each table depend on the storage engine used by that table.

Use OPTIMIZE TABLE in these cases, depending on the type of table:

* After doing substantial insert, update, or delete operations on an InnoDB table that has its own .ibd file. The table and indexes are reorganized, and disk space can be reclaimed for use by the operating system.

* After doing substantial insert, update, or delete operations on columns that are part of a FULLTEXT index in an InnoDB table. Set the configuration option innodb_optimize_fulltext_only=1 first. To keep the index maintenance period to a reasonable time, set the innodb_ft_num_word_optimize option to specify how many words to update in the search index, and run Optimize Table until the search index is fully updated.""",
                         [self.optimize_local], extra_options)


        self.check_scan_opt = mforms.newSelector()
        self.check_scan_opt.add_items(["", "Quick", "Medium", "Extended", "For Upgrade"])

        self.check_fast_opt = mforms.newCheckBox()
        self.check_fast_opt.set_text("Fast")

        self.check_changed_opt = mforms.newCheckBox()
        self.check_changed_opt.set_text("Changed")

        options = [self.check_scan_opt, self.check_fast_opt, self.check_changed_opt]

        make_command_box(self.check_table, "\n\n"+"Check Table",
                         """CHECK TABLE checks a table or tables for errors. 
For MyISAM tables, the key statistics are updated as well.""",
                         """The FOR UPGRADE option checks whether the named tables are compatible with the current version of MySQL. With FOR UPGRADE, the server checks each table to determine whether there have been any incompatible changes in any of the table's data types or indexes since the table was created.
                             
Check Options:
- QUICK    Do not scan the rows to check for incorrect links. Applies to InnoDB and MyISAM tables and views.
- FAST    Check only tables that have not been closed properly. Applies only to MyISAM tables and views; ignored for InnoDB.
- CHANGED    Check only tables that have been changed since the last check or that have not been closed properly. Applies only to MyISAM tables and views; ignored for InnoDB.
- MEDIUM    Scan rows to verify that deleted links are valid. This also calculates a key checksum for the rows and verifies this with a calculated checksum for the keys. Applies only to MyISAM tables and views; ignored for InnoDB.
- EXTENDED    Do a full key lookup for all keys for each row. This ensures that the table is 100% consistent, but takes a long time. Applies only to MyISAM tables and views; ignored for InnoDB.""",
                         options)

        # The manual is full of scary warnings about this one, maybe better just leave user perform it by hand
#        make_command_box("\n"+"Repair Table",
#                         """""",
#                         """
#                             """)

        self.checksum_quick = mforms.newCheckBox()
        self.checksum_quick.set_text("Quick (if supported)")
        options = [self.checksum_quick]
        make_command_box(self.checksum_table, "\n\n"+"Checksum Table",
                         """CHECKSUM TABLE reports a checksum for the contents of a table.""",
                         """You can use this statement to verify that the contents are the same before and after a backup, rollback, or other operation that is intended to put the data back to a known state.""", options)
Esempio n. 32
0
    def __init__(self, secman, user=""):
        mforms.Form.__init__(self, None,
                             mforms.FormResizable | mforms.FormMinimizable)

        self.set_title("New Schema Privilege Definition")

        self.secman = secman

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

        label = newLabel()
        label.set_text(
            "Select the Host and the Schema for which the user '%s'\nwill have the privileges you want to define."
            % user)
        box.add(label, False, True)

        panel = newPanel(mforms.TitledBoxPanel)
        panel.set_title("Host")
        box.add(panel, False, True)
        table = newTable()
        panel.add(table)
        table.set_padding(8)
        table.set_row_count(3)
        table.set_column_count(3)
        table.set_row_spacing(8)

        self.host1 = newRadioButton(mforms.RadioButton.new_id())
        self.host1.set_active(True)
        self.host1.add_clicked_callback(self.host_radio_changed)
        self.host1.set_text("Any Host (%)")
        table.add(self.host1, 0, 1, 0, 1, mforms.HFillFlag)

        self.host2 = newRadioButton(self.host1.group_id())
        self.host2.set_text("Hosts matching pattern or name:")
        self.host2.add_clicked_callback(self.host_radio_changed)
        table.add(self.host2, 0, 1, 1, 2, mforms.HFillFlag)

        self.host2entry = newTextEntry()
        table.add(self.host2entry, 1, 2, 1, 2,
                  mforms.HFillFlag | mforms.HExpandFlag)

        self.host3 = newRadioButton(self.host1.group_id())
        self.host3.set_text("Selected host:")
        self.host3.add_clicked_callback(self.host_radio_changed)
        table.add(self.host3, 0, 1, 2, 3, mforms.HFillFlag)

        self.host3sel = newSelector()
        table.add(self.host3sel, 1, 2, 2, 3,
                  mforms.HFillFlag | mforms.HExpandFlag)

        hosts = [h for u, h in secman.account_names if u == user]
        self.host3sel.add_items(hosts)

        panel = newPanel(mforms.TitledBoxPanel)
        panel.set_title("Schema")
        box.add(panel, True, True)
        table = newTable()
        panel.add(table)
        table.set_padding(8)
        table.set_row_count(3)
        table.set_column_count(3)
        table.set_row_spacing(8)

        self.schema1 = newRadioButton(mforms.RadioButton.new_id())
        self.schema1.set_active(True)
        self.schema1.add_clicked_callback(self.schema_radio_changed)
        self.schema1.set_text("Any Schema (%)")
        table.add(self.schema1, 0, 1, 0, 1, mforms.HFillFlag)

        self.schema2 = newRadioButton(self.schema1.group_id())
        self.schema2.add_clicked_callback(self.schema_radio_changed)
        self.schema2.set_text("Schemas matching pattern or name:")
        table.add(self.schema2, 0, 1, 1, 2, mforms.HFillFlag)

        self.schema2entry = newTextEntry()
        table.add(self.schema2entry, 1, 2, 1, 2,
                  mforms.HFillFlag | mforms.HExpandFlag)

        self.schema3 = newRadioButton(self.schema1.group_id())
        self.schema3.add_clicked_callback(self.schema_radio_changed)
        self.schema3.set_text("Selected schema:")
        table.add(self.schema3, 0, 1, 2, 3, mforms.HFillFlag)

        self.schema3sel = newListBox(False)
        table.add(
            self.schema3sel, 1, 2, 2, 3, mforms.HFillFlag | mforms.HExpandFlag
            | mforms.VFillFlag | mforms.VExpandFlag)
        self.schema3sel.add_items(self.secman.schema_names)

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

        bbox.set_spacing(8)

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

        self.cancel = newButton()
        self.cancel.set_text("Cancel")
        bbox.add_end(self.cancel, False, True)

        self.set_size(450, 500)

        self.host_radio_changed()
        self.schema_radio_changed()

        self.center()
Esempio n. 33
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.newTreeNodeView(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)
Esempio n. 34
0
    def create_ui(self):
        self.content.set_padding(20)

        self.content.add(
            mforms.newLabel(
                '''Select the connection for the source MySQL server where databases will be copied from
and the destination server where they should be copied to.'''), False, True)

        source_panel = mforms.newPanel(mforms.TitledBoxPanel)
        source_panel.set_title('Source MySQL Server')

        box = mforms.newBox(False)
        box.set_spacing(12)
        box.set_padding(8)
        box.add(
            mforms.newLabel(
                'Select the connection for the source MySQL server instance'),
            False, True)

        source_hbox = mforms.newBox(True)
        source_hbox.set_spacing(8)
        source_hbox.add(mforms.newLabel('Source Connection:'), False, True)
        self.source_selector = mforms.newSelector()
        source_hbox.add(self.source_selector, True, True)
        box.add(source_hbox, False, True)

        self.source_connection_status = mforms.newLabel('')
        self.source_connection_status.set_color('#aa3333')
        box.add(self.source_connection_status, True, True)
        self.source_selector.add_changed_callback(
            functools.partial(self.selector_changed,
                              label=self.source_connection_status,
                              selector=self.source_selector))

        source_panel.add(box)
        self.content.add(source_panel, False, True)

        target_panel = mforms.newPanel(mforms.TitledBoxPanel)
        target_panel.set_title('Destination MySQL Server')

        tbox = mforms.newBox(False)
        tbox.set_spacing(12)
        tbox.set_padding(8)
        tbox.add(
            mforms.newLabel(
                'Select the connection object for the destination MySQL server instance'
            ), False, True)

        target_hbox = mforms.newBox(True)
        target_hbox.set_spacing(8)
        target_hbox.add(mforms.newLabel('Target Connection:'), False, True)
        self.target_selector = mforms.newSelector()
        target_hbox.add(self.target_selector, True, True)
        tbox.add(target_hbox, False, True)

        self.target_connection_status = mforms.newLabel('')
        self.target_connection_status.set_color('#aa3333')
        tbox.add(self.target_connection_status, True, True)
        self.target_selector.add_changed_callback(
            functools.partial(self.selector_changed,
                              label=self.target_connection_status,
                              selector=self.target_selector))

        target_panel.add(tbox)
        self.content.add(target_panel, False, True)

        self.advanced_button.set_text('Test Connections')

        self.back_button.set_enabled(False)

        self.load_connections()
    def create_ui(self):
        self.set_spacing(16)
        format_box = mforms.newBox(True)
        format_box.set_spacing(8)
        format_box.add(mforms.newLabel("Detected file format: %s" % self.input_file_type), False, True)
        if len(self.active_module.options) != 0:
            advanced_opts_btn = mforms.newButton(mforms.ToolButton)
            advanced_opts_btn.set_icon(mforms.App.get().get_resource_path("admin_option_file.png"))
            advanced_opts_btn.add_clicked_callback(lambda: self.optpanel.show(False) if self.optpanel.is_shown() else self.optpanel.show(True) )
            format_box.add(advanced_opts_btn, False, True)
        
        self.content.add(format_box, False, True)

        if len(self.active_module.options) != 0:
            self.optpanel = mforms.newPanel(mforms.TitledBoxPanel)
            self.optpanel.set_title("Options:")
            def set_text_entry(field, output):
                txt = field.get_string_value().encode('utf-8').strip()
                if len(txt) == 0:
                    operator.setitem(output, 'value', None)
                    mforms.Utilities.add_timeout(0.1, self.call_create_preview_table)
                elif len(txt) == 1:
                    operator.setitem(output, 'value', txt)
                    mforms.Utilities.add_timeout(0.1, self.call_create_preview_table)
                else:
                    field.set_value("")
                    mforms.Utilities.show_error("Import Wizard", "Due to the nature of this wizard, you can't use unicode characters in this place, as only one character is allowed.","Ok","","")


            def set_selector_entry(selector, output):
                operator.setitem(output, 'value', output['opts'][str(selector.get_string_value())])
                mforms.Utilities.add_timeout(0.1, self.call_create_preview_table)
            
            box = mforms.newBox(False)
            box.set_spacing(8)
            box.set_padding(8)
            for name, opts in self.active_module.options.iteritems():
                label_box = mforms.newBox(True)
                label_box.set_spacing(8)
                label_box.add(mforms.newLabel(opts['description']), False, True)
                if opts['type'] == 'text':
                    opt_val = mforms.newTextEntry()
                    opt_val.set_size(35, -1)
                    opt_val.set_value(opts['value'])
                    opt_val.add_changed_callback(lambda field = opt_val, output = opts: set_text_entry(field, output))
                    label_box.add_end(opt_val, False, True)
                    self.opts_mapping[name] = lambda val: opt_val.set_value(val)
                if opts['type'] == 'select':
                    opt_val = mforms.newSelector()
                    opt_val.set_size(75, -1)
                    opt_val.add_items([v for v in opts['opts']])
                    opt_val.set_selected(opts['opts'].values().index(opts['value']))
                    opt_val.add_changed_callback(lambda selector = opt_val, output = opts: set_selector_entry(selector, output))
                    self.opts_mapping[name] = lambda input, values =  opts['opts'].values(): opt_val.set_selected(values.index(input) if input in values else 0)
                    label_box.add_end(opt_val, False, True)
                box.add(label_box, False, True)
            self.optpanel.add(box)
            self.content.add(self.optpanel, False, True)
            self.optpanel.show(False)

        if self.input_file_type == 'csv':
            # We show encoding box only for csv as json can be only utf-8, utf-16 according to rfc
            self.encoding_box = mforms.newBox(True)
            self.encoding_box.set_spacing(16)
            self.encoding_box.add(mforms.newLabel("Encoding: "), False, True)
            self.encoding_sel = mforms.newSelector()
            self.encoding_sel.set_size(250, -1)
            self.encoding_box.add(self.encoding_sel, False, True)
        
            for i,e in enumerate(self.encoding_list):
                self.encoding_sel.add_item(e)
                if self.encoding_list[e] == 'utf-8':
                    self.encoding_sel.set_selected(i)
            self.encoding_sel.add_changed_callback(self.encoding_changed)
            self.content.add(self.encoding_box, False, True)
        
        self.table_preview_box = mforms.newBox(False)
        self.table_preview_box.set_spacing(16)
        self.preview_table = None
        self.content.add(self.table_preview_box, True, True)
        
        self.column_caption = mforms.newPanel(mforms.BorderedPanel)
        self.column_caption.set_title("Columns:")
        self.column_caption.set_size(-1, 100)
        self.column_scroll = mforms.newScrollPanel(0)
        self.column_caption.add(self.column_scroll)
        self.table_preview_box.add(self.column_caption, True, True)

        extra_opts = mforms.newBox(False)
        extra_opts.set_spacing(16)
        
        self.ds_box = mforms.newBox(True)
        self.ds_box.set_spacing(8)
        extra_opts.add(self.ds_box, False, True)
        
        self.df_box = mforms.newBox(True)
        self.df_box.set_spacing(8)
        extra_opts.add_end(self.df_box, False, True)
        
        self.ds_box.add(mforms.newLabel("Decimal Separator:"), False, True)
        self.ds_entry = mforms.newTextEntry()
        self.ds_entry.set_value('.')
        self.ds_entry.set_size(30, -1)
        self.ds_box.add(self.ds_entry, False, True)
        self.ds_box.show(False)
        
        self.df_box.add(self.make_label_with_tooltip("Date format: ", "Expects string pattern with the date format.\n"
                                                    "Default format is: %Y-%m-%d %H:%M:%S\n"
                                                    "\nCommon used options:\n"
                                                    "\t%d is the day number\n"
                                                    "\t%m is the month number\n"
                                                    "\t%y is the four digits year number\n"
                                                    "\t%H is the hour number\n"
                                                    "\t%M is the minute number\n"
                                                    "\t%S is the second number\n\n"
                                                    "More formats can be found under the following location:\n" 
                                                    "https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior"), False, True)
        self.df_entry = mforms.newTextEntry()
        self.df_entry.set_value("%Y-%m-%d %H:%M:%S")
        self.df_entry.set_size(200, -1)
        self.df_box.add(self.df_entry, False, True)
        self.df_box.show(False)
        
        self.content.add_end(extra_opts, False, True)
      version_maj = int(version[0]) + int(version[1]) / 10.0
    except (ValueError, IndexError), e:
      version_maj = 5.1


    guessed_version = 5.1

    versions = copy.copy(supported_versions)

    for v in versions:
        if version_maj >= v:
            guessed_version = v
        else:
            break

    version_selector = newSelector(SelectorCombobox)
    versions.reverse()
    version_selector.add_items(map(lambda x: str(x), versions))
    version_selector.set_value(str(guessed_version))
    right_vbox.add(version_selector, False, False)
    version_selector.add_changed_callback(lambda: verify_selected_version(version_selector, True))

    info_hbox.add(img_box, False, False)
    info_hbox.add(right_vbox, True, True)
    top_vbox.add(info_hbox, True, True)

    ok = newButton()
    ok.set_text("Ok")

    button_box = newBox(True)
    button_box.add_end(ok, False, False)
    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.newTreeNodeView(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)
    def create_ui(self):
        dprint_ex(4, "Enter")
        self.suspend_layout()

        self.heading = make_panel_header("title_connections.png",
                                         self.instance_info.name,
                                         "Client Connections")
        self.add(self.heading, False, False)

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

        self.connection_list = newTreeNodeView(mforms.TreeDefault
                                               | mforms.TreeFlatList
                                               | mforms.TreeAltRowColors)
        self.connection_list.add_column(mforms.LongIntegerColumnType, "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.LongIntegerColumnType, "Time",
                                        60, False)
        self.connection_list.add_column(mforms.StringColumnType, "State", 80,
                                        False)
        self.info_column = 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)

        box.set_spacing(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"))

        refresh_label = newLabel("Refresh Rate:")
        box.add(refresh_label, False, True)

        self._menu = mforms.newContextMenu()
        self._menu.add_item_with_title("Copy Info", self.copy_selected,
                                       "copy_selected")
        self._menu.add_item_with_title("Show in Editor", self.edit_selected,
                                       "edit_selected")
        self.connection_list.set_context_menu(self._menu)

        self.refresh_values = [0.5, 1, 2, 3, 4, 5, 10, 15, 30]
        self.refresh_values_size = len(self.refresh_values)

        self.refresh_selector = newSelector()
        self.refresh_selector.set_size(100, -1)

        for s in self.refresh_values:
            self.refresh_selector.add_item(str(s) + " seconds")

        self.refresh_selector.add_item("Don't Refresh")

        refresh_rate_index = grt.root.wb.options.options.get(
            'Administrator:refresh_connections_rate_index', 9)
        self.refresh_selector.set_selected(refresh_rate_index)
        self.update_refresh_rate()
        self.refresh_selector.add_changed_callback(
            weakcb(self, "update_refresh_rate"))
        box.add(self.refresh_selector, False, True)

        self.hide_sleep_connections = newCheckBox()
        self.hide_sleep_connections.set_text('Hide sleeping connections')
        self.hide_sleep_connections.add_clicked_callback(self.refresh)
        box.add(self.hide_sleep_connections, False, True)

        self.add(box, False, True)

        self.resume_layout()

        self.connection_selected()
        dprint_ex(4, "Leave")
    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()
    def __init__(self, editor):
        mforms.Box.__init__(self, False)
        self.set_managed()
        self.set_release_on_add()

        self.editor = editor

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

        heading = mforms.newLabel("Table Maintenance Operations")
        heading.set_style(mforms.BigStyle)
        self.add(heading, False, True)

        help = mforms.newLabel(
            "Select tables and click the operation you want to perform.\nNOTE: Some commands may require locking tables until completion,\nwhich may take a long time for large tables."
        )
        self.add(help, False, True)

        self.scroll = mforms.newScrollPanel(0)
        self.add(self.scroll, True, True)
        self.content = mforms.newBox(False)
        self.content.set_spacing(8)
        self.content.set_padding(12)
        self.scroll.add(self.content)

        self._buttons = []

        def make_command_box(callable,
                             title,
                             desc,
                             tooltip,
                             options=None,
                             extra_options=None):
            l = mforms.newLabel(title)
            l.set_style(mforms.BoldStyle)
            self.content.add(l, False, True)

            l = mforms.newLabel(desc)
            self.content.add(l, False, True)

            if extra_options:
                self.content.add(extra_options, False, True)

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

            l = mforms.newImageBox()
            l.set_image(mforms.App.get().get_resource_path("mini_notice.png"))
            l.set_tooltip(tooltip)
            hb.add(l, False, True)

            for o in options:
                hb.add(o, False, True)

            btn = mforms.newButton()
            btn.add_clicked_callback(callable)
            btn.set_text(title.strip())
            hb.add_end(btn, False, True)

            self._buttons.append(btn)

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

        self.analyze_local = mforms.newCheckBox()
        self.analyze_local.set_text("Don't write to BINLOG (local)")

        make_command_box(
            self.analyze_table, "Analyze Table",
            """Analyzes and stores the key distribution for a table.
During the analysis, the table is locked with a read lock for InnoDB and MyISAM.""",
            """With InnoDB tables, when you enable the innodb_stats_persistent option, you must run ANALYZE TABLE after loading substantial data into an InnoDB table, or creating a new index for one.

MySQL uses the stored key distribution to decide the order in which tables should be joined when you perform a join on something other than a constant. In addition, key distributions can be used when deciding which indexes to use for a specific table within a query.""",
            [self.analyze_local])

        if editor.serverVersion.majorNumber > 5 or (
                editor.serverVersion.majorNumber == 5
                and editor.serverVersion.minorNumber >= 6):
            extra_options = mforms.newBox(True)
            extra_options.set_spacing(4)

            self.optimize_ft_only = mforms.newCheckBox()
            self.optimize_ft_only.set_text("Optimize FULLTEXT only")
            self.optimize_ft_only.add_clicked_callback(
                self.optimize_ft_only_toggled)
            extra_options.add(self.optimize_ft_only, False, True)

            l = mforms.newLabel("")
            l.set_size(20, -1)
            extra_options.add(l, False, True)

            extra_options.add(
                mforms.newLabel("Number of words to optimize per run:"), False,
                True)
            self.optimize_ft_numwords = mforms.newTextEntry()
            self.optimize_ft_numwords.set_size(50, -1)
            self.optimize_ft_numwords.set_enabled(False)
            extra_options.add(self.optimize_ft_numwords, False, True)

            result = editor.executeManagementQuery(
                "SHOW VARIABLES LIKE 'innodb_ft_num_word_optimize'", 0)
            if result and result.goToFirstRow():
                self.optimize_ft_numwords.set_value(result.stringFieldValue(1))
        else:
            extra_options = None
            self.optimize_ft_only = None

        self.optimize_local = mforms.newCheckBox()
        self.optimize_local.set_text("Don't write to BINLOG (local)")

        make_command_box(
            self.optimize_table, "\n\n" + "Optimize Table",
            """Reorganizes the physical storage of table data and associated index data, 
to reduce storage space and improve I/O efficiency when accessing the table.""",
            """The exact changes made to each table depend on the storage engine used by that table.

Use OPTIMIZE TABLE in these cases, depending on the type of table:

* After doing substantial insert, update, or delete operations on an InnoDB table that has its own .ibd file. The table and indexes are reorganized, and disk space can be reclaimed for use by the operating system.

* After doing substantial insert, update, or delete operations on columns that are part of a FULLTEXT index in an InnoDB table. Set the configuration option innodb_optimize_fulltext_only=1 first. To keep the index maintenance period to a reasonable time, set the innodb_ft_num_word_optimize option to specify how many words to update in the search index, and run Optimize Table until the search index is fully updated.""",
            [self.optimize_local], extra_options)

        self.check_scan_opt = mforms.newSelector()
        self.check_scan_opt.add_items(
            ["", "Quick", "Medium", "Extended", "For Upgrade"])

        self.check_fast_opt = mforms.newCheckBox()
        self.check_fast_opt.set_text("Fast")

        self.check_changed_opt = mforms.newCheckBox()
        self.check_changed_opt.set_text("Changed")

        options = [
            self.check_scan_opt, self.check_fast_opt, self.check_changed_opt
        ]

        make_command_box(
            self.check_table, "\n\n" + "Check Table",
            """CHECK TABLE checks a table or tables for errors. 
For MyISAM tables, the key statistics are updated as well.""",
            """The FOR UPGRADE option checks whether the named tables are compatible with the current version of MySQL. With FOR UPGRADE, the server checks each table to determine whether there have been any incompatible changes in any of the table's data types or indexes since the table was created.
                             
Check Options:
- QUICK    Do not scan the rows to check for incorrect links. Applies to InnoDB and MyISAM tables and views.
- FAST    Check only tables that have not been closed properly. Applies only to MyISAM tables and views; ignored for InnoDB.
- CHANGED    Check only tables that have been changed since the last check or that have not been closed properly. Applies only to MyISAM tables and views; ignored for InnoDB.
- MEDIUM    Scan rows to verify that deleted links are valid. This also calculates a key checksum for the rows and verifies this with a calculated checksum for the keys. Applies only to MyISAM tables and views; ignored for InnoDB.
- EXTENDED    Do a full key lookup for all keys for each row. This ensures that the table is 100% consistent, but takes a long time. Applies only to MyISAM tables and views; ignored for InnoDB.""",
            options)

        # The manual is full of scary warnings about this one, maybe better just leave user perform it by hand
        #        make_command_box("\n"+"Repair Table",
        #                         """""",
        #                         """
        #                             """)

        self.checksum_quick = mforms.newCheckBox()
        self.checksum_quick.set_text("Quick (if supported)")
        options = [self.checksum_quick]
        make_command_box(
            self.checksum_table, "\n\n" + "Checksum Table",
            """CHECKSUM TABLE reports a checksum for the contents of a table.""",
            """You can use this statement to verify that the contents are the same before and after a backup, rollback, or other operation that is intended to put the data back to a known state.""",
            options)
Esempio n. 41
0
    def place_control(self, ctrl_def, table, row):
        ctrl = None
        ctype = ctrl_def['type']
        name = ctrl_def['name']

        enabled = newCheckBox()
        enabled.set_text(ctrl_def['caption'])
        enabled.set_size(
            200, -1
        )  # Use a fixed fix to make all tables align their columns properly. Must be larger than the largest text, to make it work.
        enabled.set_tooltip(ctrl_def['name'])

        # place_control creates control as ctrl_def describes. Reference to a created control is placed
        # to map of controls. That is done in order to access controls via option name
        if ctype == "checkbox" or ctype == "boolean":
            ctrl = ('chk', (enabled, enabled), ctrl_def)
            self.opt2ctrl_map[name] = ctrl
            enabled.set_active(False)
            #label = newLabel(" ")
            #table.add(label, 1, 2, row, row+1, HExpandFlag | HFillFlag)
        elif ctype == 'textedit' or ctype == 'string' or ctype == 'set':
            te = self.create_textedit(name, ctrl_def)
            table.add(te, 1, 2, row, row + 1, HExpandFlag | HFillFlag)
            ctrl = ('txt', (enabled, te), ctrl_def)
            self.opt2ctrl_map[name] = ctrl
        elif ctype == "directory" or ctype == "filename" or ctype == "dirname":
            (dir_box, te, btn) = self.create_dir_file_edit(name, ctrl_def)
            table.add(dir_box, 1, 2, row, row + 1, HExpandFlag | HFillFlag)
            te.add_changed_callback(lambda: self.control_action(name))
            ctrl = ('dir', (enabled, te, btn), ctrl_def)
            self.opt2ctrl_map[name] = ctrl
        elif ctype == "numeric" or ctype == "spinedit":
            #(spin_box, te, unitcontrol, unit_items) = self.create_numeric(name, ctrl_def)
            #ctrl = ('spn', (enabled, te, unitcontrol, unit_items), ctrl_def)
            te = self.create_numeric(name, ctrl_def)
            #ctrl = ('spn', (enabled, te), ctrl_def)
            ctrl = ('txt', (enabled, te), ctrl_def)
            self.opt2ctrl_map[name] = ctrl
            #table.add(spin_box, 1, 2, row, row + 1, HExpandFlag | HFillFlag)
            table.add(te, 1, 2, row, row + 1, HExpandFlag | HFillFlag)
        elif ctype == "dropdownbox" or ctype == 'dropdownboxentry':
            if 'choice' not in ctrl_def:
                te = newTextEntry()
                te.set_enabled(False)
                te.add_changed_callback(lambda: self.control_action(name))
                table.add(te, 1, 2, row, row + 1, HExpandFlag | HFillFlag)
                ctrl = ('txt', (enabled, te), ctrl_def)
                self.opt2ctrl_map[name] = ctrl
            else:
                (dropbox,
                 items) = self.create_dropdownbox(name, ctrl_def, ctype)
                table.add(dropbox, 1, 2, row, row + 1, HExpandFlag | HFillFlag)
                ctrl = ('drp', (enabled, dropbox, items), ctrl_def)
                self.opt2ctrl_map[name] = ctrl

        if CATOPTS is None:
            table.add(enabled, 0, 1, row, row + 1, HFillFlag)
            enabled.add_clicked_callback(
                lambda: self.enabled_checkbox_click(name))
        else:
            catbox = newBox(True)
            cat = newSelector(mforms.SelectorCombobox)
            for item in cat_sec:
                cat.add_item(item)
            grp = newSelector(mforms.SelectorCombobox)
            for item in cat_grp:
                grp.add_item(item)
            cat.add_changed_callback(
                lambda: handle_cat_opt(cat, grp, ctrl_def['name']))
            grp.add_changed_callback(
                lambda: handle_cat_opt(cat, grp, ctrl_def['name']))
            catbox.add(cat, True, True)
            catbox.add(grp, True, True)
            catbox.add(enabled, True, True)
            table.add(catbox, 0, 1, row, row + 1, HExpandFlag | HFillFlag)

        return ctrl
Esempio n. 42
0
    def create_ui(self):
        dprint_ex(4, "Enter")
        self.suspend_layout()

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

        self.connection_list = newTreeNodeView(mforms.TreeDefault
                                               | mforms.TreeFlatList)
        self.connection_list.add_column(mforms.LongIntegerColumnType, "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", 60,
                                        False)
        self.connection_list.add_column(mforms.StringColumnType, "State", 80,
                                        False)
        self.info_column = 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)

        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"))

        copy_button = newButton()
        copy_button.set_text("Copy Selected")
        box.add_end(copy_button, False, True)
        copy_button.add_clicked_callback(weakcb(self, "copy_selected"))

        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"))

        refresh_label = newLabel("Refresh Rate:")
        box.add(refresh_label, False, True)

        self.refresh_values = [0.5, 1, 2, 3, 4, 5, 10, 15, 30]
        self.refresh_values_size = len(self.refresh_values)

        self.refresh_selector = newSelector()
        self.refresh_selector.set_size(100, -1)

        for s in self.refresh_values:
            self.refresh_selector.add_item(str(s) + " seconds")

        self.refresh_selector.add_item("Don't Refresh")

        self.refresh_selector.set_selected(9)
        box.add(self.refresh_selector, False, True)
        self.refresh_selector.add_changed_callback(
            weakcb(self, "update_refresh_rate"))

        self.add(box, False, True)

        self.resume_layout()

        self.connection_selected()
        dprint_ex(4, "Leave")
    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()
Esempio n. 44
0
    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)