示例#1
0
 def recreatePlotMatrixPanel(self, PD, sub):
     nr_signals = len(PD)
     plot_matrix_sizer  = wx.FlexGridSizer(rows=nr_signals, cols=nr_signals, hgap=0, vgap=3)
     self.plotMatrixPanel.DestroyChildren()
     if os.name == 'nt':
         BUTTON_SIZE = 17
     else:
         BUTTON_SIZE = 21
     for i in range(nr_signals ** 2):
         buttonLabel = "-"
         showButton = False
         if sub:
             showButton = True
             # Square matrix: up to n subplots
             if (i % nr_signals) == int(i / nr_signals):
                 buttonLabel = '1'
         else:
             # Single column: single plot
             if (i % nr_signals) == 0:
                 buttonLabel = '1'
                 showButton = True
         btn = GenButton(self.plotMatrixPanel, label=buttonLabel, size=(BUTTON_SIZE, BUTTON_SIZE), style=wx.BU_EXACTFIT)
         btn.Bind(wx.EVT_BUTTON, self._onLeftClick)
         btn.Bind(wx.EVT_CONTEXT_MENU, self._onRightClick)
         
         if showButton is False:
             btn.Hide()
         plot_matrix_sizer.Add(btn)
     self.plotMatrixPanel.SetSizer(plot_matrix_sizer)
     self.Layout()
     self.Refresh()
     self.Update()
示例#2
0
文件: ttt.py 项目: marshallstan/note
    def _init_ui(self):
        main_sizer = wx.BoxSizer(wx.VERTICAL)
        main_sizer.AddStretchSpacer()

        self.st_time = wx.StaticText(self, label='00 : 00 : 00')
        self.st_time.SetFont(wx.Font(wx.FontInfo(120)))

        self.btn_run = GenButton(self,
                                 label='开始',
                                 size=(100, 30),
                                 style=wx.BORDER_NONE)
        self.btn_reset = GenButton(self,
                                   label='复位',
                                   size=(100, 30),
                                   style=wx.BORDER_NONE)

        main_sizer.Add(self.st_time, flag=wx.ALIGN_CENTER_HORIZONTAL)
        main_sizer.AddSpacer(80)

        main_sizer.Add(self.btn_run, flag=wx.ALIGN_CENTER_HORIZONTAL)
        main_sizer.AddSpacer(30)
        main_sizer.Add(self.btn_reset, flag=wx.ALIGN_CENTER_HORIZONTAL)

        main_sizer.AddStretchSpacer()
        self.SetSizer(main_sizer)
        self.Maximize()

        self.st_time.SetForegroundColour('white')
        self.btn_run.SetBackgroundColour('#00CC99')
        self.btn_run.SetForegroundColour('white')
        self.btn_reset.SetBackgroundColour('#FF6666')
        self.btn_reset.SetForegroundColour('white')
        self.SetBackgroundColour('#444444')
示例#3
0
    def __init__(self, parent, size=(75, 21), value=None):
        GenButton.__init__(self, parent, wx.ID_ANY, label="Select...", 
                           size=size)
        self.SetBezelWidth(1)

        self.parent = parent
        self.SetValue(value)
        
        self.parent.Bind(wx.EVT_BUTTON, self.OnClick, self)
示例#4
0
    def __init__(self, parent, size=(75, 21), value=None):
        GenButton.__init__(self, parent, wx.ID_ANY, label="Select...", 
                           size=size)
        self.SetBezelWidth(1)

        self.parent = parent
        self.SetValue(value)
        
        self.parent.Bind(wx.EVT_BUTTON, self.OnClick, self)
示例#5
0
        def _makeButtons(words):
            sizer = wx.WrapSizer()
            for word in words:
                btn = GenButton(pnl, -1, word, style=wx.BU_EXACTFIT)
                sizer.Add(btn, 0, wx.ALL, 4)

                # Add a little color to make it interesting
                r = random.randint(128, 255)
                g = random.randint(128, 255)
                b = random.randint(128, 255)
                btn.SetBackgroundColour(wx.Colour(r, g, b))
                btn.Refresh()

            return sizer
示例#6
0
    def _createColorButtons(self):
        """Generate color buttons based on the presets defined in the `colors`
        module.

        When a user clicks on the buttons, it changes the current color the
        colorspace page is displaying.

        """
        # create buttons for each preset color
        colorList = list(colorNames)
        btnSize = wx.Size(120, 24)
        for color in colorList:
            btn = GenButton(self, size=btnSize, label=color, name=color)
            btn.colorData = col = Color(color, 'named')
            btn.SetOwnBackgroundColour(col.rgba255)

            # Compute the (perceived) luminance of the color, used to set the
            # foreground text to ensure it's legible on the background. Uses the
            # the luminance part of formula to convert RGB1 to YIQ.
            luminance = np.sum(np.asarray((0.299, 0.587, 0.114)) * col.rgb1)
            if luminance < 0.5:
                btn.SetForegroundColour(wx.WHITE)
            else:
                btn.SetForegroundColour(wx.BLACK)

            btn.SetBezelWidth(0)
            btn.SetUseFocusIndicator(False)
            btn.Bind(wx.EVT_BUTTON, self.onClick)
            self.sizer.Add(btn, 1, wx.ALL | wx.EXPAND, 0)
示例#7
0
 def __init__(self,parent, labelOn, labelOff, pos, sz, font, clickedCallback):
     GenButton.__init__(self,parent,id = -1,pos = pos, size = sz,label = labelOn)
     self.SetBezelWidth(0)
     self.SetUseFocusIndicator(False)
     self.SetBackgroundColour(basePurple)
     self.SetForegroundColour(btnForeground)
     self.SetFont(font)
     self.Bind(wx.EVT_LEFT_DOWN, self.OnDown)
     self.Bind(wx.EVT_LEFT_UP, self.OnUp)
     self.Bind(wx.EVT_LEFT_DCLICK, self.DoNothing)
     self.Bind(wx.EVT_MOTION, self.DoNothing)
     self.labelOn = labelOn
     self.labelOff = labelOff
     self.clickedCallback = clickedCallback
    def __init__(self,parent,n,shown=False):
        self.values = {
            "label":"",
            "running":False,
            "formatted_value":"",
            "OK":True,
            "test_code_OK":False
        }
        self.old_values = {}

        wx.Panel.__init__(self,parent)
        self.Shown = shown
        self.Title = "Test %d" % n
        self.n = n
        self.myEnabled = wx.CheckBox(self,size=(470,-1))
        from wx.lib.buttons import GenButton
        self.State = GenButton(self,size=(25,20))
        self.Setup = wx.Button(self,size=(60,-1),label="More...")
        self.Setup.Shown = False
        self.Log = wx.Button(self,size=(50,-1),label="Log...")

        self.Bind(wx.EVT_CHECKBOX,self.OnEnable,self.myEnabled)
        self.Bind(wx.EVT_BUTTON,self.OnState,self.State)
        self.Bind(wx.EVT_BUTTON,self.OnSetup,self.Setup)
        self.Bind(wx.EVT_BUTTON,self.OnLog,self.Log)

        # Layout
        self.layout = wx.BoxSizer(wx.HORIZONTAL)
        flag = wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.EXPAND
        self.layout.Add(self.myEnabled,flag=flag,proportion=1)
        self.layout.Add(self.State,flag=flag)
        self.layout.Add(self.Setup,flag=flag)
        self.layout.Add(self.Log,flag=flag)

        # Leave a 10 pixel wide border.
        self.box = wx.BoxSizer(wx.VERTICAL)
        self.box.Add(self.layout,flag=wx.ALL,border=5)
        self.SetSizer(self.box)
        self.Fit()

        self.refresh_label()

        # Periodically refresh the displayed settings.
        self.Bind(wx.EVT_TIMER,self.OnUpdate)
        from threading import Thread
        self.thread = Thread(target=self.keep_updated,name=self.name)
        self.thread.daemon = True
        self.thread.start()
