예제 #1
0
    def fetch(self, base_filename, category, import_item=object):
        file_path = '{}.{}'.format(base_filename, self.extension)

        with open(file_path, 'rb', encoding='utf-8') as csvfile:
            # TODO: implement csvReader
            csvreader = csv.DictReader(
                csvfile
            )  # TODO: do we need this, delimiter=', ', quotechar='"')
            components = []
            for row in csvreader:
                try:
                    i = import_item.PartNew()
                    i.name = str(row['Name'], errors='ignore').encode('utf-8')
                    i.description = str(row['Description'],
                                        errors='ignore').encode('utf-8')
                    i.category = category
                    i.comment = 'NEW IMPORT Timestamp:{:%y-%m-%d %H:%M:%S.%f}'.format(
                        datetime.datetime.now())
                    i.footprint = str(row['Footprint'],
                                      errors='ignore').encode('utf-8')
                    components.append(i)
                    print("Name:", row['Name'], category, row['Description'],
                          row['Footprint'])  # TODO: remove
                except Exception, e:
                    print_stack()
                    print(e)
                    pass
            return components
예제 #2
0
    def onButtonAddCategoryClick(self, event):
        category = EditCategoryFrame(self).addCategory(
            rest.model.StorageCategoryNew)
        if category:
            try:
                # retrieve parent item from selection
                parentitem = self.tree_categories.GetSelection()
                parentobj = None
                category.parent = None
                if parentitem:
                    parentobj = self.tree_categories_manager.ItemToObject(
                        parentitem)
                    category.parent = parentobj.category

                # create category on server
                category = rest.api.add_storages_category(category)
                # create category on treeview
                newitem = self.tree_categories_manager.AppendItem(
                    parentobj, DataModelCategory(category))
                # add category to item element
                self.tree_categories_manager.SelectItem(newitem)
                self.onTreeCategoriesSelChanged(None)
            except Exception as e:
                print_stack()
                wx.MessageBox(format(e), 'Error', wx.OK | wx.ICON_ERROR)
예제 #3
0
    def onApplyButtonClick(self, event):

        if self.distributor is None:
            distributor = rest.model.DistributorNew()
            distributor.allowed = True
        else:
            distributor = self.distributor

        distributor.name = self.edit_distributor_name.Value
        distributor.address = self.edit_distributor_address.Value
        distributor.website = self.edit_distributor_website.Value
        distributor.sku_url = self.edit_distributor_sku_url.Value
        distributor.email = self.edit_distributor_email.Value
        distributor.phone = self.edit_distributor_phone.Value
        distributor.comment = self.edit_distributor_comment.Value

        try:
            if self.distributor is None:
                distributor = rest.api.add_distributor(distributor)
                self.tree_distributors_manager.AppendItem(
                    None, DataModelDistributor(distributor))
            else:
                distributor = rest.api.update_distributor(
                    distributor.id, distributor)
                self.tree_distributors_manager.UpdateDistributor(distributor)

            self.panel_edit_distributor.Enabled = False
            self.panel_distributors.Enabled = True

        except Exception as e:
            print_stack()
            wx.MessageBox(format(e), 'Error', wx.OK | wx.ICON_ERROR)
