Example #1
0
    def __init__(self, app, master, label_text, buttons):
        dml = app.dml
        scrsize = app.scrsize
        scrmode = app.scrmode
        self.master = master
        font = (dml['topbar']['font'], dml['global']['fonts_size'][scrmode])
        self.frame = tk.Frame(master,
                              relief=tk.FLAT,
                              borderwidth=1,
                              bg=dml['topbar']['bar_bg'],
                              height=dml['topbar']['height'])
        self.frame.pack_propagate(0)  # don't shrink
        self.frame.pack(fill=tk.X, side=tk.BOTTOM)
        hostname = hlp.readfile("/etc/hostname")
        lbl_frame = tk.Frame(self.frame,
                             relief=tk.FLAT,
                             borderwidth=0,
                             bg=dml['topbar']['bar_bg'],
                             width=len(hostname) *
                             dml['global']['fonts_size'][scrmode])
        lbl_frame.pack_propagate(0)  # don't shrink
        lbl_frame.pack(fill=tk.Y, side=tk.LEFT)
        lbl = tk.Label(lbl_frame,
                       text=hostname,
                       anchor="w",
                       justify=tk.LEFT,
                       font=font,
                       bg=dml['topbar']['lbl_bg'],
                       fg=dml['topbar']['lbl_fg'])
        lbl.pack(side=tk.LEFT, padx=2)

        btn_frame = tk.Frame(self.frame,
                             relief=tk.FLAT,
                             borderwidth=0,
                             bg=dml['topbar']['bar_bg'])
        btn_frame.pack(fill=tk.Y, side=tk.RIGHT)
        for b in buttons:
            btn = tk.Button(btn_frame,
                            text=b[0],
                            command=b[1],
                            relief=tk.RAISED,
                            font=font,
                            fg=dml['topbar']['btn_fg'],
                            bg=dml['topbar']['btn_bg'],
                            highlightbackground=dml['topbar']['lbl_bg'],
                            padx=3,
                            pady=0,
                            bd=1,
                            width=4)
            btn.pack(fill=tk.Y, side=tk.RIGHT)
Example #2
0
    def __init__(self,app,master,name):
        panel.Switchpanel.__init__(self,app,master,name)
        self.app=app

        #self.app.dmp = Conf.Appconfig(self.app.ini)
        dml = self.app.dml
        scrsize=self.app.scrsize
        scrmode=self.app.scrmode
        self.hostname=hlp.readfile("/etc/hostname")
        Lockpin.hostinfo=hlp.hostinfo();
        self.bgimage= dml["global"]["bgimage_names"][ dml['global']['theme'] ]
        self.key_size_x = dml['lockpin']['keysize'][0]
        self.key_size_y = dml['lockpin']['keysize'][1]
        self.light_time = dml['lockpin']['lighttime']
        self.light_level = dml['lockpin']['lightlevel']
        self.keys_face ={}
        if scrmode==0:
            self.col_no=4
            self.y_start= dml['lockpin']['ystart'][scrmode]
            self.key_size_x = dml['lockpin']['keysize'][scrmode][0]
            self.key_size_y = dml['lockpin']['keysize'][scrmode][1]
            for k in Lockpin._keys_label4:
                self.keys_face[ k ] = Lockpin._keys[ k ]
        else:
            self.col_no=3
            self.y_start= dml['lockpin']['ystart'][scrmode]
            self.key_size_x =  dml['lockpin']['keysize'][scrmode][0]
            self.key_size_y =  dml['lockpin']['keysize'][scrmode][1]
            for k in Lockpin._keys_label3:
                self.keys_face[ k ] = Lockpin._keys[ k ]
        self.pin=""
        self.pin_active=dml['lockpin']['pinactive']
        self.x_start = int((scrsize[0]-self.key_size_x*self.col_no) / 2)
        self.y_start = int((scrsize[1]-self.key_size_y*len(self.keys_face)/self.col_no) / 2)+self.y_start
        self.canvas = tk.Canvas(self.frame,width=scrsize[0],height=scrsize[1],bg="black",bd=0, highlightthickness=0)
        self.canvas.pack(fill=tk.BOTH)

        self.drowlock()