示例#9
0
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)

        text = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        sizer = wx.WrapSizer()
        for letter in text:
            btn = GenButton(self, label=letter)
            r = random.randint(128, 255)
            g = random.randint(128, 255)
            b = random.randint(128, 255)
            btn.SetBackgroundColour(wx.Colour(r, g, b))
            btn.Refresh()
            sizer.Add(btn, 0, wx.ALL, 5)

        self.SetSizer(sizer)
示例#10
0
 def __init__(self, parent):
     ScrolledPanel.__init__(self, parent, size=(120,400), style=wx.VSCROLL | wx.BORDER_NONE)
     self.sizer = wx.GridBagSizer()
     self.parent = parent
     for i in range(len(colorNames)):
         color = list(colorNames)[i]
         btn = GenButton(self, size=(100, 30),
                            label=color, name=color)
         btn.SetOwnBackgroundColour(Color(color, 'named').rgba255)
         btn.SetBezelWidth(0)
         btn.SetUseFocusIndicator(False)
         btn.colorData = color
         #btn.SetBackgroundColour(wx.Colour(Color(color, 'named').rgba1))
         btn.Bind(wx.EVT_BUTTON, self.onClick)
         self.sizer.Add(btn, pos=(i,0))
     self.SetSizer(self.sizer)
     self.SetupScrolling()