예제 #4
0
    def _onItemBeginDrag( self, event ):
        event.manager = self
        '''
        @TODO: Confirm SetDragFlags under Linux
        according to documentation https://wxpython.org/Phoenix/docs/html/wx.dataview.DataViewEvent.html#wx-dataview-dataviewevent

        Currently it is only honoured by the generic version of wx.dataview.DataViewCtrl (used e.g. under MSW)'
        '''
        # Suppress the standard drag symbol on MSW (copy)
        event.SetDragFlags(wx.Drag_DefaultMove)

        TreeManager.drag_item = event.GetItem()
        TreeManager.drag_source = self
        
        if self.drag_item is None:
            event.Skip()
            return wx.DragCancel
        try:
            drag_data = self.model.ItemToObject(event.GetItem())
        except Exception as inst:
            print_stack()
            if 'logging' in globals(): logging.debug('DRAG ERROR:{} {} {} {}'.format(type(inst), inst.message,inst.args,event.GetItem()))
            return wx.DragCancel
        if drag_data.GetDragData() is None:
            event.Skip()
            return wx.DragCancel

        event.SetDataObject(TreeDataObject(drag_data))
        if 'logging' in globals():logging.debug('DRAG onItemBeginDrag STATE:{}'.format(self.OnItemBeginDrag))
        dragSource = wx.DropSource(self.tree_view.TopLevelParent)
        dataObject = TreeDataObject(drag_data)

        if self.OnItemBeginDrag:
            return self.OnItemBeginDrag(event)
        return wx.Drag_DefaultMove
 def load(self):
     try:
         self.loadSymbols()
         pass
     except Exception as e:
         print_stack()
         wx.MessageBox(format(e), 'Error', wx.OK | wx.ICON_ERROR)
예제 #6
0
    def onTreeCategoriesDropCategory(self, x, y, data):
        dest_categoryitem, _ = self.tree_categories.HitTest((x, y))
        try:
            source_category_id = data['id']
            source_category = rest.api.find_storages_category(source_category_id)
            source_categoryitem = helper.tree.TreeManager.drag_item
            source_categoryobj = self.tree_categories_manager.ItemToObject(source_categoryitem)
    
            dest_category = None
            dest_categoryobj = None
            if dest_categoryitem.IsOk():
                dest_categoryobj = self.tree_categories_manager.ItemToObject(dest_categoryitem)
                dest_category = dest_categoryobj.category
                if source_category_id==dest_category.id:
                    return wx.DragError
                source_category.parent = rest.model.StorageCategoryRef(id=dest_category.id)
            else:
                # set if as root category
                source_category.parent = None
            
            # update on server
            category = rest.api.update_storages_category(source_category.id, source_category)

            # update tree symbol
            if source_categoryobj:
                self.tree_categories_manager.MoveItem(source_categoryobj.parent, dest_categoryobj, source_categoryobj)
        except Exception as e:
            print_stack()
            wx.MessageBox(format(e), 'Error', wx.OK | wx.ICON_ERROR)

        return wx.DragMove
예제 #7
0
    def onNotebookPageChanged(self, event):
        if self.menus is None:
            return
        if self.menu_bar is None:
            return

        self.menu_bar.SetMenus(self.menus)

        try:
            page = self.pages[self.notebook.GetSelection()]
            self.page_menus = page.GetMenus()

            for menu in self.page_menus:
                self.menu_bar.Insert(
                    len(self.menu_bar.GetMenus()) - 1, menu['menu'],
                    menu['title'])
                for menu_item in menu['menu'].GetMenuItems():
                    self.Bind(wx.EVT_MENU,
                              self.OnMenuItem,
                              id=menu_item.GetId())

        except:
            print_stack()
            pass

        page.activate()
예제 #8
0
    def onApplyButtonClick( self, event ):
        
        if self.manufacturer is None:
            manufacturer = rest.model.ManufacturerNew()
        else:
            manufacturer = self.manufacturer
        
        manufacturer.name = self.edit_manufacturer_name.Value
        manufacturer.address = self.edit_manufacturer_address.Value
        manufacturer.website = self.edit_manufacturer_website.Value
        manufacturer.email = self.edit_manufacturer_email.Value
        manufacturer.phone = self.edit_manufacturer_phone.Value
        manufacturer.comment = self.edit_manufacturer_comment.Value

        try:
            if self.manufacturer is None:
                manufacturer = rest.api.add_manufacturer(manufacturer)
                self.tree_manufacturers_manager.AppendItem(None, DataModelManufacturer(manufacturer))
            else:
                manufacturer = rest.api.update_manufacturer(manufacturer.id, manufacturer)
                self.tree_manufacturers_manager.UpdateManufacturer(manufacturer)

            self.panel_edit_manufacturer.Enabled = False
            self.panel_manufacturers.Enabled = True
            
        except Exception as e:
            print_stack()
            wx.MessageBox(format(e), 'Error', wx.OK | wx.ICON_ERROR)
