Пример #1
0
    def OnPaint(self, event):
        # if __debug__: print "preview", self.previewkey, self.lastkey
        dc = wx.PaintDC(self.preview)
        if wx.VERSION >= (2, 9):
            self.frame.canvas.SetCurrent(self.frame.canvas.context)
        else:
            self.frame.canvas.SetCurrent()

        if dc.GetSize().y < 16 or not self.lastkey:
            if self.previewkey:
                self.previewkey = None
                self.previewbmp = None
                self.preview.SetBackgroundColour(wx.NullColour)
                self.preview.ClearBackground()
            return

        if self.previewkey != self.lastkey:
            # New
            self.previewkey = self.lastkey
            self.previewimg = self.previewbmp = None

            if not self.previewkey or self.previewkey in self.cb.bad or self.previewkey not in self.frame.canvas.lookup:
                self.preview.SetBackgroundColour(wx.NullColour)
                self.preview.ClearBackground()
                return  # unknown object - can't do anything

            # Look for built-in screenshot
            newfile = self.previewkey.replace('/', '_')[:-3] + 'jpg'
            if newfile[0] == '_': newfile = newfile[1:]
            newfile = join('Resources', 'previews', newfile)
            try:
                if exists(newfile):
                    self.previewimg = wx.Image(newfile, wx.BITMAP_TYPE_JPEG)
            except:
                pass

            # Look for library screenshot - <object>.jpg, picture.png or screenshot.jpg
            if not self.previewimg:
                newfile = self.frame.canvas.lookup[
                    self.previewkey].file[:-3] + 'jpg'
                try:
                    if exists(newfile):
                        self.previewimg = wx.Image(newfile,
                                                   wx.BITMAP_TYPE_JPEG)
                except:
                    pass

            # X-Plane v9 static aircraft
            if not self.previewimg:
                newfile = join(dirname(newfile), 'picture.png')
                try:
                    if exists(newfile):
                        self.previewimg = wx.Image(newfile, wx.BITMAP_TYPE_PNG)
                except:
                    pass

            # OpenSceneryX
            if not self.previewimg:
                newfile = join(dirname(newfile), 'screenshot.jpg')
                try:
                    if exists(newfile):
                        self.previewimg = wx.Image(newfile,
                                                   wx.BITMAP_TYPE_JPEG)
                except:
                    pass

            if not self.previewimg:
                # loading clutter can be slow so clear while loading
                self.preview.SetBackgroundColour(wx.NullColour)
                self.preview.ClearBackground()

                # Display object data
                filename = self.frame.canvas.lookup[self.previewkey].file
                try:
                    if filename in self.frame.canvas.defs:
                        definition = self.frame.canvas.defs[filename]
                    else:
                        self.frame.canvas.defs[
                            filename] = definition = ClutterDef.factory(
                                filename, self.frame.canvas.vertexcache,
                                self.frame.canvas.lookup,
                                self.frame.canvas.defs)
                    # Special handling to mark orthos
                    if isinstance(definition, DrapedDef) and definition.ortho:
                        for l in self.cb.lists:
                            i = l.GetSelection()
                            if i != -1:
                                (imgno, name, realname) = l.choices[i]
                                if imgno != self.cb.imgno_ortho:
                                    l.choices[i] = (self.cb.imgno_ortho, name,
                                                    realname)
                                    l.Refresh()
                                break
                    self.previewimg = definition.preview(
                        self.frame.canvas, self.frame.canvas.vertexcache)
                except:
                    if __debug__: print_exc()
                    self.cb.markbad()

        if self.previewimg:
            # rescale if necessary
            if (dc.GetSize().x >= self.previewimg.GetWidth()
                    and dc.GetSize().y >= self.previewimg.GetHeight()):
                scale = None
                newsize = (self.previewimg.GetWidth(),
                           self.previewimg.GetHeight())
            else:
                scale = min(
                    float(dc.GetSize().x) / self.previewimg.GetWidth(),
                    float(dc.GetSize().y) / self.previewimg.GetHeight())
                newsize = (int(scale * self.previewimg.GetWidth()),
                           int(scale * self.previewimg.GetHeight()))
            if not self.previewbmp or newsize != self.previewsize:
                self.previewsize = newsize
                self.preview.SetBackgroundColour(
                    wx.Colour(self.previewimg.GetRed(0, 0),
                              self.previewimg.GetGreen(0, 0),
                              self.previewimg.GetBlue(0, 0)))
                self.preview.ClearBackground()
                if scale:
                    if 'IMAGE_QUALITY_HIGH' in dir(
                            wx):  # not in 2.6 or earlier
                        self.previewbmp = wx.BitmapFromImage(
                            self.previewimg.Scale(newsize[0], newsize[1],
                                                  wx.IMAGE_QUALITY_HIGH))
                    else:
                        self.previewbmp = wx.BitmapFromImage(
                            self.previewimg.Scale(newsize[0], newsize[1]))
                else:
                    self.previewbmp = wx.BitmapFromImage(self.previewimg)
            dc.DrawBitmap(self.previewbmp,
                          (dc.GetSize().x - self.previewsize[0]) / 2,
                          (dc.GetSize().y - self.previewsize[1]) / 2, True)
        else:
            self.preview.SetBackgroundColour(wx.NullColour)
            self.preview.ClearBackground()
Пример #2
0
 def AddTool(self, id, bitmap, **kwargs):
     bitmap = '%s.png' % bitmap
     image = wx.Image(leginon.icons.getPath(bitmap))
     image.ConvertAlphaToMask(64)
     bitmap = wx.BitmapFromImage(image)
     wx.ToolBar.AddTool(self, id, bitmap, **kwargs)
Пример #3
0
def BitmapFromImage(image, depth=-1):
    if wxPythonPhoenix:
        return wx.Bitmap(img=image, depth=depth)
    else:
        return wx.BitmapFromImage(image, depth=depth)
Пример #4
0
    def __init__(self,
                 parent,
                 message,
                 caption="Message Box",
                 msg2="",
                 style=wx.OK | wx.CANCEL,
                 pos=wx.DefaultPosition,
                 icon=None,
                 btnLabels=None):
        if 'wxMac' not in wx.PlatformInfo:
            title = caption  # the caption will be displayed inside the dialog on Macs
        else:
            title = ""

        wx.Dialog.__init__(self,
                           parent,
                           -1,
                           title,
                           pos,
                           style=wx.DEFAULT_DIALOG_STYLE | style &
                           (wx.STAY_ON_TOP | wx.DIALOG_NO_PARENT))

        bitmap = None
        isize = (32, 32)

        # was an icon passed to us?
        if icon is not None:
            if isinstance(icon, wx.Icon):
                bitmap = wx.BitmapFromIcon(icon)
            elif isinstance(icon, wx.Image):
                bitmap = wx.BitmapFromImage(icon)
            else:
                assert isinstance(icon, wx.Bitmap)
                bitmap = icon

        else:
            # check for icons in the style flags
            artid = None
            if style & wx.ICON_ERROR or style & wx.ICON_HAND:
                artid = wx.ART_ERROR
            elif style & wx.ICON_EXCLAMATION:
                artid = wx.ART_WARNING
            elif style & wx.ICON_QUESTION:
                artid = wx.ART_QUESTION
            elif style & wx.ICON_INFORMATION:
                artid = wx.ART_INFORMATION

            if artid is not None:
                bitmap = wx.ArtProvider.GetBitmap(artid, wx.ART_MESSAGE_BOX,
                                                  isize)

        if bitmap:
            bitmap = wx.StaticBitmap(self, -1, bitmap)
        else:
            bitmap = isize  # will be a spacer when added to the sizer

        # Sizer to contain the icon, text area and buttons
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(bitmap, 0, wx.TOP | wx.LEFT, 12)
        sizer.Add((10, 10))

        # Make the text area
        messageSizer = wx.BoxSizer(wx.VERTICAL)
        if 'wxMac' in wx.PlatformInfo and caption:
            caption = wx.StaticText(self, -1, caption)
            caption.SetFont(wx.Font(18, wx.SWISS, wx.NORMAL, wx.BOLD))
            messageSizer.Add(caption)
            messageSizer.Add((10, 10))

        stext = wx.StaticText(self, -1, message)
        #stext.SetLabelMarkup(message)  Wrap() causes all markup to be lost, so don't try to use it yet...
        stext.Wrap(self.CONTENT_MAX_W)
        messageSizer.Add(stext)

        if msg2:
            messageSizer.Add((15, 15))
            t = wx.TextCtrl(self,
                            style=wx.TE_MULTILINE | wx.TE_READONLY | wx.TE_RICH
                            | wx.TE_DONTWRAP)
            t.SetValue(msg2)

            # Set size to be used by the sizer based on the message content,
            # with good maximums
            dc = wx.ClientDC(t)
            dc.SetFont(t.GetFont())
            w, h, lh = dc.GetMultiLineTextExtent(msg2)
            w = min(self.CONTENT_MAX_W,
                    10 + w + wx.SystemSettings.GetMetric(wx.SYS_VSCROLL_X))
            h = min(self.CONTENT_MAX_H, 10 + h)
            t.SetMinSize((w, h))
            messageSizer.Add(t, 0, wx.EXPAND)

        # Make the buttons
        buttonSizer = self.CreateStdDialogButtonSizer(
            style & (wx.OK | wx.CANCEL | wx.YES_NO | wx.NO_DEFAULT
                     | wx.CANCEL_DEFAULT | wx.YES_DEFAULT | wx.OK_DEFAULT))
        self.Bind(wx.EVT_BUTTON, self.OnButton)
        if btnLabels:
            for sid, label in btnLabels.iteritems():
                btn = self.FindWindowById(sid)
                if btn:
                    btn.SetLabel(label)
        messageSizer.Add(wx.Size(1, 15))
        messageSizer.Add(buttonSizer, 0,
                         wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.EXPAND, 12)

        sizer.Add(messageSizer, 0, wx.LEFT | wx.RIGHT | wx.TOP, 12)
        self.SetSizer(sizer)
        self.Fit()
        if parent:
            self.CenterOnParent()
        else:
            self.CenterOnScreen()

        for c in self.Children:
            if isinstance(c, wx.Button):
                wx.CallAfter(c.SetFocus)
                break
