def load_binary_syntetic(dataset, n_train): # splitting syntetic dataset X, Y = load_syntetic_dataset(dataset) Xnew = [] Ynew = [] for x, y in zip(X, Y): Xnew.append((x[0], x[1], np.ones((x[2].shape[0], 1)))) y_ = y[:, 0].astype(np.int32) labels = np.unique(y_) y[y_ == labels[0], 0] = 0 for l in labels[1:]: if l == 0: continue y[y_ == l, 0] = 1 Ynew.append(y) X = Xnew Y = Ynew x_train = X[:n_train] y_train = [ Label(y[:, 0].astype(np.int32), None, y[:, 1], True) for y in Y[:n_train] ] x_test = X[n_train:] y_test = [ Label(y[:, 0].astype(np.int32), None, y[:, 1], True) for y in Y[n_train:] ] return x_train, y_train, x_test, y_test
def test_doubled_abstract(self): test_data = lineify( textwrap.dedent("""\ [@New records of smut fungi. 4. Microbotryum coronariae comb. nov.#Title*] [@Cvetomir M. Denchev & Teodor T. Denchev#Author*] [@Institute of Biodiversity and Ecosystem Research, Bulgarian Academy of Sciences, 2 Gagarin St., 1113 Sofia, Bulgaria#Institution*] * Correspondence to: [email protected] [@Abstract — For Ustilago coronariae on Lychnis flos-cuculi, a new combination in Microbotryum, M. coronariae, is proposed. It is reported as new to Bulgaria.#Abstract*] [@Key words — Microbotryaceae, nomenclature#Key-words*] """).split('\n')) paragraphs = list(finder.parse_paragraphs(test_data)) self.assertEqual(len(paragraphs), 6) self.assertEqual(paragraphs[0].labels, [Label('Title')]) self.assertEqual(paragraphs[1].labels, [Label('Author')]) self.assertEqual(paragraphs[2].labels, [Label('Institution')]) self.assertEqual(paragraphs[3].labels, []) # correspondence self.assertEqual( paragraphs[4].labels, [Label('Abstract'), Label('Key-words')]) self.assertEqual(paragraphs[5].labels, []) # Paragraph('\n')
def load_msrc(n_full, n_train, dense=False): # loading & splitting MSRC dataset MSRC_DATA_PATH = '/home/dmitry/Documents/Thesis/data/msrc/msrc.hdf5' x_train, y_train_raw, x_test, y_test = load_msrc_hdf(MSRC_DATA_PATH) y_test = [ Label(y[:, 0].astype(np.int32), None, y[:, 1].astype(np.float64) / np.sum(y[:, 1]), True) for y in y_test ] if n_train != n_full: train_mask = load_msrc_weak_train_mask(MSRC_DATA_PATH, n_full)[:n_train] else: train_mask = [True for i in xrange(len(y_train_raw))] y_train_full = [ Label(y[:, 0].astype(np.int32), None, y[:, 1], True) for y in y_train_raw ] y_train = [] for y, f in zip(y_train_raw, train_mask): if f: y_train.append(Label(y[:, 0].astype(np.int32), None, y[:, 1], True)) else: y_train.append( Label(None, np.unique(y[:, 0].astype(np.int32)), y[:, 1], False)) x_train = [(x[0].toarray(), x[1], x[2]) for x in x_train] x_test = [(x[0].toarray(), x[1], x[2]) for x in x_test] return x_train, y_train, y_train_full, x_test, y_test
def createWidgets (self): "Creates all widgets for the dialog." # create the buttons for the next and previous buttons self.wm.register ( Button ( properties.path_dialogs + "butt-back-moff.png", properties.path_dialogs + "butt-back-mover.png", (850, 30 ), {widget.MOUSEBUTTONUP : self.prevScreen } ) ) # labels self.wm.register ( Label (self.titlefont, "Scenario order of battle ", (10,10), color=(255, 0, 0)) ) unionlabel = Label (self.smallfont, "Union brigades", (50, 80), color=(255, 255, 0) ) self.wm.register ( unionlabel ) # create the label summarizing the units of the union side unionlabel = self.createSummary ( organization.UNION, 200, 83 ) self.wm.register ( unionlabel ) # create labels for all union brigades and store the coordinate of the last used y-position lasty = self.createBrigadeLabels ( organization.UNION, 80 + unionlabel.getHeight () + 30 ); rebellabel = Label (self.smallfont, "Rebel brigades", (50, lasty + 30), color=(255, 255, 0)) self.wm.register ( rebellabel ) # create the label summarizing the units of the rebel side rebellabel = self.createSummary ( organization.REBEL, 200, lasty + 30 + 3 ) self.wm.register ( rebellabel ) # create labels for all rebel brigades unionBrigades = self.createBrigadeLabels ( organization.REBEL, lasty + 30 + rebellabel.getHeight () + 30 );
def run_game(): ai_settings = Settings() pygame.init() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption(ai_settings.screen_caption) bg = Background(screen) bg2 = Background2(screen) ship = Ship(screen) bullets = Group() aliens = Group() stats = GameStats(ai_settings) play_button = Button(ai_settings, screen, "Play") game_over_label = Label(ai_settings, screen, "Game Over! Play again!", 250, 50, 175, 300) game_paused_label = Label(ai_settings, screen, "Game Paused", 250, 50, 175, 300) gf.create_fleet(ai_settings, screen, aliens) while True: gf.check_events(ai_settings, stats, screen, ship, aliens, bullets, play_button) if stats.game_active == True: ship.update() gf.update_bullets(bullets, aliens, ai_settings, screen) gf.update_aliens(aliens, ship, ai_settings, stats, screen, bullets) gf.update_screen(ai_settings, stats, screen, bg, bg2, ship, aliens, bullets, play_button, game_over_label, game_paused_label)
def update_screen(settings, stats, screen, bg, bg2, ship, aliens, bullets, play_button, game_over_label, game_paused_label): screen.fill(settings.bg_color) bg.update(settings) bg2.update(settings) bg.blitme() bg2.blitme() set_highscore(settings, stats) if not stats.game_active and not stats.is_game_over and stats.is_game_paused: game_paused_label.draw_label() elif not stats.game_active and stats.is_game_over and not stats.is_game_paused: game_over_label.draw_label() elif not stats.game_active and not stats.is_game_over and not stats.is_game_paused: play_button.draw_button() life = "Ships: " + str(stats.ships_left) level = "Level " + str(settings.level_num) high_score = "Record: " + str(stats.high_score) high_score_label = Label(settings, screen, high_score, 100, 50, 250, 0) level_label = Label(settings, screen, level, 100, 50, 0, 0) lifeline_label = Label(settings, screen, life, 100, 50, 500, 0) lifeline_label.draw_label() level_label.draw_label() high_score_label.draw_label() ship.blitme() aliens.draw(screen) for bullet in bullets.sprites(): bullet.draw_bullet() pygame.display.flip()
def __init__(self, name, label = None, vmin=None, vmax=None, vstep=None, vformat=None, getter=None, setter=None, on_change=None, namespace=locals(), read_only=False): ''' ''' self._name = name self._namespace = namespace self._read_only = read_only self._getter = getter self._setter = setter self._on_change = on_change self._type = None if '.' in name: self._object = eval(string.join(name.split('.')[:-1],'.'),namespace) self._attribute = name.split('.')[-1] self._type = type(getattr(self._object, self._attribute)) else: self._object = None self._attribute = None self._type = type(namespace[name]) # Create dedicated entry if self._type == bool: self._entry = BoolEntry(value=self.get(), on_change=on_change, getter=self.get, setter=self.set) elif self._type == int: if vmin == None: vmin = -sys.maxint-1 if vmax == None: vmax = sys.maxint vstep = vstep or 1 vformat = vformat or '%d' self._entry = ScalarEntry(value=self.get(), on_change=on_change, getter=self.get, setter=self.set, vmin=vmin, vmax=vmax, vstep=vstep, vformat=vformat) elif self._type == float: if vmin == None: vmin = -sys.maxint-1 if vmax == None: vmax = sys.maxint vstep = vstep or 0.1 vformat = vformat or '%.2f' self._entry = ScalarEntry(self.get(), on_change=on_change, getter=self.get, setter=self.set, vmin=vmin, vmax=vmax, vstep=vstep,vformat=vformat) elif self._type == str: self._entry = TextEntry(self.get(), self.get, self.set, on_change=on_change) else: self._entry = Label(str(self.get())) if self._read_only: self._entry.focusable = False self._entry.activable = False if label: self._label = Label(label) else: self._label = Label(name) HBox.__init__(self, [self._label, self._entry], homogeneous=True)
def __init__(self): self._share = type(self).START_SHARE self._share_diff_sum = 0 self._last_share_diff = 0 self._label = Label('', 0, 0, font_size=20) self._diff_label = Label('', 0, 0, font_size=20) self.update() get_game().register('on_draw', self.on_draw)
def create_design_page(self,notebook,page_num): frame = notebook.get_frame(page_num) self.label_dict["# Parameters"] = Label(frame, "# Parameters") w1 = Dropdown(frame, ["1 Parameter", "2 Parameters"]) self.label_dict["Variable 1"] = Label(frame, "Variable 1") w2 = Dropdown(frame, self.var_names) self.label_dict["Variable 2"] = Label(frame, "Variable 2") w3 = Dropdown(frame, self.var_names)
def main() -> None: people = [ Person(Label("Alice"), Label("*****@*****.**")), Person(Label("Boby"), Label("*****@*****.**")), Person(Label("Chirs"), None) ] for p in people: print(p) p.display() print("")
def createWidgets(self): "Creates all widgets for the dialog." # labels self.wm.register( Label(self.titlefont, "Welcome to Civil", (10, 10), color=(255, 0, 0))) self.wm.register( Label(self.smallfont, "Scenario:", (50, 180), color=(255, 255, 255))) self.wm.register( Label(self.smallfont, "Play as: ", (50, 210), color=(255, 255, 255))) self.wm.register( Label(self.smallfont, "Server name: ", (50, 240), color=(255, 255, 255))) self.wm.register( Label(self.smallfont, "My name: ", (50, 270), color=(255, 255, 255))) # create the changeable labels self.scenariolabel = Label(self.smallfont, "no scenario selected", (200, 180), color=(255, 255, 0)) self.sidelabel = Label(self.smallfont, "not yet set", (200, 210), color=(255, 255, 0)) self.serverlabel = Label(self.smallfont, scenario.connection.getHost(), (200, 240), color=(255, 255, 0)) self.usernamelabel = Label(self.smallfont, scenario.local_player_name, (200, 270), color=(255, 255, 0)) # register the labels for management self.wm.register(self.serverlabel) self.wm.register(self.scenariolabel) self.wm.register(self.sidelabel) self.wm.register(self.usernamelabel) # buttons self.wm.register( Button(properties.path_dialogs + "butt-new-game-moff.png", properties.path_dialogs + "butt-new-game-mover.png", (40, 650), {widget.MOUSEBUTTONUP: self.newGame})) self.wm.register( Button(properties.path_dialogs + "butt-loadgame-moff.png", properties.path_dialogs + "butt-loadgame-mover.png", (282, 650), {widget.MOUSEBUTTONUP: self.loadGame})) self.wm.register( Button(properties.path_dialogs + "butt-quit-moff.png", properties.path_dialogs + "butt-quit-mover.png", (772, 650), {widget.MOUSEBUTTONUP: self.quit}))
def __init__(self, context, text, parameter, x, y): ''' A visual display for displaying and incrementing parametric.Parameter values in fixed steps. ''' x *= context.xscale y *= context.yscale self.parameter = parameter fontsize = 80 Label(context, text, int(x), int(y), fontsize, context.black, centered=False) context.add_widget(IconButton(context, "./icons/remove-circle.png", x+120, y+18, self.minus_x, scale=1.25)) self.value = Label(context, '+200.0', x+160, y, fontsize, context.black, centered=False) context.add_widget(IconButton(context, "./icons/add-circle.png", x+370, y+18, self.plus_x, scale=1.25)) self.update(self.parameter.value)
def create_simulate_page(self,notebook,page_num): frame = notebook.get_frame(page_num) b1 = Button(frame,'SIMULATE') self.label_dict["# Parameters"] = Label(frame, "Event") w1 = Dropdown(frame, ["Endurance","Acceleration","Skidpad","All"]) self.label_dict["Variable 1"] = Label(frame, "Car Selection") w2 = Dropdown(frame, ["None"]) self.label_dict["Variable 2"] = Label(frame, "Track selection") w3 = Dropdown(frame, ["Michigan","Germany"])
def Init(self): self._CanvasHWND = pygame.Surface((self._Width,self._Height)) self._TopLabel = Label() self._TopLabel.SetCanvasHWND(self._CanvasHWND) self._TopLabel.Init("System shutdown in", self._TextFont1, self._FGColor) self._BottomLabel = Label() self._BottomLabel.SetCanvasHWND(self._CanvasHWND) self._BottomLabel.Init("Press any key to stop countdown", self._TextFont2, self._FGColor) self._NumberLabel = Label() self._NumberLabel.SetCanvasHWND(self._CanvasHWND) self._NumberLabel.Init(str(self._Number), self._CounterFont, self._FGColor)
def __init__(self, id, center, canvas, color=VERTEX_FILL_COLOR): Element.__init__(self, id) self.center = center self.color = color self.canvas = canvas self.degree = 0 self.edgeGroups = [] self.label = Label( id, id, Point(center.x + VERTEX_RADIUS, center.y - VERTEX_RADIUS)) self.degree = 0 self.degreeLabel = Label( id, self.degree, Point(center.x - VERTEX_RADIUS, center.y - VERTEX_RADIUS), 'red')
def createWidgets (self): "Creates all widgets for the dialog." # labels self.wm.register ( Label (self.titlefont, "Select a scenario", (10, 10), color=(255, 0, 0))) # start index for the labels x = 100 y = 100 # create a scenario manager if we don't already have one. This will read the scenarios from # the server if scenario.scenario_manager == None: scenario.scenario_manager = ServerScenarioManager () # read in all scenario info:s scenario.scenario_manager.loadScenarioIndex ( properties.path_scenarios ) # start from index 0 index = 0 # loop over all infos we got for info in scenario.scenario_manager.getScenarios (): # get the name and location name = info.getName () location = info.getLocation () # get the date and create a string (year, month, day, hour, minute) = info.getDate () date = `year` + "." + `month` + "." + `day` + " " + `hour` + ":" + `minute` # create a label text = name + ", " + location + ", " + date # create a label label = Label (self.smallfont, text, (x, y), color=(255, 255, 255), callbacks = {widget.MOUSEBUTTONUP : self.select } ) # register it self.wm.register ( label ) # make sure we know the filename from the label later self.namemap [text] = ( index, info ) # increment the y-offset and index y += label.getHeight () + 5 index += 1 # buttons. We create only the Cancel button so far, the other are created later self.wm.register ( Button ( properties.path_dialogs + "butt-cancel-moff.png", properties.path_dialogs + "butt-cancel-mover.png", (650, 650 ), {widget.MOUSEBUTTONUP : self.cancel } ) )
def createWidgets(self): "Creates all widgets for the dialog." # buttons self.wm.register( Button(properties.path_dialogs + "butt-ok-moff.png", properties.path_dialogs + "butt-ok-mover.png", (284, 650), {widget.MOUSEBUTTONUP: self.ok})) self.wm.register( Button(properties.path_dialogs + "butt-forward-moff.png", properties.path_dialogs + "butt-forward-mover.png", (528, 650), {widget.MOUSEBUTTONUP: self.nextScreen})) # get the date and create a string (year, month, day, hour, minute) = self.info.getDate() date = ` year ` + "." + ` month ` + "." + ` day ` + " " + ` hour ` + ":" + ` minute ` # labels self.wm.register( Label(self.titlefont, "Scenario information", (10, 10), color=(255, 0, 0))) self.wm.register( Label(self.smallfont, "Name: ", (50, 80), color=(255, 255, 0))) self.wm.register( Label(self.smallfont, "Date: ", (50, 110), color=(255, 255, 0))) self.wm.register( Label(self.smallfont, date, (200, 110), color=(255, 255, 255))) self.wm.register( Label(self.smallfont, self.info.getName(), (200, 80), color=(255, 255, 255))) self.wm.register( Label(self.smallfont, "Location: ", (50, 140), color=(255, 255, 0))) self.wm.register( Label(self.smallfont, self.info.getLocation(), (200, 140), color=(255, 255, 255))) self.wm.register( Label(self.smallfont, "Turns: ", (50, 170), (0, 0, 0), color=(255, 255, 0))) self.wm.register( Label(self.smallfont, str(self.info.getMaxTurns()), (200, 170), color=(255, 255, 255))) self.wm.register( Label(self.smallfont, "Description:", (50, 200), color=(255, 255, 0)))
def __init__(self): self.table = Table([ Column('Folder', 50), Column('Messages', 10), Column('Progress', 10), Column('Result', 8) ], borders=False) self.table.draw_at((1, 7)) self.current = Label(100) self.current.draw_at((1, 3)) self.label = Label(100) self.label.draw_at((1, 1)) self.label.set_text('Downloading:') self.folders = [] hide_cursor()
def AddLabel(self, text, fontobj): if self._Label == None: self._Label = Label() self._Label.Init(text, fontobj) else: #just replace the text self._Label._Init(text, fontobj)
def Init(self): self._PosX = self._Index * self._Screen._Width self._Width = self._Screen._Width self._Height = self._Screen._Height self._CanvasHWND = self._Screen._CanvasHWND ps = ListPageSelector() ps._Parent = self self._Ps = ps self._PsIndex = 0 li = Label() li.SetCanvasHWND(self._CanvasHWND) li.Init(self._ConfirmText, self._ListFont) li._PosX = (self._Width - li._Width) / 2 li._PosY = (self._Height - li._Height) / 2 self._BGPosX = li._PosX - 10 self._BGPosY = li._PosY - 10 self._BGWidth = li._Width + 20 self._BGHeight = li._Height + 20 self._MyList.append(li)
def __init__(self, screen, message): """ screen """ GameObject.__init__(self) self.screen = screen self.label = Label()
def addLabel(self, aText, aPos): self.mComponents.append( Label( self.mComponentXPos, self.mComponentYPos + (self.mComponentHeight + self.mPadding) * aPos, self.mComponentWidth, self.mComponentHeight, aText)) self.mComponents[-1].setFontSize(self.mFontSize)
def __init__(self, frame, font_size=30, text_align=Label.CENTER, **kwargs): View.__init__(self, frame) self._original_image = None self._disabled_image = None self._checked_image = None self.image = None self.label = None self.font_size = font_size self._checked = False self.on_tapped = Signal() for key, value in kwargs.items(): if key == 'image': self._original_image = value self.image = value if key == 'disabled_image': self._disabled_image = value if key == 'checked_image': self._checked_image = value if key == 'text': self.label = Label(self.frame, value, self.font_size, colors.WHITE, text_align)
def createSummary (self, owner, x, y): "Creates a summary label for all the units of the specified owner." companies = [] # first get all companies of all the brigades for brigade in scenario.brigades [ owner ].values (): companies = companies + brigade.getCompanies () # now set some counters counts = { unit.INFANTRY: 0, unit.CAVALRY: 0, unit.ARTILLERY: 0 } guns = 0 # loop over all companies for company in companies: # add the men to the proper counter counts [company.getType ()] += company.getMen () guns += company.getGuns () # now create a suitable label labeltext = "infantry: " + str (counts[unit.INFANTRY]) + ", cavalry: " + str (counts[unit.CAVALRY]) labeltext += ", artillery (men/guns): " + str (counts[unit.ARTILLERY]) + "/" + str (guns) # create and return the label return Label ( self.tinyfont, labeltext, (x,y), color=(255, 255, 255))
def build_label(val): tickstring = formatter(val) if formatter is not None else str(val) return Label(text=tickstring, font=self.tick_label_font, color=self.tick_label_color, rotate_angle=self.tick_label_rotate_angle, margin=self.tick_label_margin)
def _draw_title(self, gc, label=None, axis_offset=None): """ Draws the title for the axis. """ if label is None: title_label = Label(text=self.title, font=self.title_font, color=self.title_color, rotate_angle=self.title_angle) else: title_label = label # get the _rotated_ bounding box of the label tl_bounds = array(title_label.get_bounding_box(gc), float64) text_center_to_corner = -tl_bounds/2.0 # which axis are we moving away from the axis line along? axis_index = self._major_axis.argmin() if self.title_spacing != 'auto': axis_offset = self.title_spacing if (self.title_spacing) and (axis_offset is None ): if not self.ticklabel_cache: axis_offset = 25 else: axis_offset = max([l._bounding_box[axis_index] for l in self.ticklabel_cache]) * 1.3 offset = (self._origin_point+self._end_axis_point)/2 axis_dist = self.tick_out + tl_bounds[axis_index]/2.0 + axis_offset offset -= self._inside_vector * axis_dist offset += text_center_to_corner gc.translate_ctm(*offset) title_label.draw(gc) gc.translate_ctm(*(-offset)) return
def _add_gui_elements(self): self.gui_elements = [] x = Settings.DRAW_AREA_X + Settings.DRAW_AREA_WIDTH + Settings.BUTTON_PADDING y = Settings.DRAW_AREA_Y + Settings.BUTTON_PADDING width = (Settings.WIDTH - Settings.BUTTON_PADDING) - x height = 50 predict_label = Label("Prediction: ", x, y + (height + Settings.BUTTON_PADDING) * 4) self.gui_elements.append(predict_label) predict_button = Button("Predict", x, y, width, height) predict_button.set_on_action(self.controller.predict_button_on_action) predict_button.set_associated_elements((self.screen, predict_label)) self.gui_elements.append(predict_button) load_button = Button("Load Net", x, y + height + Settings.BUTTON_PADDING, width, height) load_button.set_on_action(self.controller.load_button_on_action) self.gui_elements.append(load_button)
def get_edit(edit_type='default', widget_name='GetValue', initial_value='aBc', label_text='', Left=0, Height=23, Top=0, Width=80, TopMargin=10, RightMargin=10, BottomMargin=10, LeftMargin=10, has_OnClick=False, has_OnChange=True, AutoSize=False): if label_text: if edit_type == 'default': return LabeledEdit(**key_word_args(EDIT_PARAML, locals())) else: VLay = VStackPanel() VLay.add_widget( Label(widget_name=widget_name + 'Label', Caption=label_text, BottomMargin=0)) widget = Edit(**key_word_args(EDIT_PARAML, locals())) widget.TopMargin = 0 widget.label_text = '' VLay.add_widget(widget) return VLay else: return Edit(**key_word_args(EDIT_PARAML, locals()))
def SetSmallText(self, text): l = Label() l._PosX = 40 l.SetCanvasHWND(self._Parent._CanvasHWND) l.Init(text, self._Fonts["small"]) self._Labels["Small"] = l
def __init__(self, json_struct=None): self.multiLayer=False self.topoComponents=KeyedArrayType(ServiceEndpoint, 'endpointId') self.id="" self.noPath=False self.label=Label() #import super(PathType, self).__init__(json_struct)