예제 #9
0
 def onButtonAddStorageItemClick( self, event ):
     item = self.tree_storages.GetSelection()
     if item.IsOk()==False:
         return
     storageobj = self.tree_storages_manager.ItemToObject(item)
     if isinstance(storageobj, DataModelStorage)==False:
         return
     
     sel = self.tree_storage_parts.GetSelection()
     if sel.IsOk()==False:
         return
     partobj = self.tree_storage_parts_manager.ItemToObject(sel)
     if partobj is None:
         return
     
     if self.spin_num_parts.Value==0:
         return
     
     try:
         res = wx.MessageDialog(self, "Add %d items of %s to storage?"%(self.spin_num_parts.Value, partobj.part.name), "Add?", wx.OK|wx.CANCEL).ShowModal()
         if res==wx.ID_OK:
             part = rest.api.find_part(partobj.part.id, with_storages=True)
             for part_storage in part.storages:
                 if part_storage.id==storageobj.storage.id:
                     part_storage.quantity = part_storage.quantity+self.spin_num_parts.Value
                     break
         
             partobj.part = rest.api.update_part(part.id, part)
             partobj.quantity = part_storage.quantity
             self.tree_storage_parts_manager.UpdateItem(partobj)
         else:
             return
     except Exception as e:
         print_stack()
         wx.MessageBox(format(e), 'Error', wx.OK | wx.ICON_ERROR)
예제 #10
0
    def load(self):
        try:
            check_backend()
        except Exception as e:
            print_stack()
            self.GetParent().GetParent().error_message(format(e))
            return

        try:
            # update local disk state
            self.manager_module.LoadState()

            self.modules = self.manager_module.Synchronize()
        except Exception as e:
            print_stack()
            wx.MessageBox(
                format(e),
                'Synchronization with kipartbase failed, check your connection and try again',
                wx.OK | wx.ICON_ERROR)

        #self.modules = self.manager_module.
        #self.modules =  self.resource_module.Synchronize()

        self.loadLibraries()
        self.loadModules()
예제 #11
0
    def onTreeCategoriesDropStorage(self, x, y, data):
        dest_categoryitem, _ = self.tree_categories.HitTest((x, y))

        try:
            source_storage_id = data['id']
            source_storage = rest.api.find_storage(source_storage_id)

            dest_category = None
            dest_categoryobj = None
            if dest_categoryitem.IsOk():
                dest_categoryobj = self.tree_categories_manager.ItemToObject(dest_categoryitem)
                dest_category = dest_categoryobj.category
                source_storage.category = rest.model.StorageCategoryRef(id=dest_category.id)
            else:
                # set if as root category
                source_storage.category = None
            
            # update on server
            storage = rest.api.update_storage(source_storage.id, source_storage)
            
            # update tree symbol
            self.tree_storages_manager.DeleteStorage(source_storage)
            self.tree_storages_manager.AppendStorage(storage)
        except Exception as e:
            print_stack()
            wx.MessageBox(format(e), 'Error', wx.OK | wx.ICON_ERROR)
        return wx.DragMove
