Skip to content

Commit

Permalink
Merge pull request #218 from hildogjr/master
Browse files Browse the repository at this point in the history
Update as thread
  • Loading branch information
hildogjr authored Mar 24, 2018
2 parents 765974a + deda56e commit d945920
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions kicost/kicost_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,8 @@ def __init__( self, parent ):

#### ** End of the guide code generated by wxFormBulilder software, available in <https://github.com/wxFormBuilder/wxFormBuilder/> ** ####

self.updateChecked = False
self.set_properties()
self.updatedChecked = False
self.SetDropTarget( FileDropTarget(self) ) # Start the drop file in all the window.
self.m_textCtrl_messages.AppendText( 'Loaded KiCost v.' + __version__ )

Expand All @@ -520,7 +520,33 @@ def wxPanel_change( self, event ):
''' @brief Check version to update if the "About" tab.'''
event.Skip()
if event.GetSelection()==2: # Is the last page (about page).
self.checkUpdate()

def checkUpdate():
'''Check for updates.'''
try:
updateChecked = self.updateChecked
except:
updateChecked = False
if not updateChecked:
self.m_staticText_update.SetLabel('Checking by updates...')
try:
req = FakeBrowser(PAGE_UPDATE)
response = urlopen(req)
html = response.read()
offical_last_version = re.findall('kicost (\d+\.\d+\.\d+)', str(html), flags=re.IGNORECASE)[0]
if StrictVersion(offical_last_version) > StrictVersion(__version__):
self.m_staticText_update.SetLabel('New version (v.'
+ offical_last_version
+ ') founded.\nClick <here> to update.')
self.m_staticText_update.Bind( wx.EVT_LEFT_UP, self.m_staticText_update_click )
else:
self.m_staticText_update.SetLabel('KiCost is up to date.')
except:
self.m_staticText_update.SetLabel('Update information not founded.')
finally:
self.updateChecked = True

threading.Thread(target=checkUpdate).start()

#----------------------------------------------------------------------
def m_textCtrl_messages_rClick( self, event ):
Expand Down Expand Up @@ -568,29 +594,6 @@ def updateEDAselection( self ):
if eda_module:
self.m_listBox_edatool.SetSelection( self.m_listBox_edatool.FindString(eda_tool_dict[eda_module]['label']) )

#----------------------------------------------------------------------
def checkUpdate( self ):
''' @brief Check for updates.'''
if not self.updatedChecked:
self.m_staticText_update.SetLabel('Checking by updates...')

try:
req = FakeBrowser(PAGE_UPDATE)
response = urlopen(req)
html = response.read()
offical_last_version = re.findall('kicost (\d+\.\d+\.\d+)', str(html), flags=re.IGNORECASE)[0]
if StrictVersion(offical_last_version) > StrictVersion(__version__):
self.m_staticText_update.SetLabel('New version (v.'
+ offical_last_version
+ ') founded.\nClick <here> to update.')
self.m_staticText_update.Bind( wx.EVT_LEFT_UP, self.m_staticText_update_click )
else:
self.m_staticText_update.SetLabel('KiCost is up to date.')

self.updatedChecked = True
except:
self.m_staticText_update.SetLabel('Update information not founded.')

#----------------------------------------------------------------------
def m_staticText_update_click( self, event ):
''' @brief Open the page to download the last version.'''
Expand All @@ -617,7 +620,7 @@ def button_openfile( self, event ):
paths = dlg.GetPaths()
self.addFile( paths )
dlg.Destroy()

#----------------------------------------------------------------------
def addFile( self, filesName ):
''' @brief Add the file(s) to the history, updating it (and delete the too old).'''
Expand Down

0 comments on commit d945920

Please sign in to comment.