Example #1
0
    def __init__(self, parent, log):

        wx.Frame.__init__(self, parent)
        self.panel = wx.Panel(self, -1)

        statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
        statusbar.SetStatusWidths([-2, -1])
        # statusbar fields
        statusbar_fields = [
            ("RulerCtrl wxPython Demo, Andrea Gavana @ 03 Nov 2006"),
            ("Welcome To wxPython!")
        ]

        for i in range(len(statusbar_fields)):
            statusbar.SetStatusText(statusbar_fields[i], i)

        self.CreateMenu()
        self.LayoutItems()

        self.SetIcon(images.Mondrian.GetIcon())
        sizex = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X)
        sizey = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y)

        self.SetSize((3 * sizex / 4, 3 * sizey / 4))
        self.SendSizeEvent()
        self.CenterOnScreen()
Example #2
0
    def create_properties(self):
        WindowBase.create_properties(self)
        if not self._has_layout: return
        panel = wx.ScrolledWindow(self.notebook,
                                  -1,
                                  style=wx.TAB_TRAVERSAL
                                  | wx.FULL_REPAINT_ON_RESIZE)

        min_x = wx.SystemSettings_GetMetric(wx.SYS_WINDOWMIN_X)
        min_y = wx.SystemSettings_GetMetric(wx.SYS_WINDOWMIN_Y)
        max_x = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X)
        max_y = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y)

        szprop = self.sizer_properties
        szprop['pos'].display(panel)
        szprop['option'].display(panel)
        szprop['border'].display(panel)
        szprop['flag'].display(panel)

        sizer_tmp = wx.BoxSizer(wx.VERTICAL)
        sizer_tmp.Add(szprop['pos'].panel, 0, wx.EXPAND)
        sizer_tmp.Add(szprop['option'].panel, 0, wx.EXPAND)
        sizer_tmp.Add(szprop['border'].panel, 0, wx.EXPAND)
        sizer_tmp.Add(szprop['flag'].panel, 0, wx.EXPAND, 5)
        panel.SetAutoLayout(True)
        panel.SetSizer(sizer_tmp)
        sizer_tmp.Layout()
        sizer_tmp.Fit(panel)

        w, h = panel.GetClientSize()
        self.notebook.AddPage(panel, _("Layout"))
        panel.SetScrollbars(1, 5, 1, int(math.ceil(h / 5.0)))
Example #3
0
    def __init__(self, parent, data, col_labels, key_col_indices, grouping="Image", chMap=None):
        wx.grid.Grid.__init__(self, parent, -1)
        
        table = HugeTable(self, data, col_labels, key_col_indices)
        
        self.selectedColumns = set()
        # Index of the current column being sorted by.
        self.grouping = grouping
        self.chMap = chMap or p.image_channel_colors

        self.DisableCellEditControl()
        self.EnableEditing(False)
        self.SetCellHighlightPenWidth(0)

        # The second parameter means that the grid is to take
        # ownership of the table and will destroy it when done.
        # Otherwise you would need to keep a reference to it and call
        # it's Destroy method later.
        self.SetTable(table, True)
        # Avoid self.AutoSize() because it hangs on large tables.
        self.SetSelectionMode(self.wxGridSelectColumns)
        self.SetColumnLabels(self.GetTable().col_labels)
        # Help prevent spurious horizontal scrollbar
        self.SetMargins(0-wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X),
                        0-wx.SystemSettings_GetMetric(wx.SYS_HSCROLL_Y))
        self.SetRowLabelSize(ROW_LABEL_SIZE)
        
        wx.grid.EVT_GRID_SELECT_CELL(self, self.OnSelectCell)
        wx.grid.EVT_GRID_LABEL_LEFT_CLICK(self, self.OnLabelClick)
        wx.grid.EVT_GRID_LABEL_RIGHT_CLICK(self, self.OnLabelRightClick)
        wx.grid.EVT_GRID_LABEL_LEFT_DCLICK(self, self.OnLabelDClick)
        wx.grid.EVT_GRID_RANGE_SELECT(self, self.OnSelectedRange)
Example #4
0
 def _show_parent_fullscreen(self):
     parent = self.GetParent()
     parent.GetStatusBar().Hide()
     parent.GetToolBar().Hide()
     self._skip_on_size = wx.Platform == '__WXGTK__'
     parent.ShowFullScreen(True)
     # start the timer to hide the cursor
     #self.SetCursor(wx.StockCursor(wx.CURSOR_BLANK))
     self.hide_cursor_timer.Start(1500)
     # these two 'hidden' adjust options are needed because on GTK
     # wxWindows keeps window decorations even in fullscreen mode,
     # so we let the user tune the size/position of the frame to
     # hide them
     if common.config.has_option('cornice', 'adjust_fullscreen_size'):
         try:
             dw, dh = [int(v) for v in common.config.get(
                 'cornice', 'adjust_fullscreen_size').split(',')]
             w = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X)
             h = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y)
             parent.SetClientSize((w+dw, h+dh))
         except ValueError:
             pass
     if common.config.has_option('cornice', 'adjust_fullscreen_position'):
         try:
             x, y = [int(v) for v in common.config.get(
                 'cornice', 'adjust_fullscreen_position').split(',')]
             parent.SetPosition((x, y))
         except ValueError:
             pass
Example #5
0
def get_geometry(win):
    x, y = win.GetPosition()
    w, h = win.GetSize()
    if 0 <= x <= wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X) and \
       0 <= y <= wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y):
        return (x, y, w, h)
    return None
Example #6
0
 def GetBorders(self):
     bx = wx.SystemSettings_GetMetric(wx.SYS_BORDER_X)
     by = wx.SystemSettings_GetMetric(wx.SYS_BORDER_Y)
     if bx < 0:
         bx = 1
     if by < 0:
         by = 1
     return (bx, by)
Example #7
0
    def __init__(self,
                 parent,
                 ID=-1,
                 title="SplashScreen",
                 style=wx.SIMPLE_BORDER | wx.STAY_ON_TOP,
                 duration=1500,
                 bitmapfile="bitmaps/splashscreen.bmp",
                 callback=None):
        '''
        parent, ID, title, style -- see wx.Frame
        duration -- milliseconds to display the splash screen
        bitmapfile -- absolute or relative pathname to image file
        callback -- if specified, is called when timer completes, callback is
                    responsible for closing the splash screen
        '''
        ### Loading bitmap
        self.bitmap = bmp = wx.Image(bitmapfile,
                                     wx.BITMAP_TYPE_ANY).ConvertToBitmap()

        ### Determine size of bitmap to size window...
        size = (bmp.GetWidth(), bmp.GetHeight())

        # size of screen
        width = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X)
        height = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y)
        pos = ((width - size[0]) / 2, (height - size[1]) / 2)

        # check for overflow...
        if pos[0] < 0:
            size = (wx.SystemSettings_GetSystemMetric(wx.SYS_SCREEN_X),
                    size[1])
        if pos[1] < 0:
            size = (size[0],
                    wx.SystemSettings_GetSystemMetric(wx.SYS_SCREEN_Y))

        wx.Frame.__init__(self, parent, ID, title, pos, size, style)
        self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseClick)
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBG)

        self.Show(True)

        class SplashTimer(wx.Timer):
            def __init__(self, targetFunction):
                self.Notify = targetFunction
                wx.Timer.__init__(self)

        if callback is None:
            callback = self.OnSplashExitDefault

        self.timer = SplashTimer(callback)
        self.timer.Start(duration, 1)  # one-shot only