예제 #12
0
 def convert_mod_to_pretty_zip(src_libpath, dst_libpath):
 
     src_type = IO_MGR.GuessPluginTypeFromLibPath( src_libpath )
     dst_type = IO_MGR.GuessPluginTypeFromLibPath( dst_libpath )
     
     src_plugin = IO_MGR.PluginFind( src_type )
     dst_plugin = IO_MGR.PluginFind( dst_type )
     
     try:
         dst_plugin.FootprintLibDelete( dst_libpath )
     except:
         print_stack()
         None    # ignore, new may not exist if first run
     
     dst_plugin.FootprintLibCreate( dst_libpath )
     
     list_of_parts = src_plugin.FootprintEnumerate( src_libpath )
     
     for part_id in list_of_parts:
         module = src_plugin.FootprintLoad( src_libpath, part_id )
         dst_plugin.FootprintSave( dst_libpath, module )
     
     # create zip file with pretty
     zf = zipfile.ZipFile("%s.zip" % (dst_libpath), "w", zipfile.ZIP_DEFLATED)
     abs_src = os.path.abspath(dst_libpath)
     for dirname, subdirs, files in os.walk(dst_libpath):
         for filename in files:
             absname = os.path.abspath(os.path.join(dirname, filename))
             arcname = absname[len(abs_src) + 1:]
             print('zipping %s as %s' % (os.path.join(dirname, filename), arcname))
             zf.write(absname, arcname)
     zf.close()
     
     return dst_libpath+".zip"
예제 #13
0
    def loadStorages(self):
        try:
            check_backend()
        except Exception as e:
            print_stack()
            self.GetParent().GetParent().error_message(format(e))
            return

        # clear all
        self.tree_storages_manager.ClearItems()
        
        # load storages
        storages = rest.api.find_storages(**self.storages_filter.query_filter())

        # load categories
        categories = {}
        for storage in storages:
            if storage.category:
                category_name = storage.category.path
            else:
                category_name = "/"

            if category_name not in categories:
                categories[category_name] = DataModelCategoryPath(storage.category)
                self.tree_storages_manager.AppendItem(None, categories[category_name])
            self.tree_storages_manager.AppendItem(categories[category_name], DataModelStorage(storage))
        
        for category in categories:
            self.tree_storages_manager.Expand(categories[category])
예제 #14
0
    def loadCategories(self):
        try:
            check_backend()
        except Exception as e:
            print_stack()
            self.GetParent().GetParent().error_message(format(e))
            return

        # clear all
        self.tree_categories_manager.ClearItems()
        
        # load categories
        categories = rest.api.find_storages_categories()

        # load tree
        to_add = []
        id_category_map = {}
        for category in categories:
            to_add.append(category)
        while len(to_add)>0:
            category = to_add[0]
            id_category_map[category.id] = DataModelCategory(category)
            to_add.pop(0)
            
            # add to symbol
            if category.parent:
                self.tree_categories_manager.AppendItem(id_category_map[category.parent.id], id_category_map[category.id])
            else:
                self.tree_categories_manager.AppendItem(None, id_category_map[category.id])
            
            # load childs
            if category.childs:
                for child in category.childs:
                    to_add.append(child)
예제 #15
0
 def converted_unit_price(self, offer):
     res = [offer.unit_price, offer.currency]
     try:
         return [currency.convert(offer.unit_price, offer.currency, configuration.base_currency), configuration.base_currency]
     except:
         print_stack()
         # error during conversion, no conversion
         return res
예제 #16
0
 def onTestKipartbase( self, event ):
     try:
         base_url = self.edit_kipartbase.Value+'/api'
         client = swagger_client.ApiClient(base_url)
         api = swagger_client.DefaultApi(client)
         currencies = api.find_currencies()
     except Exception as e:
         print_stack()
         wx.MessageBox(format(e), 'Error', wx.OK | wx.ICON_ERROR)
예제 #17
0
 def onTestSnapeda( self, event ):
     connection = SnapedaConnection()
     
     try:
         connection.connect(self.edit_snapeda_user.Value, self.edit_snapeda_password.Value)
         wx.MessageBox( 'SNAPEDA CONNECTION OK', 
             'SNAPEDA CONNECTION OK', wx.OK )
     except SnapedaConnectionException as e:
         print_stack()
         wx.MessageBox(format(e.error), 'Error', wx.OK | wx.ICON_ERROR)
