diff --git a/GUItest_flexx.py b/GUItest_flexx.py index 37b4c3c..64b471c 100644 --- a/GUItest_flexx.py +++ b/GUItest_flexx.py @@ -1,69 +1,20 @@ -""" -An example demonstrating when to use what kind of HV layout in an app. -""" from flexx import flx -class AppLayoutExample(flx.Widget): +class DrawTable(flx.Widget): def init(self): - with flx.VBox(): - - flx.Label(style='background:#cfc;', wrap=1, - text='Here is some content at the top for which we want to ' - 'use minimal size. Thus the use of a VBox. ' - 'Below is a splitter, with a box layout on the left ' - 'and a fix layout on the right.') - - with flx.HSplit(flex=1): - with flx.VBox(style='border:1px solid #777;'): - - flx.Label(text='Flex 0 0 0') - with flx.HBox(flex=0): - self.b1 = flx.Button(text='Hi') - self.b2 = flx.Button(text='Helloooo world!', style='background:#03c') - self.b3 = flx.Button(text='Foo bar', style='background:#0c4') - - flx.Label(text='Flex 1 1 1') - with flx.HBox(flex=0): - self.b1 = flx.Button(flex=1, text='Hi') - self.b2 = flx.Button(flex=1, text='Helloooo world!') - self.b3 = flx.Button(flex=1, text='Foo bar') - - flx.Label(text='Flex 1 0 3') - with flx.HBox(flex=0): - self.b1 = flx.Button(flex=1, text='Hi') - self.b2 = flx.Button(flex=0, text='Helloooo world!') - self.b3 = flx.Button(flex=3, text='Foo bar') - - # flx.Widget(flex=1) # spacer widget - - with flx.VFix(style='border:1px solid #777;'): - - flx.Label(text='Flex 0 0 0 (space divided equally)', style='') - with flx.HFix(): - self.b1 = flx.Button(text='Hi') - self.b2 = flx.Button(text='Helloooo world!') - self.b3 = flx.Button(text='Foo bar') - - flx.Label(text='Flex 1 1 1', style='') - with flx.HFix(): - self.b1 = flx.Button(flex=1, text='Hi') - self.b2 = flx.Button(flex=1, text='Helloooo world!') - self.b3 = flx.Button(flex=1, text='Foo bar') - - flx.Label(text='Flex 1 0 3 (the widget with zero collapses') - with flx.HFix(): - self.b1 = flx.Button(flex=1, text='Hi') - self.b2 = flx.Button(flex=0, text='Helloooo world!') - self.b3 = flx.Button(flex=3, text='Foo bar') - - # If we would put a spacer widget with flex 1 here, the - # above widgets would collapse due to their zero flex value. + with flx.VBox(style='border:1px solid #777;'): + flx.Label(text='zhibo8数据采集') + for i in range(10): + with flx.HFix(flex=1, style='border-bottom:1px solid #ddd; font-size: 14px;'): + self.b1 = flx.Label(flex=1, text='数据采集' + str(i)) + self.b2 = flx.Label(flex=1, text='数据采集 world!' + str(i)) + self.b3 = flx.Label(flex=1, text='Foo 数据采集' + str(i)) if __name__ == '__main__': - m = flx.launch(AppLayoutExample) - flx.run() \ No newline at end of file + m = flx.launch(DrawTable) + flx.run() diff --git a/GUItest_kivy.py b/GUItest_kivy.py index 90fef3c..baf6311 100644 --- a/GUItest_kivy.py +++ b/GUItest_kivy.py @@ -1,15 +1,28 @@ -from kivy.app import App +from kivy.uix.boxlayout import BoxLayout +from kivy.base import runTouchApp from kivy.lang import Builder -kv = Builder.load_string(''' -Button: - text: "I was created by kv codes" -''') +# Note the special nature of indentation in the adapter declaration, where +# the adapter: is on one line, then the value side must be given at one +# level of indentation. +Builder.load_string(""" +#:import label kivy.uix.label +#:import sla kivy.adapters.simplelistadapter -class TestApp(App): - def build(self): - return kv +: + ListView: + + adapter: + + sla.SimpleListAdapter( + data=["Item #{0}".format(i) for i in range(100)], + cls=label.Label) +""") -TestApp().run() +class MyListView(BoxLayout): + pass + +if __name__ == '__main__': + runTouchApp(MyListView()) \ No newline at end of file diff --git a/flexxTest2.py b/flexxTest2.py new file mode 100644 index 0000000..b0bc415 --- /dev/null +++ b/flexxTest2.py @@ -0,0 +1,161 @@ +# flake8: noqa +""" +Examample data-viz app. It shows real temperature data from the region +where I live. The data are monthly average temperatures for the pas 65 +years. The month can be selected with a slider. Via another slider, the +data can be smoothed so the upward trend can be made more apparent. +This app can be exported to a standalone HTML document. +""" + + +from flexx import flx + +# Raw data obtained from +# http://cdn.knmi.nl/knmi/map/page/klimatologie/gegevens/maandgegevens/mndgeg_290_tg.txt + +raw_data = """ +Deze gegevens mogen vrij worden gebruikt mits de volgende bronvermelding wordt gegeven: +KONINKLIJK NEDERLANDS METEOROLOGISCH INSTITUUT (KNMI) + +These data can be used freely provided that the following source is acknowledged: +ROYAL NETHERLANDS METEOROLOGICAL INSTITUTE + +MAAND- en JAARGEMIDDELDE TEMPERATUREN (0.1 graden Celsius) +MONTHLY AND YEARLY MEAN TEMPERATURES (0.1 degrees Celsius) + +STN = stationsnummer / WMO-number = 06... (235=De Kooy,240=Schiphol,260=De Bilt,270=Leeuwarden,280=Eelde, + 290=Twenthe,310=Vlissingen,344=Rotterdam,370=Eindhoven,380=Maastricht) + + +STN,YYYY, JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC, YEAR + +290,1951, 35, 35, 34, 74, 120, 154, 169, 171, 155, 85, 82, 44, 97 +290,1952, 19, 20, 43, 107, 129, 149, 172, 173, 111, 80, 23, 10, 86 +290,1953, 11, 15, 47, 91, 133, 162, 170, 167, 140, 115, 71, 48, 98 +290,1954, -11, -10, 57, 65, 128, 156, 142, 160, 138, 116, 65, 51, 88 +290,1955, -1, -5, 16, 82, 100, 146, 179, 181, 146, 92, 58, 42, 86 +290,1956, 17, -71, 50, 50, 127, 130, 166, 140, 146, 94, 46, 49, 79 +290,1957, 32, 49, 80, 83, 102, 166, 176, 156, 124, 107, 60, 24, 97 +290,1958, 16, 32, 15, 62, 129, 148, 168, 177, 157, 109, 54, 44, 93 +290,1959, 12, 7, 72, 103, 131, 164, 192, 180, 156, 111, 52, 39, 102 +290,1960, 21, 25, 55, 88, 130, 161, 153, 155, 133, 107, 73, 26, 94 +290,1961, 14, 61, 71, 104, 106, 157, 152, 158, 172, 114, 45, 8, 97 +290,1962, 31, 21, 14, 80, 99, 135, 145, 152, 127, 104, 39, -14, 78 +290,1963, -63, -38, 45, 91, 112, 158, 165, 153, 137, 91, 81, -15, 76 +290,1964, -1, 28, 23, 91, 143, 156, 169, 161, 142, 78, 58, 20, 89 +290,1965, 24, 11, 37, 76, 117, 150, 147, 152, 131, 98, 19, 38, 83 +290,1966, -3, 37, 46, 87, 135, 171, 155, 158, 134, 111, 38, 36, 92 +290,1967, 32, 48, 64, 70, 128, 146, 181, 163, 141, 116, 47, 25, 97 +290,1968, 7, 13, 59, 95, 106, 155, 161, 168, 142, 111, 50, -7, 88 +290,1969, 37, -7, 13, 77, 129, 145, 175, 168, 137, 115, 60, -25, 85 +290,1970, -4, 4, 21, 56, 125, 170, 154, 165, 136, 99, 72, 18, 85 +290,1971, 22, 32, 23, 78, 138, 138, 170, 171, 125, 97, 46, 50, 91 +290,1972, -3, 34, 61, 71, 116, 137, 172, 151, 108, 82, 53, 32, 85 +290,1973, 23, 23, 49, 54, 119, 160, 171, 176, 145, 83, 49, 23, 90 +290,1974, 51, 42, 55, 85, 112, 143, 147, 164, 129, 64, 62, 66, 93 +290,1975, 62, 27, 43, 69, 108, 147, 176, 195, 148, 77, 45, 23, 93 +290,1976, 26, 19, 22, 71, 129, 173, 188, 170, 134, 107, 61, 7, 92 +290,1977, 22, 45, 68, 60, 117, 143, 161, 158, 126, 114, 61, 42, 93 +290,1978, 27, 2, 61, 67, 121, 145, 150, 147, 136, 110, 66, 13, 87 +290,1979, -39, -22, 41, 73, 116, 150, 150, 151, 125, 96, 45, 46, 78 +290,1980, -8, 38, 38, 74, 115, 145, 153, 166, 146, 87, 42, 29, 85 +290,1981, 16, 9, 81, 87, 138, 147, 163, 164, 148, 85, 60, -10, 91 +290,1982, 3, 23, 50, 71, 122, 161, 186, 169, 160, 112, 76, 31, 97 +290,1983, 57, 0, 56, 89, 111, 159, 191, 174, 134, 94, 54, 27, 96 +290,1984, 23, 14, 33, 71, 100, 129, 150, 168, 124, 109, 73, 35, 86 +290,1985, -46, -14, 35, 81, 132, 131, 165, 150, 132, 97, 17, 52, 78 +290,1986, 16, -46, 45, 68, 137, 160, 162, 151, 105, 109, 77, 41, 85 +290,1987, -40, 17, 13, 103, 99, 137, 163, 155, 145, 104, 61, 38, 83 +290,1988, 58, 42, 43, 81, 144, 145, 160, 166, 139, 104, 53, 55, 99 +290,1989, 41, 48, 77, 65, 138, 159, 178, 171, 154, 122, 50, 44, 104 +290,1990, 50, 73, 79, 84, 138, 151, 161, 182, 122, 119, 54, 35, 104 +290,1991, 29, -9, 83, 81, 97, 126, 188, 173, 147, 94, 50, 32, 91 +290,1992, 22, 47, 64, 83, 154, 170, 182, 180, 143, 73, 74, 33, 102 +290,1993, 42, 12, 51, 112, 142, 152, 157, 146, 125, 86, 15, 44, 90 +290,1994, 44, 6, 70, 81, 123, 151, 213, 174, 133, 86, 87, 48, 101 +290,1995, 27, 60, 46, 89, 124, 145, 200, 187, 136, 124, 55, -16, 98 +290,1996, -16, -10, 23, 89, 106, 151, 161, 175, 115, 99, 52, -6, 78 +290,1997, -17, 58, 72, 70, 124, 157, 173, 201, 134, 89, 57, 41, 97 +290,1998, 43, 57, 67, 90, 144, 155, 159, 160, 144, 90, 29, 35, 98 +290,1999, 45, 26, 66, 97, 135, 149, 188, 172, 177, 101, 59, 41, 105 +290,2000, 37, 52, 63, 102, 145, 160, 152, 169, 150, 111, 77, 46, 105 +290,2001, 22, 37, 42, 79, 140, 147, 183, 183, 128, 140, 61, 21, 99 +290,2002, 39, 65, 64, 89, 135, 167, 174, 186, 139, 86, 71, 16, 103 +290,2003, 16, 7, 68, 93, 134, 179, 185, 193, 139, 66, 78, 33, 99 +290,2004, 27, 40, 53, 103, 116, 152, 165, 188, 149, 110, 54, 27, 99 +290,2005, 43, 14, 58, 102, 125, 162, 176, 157, 152, 129, 61, 33, 101 +290,2006, 4, 18, 32, 85, 143, 168, 222, 159, 177, 136, 88, 62, 108 +290,2007, 61, 54, 74, 125, 139, 174, 169, 168, 133, 93, 61, 31, 107 +290,2008, 59, 47, 53, 83, 150, 164, 180, 173, 131, 97, 62, 18, 101 +290,2009, 1, 26, 55, 125, 137, 153, 178, 182, 144, 93, 94, 17, 100 +290,2010, -17, 9, 58, 93, 100, 164, 204, 164, 126, 95, 52, -27, 85 +290,2011, 27, 36, 52, 124, 138, 162, 158, 168, 152, 106, 60, 55, 103 +290,2012, 36, 1, 77, 82, 145, 145, 169, 184, 134, 96, 64, 41, 98 +290,2013, 15, 9, 12, 82, 116, 154, 188, 179, 138, 118, 59, 55, 94 +290,2014, 48, 64, 81, 118, 127, 157, 195, 157, 153, 132, 80, 41, 113 +290,2015, 34, 26, 57, 87, 120, 153, 184, 185, 132, 94, 91, 92, 105 +290,2016, 34, 39, 49, 82, 144, 171, 181, 175, 171, 89, 48, 41, 102 +290,2017, 2, 44, 85, 79, 149, 179, 180, 172, 135, 126, 63, 42, 105 +""" + +months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', + 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'total'] + +def parse_data(raw_data): + years, data = [], [[] for i in range(13)] + for line in raw_data.splitlines(): + if line.startswith('290'): + parts = [int(i.strip()) for i in line.split(',')] + years.append(parts[1]) + for i in range(13): + data[i].append(parts[i+2]/10.0) + return years, data + +years, data = parse_data(raw_data) + + +class Twente(flx.Widget): + + def init(self): + + with flx.HFix(): + flx.Widget(flex=1) + with flx.VBox(flex=0, minsize=200): + with flx.GroupWidget(title='Plot options'): + flx.Label(text='Month') + self.month = flx.ComboBox(options=months, selected_index=12, style='width: 100%') + self.smoothing_label = flx.Label(text='Smoothing') + self.smoothing = flx.Slider(max=20, step=2, text='{value} samples') + flx.Widget(flex=3) + with flx.VBox(flex=4): + self.plot = flx.PlotWidget(flex=1, + xdata=years, yrange=(-5, 20), + title='Average monthly temperature', + xlabel='year', ylabel=u'temperature (°C)') + flx.Widget(flex=1) + + @flx.reaction + def _update_plot(self): + smoothing = self.smoothing.value + yy1 = data[self.month.selected_index] + yy2 = [] + + sm2 = int(smoothing / 2) + for i in range(len(yy1)): + val = 0 + n = 0 + for j in range(max(0, i-sm2), min(len(yy1), i+sm2+1)): + val += yy1[j] + n += 1 + if n == 0: + yy2.append(yy1[i]) + else: + yy2.append(val / n) + + self.plot.set_data(self.plot.xdata, yy2) + + +if __name__ == '__main__': + a = flx.App(Twente, title='Temperature 1951 - 2014', style = 'background:#eaeaea;') + m = a.launch('app', size=(900, 400)) + flx.run() \ No newline at end of file diff --git a/studentdb.kv b/studentdb.kv new file mode 100644 index 0000000..b58c100 --- /dev/null +++ b/studentdb.kv @@ -0,0 +1,50 @@ +# Reference GUItest_kivy.py +#: import main studentdb +#: import ListAdapter kivy.adapters.listadapter.ListAdapter +#: import ListItemButton kivy.uix.listview.ListItemButton + +StudentDB: + +: + orientation: "vertical" + first_name_text_input: first_name + last_name_text_input: last_name + student_list: students_list_view + padding: 10 + spacing: 10 + + BoxLayout: + size_hint_y: None + height: "40dp" + + Label: + text: "First Name" + TextInput: + id: first_name + Label: + text: "Last Name" + TextInput: + id: last_name + + BoxLayout: + size_hint_y: None + height: "40dp" + Button: + text: "Submit" + size_hint_x: 15 + on_press: root.submit_student() + Button: + text: "Delete" + size_hint_x: 15 + on_press: root.delete_student() + Button: + text: "Replace" + size_hint_x: 15 + on_press: root.replace_student() + + # Define starting data and point to the ListItemButton + # in the Python code + ListView: + id: students_list_view + adapter: + ListAdapter(data=["Doug Smith"], cls=main.StudentListButton) \ No newline at end of file diff --git a/studentdb.py b/studentdb.py new file mode 100644 index 0000000..4bb3e06 --- /dev/null +++ b/studentdb.py @@ -0,0 +1,76 @@ +# ---------- KIVY TUTORIAL PT 4 ---------- + +# In this part of my Kivy tutorial I'll show how to use +# the ListView, ListAdapter and how to create a toolbar + +# ---------- studentdb.py ---------- + +from kivy.app import App +from kivy.uix.boxlayout import BoxLayout +from kivy.properties import ObjectProperty +from kivy.uix.listview import ListItemButton + + +class StudentListButton(ListItemButton): + pass + + +class StudentDB(BoxLayout): + # Connects the value in the TextInput widget to these + # fields + first_name_text_input = ObjectProperty() + last_name_text_input = ObjectProperty() + student_list = ObjectProperty() + + def submit_student(self): + + # Get the student name from the TextInputs + student_name = self.first_name_text_input.text + " " + self.last_name_text_input.text + + # Add the student to the ListView + self.student_list.adapter.data.extend([student_name]) + + # Reset the ListView + self.student_list._trigger_reset_populate() + + def delete_student(self, *args): + + # If a list item is selected + if self.student_list.adapter.selection: + # Get the text from the item selected + selection = self.student_list.adapter.selection[0].text + + # Remove the matching item + self.student_list.adapter.data.remove(selection) + + # Reset the ListView + self.student_list._trigger_reset_populate() + + def replace_student(self, *args): + + # If a list item is selected + if self.student_list.adapter.selection: + # Get the text from the item selected + selection = self.student_list.adapter.selection[0].text + + # Remove the matching item + self.student_list.adapter.data.remove(selection) + + # Get the student name from the TextInputs + student_name = self.first_name_text_input.text + " " + self.last_name_text_input.text + + # Add the updated data to the list + self.student_list.adapter.data.extend([student_name]) + + # Reset the ListView + self.student_list._trigger_reset_populate() + + +class StudentDBApp(App): + def build(self): + return StudentDB() + + +dbApp = StudentDBApp() + +dbApp.run() \ No newline at end of file diff --git a/style.css b/style.css new file mode 100644 index 0000000..3f78010 --- /dev/null +++ b/style.css @@ -0,0 +1,5 @@ +{ + + + +} \ No newline at end of file diff --git a/zhibo8 v1.py b/zhibo8 v1.py new file mode 100644 index 0000000..91c9bce --- /dev/null +++ b/zhibo8 v1.py @@ -0,0 +1,54 @@ +import re, requests, tkinter +from tkinter import ttk + + +def getHtml(url="https://www.zhibo8.cc/"): + req = requests.get(url) + + if req.encoding == 'ISO-8859-1': + encodings = requests.utils.get_encodings_from_content(req.text) + if encodings: + encoding = encodings[0] + else: + encoding = req.apparent_encoding + + encode_content = req.content.decode(encoding, 'replace') # 如果设置为replace,则会用?取代非法字符; + return encode_content + else: + return req.text + + +def sortByTime(listWithTimein2): + return listWithTimein2[1] + + +def showTeam(*args): + app = tkinter.Tk() + app.title('zhibo8数据过滤') + app.geometry('700x700') + + tree = ttk.Treeview(app, columns=('时间', '赛事', '转播'), + show='headings', + height=700) + + tree.column("时间", width=150) # 表示列,不显示 + tree.column("赛事", width=300) + tree.column("转播", width=250) + + showList = [] + + for team in args: + targetRE = '
  • (.*?)' + results = re.findall(targetRE, getHtml(), re.S) + for result in results: + if team in result[0] and result not in showList: + showList.append(result) + showList.sort(key=sortByTime) + for i in showList: + tree.insert("", 100, values=(i[1], i[0], i[2]), tags='even') + + tree.pack() + app.mainloop() + + +showTeam('国安', '利物浦', '阿森纳', '热刺', '勇士', '火箭', '皇家马德里') # 备选球队: diff --git a/zhibo8_v2.py b/zhibo8_v2.py index d5e4b20..f962f91 100644 --- a/zhibo8_v2.py +++ b/zhibo8_v2.py @@ -8,6 +8,7 @@ targetRE = '
  • (.*?)' ''' +from flexx import flx import re, requests, tkinter from tkinter import ttk # , Frame @@ -51,28 +52,28 @@ def sortByTime(listWithTimein2): def showTeam(*args): - app = tkinter.Tk() - app.title('zhibo8数据过滤') - app.geometry('700x700') - # frame = Frame(app) - # frame.place(x=0, y=0, width=700, height=700) - # scrollBar = tkinter.Scrollbar(frame) - # scrollBar.pack(side=tkinter.RIGHT, fill=tkinter.Y) - # style = ttk.Style() - # style.configure("mystyle.Treeview", highlightthickness=2, bd=1) # Modify the font of the body - # style.configure("mystyle.Treeview.Heading", font=('Calibri', 14, 'bold')) # Modify the font of the headings - # style.layout("mystyle.Treeview", [('mystyle.Treeview.treearea', {'sticky': 'nswe'})]) # Remove the borders - - tree = ttk.Treeview(app, columns=('时间', '赛事', '转播'), - show='headings', - height=700) - - # tree["columns"] = ("比赛", "时间", "转播") - tree.column("时间", width=150) # 表示列,不显示 - tree.column("赛事", width=300) - tree.column("转播", width=250) - # tree.tag_configure('even', background = '#E8E8E8') - # tree.tag_configure('odd', background = '#DFDFDF') + # app = tkinter.Tk() + # app.title('zhibo8数据过滤') + # app.geometry('700x700') + # # frame = Frame(app) + # # frame.place(x=0, y=0, width=700, height=700) + # # scrollBar = tkinter.Scrollbar(frame) + # # scrollBar.pack(side=tkinter.RIGHT, fill=tkinter.Y) + # # style = ttk.Style() + # # style.configure("mystyle.Treeview", highlightthickness=2, bd=1) # Modify the font of the body + # # style.configure("mystyle.Treeview.Heading", font=('Calibri', 14, 'bold')) # Modify the font of the headings + # # style.layout("mystyle.Treeview", [('mystyle.Treeview.treearea', {'sticky': 'nswe'})]) # Remove the borders + # + # tree = ttk.Treeview(app, columns=('时间', '赛事', '转播'), + # show='headings', + # height=700) + # + # # tree["columns"] = ("比赛", "时间", "转播") + # tree.column("时间", width=150) # 表示列,不显示 + # tree.column("赛事", width=300) + # tree.column("转播", width=250) + # # tree.tag_configure('even', background = '#E8E8E8') + # # tree.tag_configure('odd', background = '#DFDFDF') showList = [] @@ -83,13 +84,32 @@ def showTeam(*args): if team in result[0] and result not in showList: showList.append(result) showList.sort(key=sortByTime) + return showList # total = len(showList) - for i in showList: - # print('{0:18}{1:35}{2:20}'.format(i[1], i[0], i[2])) #本行为终端输出,下面是tk输出 - tree.insert("", 100, values=(i[1], i[0], i[2]), tags='even') - - tree.pack() - app.mainloop() - - -showTeam('国安', '利物浦', '阿森纳', '热刺', '勇士', '火箭', '皇家马德里') # 备选球队: + # for i in showList: + # # print('{0:18}{1:35}{2:20}'.format(i[1], i[0], i[2])) #本行为终端输出,下面是tk输出 + # tree.insert("", 100, values=(i[1], i[0], i[2]), tags='even') + # + # tree.pack() + # app.mainloop() + + +class DrawTable(flx.Widget): + + def init(self): + with flx.VBox(): + with flx.VBox(style='border:1px solid #777;'): + flx.Label(text='zhibo8数据采集') + for event in self.showlist: + with flx.HFix(flex=1, style='border-bottom:1px solid #ddd; font-size: 14px;'): + self.b1 = flx.Label(flex=1, text=event[1]) + self.b2 = flx.Label(flex=1, text=event[0]) + self.b3 = flx.Label(flex=1, text=event[2]) + + +if __name__ == '__main__': + showListReady = showTeam('国安', '利物浦', '阿森纳', '热刺', '勇士', '火箭', '皇家马德里') + print(showListReady) + target = DrawTable() + m = flx.launch(target) + flx.run()