Example #8
0
    def create_properties(self):
        EditBase.create_properties(self)
        min_x = wx.SystemSettings_GetMetric(wx.SYS_WINDOWMIN_X)
        min_y = wx.SystemSettings_GetMetric(wx.SYS_WINDOWMIN_Y)
        max_x = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X)
        max_y = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y)

        panel = self._common_panel

        prop = self.properties
        prop['id'].display(panel)
        prop['size'].display(panel)

        prop['background'].display(panel)
        prop['foreground'].display(panel)
        try:
            prop['font'].display(panel)
        except KeyError:
            pass
        # new properties 2002-08-15
        prop['tooltip'].display(panel)
        # new properties 2003-05-15
        prop['disabled'].display(panel)
        prop['focused'].display(panel)
        prop['hidden'].display(panel)

        sizer_tmp = wx.BoxSizer(wx.VERTICAL)
        sizer_tmp.Add(self.name_prop.panel, 0, wx.EXPAND)
        sizer_tmp.Add(self.klass_prop.panel, 0, wx.EXPAND)
        if getattr(self, '_custom_base_classes', False):
            sizer_tmp.Add(prop['custom_base'].panel, 0, wx.EXPAND)
        sizer_tmp.Add(prop['id'].panel, 0, wx.EXPAND)
        sizer_tmp.Add(prop['size'].panel, 0, wx.EXPAND)
        sizer_tmp.Add(prop['background'].panel, 0, wx.EXPAND)
        sizer_tmp.Add(prop['foreground'].panel, 0, wx.EXPAND)
        try:
            sizer_tmp.Add(prop['font'].panel, 0, wx.EXPAND)
        except KeyError:
            pass
        sizer_tmp.Add(prop['tooltip'].panel, 0, wx.EXPAND)
        sizer_tmp.Add(prop['disabled'].panel, 0, wx.EXPAND)
        sizer_tmp.Add(prop['focused'].panel, 0, wx.EXPAND)
        sizer_tmp.Add(prop['hidden'].panel, 0, wx.EXPAND)

        panel.SetAutoLayout(1)
        panel.SetSizer(sizer_tmp)
        sizer_tmp.Layout()
        sizer_tmp.Fit(panel)

        w, h = panel.GetClientSize()
        self.notebook.AddPage(panel, _("Common"))
        self.property_window.Layout()
        panel.SetScrollbars(1, 5, 1, int(math.ceil(h / 5.0)))
Example #9
0
    def GetBorders():
        """Gets border widths to better determine page size in ShowActive()"""

        bx = wx.SystemSettings_GetMetric(wx.SYS_BORDER_X)
        by = wx.SystemSettings_GetMetric(wx.SYS_BORDER_Y)

        if bx < 0:
            bx = 1
        if by < 0:
            by = 1

        return bx, by
Example #10
0
def _ABSetPos(edge, appbarWindow):
    barData = APPBARDATA()
    barData.cbSize = wintypes.DWORD(sizeof(barData))
    barData.hWnd = appbarWindow.GetHandle()
    barData.uEdge = edge

    deskW = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X)
    deskH = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y)
    winW, winH = appbarWindow.Size

    if barData.uEdge == ABEdge.Left or barData.uEdge == ABEdge.Right:
        barData.rc.top = 0
        barData.rc.bottom = deskH
        if barData.uEdge == ABEdge.Left:
            barData.rc.left = 0
            barData.rc.right = winW
        else:
            barData.rc.right = deskW
            barData.rc.left = deskW - winW
    else:
        barData.rc.left = 0
        barData.rc.right = deskW
        if barData.uEdge == ABEdge.Top:
            barData.rc.top = 0
            barData.rc.bottom = winH
        else:
            barData.rc.bottom = deskH
            barData.rc.top = deskH - winH

    shell32.SHAppBarMessage(ABMsg.ABM_QUERYPOS, PAPPBARDATA(barData))

    # http://msdn.microsoft.com/en-us/library/bb776821.aspx
    if barData.uEdge == ABEdge.Left:
        barData.rc.right = barData.rc.left + winW
    elif barData.uEdge == ABEdge.Right:
        barData.rc.left = barData.rc.right - winW
    elif barData.uEdge == ABEdge.Top:
        barData.rc.bottom = barData.rc.top + winH
    elif barData.uEdge == ABEdge.Bottom:
        barData.rc.top = barData.rc.bottom - winH

    shell32.SHAppBarMessage(ABMsg.ABM_SETPOS, PAPPBARDATA(barData))

    def _resize():
        appbarWindow.SetPosition((barData.rc.left, barData.rc.top))
        appbarWindow.SetSize((barData.rc.right - barData.rc.left,
                              barData.rc.bottom - barData.rc.top))

    # This is done async, because windows will send a resize
    # after a new appbar is added. if we size right away, the
    # windows resize comes last and overrides us.
    wx.CallAfter(_resize)
Example #11
0
 def GetAvailableWidth(self):
     availableWidth = self.GetClientSize().width
     if self.__isScrollbarVisible(
     ) and self.__isScrollbarIncludedInClientSize():
         scrollbarWidth = wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)
         availableWidth -= scrollbarWidth
     return availableWidth
Example #12
0
 def GetAvailableWidth(self):
     available_width = self.GetClientSize().width
     if self.__is_scrollbar_visible(
     ) and self.__is_scrollbar_included_in_client_size():
         scrollbar_width = wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)
         available_width -= scrollbar_width
     return available_width
Example #13
0
    def create(self, panel, value="#FFFFFF", orientation=wx.HORIZONTAL, event=None, key=None,
               *args, **kwargs):
        item_sizer = wx.BoxSizer(orientation)

        self.event = event
        self.key = key
        label_panel = wx.Panel(panel, style=wx.BORDER_SIMPLE)
        label_sizer = wx.BoxSizer(wx.HORIZONTAL)
        label_sizer2 = wx.BoxSizer(wx.VERTICAL)
        label_text = wx.StaticText(label_panel, label=unicode(value), style=wx.ALIGN_CENTER)
        self.text = label_text
        label_sizer.Add(label_text, 1, wx.ALIGN_CENTER)
        label_sizer2.Add(label_sizer, 1, wx.ALIGN_CENTER)
        label_panel.SetSizer(label_sizer2)
        label_panel.SetBackgroundColour(str(value))
        self.panel = label_panel

        button = wx.Button(panel, label=translate_key(MODULE_KEY.join(key + ['button'])))
        button.Bind(wx.EVT_BUTTON, self.on_button_press)
        border_size = wx.SystemSettings_GetMetric(wx.SYS_BORDER_Y)
        button_size = button.GetSize()
        if button_size[0] > 150:
            button_size[0] = 150
        button_size[1] -= border_size*2
        self.button = button

        label_panel.SetMinSize(button_size)
        label_panel.SetSize(button_size)

        item_sizer.Add(label_panel, 0, wx.ALIGN_CENTER)
        item_sizer.AddSpacer(2)
        item_sizer.Add(button, 0, wx.EXPAND)
        return item_sizer
Example #14
0
    def __init__(self, parent, datasource, watermark=None):
        wx.ScrolledWindow.__init__(self, parent, id=wx.NewId(), style=wx.FULL_REPAINT_ON_RESIZE|wx.SUNKEN_BORDER)
        self.exceptioncount=0
        self.EnableScrolling(False, False)
        self.datasource=datasource
        self._bufbmp=None
        self.active_section=None
        self._w, self._h=-1,-1
        self.vheight, self.maxheight=self._h,self._h
        self.sections=[]
        self.sectionheights=[]
        self._scrollbarwidth=wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)
        wx.EVT_SIZE(self, self.OnSize)
        wx.EVT_PAINT(self, self.OnPaint)
        wx.EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
        wx.EVT_LEFT_DOWN(self, self.OnLeftDown)
        wx.EVT_LEFT_DCLICK(self, self.OnLeftDClick)
        wx.EVT_RIGHT_DOWN(self, self.OnRightDown)
        if watermark is not None:
            wx.EVT_SCROLLWIN(self, self.OnScroll)

        bgcolour=wx.SystemSettings.GetColour(wx.SYS_COLOUR_WINDOW)
        if guihelper.IsMac():
            bgcolour=wx.WHITE
        self.bgbrush=wx.TheBrushList.FindOrCreateBrush(bgcolour, wx.SOLID)
        if watermark:
            self.watermark=guihelper.getbitmap(watermark)
        else:
            self.watermark=None
        self.UpdateItems()
Example #15
0
 def OnSize(self, event):
     size = self.GetClientSize()
     listWidth = size.x - 2
     if self.GetItemCount() > self.GetCountPerPage():
         scrollWidth = wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)
         listWidth = listWidth - scrollWidth
     self.SetColumnWidth(0, listWidth)
     event.Skip()
Example #16
0
 def SizeColumns(self):
     w = self.GetSize().x
     #ifdef __WXMSW__
     # w -= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X) + 6;
     #else
     w -= 2 * wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)
     #endif
     self.SetColumnWidth(0, w)