예제 #18
0
 def validate(self):
     classname = self.__class__.__name__
     print("Validating: ", classname)
     try:
         self.extension
         self.wildcard
         self.export
         return True
     except AttributeError as e:
         print_stack()
         print("{} is invalid: {}".format(classname, str(e)))
예제 #19
0
    def loadLibraries(self):
        try:
            check_backend()
        except Exception as e:
            print_stack()
            self.GetParent().GetParent().error_message(format(e))
            return

        self.tree_libraries_manager.SaveState()

        # load libraries tree
        for module_path in self.modules:
            # decompose path
            folders = []
            library_path = os.path.dirname(module_path)
            path = os.path.dirname(library_path)
            library_name = os.path.basename(library_path)
            while path != '' and path != '/':
                folders.insert(0, path)
                path = os.path.dirname(path)

            for folder in folders:
                pathobj = self.tree_libraries_manager.FindPath(folder)
                if self.tree_libraries_manager.DropStateObject(
                        pathobj) == False:
                    self.tree_libraries_manager.AppendPath(folder)

            path = os.path.dirname(library_path)
            libraryobj = self.tree_libraries_manager.FindLibrary(
                path, library_name)
            if self.tree_libraries_manager.DropStateObject(
                    libraryobj) == False:
                self.tree_libraries_manager.AppendLibrary(path, library_name)

        # add folders with no library inside
        for folder in self.file_manager_module.folders:
            if re.compile("^.*\.module$").match(
                    os.path.normpath(os.path.abspath(folder))):
                path = os.path.dirname(folder)
                library_name = os.path.basename(folder)
                libraryobj = self.tree_libraries_manager.FindLibrary(
                    path, library_name)
                if self.tree_libraries_manager.DropStateObject(
                        libraryobj) == False:
                    self.tree_libraries_manager.AppendLibrary(
                        path, library_name)
            else:
                pathobj = self.tree_libraries_manager.FindPath(folder)
                if self.tree_libraries_manager.DropStateObject(
                        pathobj) == False:
                    self.tree_libraries_manager.AppendPath(folder)

        self.tree_libraries_manager.PurgeState()
예제 #20
0
    def load(self):
        try:
            self.loadCategories()
        except Exception as e:
            print_stack()
            wx.MessageBox(format(e), 'Error', wx.OK | wx.ICON_ERROR)

        try:
            self.loadParts()
        except Exception as e:
            print_stack()
            wx.MessageBox(format(e), 'Error', wx.OK | wx.ICON_ERROR)
예제 #21
0
    def load(self):
        try:
            self.symbols = self.manager_lib.Synchronize()
        except Exception as e:
            print_stack()
            wx.MessageBox(
                format(e),
                'Synchronization with kipartbase failed, check your connection and try again',
                wx.OK | wx.ICON_ERROR)

        self.loadLibraries()
        self.loadSymbols()
예제 #22
0
    def load(self):
        try:
            check_backend()
        except Exception as e:
            print_stack()
            self.GetParent().GetParent().error_message(format(e))
            return

        try:
            self.loadManufacturers()
        except Exception as e:
            print_stack()
            wx.MessageBox(format(e), 'Error', wx.OK | wx.ICON_ERROR)
예제 #23
0
 def onMenuLibrariesRemove(self, event):
     item = self.tree_libraries.GetSelection()
     if item.IsOk() == False:
         return
     obj = self.tree_libraries_manager.ItemToObject(item)
     path = obj.path
     try:
         self.manager_lib.DeleteFolder(path)
     except Exception as e:
         print_stack()
         wx.MessageBox(format(e), 'Error removing %s:' % path,
                       wx.OK | wx.ICON_ERROR)
     self.load()
예제 #24
0
 def onButtonEditCategoryClick( self, event ):
     sel = self.tree_categories.GetSelection()
     categoryobj = self.tree_categories_manager.ItemToObject(sel)
     if categoryobj is None:
         return
     category = EditCategoryFrame(self).editCategory(categoryobj.category)
     if not category is None:
         try:
             categoryobj.category = rest.api.update_storages_category(categoryobj.category.id, category)
             self.tree_categories_manager.UpdateItem(categoryobj)
             self.onTreeCategoriesSelChanged(None)
         except Exception as e:
             print_stack()
             wx.MessageBox(format(e), 'Error', wx.OK | wx.ICON_ERROR)
