def create_ui(self):
        self._form_deactivated_conn = mforms.Form.main_form().add_deactivated_callback(self.form_deactivated)
        self.content = mforms.newScrollPanel(0)

        self.drawbox = RenderBox(self)
        self.canvas = Canvas(self.set_needs_repaint)
        if "linux" not in sys.platform:
            color = Color.getSystemColor(ControlBackgroundColor)
            self.canvas.set_background_color(color.red, color.green, color.blue)

        self.drawbox.canvas = self.canvas
        self.drawbox.set_size(1024, 700)
        self.content.add(self.drawbox)

        self.widgets = []
        self.figures = []
        self.last_refresh_time = None
        
        self.drawbox.variable_values = self.ctrl_be.server_variables
        server_version = Version.fromgrt(self.ctrl_be.target_version)
        GLOBAL_DASHBOARD_WIDGETS = GLOBAL_DASHBOARD_WIDGETS_NETWORK + GLOBAL_DASHBOARD_WIDGETS_MYSQL_PRE_80 + GLOBAL_DASHBOARD_WIDGETS_INNODB
        if server_version and server_version.is_supported_mysql_version_at_least(8, 0, 0):
            GLOBAL_DASHBOARD_WIDGETS = GLOBAL_DASHBOARD_WIDGETS_NETWORK + GLOBAL_DASHBOARD_WIDGETS_MYSQL_POST_80 + GLOBAL_DASHBOARD_WIDGETS_INNODB
        # create all widgets
        for caption, wclass, args, init, (calc, calc_expr), color, pos, hover_text in GLOBAL_DASHBOARD_WIDGETS:
            if caption:
                fig = TextFigure(caption)
                self.figures.append(fig)
                fig.set_text_color(0, 0, 0)
                fig.set_font_size(13)
                fig.set_font_bold(True)
                self.drawbox.add(fig)
                fig.move(pos[0], pos[1] - 20)
        
            w = wclass(calc(calc_expr) if calc else None, *args)
            self.drawbox.add(w)
            w.set_main_color(color)
            w.move(*pos)
            if hover_text:
                w.hover_text_template = hover_text
            
            if init:
                init_calc, init_expr = init
                w.init(init_calc(init_expr).handle(self.ctrl_be.server_variables, None))

            self.widgets.append(w)

        self.updateColors(None, None, None)
        self.refresh()
        self._refresh_tm = mforms.Utilities.add_timeout(self.ctrl_be.status_variable_poll_interval, self.refresh)
            
        self.ctrl_be.add_me_for_event("server_started", self)
        self.ctrl_be.add_me_for_event("server_stopped", self)
        
        return self.content
Exemple #2
0
    def create_ui(self):
        #self.create_basic_ui("title_dashboard.png", "Dashboard")

        self._form_deactivated_conn = mforms.Form.main_form(
        ).add_deactivated_callback(self.form_deactivated)

        self.content = mforms.newScrollPanel(0)

        self.drawbox = RenderBox(self)
        self.canvas = Canvas(self.set_needs_repaint)
        self.drawbox.canvas = self.canvas
        self.drawbox.set_size(1024, 700)
        self.content.add(self.drawbox)

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

        self.widgets = []

        self.last_refresh_time = None

        #
        self.drawbox.variable_values = self.ctrl_be.server_variables

        # create all widgets
        for caption, wclass, args, init, (
                calc,
                calc_expr), color, pos, hover_text in GLOBAL_DASHBOARD_WIDGETS:
            if caption:
                fig = TextFigure(caption)
                fig.set_text_color(0.5, 0.5, 0.5)
                fig.set_font_size(11)
                fig.set_font_bold(True)
                self.drawbox.add(fig)
                fig.move(pos[0], pos[1] - 20)

            w = wclass(calc(calc_expr) if calc else None, *args)
            self.drawbox.add(w)
            w.set_main_color(color)
            w.move(*pos)
            if hover_text:
                w.hover_text_template = hover_text

            if init:
                init_calc, init_expr = init
                w.init(
                    init_calc(init_expr).handle(self.ctrl_be.server_variables,
                                                None))

            self.widgets.append(w)

        self.refresh()
        self._refresh_tm = mforms.Utilities.add_timeout(
            self.ctrl_be.status_variable_poll_interval, self.refresh)