Example #17
0
    def _doResize(self):
        """ Resize the last column as appropriate.

            If the list's columns are too wide to fit within the window, we use
            a horizontal scrollbar.  Otherwise, we expand the right-most column
            to take up the remaining free space in the list.

            We remember the current size of the last column, before resizing,
            as the preferred minimum width if we haven't previously been given
            or calculated a minimum width.  This ensure that repeated calls to
            _doResize() don't cause the last column to size itself too large.
        """

        if not self:  # avoid a PyDeadObject error
            return

        if self.GetSize().height < 32:
            return  # avoid an endless update bug when the height is small.

        numCols = self.GetColumnCount()
        if numCols == 0: return  # Nothing to resize.

        if (self._resizeColStyle == "LAST"):
            resizeCol = self.GetColumnCount()
        else:
            resizeCol = self._resizeCol

        resizeCol = max(1, resizeCol)

        if self._resizeColMinWidth == None:
            self._resizeColMinWidth = self.GetColumnWidth(resizeCol - 1)

        # We're showing the vertical scrollbar -> allow for scrollbar width
        # NOTE: on GTK, the scrollbar is included in the client size, but on
        # Windows it is not included
        listWidth = self.GetClientSize().width
        if wx.Platform != '__WXMSW__':
            if self.GetItemCount() > self.GetCountPerPage():
                scrollWidth = wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)
                listWidth = listWidth - scrollWidth

        totColWidth = 0  # Width of all columns except last one.
        for col in range(numCols):
            if col != (resizeCol - 1):
                totColWidth = totColWidth + self.GetColumnWidth(col)

        resizeColWidth = self.GetColumnWidth(resizeCol - 1)

        if totColWidth + self._resizeColMinWidth > listWidth:
            # We haven't got the width to show the last column at its minimum
            # width -> set it to its minimum width and allow the horizontal
            # scrollbar to show.
            self.SetColumnWidth(resizeCol - 1, self._resizeColMinWidth)
            return

        # Resize the last column to take up the remaining available space.

        self.SetColumnWidth(resizeCol - 1, listWidth - totColWidth)
Example #18
0
    def SetCharDimensions(self):
        # TODO: We need a code review on this.  It appears that Linux
        # improperly reports window dimensions when the scrollbar's there.
        self.bw, self.bh = self.GetClientSize()

        if wx.Platform == "__WXMSW__":
            self.sh = self.bh / self.fh
            self.sw = (self.bw / self.fw) - 1
        else:
            self.sh = self.bh / self.fh
            if self.LinesInFile() >= self.sh:
                self.bw = self.bw - wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)
                self.sw = (self.bw / self.fw) - 1

            self.sw = (self.bw / self.fw) - 1
            if self.CalcMaxLineLen() >= self.sw:
                self.bh = self.bh - wx.SystemSettings_GetMetric(wx.SYS_HSCROLL_Y)
                self.sh = self.bh / self.fh
Example #19
0
    def __init__(self,
                 parent,
                 ID=-1,
                 title="",
                 style=wx.SIMPLE_BORDER | wx.FRAME_NO_TASKBAR | wx.STAY_ON_TOP,
                 duration=1000,
                 bitmapfile=""):

        ### Loading bitmap
        self.bitmap = bmp = wx.Image(bitmapfile,
                                     wx.BITMAP_TYPE_ANY).ConvertToBitmap()

        ### Determine size of bitmap to size window...
        size = (bmp.GetWidth(), bmp.GetHeight())
        self.textfont = wx.Font(1, wx.SWISS, wx.NORMAL, wx.NORMAL, False,
                                "Arial")
        self.textpos = (0, 0)
        self.textcolor = wx.BLACK
        self.text1 = ""
        self.text2 = ""
        self.textsize = 10.0
        self.textfont.SetPointSize(self.textsize)

        # size of screen
        width = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X)
        height = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y)
        pos = ((width - size[0]) / 2, (height - size[1]) / 2)

        # check for overflow...
        if pos[0] < 0:
            size = (wx.SystemSettings_GetSystemMetric(wx.SYS_SCREEN_X),
                    size[1])
        if pos[1] < 0:
            size = (size[0],
                    wx.SystemSettings_GetSystemMetric(wx.SYS_SCREEN_Y))

        # Setting Initial Properties
        wx.Frame.__init__(self, parent, ID, title, pos, size, style)
        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBG)

        self.Show(True)
Example #20
0
    def __init__(self, parent, id=-1, pos=(0, 0), size=wx.DefaultSize,
                 style=wx.TAB_TRAVERSAL | wx.NO_BORDER):

        wx.Panel.__init__(self, parent, id, pos, size, style)

        self._sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(self._sizer)

        self.Bind(EVT_CAPTIONBAR, self.on_caption_press)
        self.Bind(wx.EVT_SIZE, self.OnSize)

        global SCROLLBAR_WIDTH
        SCROLLBAR_WIDTH = wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)

        assert isinstance(parent, wx.ScrolledWindow)
Example #21
0
    def onSize(self, event):
        # Resize the expanding column.
        if self.expandingColumnIndex >= 0:
            # This is the new width.
            widget = self.getWxWidget()
            width = widget.GetClientSizeTuple()[0]
            # How much left from the other columns?
            total = 0
            for i in range(widget.GetColumnCount()):
                if i != self.expandingColumnIndex:
                    total += widget.GetColumnWidth(i)
            widget.SetColumnWidth(
                self.expandingColumnIndex,
                width - total - wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X))

        event.Skip()
Example #22
0
    def build_element_safe(self):
        """Build the spectra listing GUI element in a thread safe wx.CallAfter call."""

        # First freeze the element, so that the GUI element doesn't update until the end.
        self.element.Freeze()

        # Update the label if needed.
        self.set_box_label()

        # Delete the previous data.
        self.element.DeleteAllItems()

        # Update the data.
        self.update_data()

        # Size the columns.
        self.size_cols()

        # Post a size event to get the scroll panel to update correctly.
        event = wx.PyCommandEvent(wx.EVT_SIZE.typeId, self.parent.GetId())
        wx.PostEvent(self.parent.GetEventHandler(), event)

        # Set the minimum height.
        if not self.proportion:
            # The number of rows.
            n = self.element.GetItemCount()

            # Size of the header, plus a bit.
            head = self.height_char + 10

            # Size of the table central element.
            centre = (self.height_char + 6) * n

            # Size of the scrollbar for the end of the table.
            foot = wx.SystemSettings_GetMetric(wx.SYS_HSCROLL_Y)

            # Sum.
            height = head + centre + foot

            # Set the minimum size, and force a redraw.
            self.element.SetMinSize((-1, height))
            self.element.Layout()

        # Unfreeze.
        self.element.Thaw()
Example #23
0
    def doResize(self):
        # Get the listctrl's width
        listWidth = self.TrackList.GetClientSize().width
        # We're showing the vertical scrollbar -> allow for scrollbar width
        # NOTE: on GTK, the scrollbar is included in the client size, but on
        # Windows it is not included
        if wx.Platform != '__WXMSW__':
            if self.TrackList.GetItemCount() > self.TrackList.GetCountPerPage(
            ):
                scrollWidth = wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)
                listWidth = listWidth - scrollWidth

        # Only one column, set its width to list width, or the longest title if larger
        if self.MaxTitleWidth > listWidth:
            width = self.MaxTitleWidth
        else:
            width = listWidth

        self.TrackList.SetColumnWidth(0, width)