示例#11
0
 def create_begin(self):
     main_sizer = wx.BoxSizer(wx.VERTICAL)
     self.SetFont(
         wx.Font(25,
                 wx.FONTFAMILY_MODERN,
                 wx.FONTSTYLE_NORMAL,
                 wx.FONTWEIGHT_BOLD,
                 faceName="Roboto"))
     begin_button = GenButton(self,
                              id=-1,
                              label="Arrange",
                              size=(200, 55),
                              style=wx.BORDER_SIMPLE)
     begin_button.SetForegroundColour(wx.Colour(255, 255, 255))
     begin_button.SetBezelWidth(1)
     begin_button.SetBackgroundColour('#5f9ad8')
     begin_button.SetCursor(wx.Cursor(
         wx.CURSOR_HAND))  #StockCursor deprecated
     begin_button.SetWindowStyleFlag(wx.RAISED_BORDER)
     main_sizer.AddStretchSpacer()
     main_sizer.Add(begin_button, 0, wx.CENTER)
     main_sizer.AddStretchSpacer()
     self.SetSizer(main_sizer)
     self.Bind(wx.EVT_BUTTON, self.onDir, begin_button)
    def __init__(self,
                 parent,
                 id=wx.ID_ANY,
                 pos=wx.DefaultPosition,
                 size=wx.DefaultSize,
                 classparent=None):
        """
        Default class constructor.

        Used internally. Do not call directly this class in your application!
        """

        wx.Frame.__init__(self,
                          None,
                          -1,
                          "BalloonTip",
                          pos,
                          size,
                          style=wx.FRAME_SHAPED | wx.SIMPLE_BORDER
                          | wx.FRAME_NO_TASKBAR | wx.STAY_ON_TOP)

        self._parent = classparent
        self._toptitle = self._parent._toptitle
        self._topicon = self._parent._topicon
        self._message = self._parent._message
        self._shape = self._parent._shape
        self._tipstyle = self._parent._tipstyle

        self._ballooncolour = self._parent._ballooncolour
        self._balloonmsgcolour = self._parent._balloonmsgcolour
        self._balloonmsgfont = self._parent._balloonmsgfont

        if self._toptitle != "":
            self._balloontitlecolour = self._parent._balloontitlecolour
            self._balloontitlefont = self._parent._balloontitlefont

        panel = wx.Panel(self, -1)
        sizer = wx.BoxSizer(wx.VERTICAL)

        self.panel = panel

        subsizer = wx.BoxSizer(wx.VERTICAL)
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        subsizer.Add((0, 20), 0, wx.EXPAND)

        if self._topicon is not None:
            stb = wx.StaticBitmap(panel, -1, self._topicon)
            hsizer.Add(stb, 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 10)
            self._balloonbmp = stb

        if self._toptitle != "":
            stt = wx.StaticText(panel, -1, self._toptitle)
            stt.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False))
            if self._topicon is None:
                hsizer.Add((10, 0), 0, wx.EXPAND)

            hsizer.Add(stt, 1, wx.EXPAND | wx.TOP, 10)

            self._balloontitle = stt
            self._balloontitle.SetForegroundColour(self._balloontitlecolour)
            self._balloontitle.SetFont(self._balloontitlefont)

        if self._tipstyle == BT_BUTTON:
            self._closebutton = GenButton(panel, -1, "X", style=wx.NO_BORDER)
            self._closebutton.SetMinSize((16, 16))
            self._closebutton.SetFont(
                wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False))
            self._closebutton.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterButton)
            self._closebutton.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveButton)
            self._closebutton.SetUseFocusIndicator(False)
            if self._toptitle != "":
                hsizer.Add(self._closebutton, 0, wx.TOP | wx.RIGHT, 5)
            else:
                hsizer.Add((10, 0), 1, wx.EXPAND)
                hsizer.Add(self._closebutton, 0, wx.ALIGN_RIGHT | wx.TOP
                           | wx.RIGHT, 5)

        if self._topicon is not None or self._toptitle != "" \
           or self._tipstyle == BT_BUTTON:

            subsizer.Add(hsizer, 0, wx.EXPAND | wx.BOTTOM, 5)

        self._firstline = line = wx.StaticLine(panel,
                                               -1,
                                               style=wx.LI_HORIZONTAL)

        if self._topicon is not None or self._toptitle != "" \
           or self._tipstyle == BT_BUTTON:
            subsizer.Add(self._firstline, 0, wx.EXPAND | wx.LEFT | wx.RIGHT
                         | wx.BOTTOM, 10)
        else:
            subsizer.Add(self._firstline, 0, wx.EXPAND | wx.LEFT | wx.RIGHT
                         | wx.BOTTOM | wx.TOP, 10)

        mainstt = wx.StaticText(panel, -1, self._message)

        self._balloonmsg = mainstt
        self._balloonmsg.SetForegroundColour(self._balloonmsgcolour)
        self._balloonmsg.SetFont(self._balloonmsgfont)

        subsizer.Add(self._balloonmsg, 1,
                     wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, 10)
        self._secondline = wx.StaticLine(panel, -1, style=wx.LI_HORIZONTAL)
        subsizer.Add(self._secondline, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
        subsizer.Add((0, 0), 1)
        panel.SetSizer(subsizer)

        sizer.Add(panel, 1, wx.EXPAND)
        self.SetSizerAndFit(sizer)
        sizer.Layout()

        if self._tipstyle == BT_CLICK:
            if self._toptitle != "":
                self._balloontitle.Bind(wx.EVT_LEFT_DOWN, self.OnClose)

            if self._topicon is not None:
                self._balloonbmp.Bind(wx.EVT_LEFT_DOWN, self.OnClose)

            self._balloonmsg.Bind(wx.EVT_LEFT_DOWN, self.OnClose)
            self.panel.Bind(wx.EVT_LEFT_DOWN, self.OnClose)

        elif self._tipstyle == BT_BUTTON:
            self._closebutton.Bind(wx.EVT_BUTTON, self.OnClose)

        self.panel.SetBackgroundColour(self._ballooncolour)

        if wx.Platform == "__WXGTK__":
            self.Bind(wx.EVT_WINDOW_CREATE, self.SetBalloonShape)
        else:
            self.SetBalloonShape()

        self.Show(True)
class BalloonFrame(wx.Frame):
    def __init__(self,
                 parent,
                 id=wx.ID_ANY,
                 pos=wx.DefaultPosition,
                 size=wx.DefaultSize,
                 classparent=None):
        """
        Default class constructor.

        Used internally. Do not call directly this class in your application!
        """

        wx.Frame.__init__(self,
                          None,
                          -1,
                          "BalloonTip",
                          pos,
                          size,
                          style=wx.FRAME_SHAPED | wx.SIMPLE_BORDER
                          | wx.FRAME_NO_TASKBAR | wx.STAY_ON_TOP)

        self._parent = classparent
        self._toptitle = self._parent._toptitle
        self._topicon = self._parent._topicon
        self._message = self._parent._message
        self._shape = self._parent._shape
        self._tipstyle = self._parent._tipstyle

        self._ballooncolour = self._parent._ballooncolour
        self._balloonmsgcolour = self._parent._balloonmsgcolour
        self._balloonmsgfont = self._parent._balloonmsgfont

        if self._toptitle != "":
            self._balloontitlecolour = self._parent._balloontitlecolour
            self._balloontitlefont = self._parent._balloontitlefont

        panel = wx.Panel(self, -1)
        sizer = wx.BoxSizer(wx.VERTICAL)

        self.panel = panel

        subsizer = wx.BoxSizer(wx.VERTICAL)
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        subsizer.Add((0, 20), 0, wx.EXPAND)

        if self._topicon is not None:
            stb = wx.StaticBitmap(panel, -1, self._topicon)
            hsizer.Add(stb, 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 10)
            self._balloonbmp = stb

        if self._toptitle != "":
            stt = wx.StaticText(panel, -1, self._toptitle)
            stt.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False))
            if self._topicon is None:
                hsizer.Add((10, 0), 0, wx.EXPAND)

            hsizer.Add(stt, 1, wx.EXPAND | wx.TOP, 10)

            self._balloontitle = stt
            self._balloontitle.SetForegroundColour(self._balloontitlecolour)
            self._balloontitle.SetFont(self._balloontitlefont)

        if self._tipstyle == BT_BUTTON:
            self._closebutton = GenButton(panel, -1, "X", style=wx.NO_BORDER)
            self._closebutton.SetMinSize((16, 16))
            self._closebutton.SetFont(
                wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False))
            self._closebutton.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterButton)
            self._closebutton.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveButton)
            self._closebutton.SetUseFocusIndicator(False)
            if self._toptitle != "":
                hsizer.Add(self._closebutton, 0, wx.TOP | wx.RIGHT, 5)
            else:
                hsizer.Add((10, 0), 1, wx.EXPAND)
                hsizer.Add(self._closebutton, 0, wx.ALIGN_RIGHT | wx.TOP
                           | wx.RIGHT, 5)

        if self._topicon is not None or self._toptitle != "" \
           or self._tipstyle == BT_BUTTON:

            subsizer.Add(hsizer, 0, wx.EXPAND | wx.BOTTOM, 5)

        self._firstline = line = wx.StaticLine(panel,
                                               -1,
                                               style=wx.LI_HORIZONTAL)

        if self._topicon is not None or self._toptitle != "" \
           or self._tipstyle == BT_BUTTON:
            subsizer.Add(self._firstline, 0, wx.EXPAND | wx.LEFT | wx.RIGHT
                         | wx.BOTTOM, 10)
        else:
            subsizer.Add(self._firstline, 0, wx.EXPAND | wx.LEFT | wx.RIGHT
                         | wx.BOTTOM | wx.TOP, 10)

        mainstt = wx.StaticText(panel, -1, self._message)

        self._balloonmsg = mainstt
        self._balloonmsg.SetForegroundColour(self._balloonmsgcolour)
        self._balloonmsg.SetFont(self._balloonmsgfont)

        subsizer.Add(self._balloonmsg, 1,
                     wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, 10)
        self._secondline = wx.StaticLine(panel, -1, style=wx.LI_HORIZONTAL)
        subsizer.Add(self._secondline, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 10)
        subsizer.Add((0, 0), 1)
        panel.SetSizer(subsizer)

        sizer.Add(panel, 1, wx.EXPAND)
        self.SetSizerAndFit(sizer)
        sizer.Layout()

        if self._tipstyle == BT_CLICK:
            if self._toptitle != "":
                self._balloontitle.Bind(wx.EVT_LEFT_DOWN, self.OnClose)

            if self._topicon is not None:
                self._balloonbmp.Bind(wx.EVT_LEFT_DOWN, self.OnClose)

            self._balloonmsg.Bind(wx.EVT_LEFT_DOWN, self.OnClose)
            self.panel.Bind(wx.EVT_LEFT_DOWN, self.OnClose)

        elif self._tipstyle == BT_BUTTON:
            self._closebutton.Bind(wx.EVT_BUTTON, self.OnClose)

        self.panel.SetBackgroundColour(self._ballooncolour)

        if wx.Platform == "__WXGTK__":
            self.Bind(wx.EVT_WINDOW_CREATE, self.SetBalloonShape)
        else:
            self.SetBalloonShape()

        self.Show(True)

    def SetBalloonShape(self, event=None):
        """ Sets the balloon shape."""

        size = self.GetSize()
        pos = self.GetPosition()

        dc = wx.MemoryDC(wx.EmptyBitmap(1, 1))
        textlabel = self._balloonmsg.GetLabel()
        textfont = self._balloonmsg.GetFont()
        textextent = dc.GetFullTextExtent(textlabel, textfont)

        boxheight = size.y - textextent[1] * len(textlabel.split("\n"))
        boxwidth = size.x

        position = wx.GetMousePosition()

        xpos = position[0]
        ypos = position[1]

        if xpos > 20 and ypos > 20:

            # This Is NW Positioning
            positioning = "NW"
            xpos = position[0] - boxwidth + 20
            ypos = position[1] - boxheight - 20

        elif xpos <= 20 and ypos <= 20:

            # This Is SE Positioning
            positioning = "SE"
            xpos = position[0] - 20
            ypos = position[1]

        elif xpos > 20 and ypos <= 20:

            # This Is SW Positioning
            positioning = "SW"
            xpos = position[0] - boxwidth + 20
            ypos = position[1]

        else:

            # This Is NE Positioning
            positioning = "NE"
            xpos = position[0]
            ypos = position[1] - boxheight + 20

        bmp = wx.EmptyBitmap(size.x, size.y)
        dc = wx.BufferedDC(None, bmp)
        dc.BeginDrawing()
        dc.SetBackground(wx.Brush(wx.Colour(0, 0, 0), wx.SOLID))
        dc.Clear()
        dc.SetPen(wx.Pen(wx.Colour(0, 0, 0), 1, wx.TRANSPARENT))

        if self._shape == BT_ROUNDED:
            dc.DrawRoundedRectangle(0, 20, boxwidth, boxheight - 20, 12)

        elif self._shape == BT_RECTANGLE:
            dc.DrawRectangle(0, 20, boxwidth, boxheight - 20)

        if positioning == "NW":
            dc.DrawPolygon(
                ((boxwidth - 40, boxheight), (boxwidth - 20, boxheight + 20),
                 (boxwidth - 20, boxheight)))
        elif positioning == "SE":
            dc.DrawPolygon(((20, 20), (20, 0), (40, 20)))

        elif positioning == "SW":
            dc.DrawPolygon(
                ((boxwidth - 40, 20), (boxwidth - 20, 0), (boxwidth - 20, 20)))

        else:
            dc.DrawPolygon(
                ((20, boxheight), (20, boxheight + 20), (40, boxheight)))

        dc.EndDrawing()

        r = wx.RegionFromBitmapColour(bmp, wx.Colour(0, 0, 0))
        self.hasShape = self.SetShape(r)

        if self._tipstyle == BT_BUTTON:
            colour = self.panel.GetBackgroundColour()
            self._closebutton.SetBackgroundColour(colour)

        self.SetPosition((xpos, ypos))

    def OnEnterButton(self, event):
        """
        Handles the wx.EVT_ENTER_WINDOW for the BalloonTip button.

        When the BalloonTip is created with the tipstyle=BT_BUTTON, this event
        provide some kind of 3d effect when the mouse enters the button area.
        """

        button = event.GetEventObject()
        colour = button.GetBackgroundColour()
        red = colour.Red()
        green = colour.Green()
        blue = colour.Blue()

        if red < 30:
            red = red + 30
        if green < 30:
            green = green + 30
        if blue < 30:
            blue = blue + 30

        colour = wx.Colour(red - 30, green - 30, blue - 30)
        button.SetBackgroundColour(colour)
        button.SetForegroundColour(wx.WHITE)
        button.Refresh()
        event.Skip()

    def OnLeaveButton(self, event):
        """
        Handles the wx.EVT_LEAVE_WINDOW for the BalloonTip button.

        When the BalloonTip is created with the tipstyle=BT_BUTTON, this event
        restore the button appearance when the mouse leaves the button area.
        """

        button = event.GetEventObject()
        colour = self.panel.GetBackgroundColour()
        button.SetBackgroundColour(colour)
        button.SetForegroundColour(wx.BLACK)
        button.Refresh()
        event.Skip()

    def OnClose(self, event):
        """ Handles the wx.EVT_CLOSE event."""

        if isinstance(self._parent._widget, wx.TaskBarIcon):
            self._parent.taskbarcreation = 0
            self._parent.taskbartime.Stop()
            del self._parent.taskbartime
            del self._parent.BalloonFrame

        self.Destroy()