Example #3
0
 def __init__(self,app,master,name):
     panel.Switchpanel.__init__(self,app,master,name)
     dml=self.app.dml
     scrsize=self.app.scrsize
     scrmode=self.app.scrmode
     monofont=dml['global']['font']
     bpady=15
     padsize=5
     hi=hlp.hostinfo()
     dev=hi['dev']
     #print(hi)
     mt=int(hi['MemTotal'].split(" ",1)[0]) / 1000
     mf=int(hi['MemAvailable'].split(" ",1)[0]) / 1000
     self.frame.config(bg=dml['systeminfo']['frm_bg'])
     self.info_frame = tk.Frame(self.frame,relief=tk.FLAT, bg=dml['systeminfo']['frm_bg'])
     #self.frame.pack_propagate(0) # don't shrink
     self.info_frame.place(relx=0.5, rely=0.5, anchor=tk.CENTER)
     hostname = hlp.readfile('/etc/hostname')
     if 'Hardware' in hi:
         info2=hi['model name']+", "+hi['processor']+" core\nHardware: "+hi['Hardware']+", Ser.: "+hi['Serial']+"\n"+hi['Distributor ID']+' '+hi['Release']+' '+hi['Codename']+" - "+hi['system']+"\nMemory: {:4.0f} MB total, {:4.0f} MB free".format(mt,mf)
     else:
         info2=hi['model name']+", "+hi['processor']+" core\n"+hi['Distributor ID']+' '+hi['Release']+' '+hi['Codename']+" - "+hi['system']+"\nMemory: {:4.0f} MB total, {:4.0f} MB free".format(mt,mf)
     info3="{:<6} {:<17} {}".format( "DEV:","MAC:", "IPv4:" )
     info4=""
     for d in dev:
         info4=info4+"{:<6} {:^16} {}\n".format( d[0],d[1], hlp.getip(d[0]).split("/",1)[0] )
     mmcinfo=hlp.getmmcinfo()
     info2 = info2 + "\nMMC: {}, {} free, PARTUUID: {}".format(mmcinfo['size'],mmcinfo['free'],mmcinfo['PARTUUID'])
     lbl=tk.Label(self.info_frame,text=hostname,justify=tk.CENTER,anchor=tk.CENTER,font=(monofont,dml['systeminfo']['font_size']['name']),bg=dml['systeminfo']['frm_bg'], fg=dml['systeminfo']['lbl_name_fg'],pady=3 )
     lbl.pack(fill=tk.X)
     lbl=tk.Label(self.info_frame,text=info2,justify=tk.CENTER,anchor=tk.CENTER, font=(monofont,dml['global']['fonts_size'][scrmode]), bg=dml['systeminfo']['frm_bg'], fg=dml['systeminfo']['lbl_sys_fg'])
     lbl.pack(fill=tk.X)
     lbl=tk.Label(self.info_frame,text=info3,justify=tk.LEFT,anchor="nw", font=(monofont,dml['global']['fonts_size'][scrmode]), bg=dml['systeminfo']['frm_bg'], fg=dml['systeminfo']['lbl_title_fg'])
     lbl.pack(fill=tk.X)
     self.lbl=tk.Label(self.info_frame,text=info4,justify=tk.LEFT,anchor="nw",font=(monofont,dml['global']['fonts_size'][scrmode]), bg=dml['systeminfo']['frm_bg'], fg=dml['systeminfo']['lbl_dev_fg'])
     self.lbl.pack(fill=tk.X)
     self.animation=self.getnetworks()
Example #4
0
                position = i + 1
                break

            if i == len(updated_program) - 1:
                return False
    return True


def part2(program):
    found = swap_commands("nop", "jmp", program)
    found = swap_commands("jmp", "nop", program)


