def myFunction(self): if self._progressBar1.Value < self._progressBar1.Maximum: self._progressBar1.Value += 1 self._label1.Text = "Items Processing {}/{}".format( str(self._progressBar1.Value), str(self._numberLines)) try: Application.DoEvents() except: pass else: self._theBroadcaster.onChange -= self.myFunction self.Close()
def __init__(self): c = Form() self.connected = False def attached(source, args): print('Connected to splicer') self.connected = True def detached(source,args): self.connected = False print('Disconnected from splicer') a = clr.UsbFsm100ServerClass(c.Handle ) a.Attached += attached a.Detached += detached self.usb = a self.c = c #c.Visible=False #c.Show() #c.Close() Application.DoEvents() #<--- BOO YA #Application.Run(c) print('g') #c.Close() #a.close() self.usb.Clear() self.threshold = 2000. self.lastZLZR = ('0','0') self.lastarc = 0,0 self.lastmove = self.readZLZR() self.lastvelocity = (0.,0.) #important for moving fast self.lastZLZR = self.readZLZR() self.lastarc = (0,0) self.immodeSize = {1:np.array((640,480)),2:np.array((640,480)),3:np.array((486,364))} self.exposure = 0.
def LoadRss(self): """ Caches the rss feeds so they don't have to be redownloaded over and over again """ for rss in self.imageRssList: if rss not in self.rssCache: #TODO replace download with comicracks download functions Application.DoEvents() #print "rss does not exist, fetching" try: imgXml = XmlDocument() imgXml.Load(rss) #Load the wanted items imgItems = imgXml.SelectNodes("rss/channel/item") self.rssCache[rss] = imgItems except Exception, ex: # MessageBox.Show("Something went wrong accessing the images rss feed. Are you connected to the internet?") # print str(ex) # Now disabled as a result of return False
def Parse(self, entry): #print "Starting to parse entry" #print entry titlename = re.search("\d*/\d*/\d*", entry.title).group(0) #print "Name of entry title is: " #print titlename if not self.ComicList.Tables.Contains(titlename): #print "Table is not yet in dataset" Application.DoEvents() #print "Creating row for WeekList but do not add it yet as it still needs the publisherlist" row2 = self.ComicList.Tables["WeekList"].NewRow() #print "Created new row in weeklist" row2["Date"] = titlename publisherlist = [] #print "Create the datatable for the list of comics" data = DataTable(titlename) id = DataColumn("ID") pub = DataColumn("Publisher") title = DataColumn("Title") price = DataColumn("Price") image = DataColumn("Image") image.DataType = System.Type.GetType('System.String') id.DataType = System.Type.GetType('System.Int32') pub.DataType = System.Type.GetType('System.String') title.DataType = System.Type.GetType('System.String') price.DataType = System.Type.GetType('System.String') data.Columns.Add(id) data.Columns.Add(pub) data.Columns.Add(title) data.Columns.Add(price) data.Columns.Add(image) #print "Finished Creating data columns" #print "Now finding the list of comics" x = HtmlAgilityPack.HtmlDocument() x.LoadHtml(entry.content) nodes = x.DocumentNode.SelectNodes("pre") #Find the largest paragraph in the source. #The largest paragraph contains the comiclist index = {"index": 0, "length": 0} comiclistNode = None for node in nodes: if comiclistNode is None or len(node.InnerText) > len( comiclistNode.InnerText): comiclistNode = node Application.DoEvents() if comiclistNode is None: print "No comic list found" return None, None #Now that we know which node the comiclist is, parse it into a csv list try: comiclist = HtmlEntity.DeEntitize(nodes[0].InnerHtml).replace( '<br>', '\n').splitlines() except Exception, ex: print ex print "Something failed" return None, None #Don't need these del (x) del (nodes) # print comiclist count = 1 #Go through all the lines in the list execpt the first one which is the definitions. for line in comiclist[1:]: try: #print count print line Application.DoEvents() #Using python list doesn't work, so use System.Array l = System.Array[str](line.strip().replace('"', '').split(',')) row = data.NewRow() date, code, publisher, title, price = l row["ID"] = count count += 1 row["Publisher"] = publisher if not publisher in publisherlist and not publisher in self.BlackList: publisherlist.append(publisher) row["Title"] = title if price: row["Price"] = price else: row["Price"] = "" row["Image"] = "" data.Rows.Add(row) except Exception, ex: #Line was not formated in the normal pattern #print ex #print type(ex) #print line continue
def ParseImages(self, weekname, data): """ This is where the images are downloaded from the rss feed Variables: weekname is the name of the week to scrape data should be the data table to add to """ print "Starting to find images" #Fetched rss feed entrys are stored in the imageRssDownloaded with a key of the url for rss in self.imageRssList: imgItems = self.rssCache[rss] for imgItem in imgItems: Application.DoEvents() try: if re.search( "\d*/\d*/\d*", imgItem['title'].InnerText).group(0) == weekname: #Load rss into htmldocument for ease of navigation htdoc = HtmlAgilityPack.HtmlDocument() htdoc.LoadHtml(imgItem['description'].InnerText) imgTags = htdoc.DocumentNode.SelectNodes( "table/tr/td/a/img") for tag in imgTags: Application.DoEvents() imgTitle = tag.GetAttributeValue("title", None) imgSrc = tag.GetAttributeValue("src", None) #If we have both and title and src. No point in doing all this if there is no src or title if imgTitle and imgSrc: #find rows that have a simular title. #NOTE: replace occurences of ' with '' to avoid errors imgRows = data.Select( "Title LIKE '%" + imgTitle.replace("'", "''") + "%'") for imgRow in imgRows: Application.DoEvents() try: #Create the imagedownloaded imgDownloader = System.Net.WebClient() #Replace illegal charachers in the file name imgFileName = re.sub( '[\\\\<>\|:"\*/\?]', "", imgTitle) imgdirname = re.sub( '[\\\\<>\|:"\*/\?]', "", weekname) #Make sure the directory is not already there if not Directory.Exists(localdir + imgdirname): Directory.CreateDirectory( localdir + imgdirname) #In the case of varients and other duplicates. This fixes an bug in 0.5 if not File.Exists(localdir + imgdirname + "\\" + imgFileName + ".jpg"): imgDownloader.DownloadFile( imgSrc, localdir + imgdirname + "\\" + imgFileName + ".jpg") #Now set the image column to the path of the image. Note that this is already set to a blank string when the list was first downloaded. imgRow[ "Image"] = localdir + imgdirname + "\\" + imgFileName + ".jpg" except Exception, ex: print "Error 1" print str(ex) except Exception, ex: print "Error 2" print ex
def DoEvents(seconds): for i in xrange(seconds): Application.DoEvents() thread_util.SleepForSeconds(1) return
def ShutdownSession(process): for i in xrange(CLOSE_MAIN_WINDOW_ATTEMPTS): process.Refresh() process.CloseMainWindow() Application.DoEvents() return