示例#14
0
    def makeControlForProp(self, prop, parent):
        '''Make a wxWindows control for the given NWN property and add
        it to the given parent wxWindow.'''
        control = None
        typeSpec = prop.getSpec()
        type = typeSpec[0]
        if type == 'CExoLocString':
            control = CExoLocStringControl(typeSpec, prop, self,
                                           self.defaultlang)
        elif type == 'CExoString':
            if len(typeSpec) > 1:
                if typeSpec[1] != 'FactionName':
                    control = self.makeCustomChoiceControl(
                        typeSpec, prop, parent)
                else:
                    control = wx.TextCtrl(parent,-1,prop.getValue(),wx.DefaultPosition,\
                                                        (250,24),style=wx.TE_PROCESS_ENTER)
                    wx.EVT_TEXT_ENTER(self, control.GetId(), self.controlUsed)
            else:
                control = wx.TextCtrl(parent, -1, prop.getValue(),
                                      wx.DefaultPosition, (250, 24))
                wx.EVT_TEXT(self, control.GetId(), self.controlUsed)
#				self.Bind(wx.EVT_TEXT,self,self.controlUsed,id=control.GetId())
        elif type == 'Percentage':
            control = wx.SpinCtrl(parent, -1)
            control.SetRange(0, 100)
            control.SetValue(prop.getValue())
            wx.EVT_SPINCTRL(self, control.GetId(), self.controlUsed)
            #control.SetTickFreq(5,0)
        elif type == 'Boolean':
            control = wx.CheckBox(parent, -1, '')
            control.SetValue(prop.getValue())
            wx.EVT_CHECKBOX(self, control.GetId(), self.controlUsed)
        elif type == 'Integer':
            min = 0
            max = 100
            if len(typeSpec) > 1:
                maxMin = typeSpec[1].split('-')
                min = int(maxMin[0])
                max = int(maxMin[1])
            control = wx.SpinCtrl(parent, -1)
            control.SetRange(min, max)
            try:
                control.SetValue(prop.getValue())
            except OverflowError:
                # I got that with some factions that have 0xFFFFFFFF as parents
                # and as they shouldn't be edited anyway..
                control.SetValue(-1)
                control.Disable()
            wx.EVT_SPINCTRL(self, control.GetId(), self.controlUsed)
            wx.EVT_TEXT(self, control.GetId(), self.controlUsed)
        elif type == "ResRef":
            control = self.makeResRefControl(typeSpec, prop, parent)
        elif type == "BGRColour":
            blue = prop.getValue() >> 16
            green = (prop.getValue() >> 8) & (0xff)
            red = prop.getValue() & (0xff)
            control = GenButton(parent, -1, '', wx.DefaultPosition,
                                wx.Size(40, 40))
            control.SetBezelWidth(0)
            control.SetForegroundColour(wx.Colour(red, green, blue))
            control.SetBackgroundColour(wx.Colour(red, green, blue))
            wx.EVT_BUTTON(self, control.GetId(), self.handleColourButton)
        elif type == "List":
            if typeSpec[1] == 'HAKs':
                control = HAKListControl(prop, parent)
            elif typeSpec[1] == 'Vars':
                control = VarListControl(prop, parent)
        elif type == "CheckList":
            choices = []
            #            if typeSpec[1] == 'HAKs':
            #                choices = [x['Mod_Hak'].lower()
            #                           for x in prop.getValue()]
            #                choices.extend([x.split('.')[0].lower() for x in
            #                                neverglobals.getResourceManager().getHAKFileNames()
            #                                if x.split('.')[0].lower() not in choices])
            control = wx.CheckListBox(parent, -1, wx.DefaultPosition,
                                      (200, 200), choices)
            for i in range(len(choices)):
                control.Check(i, False)
#            for n in prop.getValue():
#                control.Check(choices.index(n['Mod_Hak'].lower()))
            wx.EVT_CHECKLISTBOX(self, control.GetId(), self.controlUsed)
        elif type == '2daIndex':
            twoda = neverglobals.getResourceManager().getResourceByName(
                typeSpec[1])
            choices = []
            col = typeSpec[2]
            if typeSpec[3] == 'strref':
                for i in xrange(twoda.getRowCount()):
                    entry = 'invalid'
                    try:
                        entry = neverglobals.getResourceManager().\
                                    getDialogString(int(twoda.getEntry(i,col)))
                    except ValueError:
                        if len(typeSpec) > 4:
                            entry = twoda.getEntry(i, typeSpec[4])
                    choices.append(entry)
            else:
                choices = [
                    twoda.getEntry(i, col) for i in xrange(twoda.getRowCount())
                ]
            if typeSpec[1] in [
                    'ambientmusic.2da', 'ambientsound.2da', 'soundset.2da'
            ]:
                # may be used for other 2das in the future
                control = SoundControl(prop, parent, choices, typeSpec[1])
            else:
                control = wx.Choice(parent,
                                    -1,
                                    choices=[cleanstr(s) for s in choices])
            control.SetSelection(prop.getValue())

        elif type == 'Portrait':
            p = neverglobals.getResourceManager().getPortraitByIndex(
                prop.getValue(), 's')
            if p:
                control = wx.BitmapButton(parent, -1,
                                          WxUtils.bitmapFromImage(p))
                wx.EVT_BUTTON(self, control.GetId(), self.handlePortraitButton)
            else:
                logger.error('unknown portrait index:' + str(prop.getValue()))
                import Image, ImageDraw, ImageFont
                image = Image.new("1", (32, 64))
                font = ImageFont.load_default()
                draw = ImageDraw.Draw(image)
                draw.text((3, 3), "portrait not found", font=font)
                control = wx.BitmapButton(parent, -1,
                                          WxUtils.bitmapFromImage(image))
                wx.EVT_BUTTON(self, control.GetId(), self.handlePortraitButton)
        if control:
            label = wx.StaticText(self, -1, prop.getName().split('.')[-1])
        else:
            label = None
        return (label, PropControl(control))
