Python wx.NullBitmap() Examples

The following are 30 code examples of wx.NullBitmap(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module wx , or try the search function .
Example #1
Source File: backend_wx.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _init_toolbar(self):
        DEBUG_MSG("_init_toolbar", 1, self)

        self._parent = self.canvas.GetParent()

        self.wx_ids = {}
        for text, tooltip_text, image_file, callback in self.toolitems:
            if text is None:
                self.AddSeparator()
                continue
            self.wx_ids[text] = (
                self.AddTool(
                    -1,
                    bitmap=_load_bitmap(image_file + ".png"),
                    bmpDisabled=wx.NullBitmap,
                    label=text, shortHelp=text, longHelp=tooltip_text,
                    kind=(wx.ITEM_CHECK if text in ["Pan", "Zoom"]
                          else wx.ITEM_NORMAL))
                .Id)
            self.Bind(wx.EVT_TOOL, getattr(self, callback),
                      id=self.wx_ids[text])

        self.Realize() 
Example #2
Source File: gui_mixins.py    From wxGlade with MIT License 6 votes vote down vote up
def _set_preview_bitmap(self, prop, name, ref_size=None):
        if not config.use_gui:
            return
        bmp = prop.get_value()
        OK = True
        if bmp:
            bmp_d = self.get_preview_obj_bitmap(bmp)
            if ref_size and bmp_d.Size != ref_size:
                prop.set_check_result(error="Size %s is different from normal bitmap %s."%(bmp_d.Size, ref_size))
                OK = False
            else:
                prop.set_check_result(error=None)
        else:
            bmp_d = wx.NullBitmap
        prop.set_bitmap(bmp_d)
        if self.widget:
            if compat.IS_CLASSIC and name=="Pressed":
                method = getattr(self.widget, "SetBitmapSelected")  # probably only wx 2.8
            else:
                method = getattr(self.widget, "SetBitmap%s"%name, None)
            if method is not None:
                method(bmp_d if OK else wx.NullBitmap) 
Example #3
Source File: backend_wx.py    From GraphicDesignPatternByPython with MIT License 6 votes vote down vote up
def _init_toolbar(self):
        DEBUG_MSG("_init_toolbar", 1, self)

        self._parent = self.canvas.GetParent()

        self.wx_ids = {}
        for text, tooltip_text, image_file, callback in self.toolitems:
            if text is None:
                self.AddSeparator()
                continue
            self.wx_ids[text] = (
                self.AddTool(
                    -1,
                    bitmap=_load_bitmap(image_file + ".png"),
                    bmpDisabled=wx.NullBitmap,
                    label=text, shortHelp=text, longHelp=tooltip_text,
                    kind=(wx.ITEM_CHECK if text in ["Pan", "Zoom"]
                          else wx.ITEM_NORMAL))
                .Id)
            self.Bind(wx.EVT_TOOL, getattr(self, callback),
                      id=self.wx_ids[text])

        self.Realize() 
Example #4
Source File: backend_wx.py    From coffeegrindsize with MIT License 6 votes vote down vote up
def _init_toolbar(self):
        DEBUG_MSG("_init_toolbar", 1, self)

        self._parent = self.canvas.GetParent()

        self.wx_ids = {}
        for text, tooltip_text, image_file, callback in self.toolitems:
            if text is None:
                self.AddSeparator()
                continue
            self.wx_ids[text] = (
                self.AddTool(
                    -1,
                    bitmap=_load_bitmap(image_file + ".png"),
                    bmpDisabled=wx.NullBitmap,
                    label=text, shortHelp=text, longHelp=tooltip_text,
                    kind=(wx.ITEM_CHECK if text in ["Pan", "Zoom"]
                          else wx.ITEM_NORMAL))
                .Id)
            self.Bind(wx.EVT_TOOL, getattr(self, callback),
                      id=self.wx_ids[text])

        self.Realize() 
Example #5
Source File: misc.py    From wxGlade with MIT License 6 votes vote down vote up
def get_xpm_bitmap(path):
    bmp = wx.NullBitmap
    if not os.path.exists(path):
        if '.zip' in path:
            import zipfile
            archive, name = path.split('.zip', 1)
            archive += '.zip'
            if name.startswith(os.sep):
                name = name.split(os.sep, 1)[1]
            if zipfile.is_zipfile(archive):
                # extract the XPM lines...
                try:
                    data = zipfile.ZipFile(archive).read(name)
                    data = [d[1:-1] for d in _get_xpm_bitmap_re.findall(data)]
                    bmp = wx.BitmapFromXPMData(data)
                except:
                    logging.exception(_('Internal Error'))
                    bmp = wx.NullBitmap
    else:
        bmp = wx.Bitmap(path, wx.BITMAP_TYPE_XPM)
    return bmp 
Example #6
Source File: backend_wx.py    From CogAlg with MIT License 6 votes vote down vote up
def _init_toolbar(self):
        DEBUG_MSG("_init_toolbar", 1, self)

        self._parent = self.canvas.GetParent()

        self.wx_ids = {}
        for text, tooltip_text, image_file, callback in self.toolitems:
            if text is None:
                self.AddSeparator()
                continue
            self.wx_ids[text] = (
                self.AddTool(
                    -1,
                    bitmap=_load_bitmap(image_file + ".png"),
                    bmpDisabled=wx.NullBitmap,
                    label=text, shortHelp=text, longHelp=tooltip_text,
                    kind=(wx.ITEM_CHECK if text in ["Pan", "Zoom"]
                          else wx.ITEM_NORMAL))
                .Id)
            self.Bind(wx.EVT_TOOL, getattr(self, callback),
                      id=self.wx_ids[text])

        self.Realize() 
Example #7
Source File: backend_wx.py    From Mastering-Elasticsearch-7.0 with MIT License 6 votes vote down vote up
def _init_toolbar(self):
        DEBUG_MSG("_init_toolbar", 1, self)

        self._parent = self.canvas.GetParent()

        self.wx_ids = {}
        for text, tooltip_text, image_file, callback in self.toolitems:
            if text is None:
                self.AddSeparator()
                continue
            self.wx_ids[text] = (
                self.AddTool(
                    -1,
                    bitmap=_load_bitmap(image_file + ".png"),
                    bmpDisabled=wx.NullBitmap,
                    label=text, shortHelp=text, longHelp=tooltip_text,
                    kind=(wx.ITEM_CHECK if text in ["Pan", "Zoom"]
                          else wx.ITEM_NORMAL))
                .Id)
            self.Bind(wx.EVT_TOOL, getattr(self, callback),
                      id=self.wx_ids[text])

        self.Realize() 
Example #8
Source File: ColourSelectButton.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
def __init__(
        self,
        parent,
        value=(255, 255, 255),
        pos=wx.DefaultPosition,
        size=(40, wx.Button.GetDefaultSize()[1]),
        style=wx.BU_AUTODRAW,
        validator=wx.DefaultValidator,
        name="ColourSelectButton",
        title = "Colour Picker"
    ):
        self.value = value
        self.title = title
        wx.BitmapButton.__init__(
            self, parent, -1, wx.NullBitmap, pos, size, style, validator, name
        )
        self.SetValue(value)
        self.Bind(wx.EVT_BUTTON, self.OnButton) 
Example #9
Source File: gui.py    From superpaper with MIT License 6 votes vote down vote up
def draw_canvas(self, dc, draw=True):
        if self.st_bmp_canvas:
            pos = self.st_bmp_canvas.GetPosition()
            bmp = self.st_bmp_canvas.GetBitmap()
            bmp_sz = bmp.GetSize()
            if not draw:
                bmp = wx.Bitmap.FromRGBA(bmp_sz[0], bmp_sz[1], red=30, green=30, blue=30, alpha=255)
            op = wx.COPY
            if bmp.IsOk():
                memDC = wx.MemoryDC()
                # memDC.SelectObject(wx.NullBitmap)
                memDC.SelectObject(bmp)

                dc.Blit(pos[0], pos[1],
                        bmp_sz[0], bmp_sz[1],
                        memDC, 0, 0, op, True)

                return True
            else:
                return False 
Example #10
Source File: ListCtrl.py    From BitTorrent with GNU General Public License v3.0 6 votes vote down vote up
def add_image(self, image):
        b = wx.BitmapFromImage(image)
        if not b.Ok():
            raise Exception("The image (%s) is not valid." % image)

        if (sys.platform == "darwin" and
            (b.GetWidth(), b.GetHeight()) == (self.icon_size, self.icon_size)):
            return self.il.Add(b)
        
        b2 = wx.EmptyBitmap(self.icon_size, self.icon_size)
        dc = wx.MemoryDC()
        dc.SelectObject(b2)
        dc.SetBackgroundMode(wx.TRANSPARENT)
        dc.Clear()
        x = (b2.GetWidth() - b.GetWidth()) / 2
        y = (b2.GetHeight() - b.GetHeight()) / 2
        dc.DrawBitmap(b, x, y, True)
        dc.SelectObject(wx.NullBitmap)
        b2.SetMask(wx.Mask(b2, (255, 255, 255)))

        return self.il.Add(b2)

    # Arrow drawing 
Example #11
Source File: backend_wxagg.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def blit(self, bbox=None):
        """
        Transfer the region of the agg buffer defined by bbox to the display.
        If bbox is None, the entire buffer is transferred.
        """
        if bbox is None:
            self.bitmap = _convert_agg_to_wx_bitmap(self.get_renderer(), None)
            self.gui_repaint()
            return

        l, b, w, h = bbox.bounds
        r = l + w
        t = b + h
        x = int(l)
        y = int(self.bitmap.GetHeight() - t)

        srcBmp = _convert_agg_to_wx_bitmap(self.get_renderer(), None)
        srcDC = wx.MemoryDC()
        srcDC.SelectObject(srcBmp)

        destDC = wx.MemoryDC()
        destDC.SelectObject(self.bitmap)

        destDC.Blit(x, y, int(w), int(h), srcDC, x, y)

        destDC.SelectObject(wx.NullBitmap)
        srcDC.SelectObject(wx.NullBitmap)
        self.gui_repaint() 
Example #12
Source File: new_properties.py    From wxGlade with MIT License 5 votes vote down vote up
def set_bitmap(self, bmp):
        if bmp is wx.NullBitmap:
            self._size = None
        else:
            self._size = bmp.Size
        if self.text: compat.SetToolTip(self.text, self._find_tooltip()) 
Example #13
Source File: ObjectListView.py    From bookhub with MIT License 5 votes vote down vote up
def _InitializeImages(self):
        """
        Initialize the images used to indicate expanded/collapsed state of groups.
        """
        def _makeBitmap(state, size):
            bitmap = wx.EmptyBitmap(size, size)
            dc = wx.MemoryDC(bitmap)
            dc.SetBackground(wx.Brush(self.groupBackgroundColour))
            dc.Clear()
            (x, y) = (0, 0)
            # The image under Linux is smaller and needs to be offset somewhat to look reasonable
            if wx.Platform == "__WXGTK__":
                (x, y) = (4, 4)
            wx.RendererNative.Get().DrawTreeItemButton(self, dc, (x, y, size, size), state)
            dc.SelectObject(wx.NullBitmap)
            return bitmap

        # If there isn't a small image list, make one
        if self.smallImageList is None:
            self.SetImageLists()

        size = self.smallImageList.GetSize()[0]
        self.AddNamedImages(ObjectListView.NAME_EXPANDED_IMAGE, _makeBitmap(wx.CONTROL_EXPANDED, size))
        self.AddNamedImages(ObjectListView.NAME_COLLAPSED_IMAGE, _makeBitmap(0, size))


    #----------------------------------------------------------------------------
    # Accessing 
Example #14
Source File: ObjectListView.py    From bookhub with MIT License 5 votes vote down vote up
def _InitializeCheckBoxImages(self):
        """
        Initialize some checkbox images for use by this control.
        """
        def _makeBitmap(state, size):
            bitmap = wx.EmptyBitmap(size, size)
            dc = wx.MemoryDC(bitmap)
            dc.Clear()

            # On Linux, the Renderer draws the checkbox too low
            if wx.Platform == "__WXGTK__":
                yOrigin = -1
            else:
                yOrigin = 0
            wx.RendererNative.Get().DrawCheckBox(self, dc, (0, yOrigin, size, size), state)
            dc.SelectObject(wx.NullBitmap)
            return bitmap

        def _makeBitmaps(name, state):
            self.AddNamedImages(name, _makeBitmap(state, 16), _makeBitmap(state, 32))

        # If there isn't a small image list, make one
        if self.smallImageList is None:
            self.SetImageLists()

        _makeBitmaps(ObjectListView.NAME_CHECKED_IMAGE, wx.CONTROL_CHECKED)
        _makeBitmaps(ObjectListView.NAME_UNCHECKED_IMAGE, wx.CONTROL_CURRENT)
        _makeBitmaps(ObjectListView.NAME_UNDETERMINED_IMAGE, wx.CONTROL_UNDETERMINED) 
Example #15
Source File: backend_wxagg.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def _WX28_clipped_agg_as_bitmap(agg, bbox):
    """
    Convert the region of a the agg buffer bounded by bbox to a wx.Bitmap.

    Note: agg must be a backend_agg.RendererAgg instance.
    """
    l, b, width, height = bbox.bounds
    r = l + width
    t = b + height

    srcBmp = wxc.BitmapFromBuffer(int(agg.width), int(agg.height),
                                  agg.buffer_rgba())
    srcDC = wx.MemoryDC()
    srcDC.SelectObject(srcBmp)

    destBmp = wxc.EmptyBitmap(int(width), int(height))
    destDC = wx.MemoryDC()
    destDC.SelectObject(destBmp)

    x = int(l)
    y = int(int(agg.height) - t)
    destDC.Blit(0, 0, int(width), int(height), srcDC, x, y)

    srcDC.SelectObject(wx.NullBitmap)
    destDC.SelectObject(wx.NullBitmap)

    return destBmp 
Example #16
Source File: backend_wx.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def unselect(self):
        """
        Select a Null bitmasp into this wxDC instance
        """
        if sys.platform == 'win32':
            self.dc.SelectObject(wx.NullBitmap)
            self.IsSelected = False 
Example #17
Source File: wx_compat.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def _AddTool(parent, wx_ids, text, bmp, tooltip_text):
    if text in ['Pan', 'Zoom']:
        kind = wx.ITEM_CHECK
    else:
        kind = wx.ITEM_NORMAL
    if is_phoenix:
        add_tool = parent.AddTool
    else:
        add_tool = parent.DoAddTool

    if not is_phoenix or wx_version >= str("4.0.0b2"):
        # NOTE: when support for Phoenix prior to 4.0.0b2 is dropped then
        # all that is needed is this clause, and the if and else clause can
        # be removed.
        kwargs = dict(label=text,
                      bitmap=bmp,
                      bmpDisabled=wx.NullBitmap,
                      shortHelp=text,
                      longHelp=tooltip_text,
                      kind=kind)
    else:
        kwargs = dict(label=text,
                      bitmap=bmp,
                      bmpDisabled=wx.NullBitmap,
                      shortHelpString=text,
                      longHelpString=tooltip_text,
                      kind=kind)

    return add_tool(wx_ids[text], **kwargs) 
Example #18
Source File: IDEFrame.py    From OpenPLC_Editor with GNU General Public License v3.0 5 votes vote down vote up
def RefreshEditorToolBar(self):
        selected = self.TabsOpened.GetSelection()
        menu = None
        if selected != -1:
            window = self.TabsOpened.GetPage(selected)
            if isinstance(window, (Viewer, TextViewer)):
                if not window.IsDebugging():
                    menu = self.Controler.GetEditedElementBodyType(window.GetTagName())
                else:
                    menu = "debug"
        if menu is not None and menu != self.CurrentMenu:
            self.ResetEditorToolBar()
            self.CurrentMenu = menu
            self.CurrentEditorToolBar = []
            EditorToolBar = self.Panes["EditorToolBar"]
            if EditorToolBar:
                for radio, modes, id, method, picture, help in self.EditorToolBarItems[menu]:
                    if modes & self.DrawingMode:
                        if radio or self.DrawingMode == FREEDRAWING_MODE:
                            EditorToolBar.AddRadioTool(id, GetBitmap(picture), wx.NullBitmap, help)
                        else:
                            EditorToolBar.AddSimpleTool(id, GetBitmap(picture), help)
                        self.Bind(wx.EVT_MENU, getattr(self, method), id=id)
                        self.CurrentEditorToolBar.append(id)
                EditorToolBar.Realize()
                self.AUIManager.GetPane("EditorToolBar").Show()
                self.AUIManager.Update()
                self.AUIManager.GetPane("EditorToolBar").BestSize(EditorToolBar.GetBestSize())
                self.AUIManager.Update()
        elif menu is None:
            self.ResetEditorToolBar()
            self.CurrentMenu = menu
        self.ResetCurrentMode()

    # -------------------------------------------------------------------------------
    #                           EditorToolBar Items Functions
    # ------------------------------------------------------------------------------- 
Example #19
Source File: PDFoutline.py    From PyMuPDF-Utilities with GNU General Public License v3.0 5 votes vote down vote up
def PicRefresh(dlg, seite):
    i_seite = getint(seite)
    i_seite = max(1, i_seite)               # ensure page# is within boundaries
    i_seite = min(spad.seiten, i_seite)

    dlg.zuSeite.Value = str(i_seite)        # set page number in dialog field
    if spad.oldpage == i_seite:             # avoid effort if no page change
        return
    spad.oldpage = i_seite

    bmp = pdf_show(dlg, i_seite)            # get bitmap of page

    dc = wx.MemoryDC()                      # make a device control out of bmp
    dc.SelectObject(bmp)
    dc.SetPen(wx.Pen("RED", width=1))
    d = dlg.tocgrid.GetTable()              # get data of grid
    ltab = dlg.tocgrid.Table.GetNumberRows()

    # draw horizontal line for every bookmark to this page
    # note that we don't assume any page number order!
    for i in list(range(ltab)):
        if int(d.GetValue(i, 2)) != i_seite:
            continue
        x1 = bmp.Size[0] - 1                # don't draw on last pixel
        top = int(d.GetValue(i, 3))
        # adjust to img dimension
        t = float(bmp.Size[1]) * float(top) / float(spad.height)
        t = bmp.Size[1] - int(t)            # DrawLine counts from top
        dc.DrawLine(1, t, x1, t)            # don't draw on 1st pixel

    dc.SelectObject(wx.NullBitmap)          # destroy MemoryDC
    dc = None                               # before further use

    dlg.PDFbild.SetSize(bmp.Size)           # update size
    dlg.PDFbild.SetBitmap(bmp)              # and update the picture
    dlg.Layout()
    bmp = None                              # destroy bitmap
    return
#==============================================================================
# Disable OK button
#============================================================================== 
Example #20
Source File: backend_wx.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def add_toolitem(
        self, name, group, position, image_file, description, toggle):

        before, group = self._add_to_group(group, name, position)
        idx = self.GetToolPos(before.Id)
        if image_file:
            bmp = _load_bitmap(image_file)
            kind = wx.ITEM_NORMAL if not toggle else wx.ITEM_CHECK
            tool = self.InsertTool(idx, -1, name, bmp, wx.NullBitmap, kind,
                                   description or "")
        else:
            size = (self.GetTextExtent(name)[0]+10, -1)
            if toggle:
                control = wx.ToggleButton(self, -1, name, size=size)
            else:
                control = wx.Button(self, -1, name, size=size)
            tool = self.InsertControl(idx, control, label=name)
        self.Realize()

        def handler(event):
            self.trigger_tool(name)

        if image_file:
            self.Bind(wx.EVT_TOOL, handler, tool)
        else:
            control.Bind(wx.EVT_LEFT_DOWN, handler)

        self._last = tool
        self._toolitems.setdefault(name, [])
        group.insert(position, tool)
        self._toolitems[name].append((tool, handler)) 
Example #21
Source File: __init__.py    From EventGhost with GNU General Public License v2.0 5 votes vote down vote up
def Draw(
        self,
        dc,
        foregroundColour,
        backgroundColour,
        display=0, # deprecated
    ):
        image = FOCUS_IMAGE.Copy()
        image.ConvertToMono(255, 255, 255)
        bmp = wx.BitmapFromImage(image, 1)
        bmpWidth, bmpHeight = bmp.GetSize()
        #bmp.SetMask(None)

        mdc = wx.MemoryDC()
        bmp2 = wx.EmptyBitmap(bmpWidth, bmpHeight, 1)
        mdc.SelectObject(bmp2)
        mdc.SetTextForeground((255, 255, 255))
        mdc.SetTextBackground((0, 0, 0))
        mdc.DrawBitmap(bmp, 0, 0, False)
        mdc.SelectObject(wx.NullBitmap)
        bmp = bmp2

        dc.SetTextForeground(backgroundColour)
        dc.SetTextBackground(foregroundColour)
        w, h = dc.GetSizeTuple()
        startX = (bmpWidth - (w % bmpWidth)) / 2
        startY = (bmpHeight - (h % bmpHeight)) / 2
        for x in range(-startX, w, bmpWidth):
            for y in range(-startY, h, bmpHeight):
                dc.DrawBitmap(bmp, x, y, False) 
Example #22
Source File: Tool_Menu_EventBinding_Classic.py    From wxGlade with MIT License 5 votes vote down vote up
def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame.__init__
        kwds["style"] = kwds.get("style", 0) | wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.SetSize((400, 300))
        self.SetTitle("frame")

        # Menu Bar
        self.frame_menubar = wx.MenuBar()
        wxglade_tmp_menu = wx.Menu()
        self.frame_menubar.item1 = wxglade_tmp_menu.Append(wx.ID_ANY, "My Menu Item 1", "")
        self.Bind(wx.EVT_MENU, self.on_menu_item1, id=self.frame_menubar.item1.GetId())
        item = wxglade_tmp_menu.Append(wx.ID_ANY, "My Menu Item 1", "without attribute name")
        self.Bind(wx.EVT_MENU, self.on_menu_item2, id=item.GetId())
        self.frame_menubar.Append(wxglade_tmp_menu, "Menu 1")
        self.SetMenuBar(self.frame_menubar)
        # Menu Bar end

        # Tool Bar
        self.frame_toolbar = wx.ToolBar(self, -1)
        tool = self.frame_toolbar.AddLabelTool(wx.ID_ANY, "My Tool", wx.Bitmap("..\\..\\icons\\button.xpm", wx.BITMAP_TYPE_ANY), wx.NullBitmap, wx.ITEM_NORMAL, "", "")
        self.Bind(wx.EVT_TOOL, self.on_my_tool, id=tool.GetId())
        self.SetToolBar(self.frame_toolbar)
        self.frame_toolbar.Realize()
        # Tool Bar end

        sizer_1 = wx.BoxSizer(wx.VERTICAL)

        sizer_1.Add((0, 0), 0, 0, 0)

        self.SetSizer(sizer_1)

        self.Layout()

        # end wxGlade 
Example #23
Source File: backend_wx.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def unselect(self):
        """
        Select a Null bitmasp into this wxDC instance
        """
        if sys.platform == 'win32':
            self.dc.SelectObject(wx.NullBitmap)
            self.IsSelected = False 
Example #24
Source File: main.py    From wxGlade with MIT License 5 votes vote down vote up
def _add_label_tool(self, tb, size, id, label, bmp, itemtype, msg, msg_long=None):
        os.path.join(config.icons_path, "layout2.xpm")
        ADD = tb.AddLabelTool  if compat.IS_CLASSIC else  tb.AddTool
        if compat.IS_PHOENIX:
            method = getattr(tb, "AddTool")
        else:
            method = getattr(tb, "AddLabelTool")

        if isinstance(bmp, str) and not bmp.startswith("wxART_"):
            bmp = wx.Bitmap( os.path.join(config.icons_path, bmp) )
        else:
            # a wx.ART_... constant
            bmp = wx.ArtProvider.GetBitmap(bmp, wx.ART_OTHER, size)
        return ADD(-1, _(label), bmp, wx.NullBitmap, itemtype, _(msg), _(msg_long or msg)) 
Example #25
Source File: adm.py    From admin4 with Apache License 2.0 5 votes vote down vote up
def GetId(self, name):
    if name == None:
      return -1
    id=self.list.get(name)
    if id:
      return id

    id=-1
    bmp=wh.GetBitmap(name)
    if bmp:
      if bmp.GetSize() != self.GetSize(0):
        dcs=wx.MemoryDC()
        w1,h1=bmp.GetSize()
        dcs.SelectObject(bmp)
        dc=wx.MemoryDC()
        w,h=self.GetSize(0)
        bmpneu=wx.EmptyBitmap(w,h)
        dc.SelectObject(bmpneu)
        if wx.Platform not in ("__WXMAC__"):
          b=self.GetBitmap(1)
          dc.DrawBitmap(b, 0, 0, True)
        dc.StretchBlit(0, 0, w, h, dcs, 0,0,w1,h1)
        dc.SelectObject(wx.NullBitmap)
        dcs.SelectObject(wx.NullBitmap)
        id=self.Add(bmpneu)
        logger.debug("Bitmap %s has wrong format. Need %s, is %s", name, self.GetSize(0), bmp.GetSize())
      else:
        id=self.Add(bmp)
    else:
      fn="%s.ico" % name
      if os.path.exists(fn):
        id=self.AddIcon(wx.Icon(fn))
    self.list[name]=id
    return id 
Example #26
Source File: adm.py    From admin4 with Apache License 2.0 5 votes vote down vote up
def GetJoinedId(self, ids):
    if len(ids) < 2:
      return ids[0]

    name="joined:%s" % "+".join(map(str, ids))
    id=self.list.get(name)
    if id:
      return id
    dc=wx.MemoryDC()

    w,h=self.GetSize(0)
    bmp=wx.EmptyBitmap(w,h)
    dc.SelectObject(bmp)

    # TODO should rewrite using wx.GraphicsContext
    if wx.Platform not in ("__WXMAC__"):
      b=self.GetBitmap(1)
      dc.DrawBitmap(b, 0, 0, True)
    
    for id in ids:
      if id > 0:
        b=self.GetBitmap(id)
        dc.DrawBitmap(b, 0, 0, True)
        #self.Draw(id, dc, 0,0)
      dc.DrawBitmap(b, 0, 0, True)
    dc.SelectObject(wx.NullBitmap)

    id=self.Add(bmp)
    self.list[name]=id
    return id 
Example #27
Source File: ListCtrl.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def draw_blank(self):
        b = wx.EmptyBitmap(self.icon_size, self.icon_size)
        dc = wx.MemoryDC()
        dc.SelectObject(b)
        dc.SetBackgroundMode(wx.TRANSPARENT)
        dc.Clear()
        dc.SelectObject(wx.NullBitmap)
        b.SetMask(wx.Mask(b, (255, 255, 255)))
        return b

    # this builds an identical arrow to the windows listctrl arrows, in themed
    # and non-themed mode. 
Example #28
Source File: CustomWidgets.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def redraw(self):
        dc = wx.MemoryDC()
        dc.SelectObject(self.buffer)
        size = self._calc_size()
        self.last_size = size
        self.draw(dc, size=size)
        dc.SelectObject(wx.NullBitmap)
        self.Refresh() 
Example #29
Source File: CustomWidgets.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
def init_buffer(self):
        size = self._calc_size()
        if ((self.buffer_size.width < size.width) or
            (self.buffer_size.height < size.height)):
            self.buffer = wx.EmptyBitmap(size.width, size.height)
            dc = wx.MemoryDC()
            dc.SelectObject(self.buffer)
            dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
            dc.Clear()
            dc.SelectObject(wx.NullBitmap)
            self.buffer_size = size
            return True
        return False 
Example #30
Source File: MeshCanvas.py    From laplacian-meshes with GNU General Public License v3.0 5 votes vote down vote up
def saveImage(canvas, filename):
    s = wx.ScreenDC()
    w, h = canvas.size.Get()
    b = wx.EmptyBitmap(w, h)
    m = wx.MemoryDCFromDC(s)
    m.SelectObject(b)
    m.Blit(0, 0, w, h, s, 70, 0)
    m.SelectObject(wx.NullBitmap)
    b.SaveFile(filename, wx.BITMAP_TYPE_PNG)