Example #24
0
    def setup(self):
        assert self.wxctrl is None
        base.Form.setup(self)
        #self.setupMenu()
        parent = self._parent
        if parent is None:
            parent = self.session.toolkit._activeForm
        if parent is None:
            wxparent = None
        else:
            wxparent = parent.wxctrl

        #self.dying = False

        if self.modal:
            self.wxctrl = wx.Dialog(wxparent,
                                    -1,
                                    self.getLabel(),
                                    style=wx.DEFAULT_FRAME_STYLE
                                    | wx.NO_FULL_REPAINT_ON_RESIZE)
        else:
            self.wxctrl = wx.Frame(wxparent,
                                   -1,
                                   self.getLabel(),
                                   style=wx.DEFAULT_FRAME_STYLE
                                   | wx.NO_FULL_REPAINT_ON_RESIZE
                                   | wx.TAB_TRAVERSAL)

            self.wxctrl.CreateStatusBar(1, wx.ST_SIZEGRIP)

            if self.menuBar is not None:
                wxMenuBar = wx.MenuBar()
                for mnu in self.menuBar.menus:
                    wxm = self._createMenuWidget(mnu)
                    wxMenuBar.Append(wxm, mnu.getLabel())

                self.wxctrl.SetMenuBar(wxMenuBar)

        self.wxctrl.Bind(wx.EVT_SET_FOCUS, self.OnSetFocus)
        self.wxctrl.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)

        wx.EVT_CHAR(self.wxctrl, self.OnChar)
        wx.EVT_IDLE(self.wxctrl, self.OnIdle)
        #wx.EVT_SIZE(self.wxctrl, self.OnSize)
        wx.EVT_CLOSE(self.wxctrl, self.OnCloseWindow)
        #wx.EVT_ICONIZE(self.wxctrl, self.OnIconfiy)
        #wx.EVT_MAXIMIZE(self.wxctrl, self.OnMaximize)

        #self.SetBackgroundColour(wx.RED)

        mainBox = wx.BoxSizer(wx.VERTICAL)

        self.mainComp.setup(self.wxctrl, mainBox)

        if self.defaultButton is not None:
            self.defaultButton.wxctrl.SetDefault()

        self.wxctrl.SetSizerAndFit(mainBox)
        #self.mainBox = mainBox
        #self.wxctrl.SetAutoLayout(True)
        #self.wxctrl.Layout()

        if self.halign is forms.CENTER:
            self.wxctrl.Centre(wx.HORIZONTAL)
        if self.valign is forms.CENTER:
            self.wxctrl.Centre(wx.VERTICAL)

        x, y = self.wxctrl.GetPositionTuple()

        if self.halign is forms.LEFT:
            x = 0
        elif self.halign is forms.RIGHT:
            x = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_X)
            x -= self.wxctrl.GetSizeTuple()[0]

        if self.valign is forms.TOP:
            y = 0
        elif self.halign is forms.RIGHT:
            y = wx.SystemSettings_GetMetric(wx.SYS_SCREEN_Y)
            y -= self.wxctrl.GetSizeTuple()[1]

        self.wxctrl.SetPosition((x, y))
Example #25
0
    def _ResizeColumns(self):
        """Private method to actually handle the column resizes.
        
        Don't call this from user code, this is an internal method that
        actually does the heavy lifting to resize all the columns.
        """
        if not self._resize_dirty:
            return
        self.Freeze()

        allowed_offscreen = min(self._allowed_offscreen, self.GetColumnCount())

        # get font to measure text extents
        font = self.GetFont()
        dc = wx.ClientDC(self)
        dc.SetFont(font)

        flags = self._resize_flags

        usable_width = self.GetClientSize().width
        # We're showing the vertical scrollbar -> allow for scrollbar width
        # NOTE: on GTK, the scrollbar is included in the client size, but on
        # Windows it is not included
        if wx.Platform != '__WXMSW__':
            if self.GetItemCount() > self.GetCountPerPage():
                usable_width -= wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)
        remaining_width = usable_width - self._extra_col0_padding

        # pass 1: get preferred sizes for all columns
        before = {}
        newsize = {}

        # If there are no items in the list, use the header of the column as
        # the default width to provide some reasonable values.
        if self.GetItemCount() == 0:
            resize_type = wx.LIST_AUTOSIZE_USEHEADER
        else:
            resize_type = wx.LIST_AUTOSIZE

        for col in range(self.GetColumnCount()):
            self.SetColumnWidth(col, resize_type)
            before[col] = self.GetColumnWidth(col)
            resize = before[col]

            flag = flags[col]

            # setup min and max values.  The min and max may be specified as
            # a string, which will be converted into pixels here, based on
            # the current font.
            if isinstance(flag.min, str):
                flag.min = dc.GetTextExtent(flag.min)[0]
            if isinstance(flag.max, str):
                flag.max = dc.GetTextExtent(flag.max)[0]

            if flag.min is not None and resize < flag.min:
                resize = flag.min
            elif flag.max is not None and resize > flag.max:
                resize = flag.max
            newsize[col] = resize

            if col < allowed_offscreen and flag.greedy:
                remaining_width -= resize
            #print("pass1: col %d: before=%d newsize=%d remaining=%d" % (col, before[col], newsize[col], remaining_width))

        # pass 2: resize remaining columns
        desired_width = 0
        for col in range(allowed_offscreen):
            flag = flags[col]
            if not flag.greedy:
                resize = (newsize[col] * usable_width) / remaining_width

                if flag.min is not None and resize < flag.min:
                    resize = flag.min
                elif flag.max is not None and resize > flag.max:
                    resize = flag.max
                if resize is not None:
                    newsize[col] = resize
                desired_width += newsize[col]
            #print("pass2: col %d: before=%d newsize=%d desired=%d" % (col, before[col], newsize[col], desired_width))
        #print("desired=%d remaining=%d" % (desired_width, remaining_width))

        # pass 3: scale columns up or down if necessary
        if desired_width > remaining_width:
            pass3_width = 0
            for col in range(allowed_offscreen):
                flag = flags[col]
                if not flag.greedy:
                    resize = (newsize[col] * remaining_width) / desired_width

                    if flag.min is not None and resize < flag.min:
                        resize = flag.min
                    elif flag.max is not None and resize > flag.max:
                        resize = flag.max
                    if resize is not None:
                        newsize[col] = resize
                    pass3_width += newsize[col]
                #print("pass3: col %d: before=%d newsize=%d pass3_width=%d" % (col, before[col], newsize[col], pass3_width))
        else:
            # requested size of all columns is smaller than the window.  Any
            # 'expand' columns will now expand to fill
            pass3_width = 0
            expandcount = 0
            for col in range(allowed_offscreen):
                flag = flags[col]
                if flag.expand:
                    expandcount += 1
            if expandcount == 0:
                # no columns are flagged for expansion, so expand the last one
                col = self.GetColumnCount() - 1
                newsize[col] += remaining_width
                #print("Resizing last column %d = %d" % (col, newsize[col]))
            else:
                for col in range(allowed_offscreen):
                    flag = flags[col]
                    if flag.expand:
                        distribwidth = (remaining_width -
                                        desired_width) / expandcount
                        resize = newsize[col] + distribwidth

                        if flag.max is not None and resize > flag.max:
                            resize = flag.max
                        newsize[col] = resize
                        expandcount -= 1
                        #print("pass3: col %d: before=%d newsize=%d distribwidth=%d" % (col, before[col], newsize[col], distribwidth))

        # pass 4: set column widths
        for col in range(self.GetColumnCount()):
            width = newsize[col]
            if col == 0:
                width += self._extra_col0_padding
            #print("col %d: before=%s resized=%s" % (col, before[col], width))
            if width != before[col]:
                self.SetColumnWidth(col, width)
        self.Thaw()
        self._resize_dirty = False
    def __init__(self, parent, **kwargs):
        wx.Frame.__init__(self, parent, -1, size=(640, 480), **kwargs)
        ##        CPATool.__init__(self)

        self.selected_cols = set([])

        # Toolbar
        ##        from guiutils import FilterComboBox
        ##        tb = self.CreateToolBar(wx.TB_HORIZONTAL | wx.NO_BORDER | wx.TB_FLAT)
        ##        self.filter_choice = FilterComboBox(self)
        ##        tb.AddControl(self.filter_choice)
        ##        tb.Realize()

        #
        # Create the menubar
        #
        self.SetMenuBar(wx.MenuBar())
        file_menu = wx.Menu()
        self.GetMenuBar().Append(file_menu, 'File')
        new_table_item = file_menu.Append(-1, 'New empty table\tCtrl+N')
        file_menu.AppendSeparator()
        load_csv_menu_item = file_menu.Append(-1,
                                              'Load table from CSV\tCtrl+O')
        load_db_table_menu_item = file_menu.Append(
            -1, 'Load table from database\tCtrl+Shift+O')
        file_menu.AppendSeparator()
        save_csv_menu_item = file_menu.Append(-1, 'Save table to CSV\tCtrl+S')
        save_temp_table_menu_item = file_menu.Append(
            -1, 'Save table to database\tCtrl+Shift+S')

        ##        table_menu = wx.Menu()
        ##        self.GetMenuBar().Append(table_menu, 'Table')
        ##        pca_menu_item = table_menu.Append(-1, 'Compute PCA on current table',
        ##                            help='Performs Principal Component Analysis on '
        ##                            'the current table and creates a new table with '
        ##                            'the resulting columns.')
        ##        tsne_menu_item = table_menu.Append(-1, 'Compute t-SNE on current table',
        ##                            help='Performs t-Distributed Stochastic Neighbor '
        ##                            'Embedding on the current table and creates a new '
        ##                            'table with the resulting columns.')

        view_menu = wx.Menu()
        self.GetMenuBar().Append(view_menu, 'View')
        column_width_menu = wx.Menu()
        show_hide_cols_item = view_menu.Append(-1, 'Show/Hide columns')
        view_menu.AppendMenu(-1, 'Column widths', column_width_menu)
        fixed_cols_menu_item = column_width_menu.Append(-1,
                                                        'Fixed width',
                                                        kind=wx.ITEM_RADIO)
        fit_cols_menu_item = column_width_menu.Append(-1,
                                                      'Fit to table',
                                                      kind=wx.ITEM_RADIO)

        self.GetMenuBar().Append(cpa.helpmenu.make_help_menu(self), 'Help')

        self.CreateStatusBar()

        self.Bind(wx.EVT_MENU, self.on_new_table, new_table_item)
        self.Bind(wx.EVT_MENU, self.on_load_csv, load_csv_menu_item)
        self.Bind(wx.EVT_MENU, self.on_load_db_table, load_db_table_menu_item)
        self.Bind(wx.EVT_MENU, self.on_save_csv, save_csv_menu_item)
        self.Bind(wx.EVT_MENU, self.on_save_table_to_db,
                  save_temp_table_menu_item)
        self.Bind(wx.EVT_MENU, self.on_show_hide_cols, show_hide_cols_item)
        self.Bind(wx.EVT_MENU, self.on_set_fixed_col_widths,
                  fixed_cols_menu_item)
        self.Bind(wx.EVT_MENU, self.on_set_fitted_col_widths,
                  fit_cols_menu_item)
        ##        self.Bind(wx.EVT_MENU, self.on_compute_tsne, tsne_menu_item)

        #
        # Create the grid
        #
        self.grid = gridlib.Grid(self)
        self.grid.SetRowLabelSize(ROW_LABEL_SIZE)
        self.grid.DisableCellEditControl()
        self.grid.EnableEditing(False)
        self.grid.SetCellHighlightPenWidth(0)
        # Help prevent spurious horizontal scrollbar
        self.grid.SetMargins(0 - wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X),
                             0 - wx.SystemSettings_GetMetric(wx.SYS_HSCROLL_Y))
        self.grid.SetRowLabelSize(ROW_LABEL_SIZE)

        self.grid.Bind(gridlib.EVT_GRID_CMD_LABEL_LEFT_CLICK,
                       self.on_leftclick_label)
        gridlib.EVT_GRID_LABEL_LEFT_DCLICK(self.grid, self.on_dclick_label)
        gridlib.EVT_GRID_LABEL_RIGHT_CLICK(self.grid, self.on_rightclick_label)
        gridlib.EVT_GRID_SELECT_CELL(self.grid, self.on_select_cell)
        gridlib.EVT_GRID_RANGE_SELECT(self.grid, self.on_select_range)