class ServerControl(wx.Panel):
    name = "ServersControl"
    attributes = "label","running","OK","test_code_OK","formatted_value",
    refresh_period = 1.0

    def __init__(self,parent,n,shown=False):
        self.values = {
            "label":"",
            "running":False,
            "formatted_value":"",
            "OK":True,
            "test_code_OK":False
        }
        self.old_values = {}

        wx.Panel.__init__(self,parent)
        self.Shown = shown
        self.Title = "Test %d" % n
        self.n = n
        self.myEnabled = wx.CheckBox(self,size=(470,-1))
        from wx.lib.buttons import GenButton
        self.State = GenButton(self,size=(25,20))
        self.Setup = wx.Button(self,size=(60,-1),label="More...")
        self.Setup.Shown = False
        self.Log = wx.Button(self,size=(50,-1),label="Log...")

        self.Bind(wx.EVT_CHECKBOX,self.OnEnable,self.myEnabled)
        self.Bind(wx.EVT_BUTTON,self.OnState,self.State)
        self.Bind(wx.EVT_BUTTON,self.OnSetup,self.Setup)
        self.Bind(wx.EVT_BUTTON,self.OnLog,self.Log)

        # Layout
        self.layout = wx.BoxSizer(wx.HORIZONTAL)
        flag = wx.ALL|wx.ALIGN_CENTER_VERTICAL|wx.EXPAND
        self.layout.Add(self.myEnabled,flag=flag,proportion=1)
        self.layout.Add(self.State,flag=flag)
        self.layout.Add(self.Setup,flag=flag)
        self.layout.Add(self.Log,flag=flag)

        # Leave a 10 pixel wide border.
        self.box = wx.BoxSizer(wx.VERTICAL)
        self.box.Add(self.layout,flag=wx.ALL,border=5)
        self.SetSizer(self.box)
        self.Fit()

        self.refresh_label()

        # Periodically refresh the displayed settings.
        self.Bind(wx.EVT_TIMER,self.OnUpdate)
        from threading import Thread
        self.thread = Thread(target=self.keep_updated,name=self.name)
        self.thread.daemon = True
        self.thread.start()

    @property
    def server(self): return servers[self.n]

    def keep_updated(self):
        """Periodically refresh the displayed settings."""
        from time import time,sleep
        while True:
            try:
                t0 = time()
                if self.Shown:
                    ##debug("ServerControl %s: Shown: %r" % (self.n,self.Shown))
                    self.update_data()
                    if self.data_changed:
                        event = wx.PyCommandEvent(wx.EVT_TIMER.typeId,self.Id)
                        # call OnUpdate in GUI thread
                        wx.PostEvent(self.EventHandler,event)
                while time() < t0+self.refresh_period: sleep(0.5)
            except wx.PyDeadObjectError: break

    def OnUpdate(self,event):
        """Periodically refresh the displayed settings."""
        self.refresh_status()

    def refresh(self):
        """Force update"""
        from threading import Thread
        self.thread = Thread(target=self.refresh_background,
            name=self.name+".refresh")
        self.thread.daemon = True
        self.thread.start()

    def refresh_background(self):
        """Force update"""
        self.update_data()
        if self.data_changed:
            event = wx.PyCommandEvent(wx.EVT_TIMER.typeId,self.Id)
            wx.PostEvent(self.EventHandler,event) # call OnUpdate in GUI thread

    def update_data(self):
        """Retreive status information"""
        self.old_values = dict(self.values) # make a copy
        for n in self.attributes:
            try: self.values[n] = getattr(self.server,n)
            except Exception,msg: error("%s\n%s" % (msg,traceback.format_exc()))

    @property
    def data_changed(self):
        """Did the last 'update_data' change the data to be plotted?"""
        changed = (self.values != self.old_values)
        return changed

    def refresh_label(self,event=None):
        """Update the controls with current values"""
        self.Title = self.server.label
        self.myEnabled.Value = self.server.enabled
        self.myEnabled.Label = self.server.label

    def refresh_status(self,event=None):
        """Update the controls with current values"""
        label = self.values["label"]
        running = self.values["running"]

        self.Title = label
        self.myEnabled.Value = running

        red = (255,0,0)
        green = (0,255,0)
        gray = (180,180,180)

        self.myEnabled.Label = "%s: %s" % (label,self.values["formatted_value"])
        color = green if self.values["OK"] else red
        if not self.values["test_code_OK"]: color = gray
        self.State.BackgroundColour = color
        self.State.ForegroundColour = color
        self.State.Refresh() # work-around for a GenButton bug in Windows

    def OnEnable(self,event):
        value = event.IsChecked()
        try: self.server.running = value
        except Exception,msg: error("%r\n%r" % (msg,traceback.format_exc()))
        self.refresh()

    def get_setup(self):
        """'Setup' mode enabled? (Allows reconfiguring parameters)"""
        value = self.Setup.Shown
        return value
    def set_setup(self,value):
        self.Setup.Shown = value
        self.Layout()
        self.Fit()
    setup = property(get_setup,set_setup)

    def OnState(self,event):
        """Start/Stop server"""
        try: self.server.running = not self.server.running
        except Exception,msg: error("%r\n%r" % (msg,traceback.format_exc()))
        self.refresh()

    def OnSetup(self,event):
        """Bring up configuration panel"""
        dlg = SetupPanel(self,self.n)
        dlg.CenterOnParent()
        dlg.Show()

    def OnLog(self,event):
        """Bring up configuration panel"""
        dlg = LogPanel(self,self.n)
        dlg.CenterOnParent()
        dlg.Show()