test_data = [
    "nop +0",
    "acc +1",
    "jmp +4",
    "acc +3",
    "jmp -3",
    "acc -99",
    "acc +1",
    "jmp -4",
    "acc +6",
]

#
puzzle_data = helper.readfile("2020/day8data.txt")
part1(puzzle_data)

part2(puzzle_data)
Example #5
0
        diffMat = tile(inX, (dataSetsize, 1)) - dataSet  #生成同纬度的计算向量
        sqdiffMat = power(diffMat, 2)
        sqDistances = sqdiffMat.sum(axis=1)
        distances = power(sqDistances, 0.5)
        sortDistances = distances.argsort()
        print(diffMat, sqDistances, distances, sortDistances)
        classcount = {}
        for i in range(k):
            label = labels[sortDistances[i]]
            classcount[label] = classcount.get(label, 0) + 1
        sortclass = sorted(classcount)
        sortclasssize = sortclass.__len__()
        if k > sortclasssize: k = sortclasssize
        for i in range(k):
            print("第", i + 1, "类的数据类别分别为:", sortclass[i], "类有",
                  classcount[sortclass[i]], "次,与目标距离最接近的为",
                  distances[sortDistances[i]])
        return sortclass

    "可视化数据集"

    def plotdata(self):
        pass


path = "dataset.txt"
helper = helper.dataOperator()
dataMat, labelsMat = helper.readfile(path, "\t", 3)  #
datavis = helper.dataVisual(object)
datavis.dataplot(dataMat, labelsMat)
Example #6
0
    height = len(map_data)
    trees_hit = 0
    current_position = [0, 0]

    while current_position[0] < height:
        trees_hit += has_collided_with_tree(current_position, map_data)
        current_position = update_position(current_position, width, slope[0],
                                           slope[1])

    print("Part 1, Trees Hit: " + str(trees_hit))
    return trees_hit


def part2(map_data, slopes):
    tree_counter = 1
    for slope in slopes:
        tree_counter *= part1(map_data, slope)
    print("Part 2, Trees Hit:", tree_counter)


data = helper.readfile("2020/day3data.txt")
slopes = [[1, 1], [3, 1], [5, 1], [7, 1], [1, 2]]

test_data = [
    "..##.......", "#...#...#..", ".#....#..#.", "..#.#...#.#", ".#...##..#.",
    "..#.##.....", ".#.#.#....#", ".#........#", "#.##...#...", "#...##....#",
    ".#..#...#.#"
]

part1(data, slopes[1])
part2(data, slopes)
Example #7
0
import helper,re
import pprint as pr
import os.path
from sys import exit

#TODO : ADD LOGIC OF LOCATION COUNTER
#TODO : GENERATE A LIST OF UNDEFINED SYMBOLS TO BE SEARCHED IN PASS2
#TODO : CREATION OF RELATIVE ADDRESS W.R.T location counter

keywords = [i for i in 'ABCDEF']
keywords += ['ADD','MUL','SUB', 'MOV', 'START', 'END', 'DC', 'EQU', ]

global MOT, POT ,list_of_RR_instr,list_of_RM_instr,list_of_RI_instr,list_of_POT_instr,instr_list,locations,ST,ST_headers

MOT = helper.readfile("MOT.txt")
POT = helper.readfile("POT.txt")
list_of_RR_instr =  [entry for entry in MOT if entry['Format']=='01']
list_of_RM_instr = [ entry for entry in MOT if entry['Format']=='03']
list_of_RI_instr =  [ entry for entry in MOT if entry['Format']=='02']
list_of_POT_instr = [ entry for entry in POT ]
start_instr = [ entry for entry in MOT if entry['Mnemonic']=='START'][0]
end_instr = [ entry for entry in MOT if entry['Mnemonic']=='END'] [0]
instr_list = []
locations = []
ST=[]
ST_headers = ["Symbol","Value","Length","Relocation"]


def check_RR_instr(instr,MOT):
	'''
	INPUT : SINGLE LINE OF INSTR and MOT