Пример #5
0
def getPyBitmap(shellName='PyCrust'):
    return wx.BitmapFromImage(getPyImage(shellName))
Пример #6
0
def GetCollapsedIconBitmap():
    return wx.BitmapFromImage(GetCollapsedIconImage())
Пример #7
0
    def initializeBitmaps(self):

        dict = self.pathToAP + 'multimedia/youtube/*'
        pages = sorted([
            item for item in glob.glob(dict)
            if item[item.rfind('/') + 1:].isdigit()
        ])
        self.numberOfpages = len(pages)

        self.blissBook = {
        }  #dictionary with keys as number of page and values as list of tuples (each tuple discribes one symbol) in form [bitmap, bitmap's position in sizer, bitmap's label]
        self.numberOfRows, self.numberOfColumns, self.numberOfCells = [], [], []

        for page in pages:
            try:
                pageNumber = int(page[page.rfind('/') + 1:])
            except ValueError:
                print 'Folderowi %s nadano nieprawidłową nazwę. Dopuszczalna jest tylko nazwa numeryczna.' % page[
                    page.rfind('/') + 1:]
                pass

            sizerTopology = open(page + '/sizer')

            for line in sizerTopology:

                if line[:12] == 'numberOfRows':
                    self.numberOfRows.append(int(line[-2]))
                elif line[:15] == 'numberOfColumns':
                    self.numberOfColumns.append(int(line[-2]))
                else:
                    print 'Niewłaściwie opisana tablica na stronie %' % page
                    self.numberOfColumns.append(self.defaultNumberOfColumns)
                    self.numberOfRows.append(self.defaultNumberOfRows)

            symbols = glob.glob(page + '/*.jpg') + glob.glob(
                page + '/*.png') + glob.glob(page +
                                             '/*.JPG') + glob.glob(page +
                                                                   '/*jpeg')
            symbols = [item.decode('utf-8') for item in symbols]

            symbolInfo = []

            self.newHeight = 0.6 * self.winHeight / self.numberOfRows[-1]

            for symbol in symbols:

                image = wx.ImageFromStream(open(symbol, "rb"))

                self.newWidth = image.GetSize()[0] * (
                    self.newHeight / float(image.GetSize()[1]))

                image.Rescale(self.newWidth, self.newHeight,
                              wx.IMAGE_QUALITY_HIGH)
                bitmapSymbol = wx.BitmapFromImage(image)

                symbolName = symbol[symbol.rfind('/') + 1:symbol.rfind('.')]

                try:
                    symbolPosition = int(symbolName.split('_')[0])
                    symbolTranslate = symbolName[symbolName.find('_') +
                                                 1:].replace('_', ' ')
                    symbolInfo.append(
                        [bitmapSymbol, symbolPosition, symbolTranslate])
                except ValueError:
                    print 'Symbol %s w folderze %s ma nieprawidłową nazwę.' % (
                        symbolName.split('_')[0], page[page.rfind('/') + 1:])
                    pass

            symbolInfo.sort(key=lambda symbolInfo: symbolInfo[1])
            self.blissBook[pageNumber] = symbolInfo
Пример #8
0
def GetBitmap():
    return wx.BitmapFromImage(GetImage())