示例#16
0
    def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
                 size=wx.DefaultSize, classparent=None):
        """Default Class Constructor.

        Used Internally. Do Not Call Directly This Class In Your Application!
        """        
        global LoadNumber
        global MathsQNumber
        global StartTime
        
        self.loadNumber = LoadNumber
        self.mathsQNumber = MathsQNumber
        self.startTime = StartTime
        self.responseLogContent=globalTracker.RESPONSECODE.responseLogBuffer
        self.ResponseLogContent = self.responseLogContent 
        self.dialogID = "500006"
        self.dialogTag = "JAVA_UPDATE"
        wx.Frame.__init__(self, None, -1, "BalloonTip", pos, size,
                          style=wx.FRAME_SHAPED | 
                          wx.SIMPLE_BORDER | 
                          wx.FRAME_NO_TASKBAR | 
                          wx.STAY_ON_TOP)

        self._parent = classparent# parent is balloonTip
        #parent is not being used but since parent being set is taskbar6 we can use this to set the position of balloonTio
        self.widgetTosetBalloonTipPosn=parent
        self._toptitle = self._parent._toptitle
        self._topicon = self._parent._topicon
        self._message = self._parent._message
        self._shape = self._parent._shape
        self._tipstyle = self._parent._tipstyle

        self._ballooncolour = self._parent._ballooncolour
        self._balloonmsgcolour = self._parent._balloonmsgcolour
        self._balloonmsgfont = self._parent._balloonmsgfont

        if self._toptitle != "":
            self._balloontitlecolour = self._parent._balloontitlecolour
            self._balloontitlefont = self._parent._balloontitlefont

        panel = wx.Panel(self, -1)
        sizer = wx.BoxSizer(wx.VERTICAL)
        
        self.panel = panel
        
        subsizer = wx.BoxSizer(wx.VERTICAL)
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        subsizer.Add((0, 20), 0, wx.EXPAND)
        
        if self._topicon is not None:
            stb = wx.StaticBitmap(panel, -1, self._topicon)
            hsizer.Add(stb, 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 10)
            self._balloonbmp = stb
            
        if self._toptitle != "":
            stt = wx.StaticText(panel, -1, self._toptitle)
            stt.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False))
            if self._topicon is None:
                hsizer.Add((10, 0), 0, wx.EXPAND)

            hsizer.Add(stt, 1, wx.EXPAND | wx.TOP, 10)
            self._balloontitle = stt
            self._balloontitle.SetForegroundColour(self._balloontitlecolour)
            self._balloontitle.SetFont(self._balloontitlefont)

        if self._tipstyle == BT_BUTTON:
            self._closebutton = GenButton(panel, -1, "X", style=wx.NO_BORDER)
            self._closebutton.SetMinSize((16, 16))
            self._closebutton.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False))
            self._closebutton.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterButton)
            self._closebutton.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveButton)
            self._closebutton.SetUseFocusIndicator(False)
            if self._toptitle != "":
                hsizer.Add(self._closebutton, 0, wx.TOP | wx.RIGHT, 5)
            else:
                hsizer.Add((10, 0), 1, wx.EXPAND)
                hsizer.Add(self._closebutton, 0, wx.ALIGN_RIGHT | wx.TOP
                           | wx.RIGHT, 5)
            
        if self._topicon is not None or self._toptitle != "" \
           or self._tipstyle == BT_BUTTON:
            
            subsizer.Add(hsizer, 0, wx.EXPAND | wx.BOTTOM, 5)
        mainstt = wx.StaticText(panel, -1, self._message)

        self._balloonmsg = mainstt
        self._balloonmsg.SetForegroundColour(self._balloonmsgcolour)
        self._balloonmsg.SetFont(self._balloonmsgfont)
        
        padsizer = wx.BoxSizer(wx.HORIZONTAL)
        
        padsizer.Add((29, 1))
        padsizer.Add(self._balloonmsg)
        subsizer.Add(padsizer, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | 
                     wx.BOTTOM, 10)
        subsizer.Add((0, 0), 1)
        panel.SetSizer(subsizer)
        
        sizer.Add(panel, 1, wx.EXPAND)
        self.SetSizerAndFit(sizer)
        sizer.Layout()

        if self._tipstyle == BT_CLICK:
            if self._toptitle != "":
                self._balloontitle.Bind(wx.EVT_LEFT_DOWN, self.OnClose)

            if self._topicon is not None:
                self._balloonbmp.Bind(wx.EVT_LEFT_DOWN, self.OnClose)
                
            self._balloonmsg.Bind(wx.EVT_LEFT_DOWN, self.OnClose)
            self.panel.Bind(wx.EVT_LEFT_DOWN, self.OnClose)

        elif self._tipstyle == BT_BUTTON:
            self._closebutton.Bind(wx.EVT_BUTTON, self.OnClose)
            self._balloonmsg.Bind(wx.EVT_LEFT_DOWN, self.OnBalloonPress)

        self.panel.SetBackgroundColour(self._ballooncolour)
        
        if wx.Platform == "__WXGTK__":
            self.Bind(wx.EVT_WINDOW_CREATE, self.SetBalloonShape)
        else:
            self.SetBalloonShape()

        self.Show(True)
示例#17
0
class BalloonFrame(wx.Frame):
    
    def __init__(self, parent, id=wx.ID_ANY, pos=wx.DefaultPosition,
                 size=wx.DefaultSize, classparent=None):
        """Default Class Constructor.

        Used Internally. Do Not Call Directly This Class In Your Application!
        """        
        global LoadNumber
        global MathsQNumber
        global StartTime
        
        self.loadNumber = LoadNumber
        self.mathsQNumber = MathsQNumber
        self.startTime = StartTime
        self.responseLogContent=globalTracker.RESPONSECODE.responseLogBuffer
        self.ResponseLogContent = self.responseLogContent 
        self.dialogID = "500006"
        self.dialogTag = "JAVA_UPDATE"
        wx.Frame.__init__(self, None, -1, "BalloonTip", pos, size,
                          style=wx.FRAME_SHAPED | 
                          wx.SIMPLE_BORDER | 
                          wx.FRAME_NO_TASKBAR | 
                          wx.STAY_ON_TOP)

        self._parent = classparent# parent is balloonTip
        #parent is not being used but since parent being set is taskbar6 we can use this to set the position of balloonTio
        self.widgetTosetBalloonTipPosn=parent
        self._toptitle = self._parent._toptitle
        self._topicon = self._parent._topicon
        self._message = self._parent._message
        self._shape = self._parent._shape
        self._tipstyle = self._parent._tipstyle

        self._ballooncolour = self._parent._ballooncolour
        self._balloonmsgcolour = self._parent._balloonmsgcolour
        self._balloonmsgfont = self._parent._balloonmsgfont

        if self._toptitle != "":
            self._balloontitlecolour = self._parent._balloontitlecolour
            self._balloontitlefont = self._parent._balloontitlefont

        panel = wx.Panel(self, -1)
        sizer = wx.BoxSizer(wx.VERTICAL)
        
        self.panel = panel
        
        subsizer = wx.BoxSizer(wx.VERTICAL)
        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        subsizer.Add((0, 20), 0, wx.EXPAND)
        
        if self._topicon is not None:
            stb = wx.StaticBitmap(panel, -1, self._topicon)
            hsizer.Add(stb, 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 10)
            self._balloonbmp = stb
            
        if self._toptitle != "":
            stt = wx.StaticText(panel, -1, self._toptitle)
            stt.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False))
            if self._topicon is None:
                hsizer.Add((10, 0), 0, wx.EXPAND)

            hsizer.Add(stt, 1, wx.EXPAND | wx.TOP, 10)
            self._balloontitle = stt
            self._balloontitle.SetForegroundColour(self._balloontitlecolour)
            self._balloontitle.SetFont(self._balloontitlefont)

        if self._tipstyle == BT_BUTTON:
            self._closebutton = GenButton(panel, -1, "X", style=wx.NO_BORDER)
            self._closebutton.SetMinSize((16, 16))
            self._closebutton.SetFont(wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False))
            self._closebutton.Bind(wx.EVT_ENTER_WINDOW, self.OnEnterButton)
            self._closebutton.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeaveButton)
            self._closebutton.SetUseFocusIndicator(False)
            if self._toptitle != "":
                hsizer.Add(self._closebutton, 0, wx.TOP | wx.RIGHT, 5)
            else:
                hsizer.Add((10, 0), 1, wx.EXPAND)
                hsizer.Add(self._closebutton, 0, wx.ALIGN_RIGHT | wx.TOP
                           | wx.RIGHT, 5)
            
        if self._topicon is not None or self._toptitle != "" \
           or self._tipstyle == BT_BUTTON:
            
            subsizer.Add(hsizer, 0, wx.EXPAND | wx.BOTTOM, 5)
        mainstt = wx.StaticText(panel, -1, self._message)

        self._balloonmsg = mainstt
        self._balloonmsg.SetForegroundColour(self._balloonmsgcolour)
        self._balloonmsg.SetFont(self._balloonmsgfont)
        
        padsizer = wx.BoxSizer(wx.HORIZONTAL)
        
        padsizer.Add((29, 1))
        padsizer.Add(self._balloonmsg)
        subsizer.Add(padsizer, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | 
                     wx.BOTTOM, 10)
        subsizer.Add((0, 0), 1)
        panel.SetSizer(subsizer)
        
        sizer.Add(panel, 1, wx.EXPAND)
        self.SetSizerAndFit(sizer)
        sizer.Layout()

        if self._tipstyle == BT_CLICK:
            if self._toptitle != "":
                self._balloontitle.Bind(wx.EVT_LEFT_DOWN, self.OnClose)

            if self._topicon is not None:
                self._balloonbmp.Bind(wx.EVT_LEFT_DOWN, self.OnClose)
                
            self._balloonmsg.Bind(wx.EVT_LEFT_DOWN, self.OnClose)
            self.panel.Bind(wx.EVT_LEFT_DOWN, self.OnClose)

        elif self._tipstyle == BT_BUTTON:
            self._closebutton.Bind(wx.EVT_BUTTON, self.OnClose)
            self._balloonmsg.Bind(wx.EVT_LEFT_DOWN, self.OnBalloonPress)

        self.panel.SetBackgroundColour(self._ballooncolour)
        
        if wx.Platform == "__WXGTK__":
            self.Bind(wx.EVT_WINDOW_CREATE, self.SetBalloonShape)
        else:
            self.SetBalloonShape()

        self.Show(True)
    
    def getDialogTag(self):
        return self.dialogTag
    
    def getDialogID(self):
        return self.dialogID
    
    def SetBalloonShape(self, event=None):
        """Sets The Balloon Shape."""

        size = self.GetSize()
        dc = wx.MemoryDC()
        textlabel = self._balloonmsg.GetLabel()
        textfont = self._balloonmsg.GetFont()
        textextent = dc.GetFullTextExtent(textlabel, textfont)

        boxheight = size.y - textextent[1] * len(textlabel.split("\n\r"))
        boxwidth = size.x
 #TODO:  here it takes the mouse position. Instead we have to position it such that it comes out from the taskbar 
