def onTreeSymbolsSelectionChanged(self, event):
        item = self.tree_symbols.GetSelection()
        if item.IsOk() == False:
            return
        obj = self.tree_symbols_manager.ItemToObject(item)

        if isinstance(obj, DataModelSymbol):
            print "----", obj.symbol.source_path
            if self.lib_cache.Exists(obj.symbol.source_path):
                self.lib_cache.LoadContent(obj.symbol)
                lib = kicad_lib_file.KicadLibFile()
                lib.Load(obj.symbol.content)
                image_file = tempfile.NamedTemporaryFile()
                lib.Render(image_file.name,
                           self.panel_image_symbol.GetRect().width,
                           self.panel_image_symbol.GetRect().height)
                img = wx.Image(image_file.name, wx.BITMAP_TYPE_ANY)
                image_file.close()
            else:
                img = wx.Image()
                img.Create(1, 1)
        else:
            img = wx.Image()
            img.Create(1, 1)

        img = img.ConvertToBitmap()
        self.image_symbol.SetBitmap(img)
Exemplo n.º 2
0
    def ShowSymbol(self, symbol):
        configuration = Configuration()
            
        # enable everything else
        if symbol:
            
            if symbol.metadata:
                metadata = json.loads(symbol.metadata)
            else:
                metadata = json.loads('{}')

            self.edit_symbol_name.Value = ''
            self.symbol_path = ''
            
            if NoneValue(symbol.source_path, '')!='':
                name = os.path.basename(NoneValue(symbol.source_path, ''))
                if name.endswith('.lib')==False:
                    # path is a symbol
                    self.edit_symbol_name.Value = name.replace(".mod", "")
                    self.symbol_path = os.path.dirname(symbol.source_path)
                    
            self.edit_symbol_description.Value = MetadataValue(metadata, 'description', '')
            self.edit_symbol_comment.Value = MetadataValue(metadata, 'comment', '')
             
            self.button_open_url_snapeda.Label = MetadataValue(metadata, 'snapeda', '<None>')
            
            if self.edit_symbol_name.Value!='' and self.lib_cache.Exists(symbol.source_path):
                self.lib_cache.LoadContent(symbol)
                lib = kicad_lib_file.KicadLibFile()
                lib.Load(symbol.content)
                image_file = tempfile.NamedTemporaryFile()
                lib.Render(image_file.name, self.panel_image_symbol.GetRect().width, self.panel_image_symbol.GetRect().height)
                img = wx.Image(image_file.name, wx.BITMAP_TYPE_ANY)
                image_file.close()
            else:
                img = wx.Image()
                img.Create(1, 1)

            img = img.ConvertToBitmap()
            self.bitmap_edit_symbol.SetBitmap(img)
                
        else:
            self.edit_symbol_name.Value = ''
            self.edit_symbol_description.Value = ''
            self.edit_symbol_comment.Value = ''
            self.button_open_url_snapeda.Label = "<None>"

            img = wx.Image()
            img.Create(1, 1)
            img = img.ConvertToBitmap()
            self.bitmap_edit_symbol.SetBitmap(img)
    def showSymbol(self):
        if self.part and self.part.symbol and self.lib_cache.Exists(
                self.part.symbol.source_path):
            self.lib_cache.LoadContent(self.part.symbol)
            lib = kicad_lib_file.KicadLibFile()
            lib.Load(self.part.symbol.content)
            image_file = tempfile.NamedTemporaryFile()
            lib.Render(image_file.name,
                       self.panel_image_symbol.GetRect().width,
                       self.panel_image_symbol.GetRect().height)
            img = wx.Image(image_file.name, wx.BITMAP_TYPE_ANY)
            image_file.close()
        else:
            img = wx.Image()
            img.Create(1, 1)

        img = img.ConvertToBitmap()
        self.image_symbol.SetBitmap(img)
Exemplo n.º 4
0
    def onSelectSnapedaFrameOk(self, event):
        snapeda = event.data
        if not snapeda:
            return
        print snapeda.json
        
        self.edit_symbol_name.Value = snapeda.part_number()
        self.edit_symbol_description.Value = snapeda.short_description()
        self.snapeda_uid = snapeda.uniqueid()
        
        try:
            download = DownloadQuery()
            download.get(part_number=snapeda.part_number(), 
                               manufacturer=snapeda.manufacturer(),
                               uniqueid=snapeda.uniqueid(),
                               has_symbol='True',
                               has_footprint='False')
            if download.error():
                wx.MessageBox(download.error(), 'Error downloading symbol', wx.OK | wx.ICON_ERROR)
                
        except:
            print_stack()
            DialogSnapedaError(self).ShowModal()
            return
        
        self.button_open_url_snapeda.Label = "https://www.snapeda.com"+snapeda._links().self().href()

        # download symbol
        if download.url() and download.url()!='':
            try:
                filename = os.path.join(tempfile.gettempdir(), os.path.basename(download.url()))
                print "Download from:", download.url()
                content = scraper.get(download.url()).content
                with open(filename, 'wb') as outfile:
                    outfile.write(content)
                outfile.close()
            except:
                print_stack()
                wx.MessageBox(download.url(), 'Error loading symbol', wx.OK | wx.ICON_ERROR)
                return
                
            # unzip file
            try:
                zip_ref = zipfile.ZipFile(filename, 'r')
                zip_ref.extractall(filename+".tmp")
                zip_ref.close()
            except Exception as e:
                print_stack()
                wx.MessageBox(format(e), 'Error unziping symbol', wx.OK | wx.ICON_ERROR)

            self.symbol.content = ''
            for file in glob.glob(filename+".tmp/*"):
                if file.endswith(".lib"):
                    print "---------", file
                    lib = KicadLibCache(filename+".tmp")
                    symbols = lib.read_lib_file(os.path.basename(file))
                    if len(symbols)>0:
                        for symbol in symbols:
                            self.symbol.content = symbols[symbol].content
                            break
                    print "****", self.symbol.content
                    
                    mod = kicad_lib_file.KicadLibFile()
                    mod.LoadFile(file)
                    image_file = tempfile.NamedTemporaryFile()
                    mod.Render(image_file.name, self.panel_image_symbol.GetRect().width, self.panel_image_symbol.GetRect().height)
                    img = wx.Image(image_file.name, wx.BITMAP_TYPE_ANY)
                    image_file.close()
                    img = img.ConvertToBitmap()
                    self.bitmap_edit_symbol.SetBitmap(img)
            
            self.symbol.md5 = hashlib.md5(self.symbol.content).hexdigest()