예제 #25
0
    def GetUnitPrefix(self, spec):
        symbol = self.GetUnitPrefixSymbol(spec)
        if symbol=='' or symbol is None:
            return None
        if spec.metadata().unit():
            try:
                return rest.api.find_unit_prefixes(symbol=symbol)[0]
            except Exception as e:
                print_stack()
                # TODO: create unit_prefix in kipartbase if not found

                wx.MessageBox('%s: unit prefix unknown' % (symbol), 'Warning', wx.OK | wx.ICON_EXCLAMATION)
#            except:
#                wx.MessageBox('%s: unit prefix unknown' % (symbol), 'Warning', wx.OK | wx.ICON_EXCLAMATION)
        return None
예제 #26
0
 def onTreePartsSelChanged(self, event):
     self.data_frame.SetPart(None)
     if len(self.tree_parts.GetSelections()) > 1:
         return
     item = self.tree_parts.GetSelection()
     if item.IsOk():
         partobj = self.tree_parts_manager.ItemToObject(item)
         part = None
         try:
             if partobj.component.kipart_id != '':
                 part = rest.api.find_part(partobj.component.kipart_id)
         except Exception as e:
             print_stack()
             print format(e)
         self.data_frame.SetPart(part)
예제 #27
0
 def onButtonRemoveCategoryClick( self, event ):
     sel = self.tree_categories.GetSelection()
     categoryobj = self.tree_categories_manager.ItemToObject(sel)
     if categoryobj is None:
         return
     try:
         res = wx.MessageDialog(self, "Remove category '"+categoryobj.category.name+"'", "Remove?", wx.OK|wx.CANCEL).ShowModal()
         if res==wx.ID_OK:
             rest.api.delete_storages_category(categoryobj.category.id)
             self.tree_categories_manager.DeleteItem(categoryobj.parent, categoryobj)
         else:
             return
     except Exception as e:
         print_stack()
         wx.MessageBox(format(e), 'Error', wx.OK | wx.ICON_ERROR)
예제 #28
0
 def onTestOctopart( self, event ):
     apikey = OctpartPartsQuery.apikey
     
     OctpartPartsQuery.apikey = self.edit_octopart_apikey.Value
     try:
         q = OctpartPartsQuery()
         q.get('atmega328p')
         self.data = q.results()
         print(self.data)
         wx.MessageBox( 'OCTOPART CONNECTION OK', 
             'OCTOPART CONNECTION OK', wx.OK )
     except Exception as e:
         print_stack()
         wx.MessageBox(format(e), 'Error', wx.OK | wx.ICON_ERROR)
     OctpartPartsQuery.apikey = apikey
예제 #29
0
    def loadBomParts(self):
        self.tree_bom_parts_manager.ClearItems()

        for bom_file in self.basket.boms:
            bom_product = self.basket.boms[bom_file]
            
            try:
                bom_product.load()
            except Exception as e:
                print_stack()
                print format(e)
                
            for bom_part in bom_product.bom.Parts():
                full_part = rest.api.find_part(bom_part.id, with_childs=True, with_storages=True)
                self.tree_bom_parts_manager.AppendBomPart(bom_product, full_part)
예제 #30
0
    def load(self):
        try:
            self.footprints = self.manager_pretty.Synchronize()
        except Exception as e:
            print_stack()
            wx.MessageBox(
                format(e),
                'Synchronization with kipartbase failed, check your connection and try again',
                wx.OK | wx.ICON_ERROR)

        #self.footprints = self.manager_pretty.
        #self.footprints =  self.resource_pretty.Synchronize()

        self.loadLibraries()
        self.loadFootprints()