Exemple #1
0
class EzTableView(EzControl):
    def __init__(self, h):
        self.ctrl = ListView()
        self.table = DataTable('table')
        self.Initialize(h)
        if h.get('fontsize'): self.SetFontSize(h['fontsize'])
        if h.get('handler'): self.ctrl.SelectionChanged += h['handler']
        self.grid = GridView()
        self.grid.AllowsColumnReorder = True
        self.grid.ColumnHeaderToolTip = "ListView Column Info"
        if h.get('columns'):
            items = h['columns']
            width = None
            if h.get('widths'): width = h['widths']
            for i in range(0, len(items)):
                col = GridViewColumn()
                col.DisplayMemberBinding = Binding(items[i])
                col.Header = items[i]
                if width: col.Width = width[i]
                self.grid.Columns.Add(col)
                self.AddColumn(items[i])
        self.ctrl.View = self.grid
        self.ctrl.ItemsSource = self.table.DefaultView  #DataView(self.table)

    def AddColumn(self, label):
        item = DataColumn(label, GetType("System.String"))
        '''
        column.DataType = System.Type.GetType("System.String");
        column.ColumnName = "ParentItem";
        column.AutoIncrement = false;
        column.Caption = "ParentItem";
        column.ReadOnly = false;
        column.Unique = false;        
        '''
        self.table.Columns.Add(item)

    def AddItem(self, items):
        item = self.table.NewRow()
        for key, value in items.items():
            item[key] = value
        self.table.Rows.Add(item)

    def GetValue(self):
        return self.ctrl.SelectedItem
Exemple #2
0
    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
Exemple #3
0
from System.Net import HttpWebRequest
import time
from Spotfire.Dxp.Data.Import import TextFileDataSource, TextDataReaderSettings

dataSet = DataSet()
dataTable = DataTable("timelineEvents")
dataTable.Columns.Add("parentType", System.String)
dataTable.Columns.Add("parentId", System.String)
dataTable.Columns.Add("start", System.DateTime)
dataTable.Columns.Add("end", System.DateTime)
dataTable.Columns.Add("eventType", System.String)
dataTable.Columns.Add("desc", System.String)
dataTable.Columns.Add("singleEvent", System.String)
dataSet.Tables.Add(dataTable)

dt = dataTable.NewRow()
dt["parentType"] = "Case"
dt["parentId"] = "28081"
dt["start"] = "2017-08-28T15:47:01.572Z"
dt["end"] = "2017-08-28T15:47:01.572Z"
dt["eventType"] = "CASE_STARTER"
dt["desc"] = "Enter Customer Onboarding Data"
dt["singleEvent"] = "TRUE"
dataTable.Rows.Add(dt)

textData = "parentType\tparentId\tstart\tend\teventType\tdesc\tsingleEvent\r\n"
for row in dataTable.Rows:
    textData += row["parentType"] + "\t" + str(row["parentId"]) + "\t" + str(
        row["start"]) + "\t" + str(row["end"]) + "\t" + str(
            row["eventType"]) + "\t" + str(
                row["desc"]) + "\t" + row["singleEvent"] + "\r\n"
Exemple #4
0
class ExampleAppForm(Form):

    _COLUMNS = [
        ("Name", System.String, "name"),
        ("Surname", System.String, "surname"),
        ("Company", System.String, lambda x: x["company"]["name"])
    ]

    def __init__(self):
        self.Text = "Example App"
        self.Name = "ExampleApp"
        self.ClientSize = Size(370, 400)
        self.MinimumSize = Size(370, 300)
        self._table = DataTable()
        self._columns = {
            d[0]: self._table.Columns.Add(d[0], d[1])
            for d in self._COLUMNS
        }
        self._loadPanel = Panel()
        self._loadPanel.Location = Point(0, 0)
        self._loadPanel.Size = Size(215, 30)
        self._loadPanel.Dock = DockStyle.Top

        self._fileTextBoxLabel = Label()
        self._fileTextBoxLabel.Text = "Load file"
        self._fileTextBoxLabel.Size = Size(100, 16)
        self._fileTextBoxLabel.Location = Point(5, 7)
        self._loadPanel.Controls.Add(self._fileTextBoxLabel)

        self._fileTextBox = TextBox()
        self._fileTextBox.Size = Size(200, 20)
        self._fileTextBox.Location = Point(110, 5)
        self._loadPanel.Controls.Add(self._fileTextBox)

        self._loadButton = Button()
        self._loadButton.Size = Size(50, 20)
        self._loadButton.Location = Point(315, 5)
        self._loadButton.Text = "Load"
        self._loadPanel.Controls.Add(self._loadButton)

        self._dataPanel = Panel()
        self._dataPanel.Location = Point(0, 35)
        self._dataPanel.Size = Size(370, 185)

        self._dataGrid = DataGridView()
        self._dataGrid.AllowUserToOrderColumns = True
        self._dataGrid.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize
        self._dataGrid.Location = Point(0, 0)
        self._dataGrid.Size = Size(360, 180)
        self._dataGrid.DataSource = self._table
        self._dataPanel.Controls.Add(self._dataGrid)

        self.Controls.Add(self._loadPanel)
        self.Controls.Add(self._dataPanel)

        self._loadButton.Click += self.loadData

    def loadData(self, sender, event):
        filepath = self._fileTextBox.Text
        if not filepath or not os.path.exists(filepath):
            return
        try:
            contacts, meta = parseXML(filepath)
        except:
            traceback.print_exc()
            return
        for contact in contacts:
            row = self._table.NewRow()
            for col_name, __, key in self._COLUMNS:
                if callable(key):
                    row[col_name] = key(contact)
                else:
                    row[col_name] = contact[key]
            self._table.Rows.Add(row)