Пример #9
0
    def drawToFitDC(self,
                    dc,
                    rowDrawStart=0,
                    rowDrawCount=1000000,
                    pageNumber=None,
                    pageNumberTotal=None):
        self.combineFirstLastNames()
        bitmapCache = {}

        self.rowDrawCount = rowDrawCount

        # Get the dimensions of what we are printing on.
        (widthPix, heightPix) = dc.GetSizeTuple()

        # Get a reasonable border.
        borderPix = max(widthPix, heightPix) / 20

        widthFieldPix = widthPix - borderPix * 2
        heightFieldPix = heightPix - borderPix * 2

        xPix = yPix = borderPix

        # Draw the graphic.
        bitmap = getHeaderBitmap()
        bmWidth, bmHeight = bitmap.GetWidth(), bitmap.GetHeight()
        graphicHeight = heightPix * 0.15
        graphicWidth = float(bmWidth) / float(bmHeight) * graphicHeight
        graphicBorder = int(graphicWidth * 0.15)

        # Rescale the graphic to the correct size.
        # We cannot use a GraphicContext because it does not support a PrintDC.
        image = bitmap.ConvertToImage()
        image.Rescale(graphicWidth, graphicHeight, wx.IMAGE_QUALITY_HIGH)
        bitmap = wx.BitmapFromImage(
            image.ConvertToGreyscale() if dc.GetDepth() == 8 else image)
        dc.DrawBitmap(bitmap, xPix, yPix)
        image, bitmap = None, None

        # Get the race URL (if defined).
        with Model.LockRace() as race:
            url = getattr(race, 'urlFull', None)
        if url and url.startswith('http://'):
            url = urllib.quote(url[7:])

        qrWidth = 0
        if url:
            qrWidth = graphicHeight
            drawQRCode(url, dc, widthPix - borderPix - qrWidth, borderPix,
                       qrWidth)
            qrWidth += graphicBorder
            url = url.replace('%20', ' ')

        # Draw the title.
        font = self._getFontToFit(
            widthFieldPix - graphicWidth - graphicBorder - qrWidth,
            graphicHeight,
            lambda font: dc.GetMultiLineTextExtent(self.title, font)[:2], True)
        dc.SetFont(font)
        self._drawMultiLineText(dc, self.title,
                                xPix + graphicWidth + graphicBorder, yPix)
        # wText, hText, lineHeightText = dc.GetMultiLineTextExtent( self.title, font )
        # yPix += hText + lineHeightText/4
        yPix += graphicHeight + graphicBorder

        heightFieldPix = heightPix - yPix - borderPix

        # Draw the table.
        # Add space for the flag on the NatCode.
        def padCol(iCodeCol):
            for c, v in enumerate(self.data[iCodeCol]):
                self.data[iCodeCol][c] = u'     ' + v

        try:
            iUCICodeCol = self.colnames.index(_("UCICode"))
            padCol(iUCICodeCol)
        except ValueError:
            iUCICodeCol = None

        try:
            iNatCodeCol = self.colnames.index(_("NatCode"))
            padCol(iNatCodeCol)
        except ValueError:
            iNatCodeCol = None

        # Remember: _getDataSizeTuple understands self.rowDrawCount and will compute the height using the count.
        font = self._getFontToFit(
            widthFieldPix, heightFieldPix,
            lambda font: self._getDataSizeTuple(dc, font))
        dc.SetFont(font)
        wSpace, hSpace, textHeight = dc.GetMultiLineTextExtent(u'    ', font)

        # Get the row slice for each column.
        dataDraw = [
            col[rowDrawStart:rowDrawStart + rowDrawCount] for col in self.data
        ]

        yPixTop = yPixMax = yPix
        for col, c in enumerate(self.colnames):
            isSpeed = (c == _('Speed'))
            if isSpeed and dataDraw[col]:
                try:
                    c = self.colnames[col] = self.data[col][0].split()[1]
                except IndexError:
                    c = self.colnames[col] = ''

            colWidth = self._getColSizeTuple(dc, font, col)[0]
            yPix = yPixTop
            w, h, lh = dc.GetMultiLineTextExtent(c, font)
            if col in self.leftJustifyCols:
                self._drawMultiLineText(dc, u'{}'.format(c), xPix,
                                        yPix)  # left justify
            else:
                self._drawMultiLineText(dc, u'{}'.format(c),
                                        xPix + colWidth - w,
                                        yPix)  # right justify
            yPix += h + hSpace / 4
            if col == 0:
                yLine = yPix - hSpace / 8
                dc.SetPen(wx.Pen(wx.Colour(200, 200, 200)))
                for r in xrange(max(len(cData) for cData in dataDraw) + 1):
                    dc.DrawLine(borderPix, yLine + r * textHeight,
                                widthPix - borderPix, yLine + r * textHeight)
                dc.SetPen(wx.BLACK_PEN)

            for v in dataDraw[col]:
                vStr = u'{}'.format(v)
                if vStr:
                    if isSpeed:
                        vStr = vStr.split()[0]
                        if vStr == '"':
                            vStr += '    '
                    w, h, lh = dc.GetMultiLineTextExtent(vStr, font)
                    if col in self.leftJustifyCols:
                        self._drawMultiLineText(dc, vStr, xPix,
                                                yPix)  # left justify
                    else:
                        self._drawMultiLineText(dc, vStr, xPix + colWidth - w,
                                                yPix)  # right justify
                if col == iUCICodeCol or col == iNatCodeCol:
                    ioc = vStr.strip()[:3]
                    try:
                        bmp = bitmapCache[ioc]
                    except KeyError:
                        img = Flags.GetFlagImage(ioc)
                        if img:
                            h = int(textHeight * 0.66)
                            w = int(
                                float(img.GetWidth()) /
                                float(img.GetHeight()) * float(h))
                            bmp = bitmapCache[ioc] = wx.BitmapFromImage(
                                img.Scale(w, h, wx.IMAGE_QUALITY_HIGH))
                        else:
                            bmp = bitmapCache[ioc] = None
                    if bmp:
                        padding = (textHeight - bmp.GetHeight()) // 2
                        dc.DrawBitmap(bmp, xPix, yPix + padding)
                        # dc.DrawRectangle( xPix, yPix+padding, bmp.GetWidth(), bmp.GetHeight() )

                yPix += textHeight
            yPixMax = max(yPixMax, yPix)
            xPix += colWidth + wSpace

            if isSpeed:
                self.colnames[col] = _('Speed')

        # Switch to smaller font.
        font = self._getFont(borderPix // 4, False)
        dc.SetFont(font)

        if url:
            yPix = yPixMax + textHeight
            w, h, lh = dc.GetMultiLineTextExtent(url, font)
            self._drawMultiLineText(dc, url, widthPix - borderPix - w, yPix)

        # Put CrossMgr branding at the bottom of the page.
        w, h, lh = dc.GetMultiLineTextExtent(self.brandText, font)
        yFooter = heightPix - borderPix + int(h * 1.8)

        self._drawMultiLineText(dc, self.brandText, borderPix, yFooter)

        # Put the page number info at the bottom of the page.
        if pageNumber is not None:
            if pageNumberTotal is not None:
                s = u'{} {} / {}'.format(_('Page'), pageNumber,
                                         pageNumberTotal)
            else:
                s = u'{} {}'.format(_('Page'), pageNumber)
            w, h, lh = dc.GetMultiLineTextExtent(s, font)
            self._drawMultiLineText(dc, s, widthPix - w - borderPix, yFooter)

        # Clean up the extra spaces for the flags.
        for iColCode in (iUCICodeCol, iNatCodeCol):
            if iColCode is not None:
                for c, v in enumerate(self.data[iColCode]):
                    self.data[iColCode][c] = v.strip()
Пример #10
0
    def Compose(self, cmdLists, regions, opacityList, bgcolor, force, nprocs):
        """Performs the composition of ppm/pgm files.

        :param cmdLists: lists of rendering commands lists to compose
        :param regions: regions for 2D rendering assigned to commands
        :param opacityList: list of lists of opacity values
        :param bgcolor: background color as a tuple of 3 values 0 to 255
        :param force: if True reload all data, otherwise only missing data
        :param nprocs: number of procs to be used for rendering
        """
        Debug.msg(3, "BitmapComposer.Compose")

        count = 0

        # Variables for parallel rendering
        proc_count = 0
        proc_list = []
        queue_list = []
        cmd_lists = []

        filteredCmdLists = []
        for cmdList, region in zip(cmdLists, regions):
            if not force and HashCmds(
                    cmdList,
                    region) in self._bitmapPool and self._bitmapPool[HashCmds(
                        cmdList, region)].GetSize() == (self.imageWidth,
                                                        self.imageHeight):
                # TODO: find a better way than to assign the same to increase
                # the reference
                self._bitmapPool[HashCmds(cmdList,
                                          region)] = self._bitmapPool[HashCmds(
                                              cmdList, region)]
                continue
            filteredCmdLists.append((cmdList, region))

        num = len(filteredCmdLists)

        self._isComposing = True
        for cmdList, region in filteredCmdLists:
            count += 1
            # Queue object for interprocess communication
            q = Queue()
            # The separate render process
            p = Process(target=CompositeProcess,
                        args=(self.imageWidth, self.imageHeight, self._tempDir,
                              cmdList, region, opacityList, bgcolor, q))
            p.start()

            queue_list.append(q)
            proc_list.append(p)
            cmd_lists.append((cmdList, region))

            proc_count += 1

            # Wait for all running processes and read/store the created images
            if proc_count == nprocs or count == num:
                for i in range(len(cmd_lists)):
                    proc_list[i].join()
                    filename = queue_list[i].get()
                    if filename is None:
                        self._bitmapPool[HashCmds(
                            cmd_lists[i][0],
                            cmd_lists[i][1])] = createNoDataBitmap(
                                self.imageWidth,
                                self.imageHeight,
                                text="Failed to render")
                    else:
                        self._bitmapPool[HashCmds(
                            cmd_lists[i][0],
                            cmd_lists[i][1])] = wx.BitmapFromImage(
                                wx.Image(filename))
                        os.remove(filename)
                proc_count = 0
                proc_list = []
                queue_list = []
                cmd_lists = []

            self.compositionContinues.emit(current=count,
                                           text=_("Overlaying map layers"))
            if self._stopComposing:
                self._stopComposing = False
                break

        self._isComposing = False
Пример #11
0
    def initializeBitmaps(self):

        try:
            self.path = self.pathToATPlatform + 'multimedia/music/'
            directories = [
                directory for directory in os.listdir(self.path)
                if os.path.isdir(os.path.join(self.path, directory))
            ]
            #directories.sort( key=lambda directory: os.path.getmtime( os.path.join(self.path, directory) ) )

            directories = sorted(directories,
                                 key=lambda x: int(x.split("_")[0]))

            self.existingLogos, self.existingMedia = [], []

            for item in directories:
                if 'playlist.m3u' in os.listdir(self.path + item):

                    self.existingMedia.append(self.path + item +
                                              '/playlist.m3u')
                    self.existingLogos.append(self.path + item + '/cover.jpg')

                else:
                    ositem = item.replace(' ',
                                          '\ ').replace('(', '\(').replace(
                                              ')', '\)').replace('&', '\&')
                    os.system('ls -d -1 %s/*.mp3 > %s/playlist.m3u' %
                              (self.path.replace(' ', '\ ') + ositem,
                               self.path.replace(' ', '\ ') + ositem))

                    self.existingMedia.append(self.path + item +
                                              '/playlist.m3u')
                    self.existingLogos.append(self.path + item + '/cover.jpg')

            self.numberOfPanels = 1 + len(self.existingMedia) / (
                (self.numberOfRows[0] - 1) * self.numberOfColumns[0] + 1)

            self.newHeight = 0.9 * self.winHeight / self.numberOfRows[0]

            self.panels = {}

            for number in range(self.numberOfPanels):
                logoNames = self.existingLogos[number *
                                               (self.numberOfRows[0] - 1) *
                                               self.numberOfColumns[0]:
                                               (number + 1) *
                                               (self.numberOfRows[0] - 1) *
                                               self.numberOfColumns[0]]

                logos = [
                    wx.ImageFromStream(open(logo, "rb")) for logo in logoNames
                ]
                logos = [
                    logo.Rescale(
                        logo.GetSize()[0] *
                        (self.newHeight / float(logo.GetSize()[1])),
                        self.newHeight, wx.IMAGE_QUALITY_HIGH)
                    for logo in logos
                ]
                logoBitmaps = [wx.BitmapFromImage(logo) for logo in logos]

                self.panels[number + 1] = [logoNames, logoBitmaps]

        except OSError:
            self.panels = {1: [[], []]}
            self.numberOfPanels = 1
            print "Błąd w strukturze plików."

        self.functionButtonPath = [
            wx.BitmapFromImage(
                wx.ImageFromStream(
                    open(self.pathToATPlatform + 'icons/volume down.png',
                         'rb'))),
            wx.BitmapFromImage(
                wx.ImageFromStream(
                    open(self.pathToATPlatform + 'icons/volume up.png',
                         'rb'))),
            wx.BitmapFromImage(
                wx.ImageFromStream(
                    open(self.pathToATPlatform + 'icons/show.png', 'rb'))),
            wx.BitmapFromImage(
                wx.ImageFromStream(
                    open(self.pathToATPlatform + 'icons/delete.png', 'rb'))),
            wx.BitmapFromImage(
                wx.ImageFromStream(
                    open(self.pathToATPlatform + 'icons/back.png', 'rb')))
        ]

        if self.numberOfPanels == 1:
            self.flag = 'row'
        else:
            self.flag = 'panel'
Пример #12
0
def GetDBBitmap(state):
    return wx.BitmapFromImage(GetDBImage(state))
Пример #13
0
    def __init__(self, parent, id, mainPanel):
        self.englishNumberArray = [
            '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
        ]
        self.nepaliNumberArray = loadDataArithmetic.numberStr
        self.currentNumber = 0
        self.nextNumber = 0
        self.numberArithmetic = 0
        self.currentLesson = "oneMore"
        self.mainWin = mainPanel

        self.menuPanel = wx.Panel(parent, wx.ID_ANY, (0, 0), (800, 100))
        self.menuPanel.SetBackgroundColour(config.backgroundColour)

        oneMoreImg = wx.Bitmap(join(config.buttonsPath, 'oneMore.png'),
                               wx.BITMAP_TYPE_PNG)
        self.oneMoreButton = wx.BitmapButton(self.menuPanel,
                                             wx.ID_ANY,
                                             oneMoreImg, (50, 10),
                                             style=wx.NO_BORDER)
        self.oneMoreButton.SetBackgroundColour(config.backgroundColour)
        self.oneMoreButton.Bind(wx.EVT_BUTTON,
                                self.OnOneMoreButton,
                                id=self.oneMoreButton.GetId())

        oneLessImg = wx.Bitmap(join(config.buttonsPath, 'oneLess.png'),
                               wx.BITMAP_TYPE_PNG)
        self.oneLessButton = wx.BitmapButton(self.menuPanel,
                                             wx.ID_ANY,
                                             oneLessImg, (200, 10),
                                             style=wx.NO_BORDER)
        self.oneLessButton.SetBackgroundColour(config.backgroundColour)
        self.oneLessButton.Bind(wx.EVT_BUTTON,
                                self.OnOneLessButton,
                                id=self.oneLessButton.GetId())

        simplePlusImg = wx.Bitmap(join(config.buttonsPath, 'simplePlus.png'),
                                  wx.BITMAP_TYPE_PNG)
        self.simplePlusButton = wx.BitmapButton(self.menuPanel,
                                                wx.ID_ANY,
                                                simplePlusImg, (350, 10),
                                                style=wx.NO_BORDER)
        self.simplePlusButton.SetBackgroundColour(config.backgroundColour)
        self.simplePlusButton.Bind(wx.EVT_BUTTON,
                                   self.OnSimplePlusButton,
                                   id=self.simplePlusButton.GetId())

        simpleMinusImg = wx.Bitmap(join(config.buttonsPath, 'simpleMinus.png'),
                                   wx.BITMAP_TYPE_PNG)
        self.simpleMinusButton = wx.BitmapButton(self.menuPanel,
                                                 wx.ID_ANY,
                                                 simpleMinusImg, (500, 10),
                                                 style=wx.NO_BORDER)
        self.simpleMinusButton.SetBackgroundColour(config.backgroundColour)
        self.simpleMinusButton.Bind(wx.EVT_BUTTON,
                                    self.OnSimpleMinusButton,
                                    id=self.simpleMinusButton.GetId())

        self.displayPanel = wx.Panel(parent, wx.ID_ANY, (0, 100), (800, 500))
        self.displayPanel.SetBackgroundColour(config.backgroundColour)

        self.displayLabel0 = wx.StaticText(self.displayPanel,
                                           wx.ID_ANY,
                                           messages.number, (80, 110),
                                           style=wx.ALIGN_CENTRE)
        self.displayLabel0.SetFont(
            wx.Font(config.fontSize[0], wx.SWISS, wx.NORMAL, wx.NORMAL, False,
                    config.fontName))
        self.displayLabel1 = wx.StaticText(self.displayPanel,
                                           wx.ID_ANY,
                                           messages.oneMoreLabel, (320, 110),
                                           style=wx.ALIGN_CENTRE)
        self.displayLabel1.SetFont(
            wx.Font(config.fontSize[0], wx.SWISS, wx.NORMAL, wx.NORMAL, False,
                    config.fontName))
        self.displayLabel2 = wx.StaticText(self.displayPanel,
                                           wx.ID_ANY,
                                           messages.upNumberLabel, (540, 110),
                                           style=wx.ALIGN_CENTRE)
        self.displayLabel2.SetFont(
            wx.Font(config.fontSize[0], wx.SWISS, wx.NORMAL, wx.NORMAL, False,
                    config.fontName))

        self.nextNumber, self.currentNumber = arithmeticUtils.nextNumber(
            self.currentLesson, self.currentNumber)
        self.displayLabel3 = wx.StaticText(self.displayPanel,
                                           wx.ID_ANY,
                                           self.mreplace(
                                               str(self.currentNumber),
                                               "engToNep"), (80, 160),
                                           style=wx.ALIGN_CENTRE)
        self.displayLabel3.SetFont(
            wx.Font(config.fontSize[0], wx.SWISS, wx.NORMAL, wx.NORMAL, False,
                    config.fontNameArithmetic))
        self.displayLabel4 = wx.StaticText(self.displayPanel,
                                           wx.ID_ANY,
                                           " + ", (220, 160),
                                           style=wx.ALIGN_CENTRE)
        self.displayLabel4.SetFont(
            wx.Font(config.fontSize[0], wx.SWISS, wx.NORMAL, wx.NORMAL, False,
                    config.fontNameArithmetic))
        self.displayLabel5 = wx.StaticText(self.displayPanel,
                                           wx.ID_ANY,
                                           self.mreplace(str(1), "engToNep"),
                                           (360, 160),
                                           style=wx.ALIGN_CENTRE)
        self.displayLabel5.SetFont(
            wx.Font(config.fontSize[0], wx.SWISS, wx.NORMAL, wx.NORMAL, False,
                    config.fontNameArithmetic))
        self.displayLabel6 = wx.StaticText(self.displayPanel,
                                           wx.ID_ANY,
                                           " = ", (470, 160),
                                           style=wx.ALIGN_CENTRE)
        self.displayLabel6.SetFont(
            wx.Font(config.fontSize[0], wx.SWISS, wx.NORMAL, wx.NORMAL, False,
                    config.fontNameArithmetic))
        self.displayLabel7 = wx.StaticText(self.displayPanel,
                                           wx.ID_ANY,
                                           self.mreplace(
                                               str(self.nextNumber),
                                               "engToNep"), (580, 160),
                                           style=wx.ALIGN_CENTRE)
        self.displayLabel7.SetFont(
            wx.Font(config.fontSize[0], wx.SWISS, wx.NORMAL, wx.NORMAL, False,
                    config.fontNameArithmetic))

        ###Display the image based arithmetic
        currentImg = arithmeticUtils.nextImage(self.currentLesson,
                                               self.currentNumber)
        nextImg = arithmeticUtils.nextImage(self.currentLesson,
                                            self.nextNumber)
        currentNumberImg = wx.BitmapFromImage(currentImg)
        self.currentNumberImage = wx.StaticBitmap(
            self.displayPanel, -1, currentNumberImg, (50, 230),
            (currentNumberImg.GetWidth(), currentNumberImg.GetHeight()))

        self.arithmeticSignLabel = wx.StaticText(self.displayPanel,
                                                 wx.ID_ANY,
                                                 " + ", (220, 230),
                                                 style=wx.ALIGN_CENTRE)
        self.arithmeticSignLabel.SetFont(
            wx.Font(config.fontSize[0], wx.SWISS, wx.NORMAL, wx.NORMAL, False,
                    config.fontNameArithmetic))

        nextImg = arithmeticUtils.nextImage(self.currentLesson, 1)
        numberArithmeticImg = wx.BitmapFromImage(nextImg)
        self.numberArithmeticImage = wx.StaticBitmap(
            self.displayPanel, -1, numberArithmeticImg, (360, 230),
            (numberArithmeticImg.GetWidth(), numberArithmeticImg.GetHeight()))

        self.equalToLabel = wx.StaticText(self.displayPanel,
                                          wx.ID_ANY,
                                          " = ", (470, 230),
                                          style=wx.ALIGN_CENTRE)
        self.equalToLabel.SetFont(
            wx.Font(config.fontSize[0], wx.SWISS, wx.NORMAL, wx.NORMAL, False,
                    config.fontNameArithmetic))

        nextNumberImg = wx.BitmapFromImage(nextImg)
        self.nextNumberImage = wx.StaticBitmap(
            self.displayPanel, -1, nextNumberImg, (570, 230),
            (nextNumberImg.GetWidth(), nextNumberImg.GetHeight()))

        self.displayLabel8 = wx.StaticText(self.displayPanel,
                                           wx.ID_ANY,
                                           loadDataArithmetic.numberNames[int(
                                               self.currentNumber)], (80, 330),
                                           style=wx.ALIGN_CENTRE)
        self.displayLabel8.SetFont(
            wx.Font(config.fontSize[0], wx.SWISS, wx.NORMAL, wx.NORMAL, False,
                    config.fontName))
        self.displayLabel9 = wx.StaticText(self.displayPanel,
                                           wx.ID_ANY,
                                           " + ", (220, 310),
                                           style=wx.ALIGN_CENTRE)
        self.displayLabel9.SetFont(
            wx.Font(config.fontSize[0], wx.SWISS, wx.NORMAL, wx.NORMAL, False,
                    config.fontNameArithmetic))
        self.displayLabel10 = wx.StaticText(self.displayPanel,
                                            wx.ID_ANY,
                                            loadDataArithmetic.numberNames[1],
                                            (360, 330),
                                            style=wx.ALIGN_CENTRE)
        self.displayLabel10.SetFont(
            wx.Font(config.fontSize[0], wx.SWISS, wx.NORMAL, wx.NORMAL, False,
                    config.fontName))
        self.displayLabel11 = wx.StaticText(self.displayPanel,
                                            wx.ID_ANY,
                                            " = ", (470, 310),
                                            style=wx.ALIGN_CENTRE)
        self.displayLabel11.SetFont(
            wx.Font(config.fontSize[0], wx.SWISS, wx.NORMAL, wx.NORMAL, False,
                    config.fontNameArithmetic))
        self.displayLabel12 = wx.StaticText(self.displayPanel,
                                            wx.ID_ANY,
                                            loadDataArithmetic.numberNames[int(
                                                self.nextNumber)], (580, 330),
                                            style=wx.ALIGN_CENTRE)
        self.displayLabel12.SetFont(
            wx.Font(config.fontSize[0], wx.SWISS, wx.NORMAL, wx.NORMAL, False,
                    config.fontName))

        ###End of image based arithmetic

        previousArrowImg = wx.Bitmap(
            join(config.coreImagesPath, 'previousArrow.png'),
            wx.BITMAP_TYPE_PNG)
        self.previousArrowButton = wx.BitmapButton(self.displayPanel,
                                                   wx.ID_ANY,
                                                   previousArrowImg, (50, 0),
                                                   style=wx.NO_BORDER)
        self.previousArrowButton.SetBackgroundColour(config.backgroundColour)
        self.previousArrowButton.Bind(wx.EVT_BUTTON,
                                      self.OnPreviousArrow,
                                      id=self.previousArrowButton.GetId())

        nextArrowImg = wx.Bitmap(join(config.coreImagesPath, 'nextArrow.png'),
                                 wx.BITMAP_TYPE_PNG)
        self.nextArrowButton = wx.BitmapButton(self.displayPanel,
                                               wx.ID_ANY,
                                               nextArrowImg, (650, 0),
                                               style=wx.NO_BORDER)
        self.nextArrowButton.SetBackgroundColour(config.backgroundColour)
        self.nextArrowButton.Bind(wx.EVT_BUTTON,
                                  self.OnNextArrow,
                                  id=self.nextArrowButton.GetId())

        bottomMenu.bottomMenu([self.displayPanel, self.menuPanel], parent,
                              self.mainWin, 'twoButton')
Пример #14
0
win.CenterOnScreen()
bkg = wx.Panel(win)
# We define the object for our class "Core"
obj = Core()
backButton = wx.Button(bkg, label='Back')
backButton.Bind(wx.EVT_BUTTON, obj.back)
commandButton = wx.Button(bkg, label='Command')
commandButton.Bind(wx.EVT_BUTTON, obj.execommand)
# Unless the player has pressed the Next button for the first time, the Back and Command buttons will be disabled
backButton.Disable()
commandButton.Disable()
nextButton = wx.Button(bkg, label='Next')
nextButton.Bind(wx.EVT_BUTTON, obj.next)
nextButton.SetDefault()
i = wx.Image('./images/test-1.jpg', type=wx.BITMAP_TYPE_JPEG)
b = wx.BitmapFromImage(i)
image = wx.StaticBitmap(bkg, bitmap=b)
title = wx.StaticText(bkg, label="Welcome to Granular", style=wx.ALIGN_CENTER)
text = wx.StaticText(bkg, label="Your journey of exploration begins from here")
hline1 = wx.StaticLine(bkg, style=wx.LI_HORIZONTAL)
hline2 = wx.StaticLine(bkg, style=wx.LI_HORIZONTAL)
# We define some stylish fonts for the welcome message / game questions
font_title = wx.Font(pointSize=18,
                     family=wx.DECORATIVE,
                     style=wx.NORMAL,
                     weight=wx.NORMAL)
font_text = wx.Font(pointSize=12,
                    family=wx.DECORATIVE,
                    style=wx.NORMAL,
                    weight=wx.NORMAL)
title.SetFont(font_title)
Пример #15
0
 def set_play_button_image(self, data):
     stream = StringIO.StringIO(data)
     image = wx.ImageFromStream(stream)
     bitmap = wx.BitmapFromImage(image)
     self.play_button.SetBitmapLabel(bitmap)
Пример #16
0
def convert_icon(icon_data):
    stream = cStringIO.StringIO(icon_data)
    image = wx.ImageFromStream(stream)
    stream.close()
    return wx.BitmapFromImage(image)
Пример #17
0
 def make_bitmap_button(self, data):
     stream = StringIO.StringIO(data)
     image = wx.ImageFromStream(stream)
     bitmap = wx.BitmapFromImage(image)
     button = wx.BitmapButton(self, -1, bitmap)
     return button
Пример #18
0
def scaleBitmap(bitmap, size):
    image = wx.ImageFromBitmap(bitmap)
    image = image.Scale(size.GetWidth(), size.GetHeight(),
                        wx.IMAGE_QUALITY_HIGH)
    result = wx.BitmapFromImage(image)
    return result
Пример #19
0
def GetExpandedIconBitmap():
    return wx.BitmapFromImage(GetExpandedIconImage())
Пример #20
0
        self.sizer.Add(self.panel,1,wx.ALIGN_CENTER,0)
        self.SetSizer(self.sizer)
        self.showimage(title)
        self.panel.Bind(wx.EVT_KEY_DOWN,self.keydown)
        self.panel.Bind(wx.EVT_CHAR,self.keychar)
        self.panel.Bind(wx.EVT_MOTION,self.drag)
        self.panel.Bind(wx.EVT_MOUSE_EVENTS,self.drag)
        self.bitmap.Bind(wx.EVT_MOTION,self.drag)
        self.bitmap.Bind(wx.EVT_MOUSE_EVENTS,self.drag)
        self.Bind(wx.EVT_SIZE,self.fresize)
        if osflag: self._icon=bpglogo.GetIcon()
        else:
            tmp_icon=bpglogo.GetImage()
            tmp_icon.Rescale(32,32,wx.IMAGE_QUALITY_HIGH)
            self._icon=wx.EmptyIcon()
            self._icon.CopyFromBitmap(wx.BitmapFromImage(tmp_icon))
        try: self.SetIcon(self._icon)
        except: pass
        self.Layout()
        self.Center()
        self.panel.SetFocus()

    def loadindex(self,old):
        if self.index!=old:
            self.stitle(_('Loading...'))
            self.showimage(self.filelist[self.index])

    def previous(self):
        if len(self.filelist):
            old=self.index
            if self.index: self.index-=1
Пример #21
0
    def onPress(self, event):

        if self.pressSound.lower() != 'off':
            self.pressingSound.play()

        if self.numberOfPresses == 0:

            if self.flag == 'panel':
                items = self.subSizers[self.panelIteration].GetChildren()

                for item in items:
                    b = item.GetWindow()
                    b.SetBackgroundColour(self.scanningColour)
                    b.SetFocus()
                if self.blissBook[self.panelIteration][0][
                        2] == 'EXIT' and self.panelIteration == len(
                            self.subSizers) - 1:
                    if self.pressSound.lower() == "voice":
                        self.stoper.Stop()
                        time.sleep(
                            (self.selectionTime + self.timeGap) / (1000. * 2))
                        self.powrotSound.play()
                        time.sleep(
                            (self.selectionTime + self.timeGap) / (1000. * 2))
                        self.stoper.Start(self.timeGap)
                    self.onExit()

                else:

                    self.flag = 'row'
                    self.rowIteration = 0

            elif self.flag == 'row':

                self.rowIteration -= 1

                if self.pressSound == "voice":
                    if (self.rowIteration == 0):
                        self.oneSound.play()
                    if (self.rowIteration == 1):
                        self.twoSound.play()

                buttonsToHighlight = range(
                    (self.rowIteration) *
                    self.numberOfColumns[self.panelIteration],
                    (self.rowIteration) *
                    self.numberOfColumns[self.panelIteration] +
                    self.numberOfColumns[self.panelIteration])

                for button in buttonsToHighlight:
                    item = self.subSizers[self.panelIteration].GetItem(button)
                    b = item.GetWindow()
                    b.SetBackgroundColour(self.selectionColour)
                    b.SetFocus()

                self.flag = 'columns'
                self.columnIteration = 0

            elif self.flag == 'columns':

                self.columnIteration -= 1

                item = self.subSizers[self.panelIteration].GetItem(
                    (self.rowIteration) *
                    self.numberOfColumns[self.panelIteration] +
                    self.columnIteration)
                selectedButton = item.GetWindow()

                self.Update()

                if self.pressSound == 'voice':
                    if selectedButton.GetName() == 'puste':
                        selectedButton.SetBackgroundColour("red")
                        selectedButton.SetFocus()
                        self.Update()
                        self.pusteSound.play()
                    else:
                        selectedButton.SetBackgroundColour(
                            self.selectionColour)
                        selectedButton.SetFocus()
                        cmd = "milena_say %s" % selectedButton.GetName()
                        subprocess.Popen(cmd,
                                         shell=True,
                                         stdin=subprocess.PIPE)

                        for item in self.blissBook[self.panelIteration]:

                            if item[1] == self.rowIteration * self.numberOfColumns[
                                    self.
                                    panelIteration] + self.columnIteration + 1:

                                self.bitmapSize = item[0].GetSize()

                                if self.bitmapSize[1] > 0.7 * self.panelSize[1]:
                                    image = wx.ImageFromBitmap(item[0])
                                    rescaleImage = image.Rescale(
                                        (0.7 * self.panelSize[1] /
                                         self.bitmapSize[1]) *
                                        self.bitmapSize[0],
                                        0.7 * self.panelSize[1],
                                        wx.IMAGE_QUALITY_HIGH)
                                    rescaleItem = wx.BitmapFromImage(image)

                                    b = GenSymbolTextButton(self,
                                                            -1,
                                                            bitmap=rescaleItem,
                                                            label=item[2])

                                else:
                                    b = GenSymbolTextButton(self,
                                                            -1,
                                                            bitmap=item[0],
                                                            label=item[2])

                                b.SetFont(
                                    wx.Font(21, wx.FONTFAMILY_ROMAN,
                                            wx.FONTSTYLE_NORMAL,
                                            wx.FONTWEIGHT_NORMAL, False))
                                b.SetBackgroundColour(self.backgroundColour)

                                self.displaySizer.Add(b,
                                                      0,
                                                      flag=wx.EXPAND
                                                      | wx.BOTTOM | wx.TOP
                                                      | wx.ALIGN_LEFT,
                                                      border=2)
                                self.displaySizer.Layout()

                                unicodeLabel = item[2].encode('utf-8')
                                self.lastTextLenght = len(unicodeLabel) + 1
                                os.system('minitube "%s" &' % unicodeLabel)

                                time.sleep(0.5)

                                self.numberOfSymbol += 1
                                os.system("sleep 1")

                                self.stoper.Stop()
                                self.Hide()
                                self.menu = minitubePilot.pilot(self, id=1)

                                self.menu.Show()

                                selectedButton.SetBackgroundColour(
                                    self.backgroundColour)
                                # selectedButton.SetFocus( )
                                # self.Update( )
                                # selectedButto.nSetBackgroundColour( self.backgroundColour )

                self.flag = 'panel'
                self.panelIteration = 0
                self.rowIteration = 0
                self.columnIteration = 0
                self.count = 0
                self.countRows = 0

            self.numberOfPresses += 1
Пример #22
0
def GetMondrianBitmap():
    stream = GetMondrianStream()
    image = wx.ImageFromStream(stream)
    return wx.BitmapFromImage(image)
Пример #23
0
    def populateObjectSizer(self, attribute=None):
        if attribute is None or attribute == 'neuronClass':
            # Choose the appropriate item in the pop-up menu.
            if self.objects.haveEqualAttr('neuronClass'):
                if self.objects[0].neuronClass is None:
                    self._neuronClassChoice.SetSelection(
                        self._unknownNeuronClassId)
                else:
                    for index in range(0, self._neuronClassChoice.GetCount()):
                        if self._neuronClassChoice.GetClientData(
                                index) == self.objects[0].neuronClass:
                            self._neuronClassChoice.SetSelection(index)
            else:
                self._multipleNeuronClassesId = self._neuronClassChoice.Append(
                    gettext('Multiple values'), None)
                self._neuronClassChoice.SetSelection(
                    self._multipleNeuronClassesId)

        if attribute is None or attribute == 'functions':
            for function, checkBox in [
                (Neuron.Function.SENSORY, self._sensoryCheckBox),
                (Neuron.Function.INTERNEURON, self._interneuronCheckBox),
                (Neuron.Function.MOTOR, self._motorCheckBox)
            ]:
                mixedFunction = False
                hasFunction = self.objects[0].hasFunction(function)
                for object in self.objects[1:]:
                    if hasFunction != object.hasFunction(function):
                        mixedFunction = True
                if mixedFunction:
                    checkBox.Set3StateValue(wx.CHK_UNDETERMINED)
                elif hasFunction:
                    checkBox.Set3StateValue(wx.CHK_CHECKED)
                else:
                    checkBox.Set3StateValue(wx.CHK_UNCHECKED)

        if attribute is None or attribute == 'polarity':
            # Choose the appropriate item in the pop-up menu.
            if self.objects.haveEqualAttr('polarity'):
                if self.objects[0].polarity is None:
                    self._polarityChoice.SetSelection(self._unknownPolarityId)
                else:
                    for index in range(0, self._polarityChoice.GetCount()):
                        if self._polarityChoice.GetClientData(
                                index) == self.objects[0].polarity:
                            self._polarityChoice.SetSelection(index)
            else:
                self._multiplePolaritiesId = self._polarityChoice.Append(
                    gettext('Multiple values'), None)
                self._polarityChoice.SetSelection(self._multiplePolaritiesId)

        if attribute is None or attribute == 'neurotransmitters':
            if self.objects.haveEqualAttr('neurotransmitters'):
                self._neurotransmittersSizer.Clear(True)
                self._neurotransmitterChoice.Clear()
                self._neurotransmitterChoice.Append(gettext('Add...'))
                self._neurotransmitterChoice.SetSelection(0)
                for neurotransmitter in neuroptikon.library.neurotransmitters(
                ):
                    if neurotransmitter in self.objects[0].neurotransmitters:
                        self._neurotransmittersSizer.Add(
                            wx.StaticText(self._parentWindow, wx.ID_ANY,
                                          neurotransmitter.name))
                        removeButton = wx.Button(self._parentWindow,
                                                 wx.ID_ANY,
                                                 gettext('Remove'),
                                                 style=wx.BU_EXACTFIT)
                        removeButton.SetWindowVariant(wx.WINDOW_VARIANT_SMALL)
                        removeButton.SetSize(
                            wx.Size(60,
                                    removeButton.GetSize().GetHeight()))
                        removeButton.SetMinSize(removeButton.GetSize())
                        self._parentWindow.Bind(wx.EVT_BUTTON,
                                                self.onRemoveNeurotransmitter,
                                                removeButton)
                        self._neurotransmittersSizer.Add(
                            removeButton, 0, 0, 0, neurotransmitter)
                    else:
                        self._neurotransmitterChoice.Append(
                            neurotransmitter.name, neurotransmitter)
                if len(self.objects[0].neurotransmitters) == 0:
                    self._neurotransmittersSizer.Add(
                        wx.StaticText(self._parentWindow, wx.ID_ANY,
                                      gettext('Unknown')))
                self._neurotransmitterChoice.Enable(
                    self._neurotransmitterChoice.GetCount() > 1)
            else:
                self._neurotransmittersSizer.Add(
                    wx.StaticText(self._parentWindow, wx.ID_ANY,
                                  gettext('Multiple values')))
                self._neurotransmitterChoice.Disable()

        if attribute is None or attribute == 'neuronImage':
            if self.objects.haveEqualAttr('neuronImage'):
                image = self.objects[0].neuronImage
                self._imageSizer.Clear(True)
                self._imageSizer.Clear()
                if image == None or image == []:
                    pass
                else:
                    imagesGridSizer = wx.FlexGridSizer(2 * len(image), 0, 2, 5)
                    imagesGridSizer.SetFlexibleDirection(wx.VERTICAL)
                    self._imageSizer.Add(imagesGridSizer)
                    for idx, img in enumerate(image):
                        labelForNeuron = wx.StaticText(self._window, wx.ID_ANY,
                                                       gettext(img.label))
                        imagesGridSizer.Add(labelForNeuron)
                        if img.bmp:
                            scaledImage = img.bmp.Copy().Rescale(
                                100, 100, wx.IMAGE_QUALITY_HIGH)
                            imageOfNeuron = wx.StaticBitmap(self._window,
                                                            wx.ID_ANY,
                                                            name=str(idx))
                            imageOfNeuron.SetBitmap(
                                wx.BitmapFromImage(scaledImage))
                            imageOfNeuron.SetMinSize(wx.Size(100, 100))
                            imageOfNeuron.SetMaxSize(wx.Size(100, 100))
                            imageOfNeuron.Bind(wx.EVT_LEFT_DOWN,
                                               self.onSelectImage)
                            imagesGridSizer.Add(imageOfNeuron)
            else:
                pass
                #option if not all neurons have the same image

        if attribute is None or attribute == 'links':
            if self.objects.haveEqualAttr('links'):
                self._linkSizer.Clear(True)
                self._linkSizer.Clear()
                if self.objects[0].links:
                    for url in self.objects[0].links:
                        if (url):
                            self._linkOut = wx.HyperlinkCtrl(
                                self._parentWindow, wx.ID_ANY, gettext(url),
                                gettext(url))
                            self._linkSizer.Add(self._linkOut)

        self._sizer.Layout()
Пример #24
0
def get_bitmap(name, size = None):
    image = icons.icons.catalog[name].GetImage()
    if size is not None:
        image.Rescale( size[0], size[1], wx.IMAGE_QUALITY_HIGH  )
    return wx.BitmapFromImage( image )
Пример #25
0
 def InsertTool(self, pos, id, bitmap, **kwargs):
     bitmap = '%s.png' % bitmap
     bitmap = wx.BitmapFromImage(wx.Image(leginon.icons.getPath(bitmap)))
     wx.ToolBar.InsertTool(self, pos, id, bitmap, **kwargs)
Пример #26
0
 def loadgambar(self):
     self.PhotoMaxSize = 130
     img = wx.EmptyImage(120, 130)
     self.imageCtrl = wx.StaticBitmap(self, wx.ID_ANY,
                                      wx.BitmapFromImage(img),
                                      wx.Point(52, 251))
Пример #27
0
    def drawBkg(self):
        if self.bw:
            self.bkgclr = (255, 255, 255)
        else:
            self.bkgclr = self.options.clrbackground

        self.SetBackgroundColour(self.bkgclr)

        tableclr = self.options.clrtable
        if self.bw:
            tableclr = (0, 0, 0)

        txtclr = self.options.clrtexts
        if self.bw:
            txtclr = (0, 0, 0)

        img = Image.new('RGB', (self.WIDTH, self.HEIGHT), self.bkgclr)
        draw = ImageDraw.Draw(img)

        BOR = commonwnd.CommonWnd.BORDER

        #Grid
        x = BOR
        y = BOR
        for i in range(self.LINE_NUM + 1):
            draw.line((x, y + self.LINE_HEIGHT * i, x + self.TABLE_WIDTH,
                       y + self.LINE_HEIGHT * i),
                      fill=tableclr)

        for i in range(self.COLUMN_NUM + 1 + 1):
            draw.line((x + self.CELL_WIDTH * i, y, x + self.CELL_WIDTH * i,
                       y + self.TABLE_HEIGHT),
                      fill=tableclr)

        #Data
        SIDTIME = 0
        OBL = 1
        JD = 2
        VERTEX = 3
        EQUATASC = 4

        txts = (mtexts.txts['SidTime'], mtexts.txts['OblEcl'],
                mtexts.txts['JulianDay'], mtexts.txts['Vertex'],
                mtexts.txts['EquAsc'])
        data = (self.chart.houses.ascmc[houses.Houses.ARMC] / 15.0,
                self.chart.obl[0], self.chart.time.jd,
                self.chart.houses.ascmc[houses.Houses.VERTEX],
                self.chart.houses.ascmc[houses.Houses.EQUASC])
        for i in range(self.LINE_NUM):
            w, h = draw.textsize(txts[i], self.fntText)
            draw.text(
                (BOR + (self.CELL_WIDTH - w) / 2, BOR + self.LINE_HEIGHT * i +
                 (self.LINE_HEIGHT - h) / 2),
                txts[i],
                fill=txtclr,
                font=self.fntText)

            d, m, s = util.decToDeg(data[i])

            if i == SIDTIME:
                txt = str(d) + ':' + (str(m)).zfill(2) + ':' + (
                    str(s)).zfill(2)
                w, h = draw.textsize(txt, self.fntText)
                draw.text(
                    (BOR + self.CELL_WIDTH + (self.CELL_WIDTH - w) / 2,
                     BOR + self.LINE_HEIGHT * i + (self.LINE_HEIGHT - h) / 2),
                    txt,
                    fill=txtclr,
                    font=self.fntText)
            elif i == OBL:
                txt = (str(d)).rjust(2) + self.deg_symbol + (
                    str(m)).zfill(2) + "'" + (str(s)).zfill(2) + '"'
                w, h = draw.textsize(txt, self.fntText)
                draw.text(
                    (BOR + self.CELL_WIDTH + (self.CELL_WIDTH - w) / 2,
                     BOR + self.LINE_HEIGHT * i + (self.LINE_HEIGHT - h) / 2),
                    txt,
                    fill=txtclr,
                    font=self.fntText)
            elif i == JD:
                txt = str(data[i])
                w, h = draw.textsize(txt, self.fntText)
                draw.text(
                    (BOR + self.CELL_WIDTH + (self.CELL_WIDTH - w) / 2,
                     BOR + self.LINE_HEIGHT * i + (self.LINE_HEIGHT - h) / 2),
                    txt,
                    fill=txtclr,
                    font=self.fntText)
            else:
                if self.options.ayanamsha != 0:
                    ayanlon = data[i] - self.chart.ayanamsha
                    ayanlon = util.normalize(ayanlon)
                    d, m, s = util.decToDeg(ayanlon)
                sign = d / chart.Chart.SIGN_DEG
                pos = d % chart.Chart.SIGN_DEG
                wsp, hsp = draw.textsize(' ', self.fntText)
                txtsign = self.signs[sign]
                wsg, hsg = draw.textsize(txtsign, self.fntMorinus)
                txt = (str(pos)).rjust(2) + self.deg_symbol + (
                    str(m)).zfill(2) + "'" + (str(s)).zfill(2) + '"'
                w, h = draw.textsize(txt, self.fntText)
                offset = (self.CELL_WIDTH - (w + wsp + wsg)) / 2
                draw.text(
                    (BOR + self.CELL_WIDTH + offset,
                     BOR + self.LINE_HEIGHT * i + (self.LINE_HEIGHT - h) / 2),
                    txt,
                    fill=txtclr,
                    font=self.fntText)
                draw.text(
                    (BOR + self.CELL_WIDTH + offset + w + wsp,
                     BOR + self.LINE_HEIGHT * i + (self.LINE_HEIGHT - h) / 2),
                    txtsign,
                    fill=txtclr,
                    font=self.fntMorinus)

        #Table 2
        txts = (mtexts.txts['Syzygy'], mtexts.txts['Date2'],
                mtexts.txts['Longitude'])
        x = BOR
        y = BOR + self.LINE_NUM * self.LINE_HEIGHT + self.TABLE2_OFFS

        draw.line((x, y, x + self.TABLE_WIDTH2, y), fill=tableclr)
        draw.line((x, y + self.LINE_HEIGHT, x + self.TABLE_WIDTH2,
                   y + self.LINE_HEIGHT),
                  fill=tableclr)
        draw.line((x, y + 2 * self.LINE_HEIGHT, x + self.TABLE_WIDTH2,
                   y + 2 * self.LINE_HEIGHT),
                  fill=tableclr)
        draw.line((x, y, x, y + 2 * self.LINE_HEIGHT), fill=tableclr)
        draw.line((x + self.CELL_WIDTH, y + self.LINE_HEIGHT,
                   x + self.CELL_WIDTH, y + 2 * self.LINE_HEIGHT),
                  fill=tableclr)
        draw.line((x + 2 * self.CELL_WIDTH, y + self.LINE_HEIGHT,
                   x + 2 * self.CELL_WIDTH, y + 2 * self.LINE_HEIGHT),
                  fill=tableclr)
        draw.line((x + 3 * self.CELL_WIDTH, y + self.LINE_HEIGHT,
                   x + 3 * self.CELL_WIDTH, y + 2 * self.LINE_HEIGHT),
                  fill=tableclr)
        draw.line((x + self.TABLE_WIDTH2, y, x + self.TABLE_WIDTH2,
                   y + 2 * self.LINE_HEIGHT),
                  fill=tableclr)

        num = len(txts)
        for i in range(num):
            w, h = draw.textsize(txts[i], self.fntText)
            draw.text(
                (BOR + self.CELL_WIDTH * i + (self.CELL_WIDTH - w) / 2, y +
                 (self.LINE_HEIGHT - h) / 2),
                txts[i],
                fill=txtclr,
                font=self.fntText)

        if not self.chart.time.bc:
            txt = mtexts.txts['NewMoon']
            if not self.chart.syzygy.newmoon:
                txt = mtexts.txts['FullMoon']
            w, h = draw.textsize(txt, self.fntText)
            draw.text((x + (self.CELL_WIDTH - w) / 2, y + self.LINE_HEIGHT +
                       (self.LINE_HEIGHT - h) / 2),
                      txt,
                      fill=txtclr,
                      font=self.fntText)

            h, m, s = util.decToDeg(self.chart.syzygy.time.time)
            txt = str(self.chart.syzygy.time.year) + '.' + str(
                self.chart.syzygy.time.month).zfill(2) + '.' + str(
                    self.chart.syzygy.time.day).zfill(2) + '.' + ' ' + str(
                        h).rjust(2) + ':' + str(m).zfill(2) + ':' + str(
                            s).zfill(2)
            w, h = draw.textsize(txt, self.fntText)
            draw.text((x + self.CELL_WIDTH + (self.CELL_WIDTH - w) / 2,
                       y + self.LINE_HEIGHT + (self.LINE_HEIGHT - h) / 2),
                      txt,
                      fill=txtclr,
                      font=self.fntText)

            lon = self.chart.syzygy.lon
            if self.options.ayanamsha != 0:
                lon = lon - self.chart.ayanamsha
                lon = util.normalize(lon)

            d, m, s = util.decToDeg(lon)
            sign = d / chart.Chart.SIGN_DEG
            pos = d % chart.Chart.SIGN_DEG
            wsp, hsp = draw.textsize(' ', self.fntText)
            wsg, hsg = draw.textsize(self.signs[sign], self.fntMorinus)
            txt = (str(pos)).rjust(2) + self.deg_symbol + (
                str(m)).zfill(2) + "'" + (str(s)).zfill(2) + '"'
            w, h = draw.textsize(txt, self.fntText)
            offset = (self.CELL_WIDTH - (w + wsp + wsg)) / 2
            draw.text((x + 2 * self.CELL_WIDTH + offset, y + self.LINE_HEIGHT +
                       (self.LINE_HEIGHT - h) / 2),
                      txt,
                      fill=txtclr,
                      font=self.fntText)
            draw.text((x + 2 * self.CELL_WIDTH + offset + w + wsp,
                       y + self.LINE_HEIGHT + (self.LINE_HEIGHT - hsg) / 2),
                      self.signs[sign],
                      fill=txtclr,
                      font=self.fntMorinus)

        wxImg = wx.EmptyImage(img.size[0], img.size[1])
        wxImg.SetData(img.tostring())
        self.buffer = wx.BitmapFromImage(wxImg)
Пример #28
0
def GetIndicadorBitmap():
    return wx.BitmapFromImage(GetIndicadorImage())
Пример #29
0
 def _build_bitmap(self, image):
     bmp = wx.BitmapFromImage(image)
     return bmp
	def __init__( self, parent ):

		wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 500,274 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
		icon = wx.EmptyIcon()
		icon.CopyFromBitmap(wx.BitmapFromImage(wx.Image(("LOGO1.png"), wx.BITMAP_TYPE_PNG)))
		self.SetIcon(icon)
		self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )
		self.SetBackgroundColour( wx.SystemSettings.GetColour( wx.SYS_COLOUR_WINDOW ) )

		bSizer1 = wx.BoxSizer( wx.VERTICAL )

		self.m_staticText1 = wx.StaticText( self, wx.ID_ANY, u"墨石协会测试成绩查询", wx.DefaultPosition, wx.DefaultSize, 0 )
		self.m_staticText1.Wrap( -1 )

		self.m_staticText1.SetFont( wx.Font( 20, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, "字魂87号-乾坤手书" ) )

		bSizer1.Add( self.m_staticText1, 0, wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, 5 )

		bSizer2 = wx.BoxSizer( wx.VERTICAL )

		bSizer4 = wx.BoxSizer( wx.HORIZONTAL )

		self.m_staticText41 = wx.StaticText( self, wx.ID_ANY, u"学号:", wx.DefaultPosition, wx.DefaultSize, 0 )
		self.m_staticText41.Wrap( -1 )

		bSizer4.Add( self.m_staticText41, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )

		self.StudentNo_text = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
		bSizer4.Add( self.StudentNo_text, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )

		self.m_staticText51 = wx.StaticText( self, wx.ID_ANY, u"科目名:", wx.DefaultPosition, wx.DefaultSize, 0 )
		self.m_staticText51.Wrap( -1 )

		bSizer4.Add( self.m_staticText51, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )

		self.CourseName_text = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
		bSizer4.Add( self.CourseName_text, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )

		self.SelectCourse = wx.Button( self, wx.ID_ANY, u"查询", wx.DefaultPosition, wx.DefaultSize, 0 )
		bSizer4.Add( self.SelectCourse, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )


		bSizer2.Add( bSizer4, 0, 0, 5 )

		bSizer5 = wx.BoxSizer( wx.HORIZONTAL )

		self.m_staticText61 = wx.StaticText( self, wx.ID_ANY, u"编号:", wx.DefaultPosition, wx.DefaultSize, 0 )
		self.m_staticText61.Wrap( -1 )

		bSizer5.Add( self.m_staticText61, 0, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )

		self.CourseNo_text = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
		bSizer5.Add( self.CourseNo_text, 1, wx.ALL|wx.ALIGN_CENTER_VERTICAL, 5 )


		bSizer2.Add( bSizer5, 0, wx.EXPAND, 5 )

		bSizer6 = wx.BoxSizer( wx.HORIZONTAL )

		self.m_staticText8 = wx.StaticText( self, wx.ID_ANY, u"成绩:", wx.DefaultPosition, wx.DefaultSize, 0 )
		self.m_staticText8.Wrap( -1 )

		bSizer6.Add( self.m_staticText8, 0, wx.ALL, 5 )

		self.CourseGrade_text = wx.TextCtrl( self, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0 )
		bSizer6.Add( self.CourseGrade_text, 1, wx.ALL|wx.EXPAND, 5 )


		bSizer2.Add( bSizer6, 0, wx.EXPAND, 5 )

		bSizer13 = wx.BoxSizer( wx.HORIZONTAL )

		self.SelCouDet = wx.Button( self, wx.ID_ANY, u"确定", wx.DefaultPosition, wx.DefaultSize, 0 )
		bSizer13.Add( self.SelCouDet, 0, wx.ALL, 5 )

		self.SelCouCan = wx.Button( self, wx.ID_ANY, u"取消", wx.DefaultPosition, wx.DefaultSize, 0 )
		bSizer13.Add( self.SelCouCan, 0, wx.ALL, 5 )


		bSizer2.Add( bSizer13, 0, wx.ALIGN_CENTER_HORIZONTAL, 5 )


		bSizer1.Add( bSizer2, 1, wx.EXPAND, 5 )


		self.SetSizer( bSizer1 )
		self.Layout()

		self.Centre( wx.BOTH )

		# Connect Events
		self.SelectCourse.Bind( wx.EVT_BUTTON, self.SelectCoursef )
		self.SelCouDet.Bind( wx.EVT_BUTTON, self.SelCouDetf )
		self.SelCouCan.Bind( wx.EVT_BUTTON, self.SelCouCanf )