Example #27
0
    def __init__(self,
                 parent,
                 mainFrame,
                 filterName,
                 filterInfo,
                 title=_('Edit filter database')):
        wx.Dialog.__init__(self,
                           parent,
                           wx.ID_ANY,
                           title,
                           style=wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER)
        self.mainFrame = mainFrame
        self.newFilterInfo = None
        # Filter name label
        filterLabel = wx.StaticText(self, wx.ID_ANY, filterName)
        font = filterLabel.GetFont()
        font.SetPointSize(10)
        font.SetWeight(wx.FONTWEIGHT_BOLD)
        filterLabel.SetFont(font)
        # Arguments
        argWindow = wx.ScrolledWindow(self, wx.ID_ANY, style=wx.TAB_TRAVERSAL)
        argWindow.SetScrollRate(10, 10)
        argSizer = wx.GridBagSizer(hgap=0, vgap=10)
        row = 0
        growable = False
        self.argctrls = []
        for argInfo in self.mainFrame.currentScript.GetFilterCalltipArgInfo(
                calltip=filterInfo):
            totalInfo, cArgType, cArgName, boolRepeatArg, boolOptionalArg, cArgInfo = argInfo
            argtype, argname, guitype, defaultValue, other = self.mainFrame.ParseCalltipArgInfo(
                totalInfo)
            #~ if guitype is None or argname is None or argtype not in ('int', 'float', 'bool', 'string'):
            if argname is None or argtype not in ('int', 'float', 'bool',
                                                  'string'):
                self.argctrls.append(
                    (argtype, argname, None, boolRepeatArg, boolOptionalArg))
            else:
                argLabel = wx.StaticText(argWindow, wx.ID_ANY,
                                         '%(argtype)s %(argname)s' % locals())
                argLabel.controls = []
                argSizer.Add(
                    argLabel, (row, 0), wx.DefaultSpan,
                    wx.ALIGN_RIGHT | wx.ALIGN_BOTTOM | wx.BOTTOM | wx.RIGHT, 5)
                if argtype in ('int', 'float') and guitype != 'intlist':
                    strDefaultValue = strMinValue = strMaxValue = strMod = ''
                    if other is not None:
                        minValue, maxValue, nDecimal, mod = other
                        if nDecimal is None:
                            nDecimal = 0
                        strTemplate = '%.' + str(nDecimal) + 'f'
                        if defaultValue is not None:
                            try:
                                strDefaultValue = strTemplate % defaultValue
                            except TypeError:
                                strDefaultValue = defaultValue
                        if minValue is not None:
                            try:
                                strMinValue = strTemplate % minValue
                            except TypeError:
                                strMinValue = minValue
                        if maxValue is not None:
                            try:
                                strMaxValue = strTemplate % maxValue
                            except TypeError:
                                strMaxValue = maxValue
                        if mod is not None:
                            try:
                                strMod = '%i' % mod
                            except TypeError:
                                strMod = mod
                    elif guitype == 'color':
                        strDefaultValue = '$%s' % defaultValue
                    itemData = (
                        (strDefaultValue, _('Default')),
                        (strMinValue, _('Min value')),
                        (strMaxValue, _('Max value')),
                        (strMod, _('Step size')),
                    )
                    hsizer = wx.BoxSizer(wx.HORIZONTAL)
                    for itemValue, itemName in itemData:
                        itemLabel = wx.StaticText(argWindow, wx.ID_ANY,
                                                  itemName)
                        itemTextCtrl = wx.TextCtrl(argWindow,
                                                   wx.ID_ANY,
                                                   itemValue,
                                                   size=(75, -1))
                        vsizer = wx.BoxSizer(wx.VERTICAL)
                        vsizer.Add(itemLabel, 0, wx.LEFT, 2)
                        vsizer.Add(itemTextCtrl, 0, wx.ALL, 0)
                        hsizer.Add(vsizer, 0, wx.EXPAND | wx.RIGHT, 5)
                        argLabel.controls.append(itemTextCtrl)
                    argSizer.Add(hsizer, (row, 1), wx.DefaultSpan,
                                 wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 0)
                elif argtype == 'bool':
                    strDefaultValue = ''
                    if defaultValue is not None:
                        if defaultValue.lower() == 'true':
                            strDefaultValue = 'True'
                        if defaultValue.lower() == 'false':
                            strDefaultValue = 'False'
                    itemLabel = wx.StaticText(argWindow, wx.ID_ANY,
                                              _('Default'))
                    itemTextCtrl = wx.ComboBox(argWindow,
                                               wx.ID_ANY,
                                               strDefaultValue,
                                               choices=['True', 'False'],
                                               style=wx.CB_DROPDOWN,
                                               size=(75, -1))
                    vsizer = wx.BoxSizer(wx.VERTICAL)
                    vsizer.Add(itemLabel, 0, wx.LEFT, 2)
                    vsizer.Add(itemTextCtrl, 0, wx.ALL, 0)
                    argLabel.controls.append(itemTextCtrl)
                    argSizer.Add(vsizer, (row, 1), wx.DefaultSpan,
                                 wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 0)
                elif argtype == 'string' or argtype == 'int' and guitype == 'intlist':
                    strDefaultValue = strValuesList = ''
                    if defaultValue is not None:
                        if defaultValue:
                            if argtype == 'string':
                                strDefaultValue = '"%s"' % defaultValue.strip(
                                    '"')
                            else:
                                strDefaultValue = str(defaultValue)
                    if other is not None:
                        strValuesList = ', '.join(other)
                    hsizer = wx.BoxSizer(wx.HORIZONTAL)
                    # Default control
                    itemLabel = wx.StaticText(argWindow, wx.ID_ANY,
                                              _('Default'))
                    itemTextCtrl = wx.TextCtrl(argWindow,
                                               wx.ID_ANY,
                                               strDefaultValue,
                                               size=(75, -1))
                    vsizer = wx.BoxSizer(wx.VERTICAL)
                    vsizer.Add(itemLabel, 0, wx.LEFT, 2)
                    vsizer.Add(itemTextCtrl, 0, wx.ALL, 0)
                    argLabel.controls.append(itemTextCtrl)
                    hsizer.Add(vsizer, 0, wx.EXPAND | wx.RIGHT, 5)
                    # Values control
                    itemLabel = wx.StaticText(
                        argWindow, wx.ID_ANY,
                        _('Value list (comma separated)'))
                    itemTextCtrl = wx.TextCtrl(argWindow,
                                               wx.ID_ANY,
                                               strValuesList,
                                               size=(200, -1))
                    vsizer = wx.BoxSizer(wx.VERTICAL)
                    vsizer.Add(itemLabel, 0, wx.LEFT, 2)
                    vsizer.Add(itemTextCtrl, 1, wx.EXPAND | wx.ALL, 0)
                    argLabel.controls.append(itemTextCtrl)
                    hsizer.Add(vsizer, 1, wx.EXPAND | wx.RIGHT, 5)

                    argSizer.Add(
                        hsizer, (row, 1), wx.DefaultSpan,
                        wx.EXPAND | wx.ALIGN_CENTER_VERTICAL | wx.RIGHT, 0)
                    if wx.VERSION > (2, 9):
                        if not argSizer.IsColGrowable(1):
                            argSizer.AddGrowableCol(1)
                    else:
                        if not growable:
                            argSizer.AddGrowableCol(1)
                            growable = True
                row += 1
                self.argctrls.append((argtype, argname, argLabel,
                                      boolRepeatArg, boolOptionalArg))
        argWindow.SetSizer(argSizer)
        # Standard buttons
        okay = wx.Button(self, wx.ID_OK, _('OK'))
        self.Bind(wx.EVT_BUTTON, self.OnButtonOK, okay)
        okay.SetDefault()
        cancel = wx.Button(self, wx.ID_CANCEL, _('Cancel'))
        btns = wx.StdDialogButtonSizer()
        btns.AddButton(okay)
        btns.AddButton(cancel)
        btns.Realize()
        # Set the sizer
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add((-1, -1), 0, wx.TOP, 10)
        sizer.Add(filterLabel, 0, wx.EXPAND | wx.ALL, 5)
        sizer.Add(wx.StaticLine(self, wx.ID_ANY), 0,
                  wx.EXPAND | wx.LEFT | wx.RIGHT, 5)
        sizer.Add(argWindow, 1, wx.EXPAND | wx.ALL, 5)
        sizer.Add(wx.StaticLine(self, wx.ID_ANY), 0,
                  wx.EXPAND | wx.LEFT | wx.RIGHT, 5)
        #~ sizer.Add(wx.StaticText(self,wx.ID_ANY, _('* optional value')), 0, wx.EXPAND|wx.ALL, 10)
        sizer.Add(btns, 0, wx.EXPAND | wx.ALL, 5)
        self.SetSizer(sizer)
        sizer.Layout()
        argWindow.FitInside()
        w, h = argSizer.GetMinSize()
        w = max(w + 10, 400)
        h = min(h + 100, 700)
        self.SetSize(self.ClientToWindowSize((w, h)))
        if argWindow.HasScrollbar(wx.HORIZONTAL):
            scrollbar_w = wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X)
            self.SetSize(self.ClientToWindowSize((w + scrollbar_w, -1)))