Exemple #3
0
class WbAdminDashboard(WbAdminTabBase):
    def __init__(self, ctrl_be, instance_info, main_view):
        WbAdminTabBase.__init__(self, ctrl_be, instance_info, main_view)

        nc.add_observer(self.updateColors, "GNColorsChanged")

        self.min_server_version = (5, 6, 6)

        self._refresh_tm = None
        self.drawbox = None
        self._form_deactivated_conn = None

        self.add_validation(WbAdminValidationConnection(ctrl_be))

    @classmethod
    def wba_register(cls, admin_context):
        admin_context.register_page(cls, "Performance", "Dashboard",
                                    "Dashboard", False)

    @classmethod
    def identifier(cls):
        return "admin_dashboard"

    def set_needs_repaint(self, x, y, w, h):
        self.drawbox.set_needs_repaint()

    def create_ui(self):
        self._form_deactivated_conn = mforms.Form.main_form(
        ).add_deactivated_callback(self.form_deactivated)
        self.content = mforms.newScrollPanel(0)

        self.drawbox = RenderBox(self)
        self.canvas = Canvas(self.set_needs_repaint)
        if "linux" not in sys.platform:
            color = Color.getSystemColor(ControlBackgroundColor)
            self.canvas.set_background_color(color.red, color.green,
                                             color.blue)

        self.drawbox.canvas = self.canvas
        self.drawbox.set_size(1024, 700)
        self.content.add(self.drawbox)

        self.widgets = []
        self.figures = []
        self.last_refresh_time = None

        self.drawbox.variable_values = self.ctrl_be.server_variables
        server_version = Version.fromgrt(self.ctrl_be.target_version)
        GLOBAL_DASHBOARD_WIDGETS = GLOBAL_DASHBOARD_WIDGETS_NETWORK + GLOBAL_DASHBOARD_WIDGETS_MYSQL_PRE_80 + GLOBAL_DASHBOARD_WIDGETS_INNODB
        if server_version and server_version.is_supported_mysql_version_at_least(
                8, 0, 0):
            GLOBAL_DASHBOARD_WIDGETS = GLOBAL_DASHBOARD_WIDGETS_NETWORK + GLOBAL_DASHBOARD_WIDGETS_MYSQL_POST_80 + GLOBAL_DASHBOARD_WIDGETS_INNODB
        # create all widgets
        for caption, wclass, args, init, (
                calc,
                calc_expr), color, pos, hover_text in GLOBAL_DASHBOARD_WIDGETS:
            if caption:
                fig = TextFigure(caption)
                self.figures.append(fig)
                fig.set_text_color(0, 0, 0)
                fig.set_font_size(13)
                fig.set_font_bold(True)
                self.drawbox.add(fig)
                fig.move(pos[0], pos[1] - 20)

            w = wclass(calc(calc_expr) if calc else None, *args)
            self.drawbox.add(w)
            w.set_main_color(color)
            w.move(*pos)
            if hover_text:
                w.hover_text_template = hover_text

            if init:
                init_calc, init_expr = init
                w.init(
                    init_calc(init_expr).handle(self.ctrl_be.server_variables,
                                                None))

            self.widgets.append(w)

        self.updateColors(None, None, None)
        self.refresh()
        self._refresh_tm = mforms.Utilities.add_timeout(
            self.ctrl_be.status_variable_poll_interval, self.refresh)

        self.ctrl_be.add_me_for_event("server_started", self)
        self.ctrl_be.add_me_for_event("server_stopped", self)

        return self.content

    def server_started_event(self):
        for widget in self.widgets:
            if not hasattr(widget, "calc"):
                continue

            if issubclass(type(widget.calc), CDifferencePerSecond):
                widget.calc.reset()

    #---------------------------------------------------------------------------
    def server_stopped_event(self):
        pass

    def repaint(self):
        self.drawbox.set_needs_repaint()
        return True

    def shutdown(self):
        nc.remove_observer(self.updateColors)

        if self._form_deactivated_conn:
            self._form_deactivated_conn.disconnect()
            self._form_deactivated_conn = None

        if self._refresh_tm:
            mforms.Utilities.cancel_timeout(self._refresh_tm)
            self._refresh_tm = None

    def refresh(self):
        status_variables, timestamp = self.ctrl_be.status_variables, self.ctrl_be.status_variables_time
        if self.last_refresh_time != timestamp:
            for w in self.widgets:
                if hasattr(w, 'process'):
                    w.process(status_variables, timestamp)

            self.drawbox.variable_values.update(status_variables)

            self.drawbox.set_needs_repaint()

        return True

    def form_deactivated(self):
        if self.drawbox:
            self.drawbox.close_tooltip()

    def page_deactivated(self):
        if self.drawbox:
            self.drawbox.close_tooltip()

    def relayout(self):
        full_width = max(1024, self.content.get_width())
        full_height = max(700, self.content.get_height())

        if sys.platform.lower() == "darwin":
            if self.drawbox.get_width(
            ) != full_width or self.drawbox.get_height() != full_height:
                self.drawbox.set_size(full_width, full_height)
        # return offset
        return (full_width - 1024) / 2, (full_height - 700) / 2

    def updateColors(self, name, sender, info):
        if "linux" not in sys.platform:
            color = Color.getSystemColor(ControlBackgroundColor)
            self.canvas.set_background_color(color.red, color.green,
                                             color.blue)

        textColor = Color.getSystemColor(TextColor)
        backgroundColor = Color.getSystemColor(TextBackgroundColor)
        for f in self.figures:
            f.set_text_color(textColor.red, textColor.green, textColor.blue,
                             textColor.alpha)

        dark = mforms.App.get().isDarkModeActive()
        for w in self.widgets:
            if hasattr(w, "switch_image_mode"):
                w.switch_image_mode(dark)
            if hasattr(w, "set_fill_color"):
                w.set_fill_color(backgroundColor.red, backgroundColor.green,
                                 backgroundColor.blue, backgroundColor.alpha)
            if hasattr(w, "set_text_color"):
                w.set_text_color(textColor.red, textColor.green,
                                 textColor.blue, textColor.alpha)