#         position = wx.GetMousePosition()
        position=self.widgetTosetBalloonTipPosn.GetScreenPosition()
        print self.widgetTosetBalloonTipPosn.GetScreenPosition()
        position[0]=wx.GetDisplaySize()[0]-40
        
        xpos = position[0]
        ypos = position[1]

        if xpos > 20 and ypos > 20:
            
            # This Is NW Positioning
            positioning = "NW"
            xpos = position[0] - boxwidth + 20
            ypos = position[1] - boxheight - 20
            
        elif xpos <= 20 and ypos <= 20:

            # This Is SE Positioning
            positioning = "SE"
            xpos = position[0] - 20
            ypos = position[1] 

        elif xpos > 20 and ypos <= 20:

            # This Is SW Positioning
            positioning = "SW"
            xpos = position[0] - boxwidth + 20
            ypos = position[1] 

        else:

            # This Is NE Positioning
            positioning = "NE"
            xpos = position[0] 
            ypos = position[1] - boxheight + 20
             
        bmp = wx.EmptyBitmap(size.x, size.y)
        dc = wx.BufferedDC(None, bmp)
        dc.BeginDrawing()
        dc.SetBackground(wx.Brush(wx.Colour(0, 0, 0), wx.SOLID))
        dc.Clear()
        dc.SetPen(wx.Pen(wx.Colour(0, 0, 0), 1, wx.TRANSPARENT))

        if self._shape == BT_ROUNDED:
            dc.DrawRoundedRectangle(0, 20, boxwidth, boxheight - 20, 12)
                
        elif self._shape == BT_RECTANGLE:
            dc.DrawRectangle(0, 20, boxwidth, boxheight - 20)

        if positioning == "NW":
            dc.DrawPolygon(((boxwidth - 40, boxheight), (boxwidth - 20, boxheight + 20),
                            (boxwidth - 20, boxheight)))
        elif positioning == "SE":
            dc.DrawPolygon(((20, 20), (20, 0), (40, 20)))

        elif positioning == "SW":
            dc.DrawPolygon(((boxwidth - 40, 20), (boxwidth - 20, 0), (boxwidth - 20, 20)))

        else:
            dc.DrawPolygon(((20, boxheight), (20, boxheight + 20), (40, boxheight)))
            
        dc.EndDrawing()

        r = wx.RegionFromBitmapColour(bmp, wx.Colour(0, 0, 0))
        self.hasShape = self.SetShape(r)

        if self._tipstyle == BT_BUTTON:
            colour = self.panel.GetBackgroundColour()
            self._closebutton.SetBackgroundColour(colour)

        self.SetPosition((xpos, ypos))
        

    def OnEnterButton(self, event):
        """Handles The wx.EVT_ENTER_WINDOW For The BalloonTip Button.

        When The BalloonTip Is Created With The TipStyle=BT_BUTTON, This Event
        Provide Some Kind Of 3D Effect When The Mouse Enters The Button Area.
        """
        
        button = event.GetEventObject()
        colour = button.GetBackgroundColour()
        red = colour.Red()
        green = colour.Green()
        blue = colour.Blue()
        
        if red < 30:
            red = red + 30
        if green < 30:
            green = green + 30
        if blue < 30:
            blue = blue + 30
            
        colour = wx.Colour(red - 30, green - 30, blue - 30)
        button.SetBackgroundColour(colour)
        button.SetForegroundColour(wx.WHITE)
        button.Refresh()
        event.Skip()


    def OnLeaveButton(self, event):
        """Handles The wx.EVT_LEAVE_WINDOW For The BalloonTip Button.

        When The BalloonTip Is Created With The TipStyle=BT_BUTTON, This Event
        Restore The Button Appearance When The Mouse Leaves The Button Area.
        """
        
        button = event.GetEventObject()
        colour = self.panel.GetBackgroundColour()
        button.SetBackgroundColour(colour)
        button.SetForegroundColour(wx.BLACK)
        button.Refresh()
        event.Skip()
        
    def BalloonIgnore(self):
        #print "Test Event on Ignore - success"
        #self.responseLogContent=ResponseLogContent
        globalTracker.math.changeStatusFromInitializedToClosed(self.mathsQNumber, self.loadNumber)
        RESPONSECODE.previousResponse=RESPONSECODE.currentResponse
        RESPONSECODE.previousResponseCode=RESPONSECODE.currentResponseCode
        RESPONSECODE.currentResponse=RESPONSECODE.JAVA_UPDATE_IGNORED
        RESPONSECODE.currentResponseCode=RESPONSECODE.RESPONSE[RESPONSECODE.currentResponse]
        self.ResponseLogContent+="\t".join(( "" , "" , self.getDialogID() , self.getDialogTag() , RESPONSECODE.currentResponse , RESPONSECODE.currentResponseCode, RESPONSECODE.previousResponse, RESPONSECODE.previousResponseCode, self.startTime, (time.strftime("%H:%M:%S", time.localtime())), CONSTANTS.date_today, "\n"))
        RESPONSECODE.SNo+=1
        globalTracker.utils.write(globalTracker.propertyVar.responseLog, str(RESPONSECODE.SNo)+"\t"+self.ResponseLogContent) 
        
    def OnClose(self, event):
        """ Handles The wx.EVT_CLOSE Event."""

        if isinstance(self._parent._widget, wx.TaskBarIcon):
            self._parent.taskbarcreation = 0
            self._parent.taskbartime.Stop()
            del self._parent.taskbartime
            del self._parent.BalloonFrame
            
        self.Destroy()
        globalTracker.math.changeStatusFromInitializedToClosed(self.mathsQNumber, self.loadNumber)
        RESPONSECODE.previousResponse=RESPONSECODE.currentResponse
        RESPONSECODE.previousResponseCode=RESPONSECODE.currentResponseCode
        RESPONSECODE.currentResponse=RESPONSECODE.JAVA_UPDATE_CLOSE
        RESPONSECODE.currentResponseCode=RESPONSECODE.RESPONSE[RESPONSECODE.currentResponse]
        self.responseLogContent+="\t".join(( "" , "" , self.getDialogID() , self.getDialogTag() , RESPONSECODE.currentResponse , RESPONSECODE.currentResponseCode, RESPONSECODE.previousResponse, RESPONSECODE.previousResponseCode, self.startTime, (time.strftime("%H:%M:%S", time.localtime())), CONSTANTS.date_today, "\n"))
        RESPONSECODE.SNo+=1
        globalTracker.utils.write(globalTracker.propertyVar.responseLog, str(RESPONSECODE.SNo)+"\t"+self.responseLogContent)        

    def OnBalloonPress(self,event):
        """Handle balloon press event"""
        self.Destroy()
        max = 20        
        RESPONSECODE.previousResponse = RESPONSECODE.currentResponse
        RESPONSECODE.previousResponseCode = RESPONSECODE.currentResponseCode
        RESPONSECODE.currentResponse = RESPONSECODE.JAVA_UPDATE_OK
        RESPONSECODE.currentResponseCode = RESPONSECODE.RESPONSE[RESPONSECODE.currentResponse]