Example #28
0
	def __init__(self, parent, manager, ym):
		super(newDesignWindow, self).__init__(parent, title='Share on YouMagine')
		p = wx.Panel(self)
		self.SetSizer(wx.BoxSizer())
		self.GetSizer().Add(p, 1, wx.EXPAND)
		self._manager = manager
		self._ym = ym

		categoryOptions = ym.getCategories()
		licenseOptions = ym.getLicenses()
		self._designName = wx.TextCtrl(p, -1, _("Design name"))
		self._designDescription = wx.TextCtrl(p, -1, '', size=(1, 150), style = wx.TE_MULTILINE)
		self._designLicense = wx.ComboBox(p, -1, licenseOptions[0], choices=licenseOptions, style=wx.CB_DROPDOWN|wx.CB_READONLY)
		self._category = wx.ComboBox(p, -1, categoryOptions[-1], choices=categoryOptions, style=wx.CB_DROPDOWN|wx.CB_READONLY)
		self._publish = wx.CheckBox(p, -1, _("Publish after upload"))
		self._shareButton = wx.Button(p, -1, _("Share!"))
		self._imageScroll = wx.lib.scrolledpanel.ScrolledPanel(p)
		self._additionalFiles = wx.CheckListBox(p, -1)
		self._additionalFiles.InsertItems(getAdditionalFiles(self._manager._scene.objects(), True), 0)
		self._additionalFiles.SetChecked(range(0, self._additionalFiles.GetCount()))
		self._additionalFiles.InsertItems(getAdditionalFiles(self._manager._scene.objects(), False), self._additionalFiles.GetCount())

		self._imageScroll.SetSizer(wx.BoxSizer(wx.HORIZONTAL))
		self._addImageButton = wx.Button(self._imageScroll, -1, _("Add..."), size=(70,52))
		self._imageScroll.GetSizer().Add(self._addImageButton)
		self._snapshotButton = wx.Button(self._imageScroll, -1, _("Webcam..."), size=(70,52))
		self._imageScroll.GetSizer().Add(self._snapshotButton)
		if not webcam.hasWebcamSupport():
			self._snapshotButton.Hide()
		self._imageScroll.Fit()
		self._imageScroll.SetupScrolling(scroll_x=True, scroll_y=False)
		self._imageScroll.SetMinSize((20, self._imageScroll.GetSize()[1] + wx.SystemSettings_GetMetric(wx.SYS_HSCROLL_Y)))

		self._publish.SetValue(True)
		self._publish.SetToolTipString(
			_("Directly publish the design after uploading.\nWithout this check the design will not be public\nuntil you publish it yourself on YouMagine.com"))

		s = wx.GridBagSizer(5, 5)
		p.SetSizer(s)

		s.Add(wx.StaticBitmap(p, -1, wx.Bitmap(getPathForImage('youmagine-text.png'))), (0,0), span=(1,3), flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
		s.Add(wx.StaticText(p, -1, _("Design name:")), (1, 0), flag=wx.LEFT|wx.TOP, border=5)
		s.Add(self._designName, (1, 1), span=(1,2), flag=wx.EXPAND|wx.LEFT|wx.TOP|wx.RIGHT, border=5)
		s.Add(wx.StaticText(p, -1, _("Description:")), (2, 0), flag=wx.LEFT|wx.TOP, border=5)
		s.Add(self._designDescription, (2, 1), span=(1,2), flag=wx.EXPAND|wx.LEFT|wx.TOP|wx.RIGHT, border=5)
		s.Add(wx.StaticText(p, -1, _("Category:")), (3, 0), flag=wx.LEFT|wx.TOP, border=5)
		s.Add(self._category, (3, 1), span=(1,2), flag=wx.EXPAND|wx.LEFT|wx.TOP|wx.RIGHT, border=5)
		s.Add(wx.StaticText(p, -1, _("License:")), (4, 0), flag=wx.LEFT|wx.TOP, border=5)
		s.Add(self._designLicense, (4, 1), span=(1,2), flag=wx.EXPAND|wx.LEFT|wx.TOP|wx.RIGHT, border=5)
		s.Add(wx.StaticLine(p, -1), (5,0), span=(1,3), flag=wx.EXPAND|wx.ALL)
		s.Add(wx.StaticText(p, -1, _("Images:")), (6, 0), flag=wx.LEFT|wx.TOP, border=5)
		s.Add(self._imageScroll, (6, 1), span=(1, 2), flag=wx.EXPAND|wx.LEFT|wx.TOP|wx.RIGHT, border=5)
		s.Add(wx.StaticLine(p, -1), (7,0), span=(1,3), flag=wx.EXPAND|wx.ALL)
		s.Add(wx.StaticText(p, -1, _("Related design files:")), (8, 0), flag=wx.LEFT|wx.TOP, border=5)

		s.Add(self._additionalFiles, (8, 1), span=(1, 2), flag=wx.EXPAND|wx.LEFT|wx.TOP|wx.RIGHT, border=5)
		s.Add(wx.StaticLine(p, -1), (9,0), span=(1,3), flag=wx.EXPAND|wx.ALL)
		s.Add(self._shareButton, (10, 1), flag=wx.BOTTOM, border=15)
		s.Add(self._publish, (10, 2), flag=wx.BOTTOM|wx.ALIGN_CENTER_VERTICAL, border=15)

		s.AddGrowableRow(2)
		s.AddGrowableCol(2)

		self.Bind(wx.EVT_BUTTON, self.OnShare, self._shareButton)
		self.Bind(wx.EVT_BUTTON, self.OnAddImage, self._addImageButton)
		self.Bind(wx.EVT_BUTTON, self.OnTakeImage, self._snapshotButton)

		self.Fit()
		self.Centre()

		self._designDescription.SetMinSize((1,1))
		self._designName.SetFocus()
		self._designName.SelectAll()
Example #29
0
    def __init__(self, graph, settings):
        wx.Panel.__init__(self, graph)

        self.spectrum = None
        self.graph = graph
        self.settings = settings

        self.measure = None

        self.checked = {
            Measure.MIN: None,
            Measure.MAX: None,
            Measure.AVG: None,
            Measure.GMEAN: None,
            Measure.HBW: None,
            Measure.OBW: None
        }

        self.selected = None

        self.SetBackgroundColour('white')

        self.grid = wxGrid.Grid(self)
        self.grid.CreateGrid(3, 19)
        self.grid.EnableEditing(True)
        self.grid.EnableDragGridSize(False)
        self.grid.SetColLabelSize(1)
        self.grid.SetRowLabelSize(1)
        self.grid.SetColMinimalAcceptableWidth(1)
        self.grid.SetColSize(2, 1)
        self.grid.SetColSize(7, 1)
        self.grid.SetColSize(11, 1)
        self.grid.SetColSize(15, 1)
        self.grid.SetMargins(0, wx.SystemSettings_GetMetric(wx.SYS_HSCROLL_Y))

        for x in range(self.grid.GetNumberRows()):
            self.grid.SetRowLabelValue(x, '')
        for y in range(self.grid.GetNumberCols()):
            self.grid.SetColLabelValue(y, '')

        for row in range(self.grid.GetNumberRows()):
            for col in range(self.grid.GetNumberCols()):
                self.grid.SetReadOnly(row, col, True)

        self.locsDesc = {
            'F Start': (0, 0),
            'F End': (1, 0),
            'F Delta': (2, 0),
            'P Min': (0, 4),
            'P Max': (1, 4),
            'P Delta': (2, 4),
            'Mean': (0, 9),
            'GMean': (1, 9),
            'Flatness': (2, 9),
            '-3dB Start': (0, 13),
            '-3dB End': (1, 13),
            '-3dB Delta': (2, 13),
            'OBW Start': (0, 17),
            'OBW End': (1, 17),
            'OBW Delta': (2, 17)
        }
        self.__set_descs()

        self.locsCheck = {
            Measure.MIN: (0, 3),
            Measure.MAX: (1, 3),
            Measure.AVG: (0, 8),
            Measure.GMEAN: (1, 8),
            Measure.HBW: (0, 12),
            Measure.OBW: (0, 16)
        }
        self.__set_check_editor()

        self.locsFreq = [(0, 1), (1, 1)]
        self.__set_freq_editor()

        colour = self.grid.GetBackgroundColour()
        self.grid.SetCellTextColour(2, 3, colour)
        self.grid.SetCellTextColour(2, 8, colour)
        self.grid.SetCellTextColour(1, 12, colour)
        self.grid.SetCellTextColour(2, 12, colour)
        self.grid.SetCellTextColour(1, 16, colour)
        self.grid.SetCellTextColour(2, 16, colour)

        self.__clear_checks()

        self.locsMeasure = {
            'start': (0, 1),
            'end': (1, 1),
            'deltaF': (2, 1),
            'minFP': (0, 5),
            'maxFP': (1, 5),
            'deltaFP': (2, 5),
            'minP': (0, 6),
            'maxP': (1, 6),
            'deltaP': (2, 6),
            'avg': (0, 10),
            'gmean': (1, 10),
            'flat': (2, 10),
            'hbwstart': (0, 14),
            'hbwend': (1, 14),
            'hbwdelta': (2, 14),
            'obwstart': (0, 18),
            'obwend': (1, 18),
            'obwdelta': (2, 18)
        }

        fontCell = self.grid.GetDefaultCellFont()
        fontSize = fontCell.GetPointSize()
        fontStyle = fontCell.GetStyle()
        fontWeight = fontCell.GetWeight()
        font = wx.Font(fontSize, wx.FONTFAMILY_MODERN, fontStyle, fontWeight)
        dc = wx.WindowDC(self.grid)
        dc.SetFont(font)
        widthMHz = dc.GetTextExtent('###.######')[0] * 1.2
        widthdB = dc.GetTextExtent('-##.##')[0] * 1.2
        for _desc, (_row, col) in self.locsDesc.iteritems():
            self.grid.AutoSizeColumn(col)
        for col in [1, 5, 14, 18]:
            self.grid.SetColSize(col, widthMHz)
            for row in xrange(self.grid.GetNumberRows()):
                self.grid.SetCellFont(row, col, font)
        for col in [6, 10]:
            self.grid.SetColSize(col, widthdB)
            for row in xrange(self.grid.GetNumberRows()):
                self.grid.SetCellFont(row, col, font)
        for _desc, (_row, col) in self.locsCheck.iteritems():
            self.grid.AutoSizeColumn(col)

        toolTips = {}
        toolTips[self.locsMeasure['start']] = 'Selection start (MHz)'
        toolTips[self.locsMeasure['end']] = 'Selection end (MHz)'
        toolTips[self.locsMeasure['deltaF']] = 'Selection bandwidth (MHz)'
        toolTips[self.locsMeasure['minFP']] = 'Minimum power location (MHz)'
        toolTips[self.locsMeasure['maxFP']] = 'Maximum power location (MHz)'
        toolTips[
            self.locsMeasure['deltaFP']] = 'Power location difference (MHz)'
        toolTips[self.locsMeasure['minP']] = 'Minimum power (dB)'
        toolTips[self.locsMeasure['maxP']] = 'Maximum power (dB)'
        toolTips[self.locsMeasure['deltaP']] = 'Power difference (dB)'
        toolTips[self.locsMeasure['avg']] = 'Mean power (dB)'
        toolTips[self.locsMeasure['gmean']] = 'Geometric mean power (dB)'
        toolTips[self.locsMeasure['flat']] = 'Spectral flatness'
        toolTips[self.locsMeasure['hbwstart']] = '-3db start location (MHz)'
        toolTips[self.locsMeasure['hbwend']] = '-3db end location (MHz)'
        toolTips[self.locsMeasure['hbwdelta']] = '-3db bandwidth (MHz)'
        toolTips[self.locsMeasure['obwstart']] = '99% start location (MHz)'
        toolTips[self.locsMeasure['obwend']] = '99% end location (MHz)'
        toolTips[self.locsMeasure['obwdelta']] = '99% bandwidth (MHz)'

        self.toolTips = GridToolTips(self.grid, toolTips)

        self.popupMenu = wx.Menu()
        self.popupMenuCopy = self.popupMenu.Append(wx.ID_ANY, "&Copy",
                                                   "Copy entry")
        self.Bind(wx.EVT_MENU, self.__on_copy, self.popupMenuCopy)

        self.Bind(wxGrid.EVT_GRID_CELL_RIGHT_CLICK, self.__on_popup_menu)
        self.Bind(wxGrid.EVT_GRID_CELL_LEFT_CLICK, self.__on_cell_click)
        if wx.VERSION >= (3, 0, 0, 0):
            self.Bind(wxGrid.EVT_GRID_CELL_CHANGED, self.__on_cell_change)

        box = wx.BoxSizer(wx.VERTICAL)
        box.Add(self.grid,
                0,
                wx.EXPAND | wx.TOP | wx.LEFT | wx.RIGHT,
                border=10)
        self.SetSizer(box)
Example #30
0
  def __init__(self, parent, b):
    wx.Panel.__init__(self, parent, -1)

    self.NeedToSaveBallots = False
    self.NeedToSaveLog = False
    self.b = b
    self.i = 0   # The number of the ballot being displayed
    if self.b.numBallots == 0:
      self.b.appendBallot([])
    self.currentBallot = self.b.getBallot(self.i)

    # Information box
    informationBox = wx.StaticBox(self, -1, "Information")
    fNameL = wx.StaticText(self, -1, "Filename:")
    fn = self.b.getFileName()
    if fn is None:
      fn = "New File"
    else:
      fn = os.path.basename(fn)
    self.fNameC = wx.StaticText(self, -1, fn)
    numBallotsL = wx.StaticText(self, -1, "No. of ballots:")
    self.numBallotsC = wx.StaticText(self, -1, "%d" % self.b.numBallots)
    numSeatsL = wx.StaticText(self, -1, "No. of seats:")
    numSeatsC = wx.StaticText(self, -1, "%d" % self.b.numSeats)
    numCandidatesL = wx.StaticText(self, -1, "No. of candidates:")
    numCandidatesC = wx.StaticText(self, -1, "%d" % self.b.numCandidates)
    titleL = wx.StaticText(self, -1, "Title:")
    title = ""
    if "title" in vars(self.b):
      title = self.b.title
    titleC = wx.TextCtrl(self, -1, title)
    self.Bind(wx.EVT_TEXT, self.OnTitle, titleC)

    # Rankings box
    rankingsBox = wx.StaticBox(self, -1, "Rankings")
    txt = """\
Click on a candidate's name to assign that candidate the next
available ranking, and double-click on a candidate's name to
remove the ranking and reorder the remaining candidates."""
    rankingsHelp = wx.StaticText(self, -1, txt)

    # Navigation box
    navigationBox = wx.StaticBox(self, -1, "Navigation")
    first = wx.Button(self, -1, "|<", style=wx.BU_EXACTFIT)
    prev = wx.Button(self, -1, "<", style=wx.BU_EXACTFIT)
    next = wx.Button(self, -1, ">", style=wx.BU_EXACTFIT)
    last = wx.Button(self, -1, ">|", style=wx.BU_EXACTFIT)
    self.spin = wx.SpinCtrl(self, -1, size=(60, -1))
    self.spin.SetRange(1, self.b.numBallots)
    self.spin.SetValue(1)
    go = wx.Button(self, -1, "Go", style=wx.BU_EXACTFIT)
    
    self.Bind(wx.EVT_BUTTON, self.OnNav, first)
    self.Bind(wx.EVT_BUTTON, self.OnNav, prev)
    self.Bind(wx.EVT_BUTTON, self.OnNav, next)
    self.Bind(wx.EVT_BUTTON, self.OnNav, last)
    self.Bind(wx.EVT_BUTTON, self.OnNav, go)

    # Operations box
    operationsBox = wx.StaticBox(self, -1, "Operations")
    clear = wx.Button(self, -1, "Clear This Ballot")
    delete = wx.Button(self, -1, "Delete This Ballot")
    append = wx.Button(self, -1, "Append New Ballot")
    exitBFE = wx.Button(self, -1, "Exit")

    self.Bind(wx.EVT_BUTTON, self.OnClear, clear)
    self.Bind(wx.EVT_BUTTON, self.OnDelete, delete)
    self.Bind(wx.EVT_BUTTON, self.OnAppend, append)
    self.Bind(wx.EVT_BUTTON, self.OnExit, exitBFE)

    # Ballot box
    self.ballotBox = wx.StaticBox(self, -1, "Ballot No. %d" % (self.i + 1))
    self.ballotC = BallotCtrl(self, -1)
    self.ballotC.InsertColumn(0, " R ", wx.LIST_FORMAT_RIGHT)
    self.ballotC.InsertColumn(1, "Candidate")
    self.ballotBox.SetLabel("Ballot No. %d" % (self.i+1))
    for c, name in enumerate(self.b.names):
      if c in self.currentBallot:
        r = self.currentBallot.index(c)
        self.ballotC.InsertStringItem(c, str(r+1))
      else:
        self.ballotC.InsertStringItem(c, "")
      self.ballotC.SetStringItem(c, 1, name)
    self.ballotC.SetColumnWidth(0, wx.LIST_AUTOSIZE_USEHEADER)
    w = self.ballotC.computeColumnWidth()
    self.ballotC.SetColumnWidth(1, w)

    self.Bind(wx.EVT_LIST_COL_BEGIN_DRAG, self.OnColBeginDrag, self.ballotC)
    self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnListClick, self.ballotC)
    self.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnListDClick, self.ballotC)

    # Sizers
    sizer = wx.BoxSizer(wx.HORIZONTAL)
    leftSizer = wx.BoxSizer(wx.VERTICAL)

    # Information
    informationSizer = wx.StaticBoxSizer(informationBox, wx.VERTICAL)
    fgs = wx.FlexGridSizer(5, 2, 5, 5)
    fgs.Add(fNameL, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
    fgs.Add(self.fNameC, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
    fgs.Add(numBallotsL, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
    fgs.Add(self.numBallotsC, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
    fgs.Add(numSeatsL, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
    fgs.Add(numSeatsC, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
    fgs.Add(numCandidatesL, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
    fgs.Add(numCandidatesC, 0, wx.ALIGN_LEFT|wx.ALIGN_CENTER_VERTICAL)
    fgs.Add(titleL, 0, wx.ALIGN_RIGHT|wx.ALIGN_CENTER_VERTICAL)
    fgs.Add(titleC, 1, wx.EXPAND|wx.ALL)
    fgs.AddGrowableCol(1)
    informationSizer.Add(fgs, 0, wx.EXPAND|wx.ALL, 5)
    leftSizer.Add(informationSizer, 0, wx.EXPAND|wx.ALL, 5)

    # Rankings
    rankingsSizer = wx.StaticBoxSizer(rankingsBox, wx.VERTICAL)
    rankingsSizer.Add(rankingsHelp, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    leftSizer.Add(rankingsSizer, 0, wx.EXPAND|wx.ALL, 5)

    # Navigation
    navigationSizer = wx.StaticBoxSizer(navigationBox, wx.VERTICAL)

    hSizer = wx.BoxSizer(wx.HORIZONTAL)
    hSizer.Add(first, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    hSizer.Add(prev, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    hSizer.Add(next, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    hSizer.Add(last, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    navigationSizer.Add(hSizer, 0, wx.ALIGN_CENTER, 0)

    hSizer = wx.BoxSizer(wx.HORIZONTAL)
    hSizer.Add(self.spin, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    hSizer.Add(go, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    navigationSizer.Add(hSizer, 0, wx.ALIGN_CENTER, 0)

    leftSizer.Add(navigationSizer, 0, wx.EXPAND|wx.ALL, 5)

    # Operations
    operationsSizer = wx.StaticBoxSizer(operationsBox, wx.VERTICAL)
    gs = wx.GridSizer(2, 2, 5, 5)
    gs.Add(clear, 0, wx.EXPAND)
    gs.Add(delete, 0, wx.EXPAND)
    gs.Add(append, 0, wx.EXPAND)
    gs.Add(exitBFE, 0, wx.EXPAND)
    operationsSizer.Add(gs, 0, wx.ALIGN_CENTER|wx.ALL, 5)
    leftSizer.Add(operationsSizer, 0, wx.EXPAND|wx.ALL, 5)

    # Ballot
    ballotSizer = wx.StaticBoxSizer(self.ballotBox, wx.VERTICAL)
    ballotSizer.Add(self.ballotC, 1, wx.EXPAND|wx.ALL, 5)
    # Need this ugly hack since wx.ListCtrl doesn't properly set its size
    w = self.ballotC.GetColumnWidth(0) + self.ballotC.GetColumnWidth(1)\
        + wx.SystemSettings_GetMetric(wx.SYS_VSCROLL_X) + 5
    ballotSizer.SetItemMinSize(self.ballotC, (w, -1))

    sizer.Add(leftSizer, 0, wx.EXPAND, 0)
    sizer.Add(ballotSizer, 0, wx.EXPAND|wx.ALL, 5)
    
    self.SetSizer(sizer)
    sizer.Fit(self)