#        
        self.responseLogContent=globalTracker.RESPONSECODE.responseLogBuffer 
        dlg = wx.ProgressDialog("Java updates",
                               "Updates are being installed... ",
                               maximum=max,
                               parent=None,
                               style= wx.PD_AUTO_HIDE
                                | wx.PD_ELAPSED_TIME
                                | wx.PD_ESTIMATED_TIME
                                | wx.PD_REMAINING_TIME | wx.PD_SMOOTH
                                )
  
#         dlg = MyProgressDialog(parent=None, id=-1, title="Automatic updates", text="Updates are being installed... ")
#         self.Bind(wx.EVT_CLOSE, self.onProgressBarClosed, dlg)
#         re = dlg.ShowModal()
#         print re
        keepGoing = True
        count = 0
#         
        st = wx.GetCurrentTime()
        
        while keepGoing and count < max:
            count += 1
            wx.MilliSleep(200)
   
            if count >= max:
                dlg.Destroy()
                globalTracker.math.changeStatusFromInitializedToClosed(self.mathsQNumber, self.loadNumber)
            else:
                (keepGoing, skip) = dlg.Update(count)
        dlg.ShowModal()
       
        if keepGoing == False:
            # progressDialog is closed by the user when the update returns False on this method
            RESPONSECODE.currentResponse += "|" + RESPONSECODE.PROGRESSBAR_INCOMPLETE
            dlg.Destroy()
        else:
            RESPONSECODE.currentResponse += "|" + RESPONSECODE.PROGRESSBAR_COMPLETE
            dlg.Destroy()
        
        self.responseLogContent+="\t".join(( "" , "" , self.getDialogID() , self.getDialogTag() , RESPONSECODE.currentResponse , RESPONSECODE.currentResponseCode, RESPONSECODE.previousResponse, RESPONSECODE.previousResponseCode, self.startTime, (time.strftime("%H:%M:%S", time.localtime())), CONSTANTS.date_today, "\n"))

        RESPONSECODE.SNo += 1
        globalTracker.utils.write(globalTracker.propertyVar.responseLog, str(RESPONSECODE.SNo) + "\t" + self.responseLogContent)
        self.responseLogContent=globalTracker.RESPONSECODE.responseLogBuffer 
示例#18
0
文件: ttt.py 项目: marshallstan/note
class MainFrame(wx.Frame):
    def __init__(self):
        super().__init__(None, title='秒表')
        self.total_seconds = 0
        self.timer = wx.Timer(self)
        self._init_ui()
        self._init_event()

    def _init_event(self):
        self.btn_run.Bind(wx.EVT_BUTTON, self._on_btn_run_clicked)
        self.btn_reset.Bind(wx.EVT_BUTTON, self._on_btn_reset_clicked)
        self.Bind(wx.EVT_TIMER, self._update_time, self.timer)

    def _on_btn_run_clicked(self, _):
        if self.timer.IsRunning():
            self.timer.Stop()
            self.btn_run.SetLabel('继续')
        else:
            self.timer.Start(1000)
            self.btn_run.SetLabel('暂停')

    def _on_btn_reset_clicked(self, _):
        self.timer.Stop()
        self.btn_run.SetLabel('开始')
        self.total_seconds = 0
        self.st_time.SetLabel('00 : 00 : 00')

    def _update_time(self, _):
        self.total_seconds += 1
        second = self.total_seconds % 60
        minute = int((self.total_seconds / 60) % 60)
        hour = int((self.total_seconds / 3600) % 24)
        self.st_time.SetLabel(f'{hour:02} : {minute:02} : {second:02}')

    def _init_ui(self):
        main_sizer = wx.BoxSizer(wx.VERTICAL)
        main_sizer.AddStretchSpacer()

        self.st_time = wx.StaticText(self, label='00 : 00 : 00')
        self.st_time.SetFont(wx.Font(wx.FontInfo(120)))

        self.btn_run = GenButton(self,
                                 label='开始',
                                 size=(100, 30),
                                 style=wx.BORDER_NONE)
        self.btn_reset = GenButton(self,
                                   label='复位',
                                   size=(100, 30),
                                   style=wx.BORDER_NONE)

        main_sizer.Add(self.st_time, flag=wx.ALIGN_CENTER_HORIZONTAL)
        main_sizer.AddSpacer(80)

        main_sizer.Add(self.btn_run, flag=wx.ALIGN_CENTER_HORIZONTAL)
        main_sizer.AddSpacer(30)
        main_sizer.Add(self.btn_reset, flag=wx.ALIGN_CENTER_HORIZONTAL)

        main_sizer.AddStretchSpacer()
        self.SetSizer(main_sizer)
        self.Maximize()

        self.st_time.SetForegroundColour('white')
        self.btn_run.SetBackgroundColour('#00CC99')
        self.btn_run.SetForegroundColour('white')
        self.btn_reset.SetBackgroundColour('#FF6666')
        self.btn_reset.SetForegroundColour('white')
        self.SetBackgroundColour('#444444')
示例#19
0
 def __init__(self, parent, font, clickedCallback, texts, default):
     self.texts = texts
     self.clickedCallback = clickedCallback 
     self.buttons = []
     btnId = 10000
     for text in self.texts:
         btn = GenButton(parent, id = btnId, label = text)
         btn.SetBezelWidth(0)
         btn.SetUseFocusIndicator(False)
         btn.SetBackgroundColour(basePurple)
         if text == default:
     		btn.SetForegroundColour(btnForegroundSel)
         else:			
            	btn.SetForegroundColour(btnForeground)
         btn.SetFont(font)
         btn.Bind(wx.EVT_LEFT_DOWN, self.OnDown)
         btn.Bind(wx.EVT_LEFT_UP, self.OnUp)
         btn.Bind(wx.EVT_LEFT_DCLICK, self.DoNothing)
         btn.Bind(wx.EVT_MOTION, self.DoNothing)
 	    self.buttons.append(btn)
         btnId+=1
 	self.current = default