我们从Python开源项目中,提取了以下24个代码示例,用于说明如何使用ui.get_screen_size()。
def did_change_size(self, old_size): print('did_change_size: {} --> {}'.format(old_size, self.size)) #w, h = ui.get_screen_size() global square_size #, half_ss, tile_Size, piece_Size w, h = self.size square_size = min(w, h) / 8 #half_ss = square_size / 2 tile_Size = sk.Size(square_size, square_size) piece_Size = sk.Size(square_size - 2, square_size - 2) for node in self.get_children_with_name('*'): if isinstance(node, sk_BoardSquare): node.size = tile_Size elif isinstance(node, sk_ChessPiece): node.size = piece_Size else: print(node)
def get_view(download_action, refresh_all_views, delete_action, refresh_usercontributed_action, theme_manager): w,h = ui.get_screen_size() tv.width = w tv.height = h tv.flex = 'WH' tv.name = 'User Contributed Docsets' data = UserContributedManagementView(download_action, refresh_all_views, delete_action, refresh_usercontributed_action, theme_manager) tv.delegate = data tv.data_source = data return tv
def get_view(docsets, download_action, refresh_docsets_action, delete_action, refresh_main_view, theme_manager): w,h = ui.get_screen_size() tv.width = w tv.height = h tv.flex = 'WH' tv.name = 'Docsets' data = DocsetManagementView(docsets, download_action, refresh_docsets_action, delete_action, refresh_main_view, theme_manager) tv.delegate = data tv.data_source = data return tv
def get_view(theme_manager): tv = ui.TableView() w,h = ui.get_screen_size() tv.width = w tv.height = h tv.flex = 'WH' tv.name = 'PyDoc' data = DocsetView(theme_manager) tv.delegate = data tv.data_source = data return tv
def get_view(show_docset_management_view, show_cheatsheet_management_view, show_usercontributed_management_view, theme_manager, show_stackoverflow_management_view,websearch_manager, show_transfer_management_view): w,h = ui.get_screen_size() tv.width = w tv.height = h tv.flex = 'WH' tv.name = 'Settings' data = SettingsView(show_docset_management_view, show_cheatsheet_management_view, show_usercontributed_management_view, theme_manager, show_stackoverflow_management_view,websearch_manager, show_transfer_management_view) tv.delegate = data tv.data_source = data return tv
def get_view(download_action, refresh_all_views, delete_action, refresh_stackoverflow_action, theme_manager): w,h = ui.get_screen_size() tv.width = w tv.height = h tv.flex = 'WH' tv.name = 'Stack Overflow Docsets' data = StackOverflowManagementView(download_action, refresh_all_views, delete_action, refresh_stackoverflow_action, theme_manager) tv.delegate = data tv.data_source = data return tv
def get_view(download_action, refresh_all_views, delete_action, refresh_transfer_action, theme_manager, transfer_manager): w,h = ui.get_screen_size() tv.width = w tv.height = h tv.flex = 'WH' tv.name = 'Transferred Docsets' data = TransferManagementView(download_action, refresh_all_views, delete_action, refresh_transfer_action, theme_manager, transfer_manager, tv) tv.delegate = data tv.data_source = data return tv
def get_view(download_action, refresh_all_views, delete_action, refresh_cheatsheets_action, theme_manager): w,h = ui.get_screen_size() tv.width = w tv.height = h tv.flex = 'WH' tv.name = 'Cheatsheets' data = CheatsheetManagementView(download_action, refresh_all_views, delete_action, refresh_cheatsheets_action, theme_manager) tv.delegate = data tv.data_source = data return tv
def get_view(theme_manger, stackOverflowOnlineCallback): tv = ui.TableView() w,h = ui.get_screen_size() tv.width = w tv.height = h tv.flex = 'WH' tv.name = 'PyDoc' data = DocsetIndexView(theme_manger, stackOverflowOnlineCallback) tv.delegate = data tv.data_source = data return tv
def size(self): """Get screen size.""" return ui.get_screen_size()
def screen_frames(status_height=24): w, h = ui.get_screen_size() # (1024, 768) on iPad in landscape mode assert w > h, 'This app only works in landscape mode!!' square_side = min(w, h) - status_height # make room for a line of status text panel_width = (w - square_side) / 2 center_frame = sk.Rect(panel_width, 0, square_side, square_side) left_frame = sk.Rect(0, 0, panel_width, square_side) right_frame = sk.Rect(panel_width + square_side, 0, panel_width, square_side) status_frame = sk.Rect(0, square_side, w, status_height) return center_frame, left_frame, right_frame, status_frame #print(screen_frames())
def __init__(self, game=None): self.game = game or ChessGame() self.width, self.height = ui.get_screen_size() assert self.width > self.height, 'This app only works in landscape mode!!' if photos.is_authorized(): # add a photo as the background image self.add_subview(self.make_image_view()) center_frame, left_frame, right_frame, status_frame = screen_frames() self.add_subview(self.make_left_side_view(left_frame)) self.make_buttons(left_frame) self.add_subview(self.make_board_scene(center_frame)) self.info_view = self.make_right_side_view(right_frame) self.add_subview(self.info_view) self.status_view = self.make_status_view(status_frame) self.add_subview(self.status_view) self.present(orientations=['landscape'], hide_title_bar=True)
def tableview_cell_for_row(self, tableview, section, row): self.width, height = ui.get_screen_size() cell = ui.TableViewCell() cell.bounds = (0,0,self.width,self.row_height) for i in range(3): self.make_labels(cell, tableview.data_source.items[row][i], i) return cell
def __init__(self): w,h = ui.get_screen_size() self.ty = ui.Label() self.ty.text = 'Hello' self.ty.text_color = 'black' self.ty.font = ('<system>', 60) self.ty.frame = (0, 0, w, h*0.25) self.ty.bg_color = 'yellow' self.sv = ui.ScrollView() self.sv.width = w self.sv.height = h*0.25 self.sv.content_size = (2*w, h*0.25) self.sv.add_subview(self.ty) self.add_subview(self.sv)
def get_keyboard_frame(self,frame=None): '''get corrected keyboard frame, in the screen coordinates. built in function breaks when in fullscreen, as it reports kbframe relative to a landscape screen''' #TODO: remove dependence on webview, use xaxis/yaxis to determine rotation instead if frame is None: frame=ui.get_keyboard_frame() origin=ui.convert_point((0,0),None,self ) xaxis=ui.convert_point((1,0),None,self ) xaxis=[xaxis[j]-origin[j] for j in (0,1)] yaxis=ui.convert_point((0,1),None,self ) yaxis=[yaxis[j]-origin[j] for j in (0,1)] o=self.__w.eval_js('window.orientation') (w,h)=ui.get_screen_size() if xaxis[0]==1 and yaxis[1]==1 and frame[0]==0: #we are not in fullscreen, just return kbframe fixedframe=frame elif o=='0': fixedframe= frame #ok elif o=='-90': fixedframe= [frame[1], frame[0], h,frame[2]] elif o=='180': fixedframe= [frame[0], h-frame[1]-frame[3], frame[2],frame[3]] #okrqq elif o=='90': fixedframe= [frame[1], w-frame[0]-frame[2],h,frame[2]] else: raise Error('UnexpectedOrientation') return fixedframe
def __init__(self,tablist=[], frame=(0,0)+ui.get_screen_size()): '''takes an iterable of Views, using the view name as the tab selector. empty views sre just given generic names''' self.tabcounter=0 #unique counter, for name disambiguation self.buttonheight=30 #height of buttonbar #setup button bar self.tabbuttons=ui.SegmentedControl(frame=(0,-5,self.width, self.buttonheight+5),bg_color='white') self.tabbuttons.action=self.tab_action self.tabbuttons.flex='W' self.tabbuttons.segments=[] self.add_subview(self.tabbuttons) for tab in tablist: self.addtab(tab)
def convert_point(self,point=(0,0),from_view=None,to_view=None): '''fixed convert point for fullscreen application. works for any present type existing function in fullscreen reports relative to portrait TODO: does not work if from_view or to_view has been Transformed''' (w,h)=ui.get_screen_size() #detect what convert_point things rotation is. origin=ui.convert_point((0,0),from_view,to_view ) xaxis=ui.convert_point((1,0),from_view,to_view ) xaxis=[xaxis[j]-origin[j] for j in (0,1)] yaxis=ui.convert_point((0,1),from_view,to_view ) yaxis=[yaxis[j]-origin[j] for j in (0,1)] pt_c=ui.convert_point(tuple(point),from_view,to_view) pt=[0,0] if from_view is not None: pt[0]=( (xaxis[0]==-1)*h + xaxis[0]*pt_c[0] + (yaxis[0]==1)*w - yaxis[0]*pt_c[1]) pt[1] = ( (xaxis[1]==1)*h - xaxis[1]*pt_c[0] + (yaxis[1]==-1)*w + yaxis[1]*pt_c[1]) else: #just get corrected origin, and subtract out origin_offset=self.convert_point((0,0),to_view,from_view) pt[0]= point[0] - origin_offset[0] pt[1]= point[1] - origin_offset[1] return tuple(pt)
def get_keyboard_frame(self): '''get corrected keyboard frame, in the screen coordinates. built in function breaks when in fullscreen, as it reports kbframe relative to a landscape screen''' #TODO: remove dependence on webview, use xaxis/yaxis to determine rotation instead origin=ui.convert_point((0,0),None,self ) xaxis=ui.convert_point((1,0),None,self ) xaxis=[xaxis[j]-origin[j] for j in (0,1)] yaxis=ui.convert_point((0,1),None,self ) yaxis=[yaxis[j]-origin[j] for j in (0,1)] o=self.__w.eval_js('window.orientation') frame=ui.get_keyboard_frame() (w,h)=ui.get_screen_size() if xaxis[0]==1 and yaxis[1]==1 and frame[0]==0: #we are not in fullscreen, just return kbframe fixedframe=frame elif o=='0': fixedframe= frame #ok elif o=='-90': fixedframe= [frame[1], frame[0], h,frame[2]] elif o=='180': fixedframe= [frame[0], h-frame[1]-frame[3], frame[2],frame[3]] #okrqq elif o=='90': fixedframe= [frame[1], w-frame[0]-frame[2],h,frame[2]] else: raise Error('UnexpectedOrientation') return fixedframe
def main(args): if ui.get_screen_size()[0] >= 768: from filenav import full full.main(args) else: from filenav import slim slim.main(args)
def display_toast(view, help_text, width = 220, height = 110, show_duration=2, fade_duration=0.5, background_colour=(.42, .42, .42), text_colour= (.96, .96, .96), corner_radius=10): w, h = ui.get_screen_size() help_view = ui.View(frame=((w/2)-(width/2),(h/2)-height, width, height)) help_view.background_color = background_colour help_view.corner_radius = corner_radius label = ui.Label() label.text = help_text label.flex = 'H' label.width = help_view.width * 0.9 label.alignment = ui.ALIGN_CENTER label.x = (help_view.width / 2) - (label.width / 2) label.y = (help_view.height / 2) - (label.height / 2) label.number_of_lines = 3 label.text_color = text_colour help_view.add_subview(label) def animation_fade_in(): help_view.alpha = 1.0 def animation_fade_out(): help_view.alpha = 0.0 help_view.alpha = 0.0 view.add_subview(help_view) ui.animate(animation_fade_in, duration=fade_duration) time.sleep(show_duration+fade_duration) ui.animate(animation_fade_out, duration=fade_duration) time.sleep(fade_duration) view.remove_subview(help_view)
def setscreen(self): if self.kivy: from kivy.config import Config Config.set('input', 'mouse', 'mouse,multitouch_on_demand') from kivy.uix.floatlayout import FloatLayout from kivy.core.window import Window from kivy.utils import platform as core_platform self.root = FloatLayout() if (self.xratio == 0) or (self.yratio == 0): if core_platform == 'android': self.screen_size = Window.size else: self.screen_size = (800, 600) self.xratio = self.screen_size[0] / 800.0 self.yratio = self.screen_size[1] / 600.0 if core_platform == 'android': Window.softinput_mode = 'pan' else: Window.size = self.screen_size else: import ui if (self.xratio == 0) or (self.yratio == 0): ss1 = ui.get_screen_size()[0] ss3 = ui.get_screen_size()[1] notoptimal = True while notoptimal: if ss1 % 8 == 0: notoptimal = False else: ss1 -= 1 ss1 = ss1 - 124 ss2 = (ss1 / 4) * 3 if ss2 > ss3: ss2 = ss3 - ss2 - ((ss3 - ss2) % 3) ss1 = (ss2 / 3) * 4 self.screen_size = (ss1, ss2) self.xratio = self.screen_size[0] / 800 self.yratio = self.screen_size[1] / 600 self.root = ui.View(frame=(0,0,self.screen_size[0], \ self.screen_size[1]))
def setscreen(self): if self.kivy: from kivy.config import Config Config.set('input', 'mouse', 'mouse,multitouch_on_demand') from kivy.uix.floatlayout import FloatLayout from kivy.core.window import Window from kivy.utils import platform as core_platform self.root = FloatLayout() if (self.xratio == 0) or (self.yratio == 0): if core_platform == 'android': self.screen_size = Window.size if self.screen_size[0] < self.screen_size[1]: x = self.screen_size[0] y = self.screen_size[0] / 4 * 3 self.screen_size = (x, y) else: self.screen_size = (800, 600) self.xratio = self.screen_size[0] / 800.0 self.yratio = self.screen_size[1] / 600.0 if core_platform == 'android': Window.softinput_mode = 'pan' else: Window.size = self.screen_size else: import ui if (self.xratio == 0) or (self.yratio == 0): ss1 = ui.get_screen_size()[0] ss3 = ui.get_screen_size()[1] notoptimal = True while notoptimal: if ss1 % 8 == 0: notoptimal = False else: ss1 -= 1 ss2 = (ss1 / 4) * 3 title_bar_height = int(ss3 / 600 * 50) if ss2 > ss3 - title_bar_height: ss2 = ss3 - title_bar_height notoptimal = True while notoptimal: if ss2 % 6 == 0: notoptimal = False else: ss2 -= 1 ss1 = (ss2 / 3) * 4 self.screen_size = (ss1, ss2) self.xratio = ss1 / 800 self.yratio = ss2 / 600 self.root = ui.View(frame=(0,0,self.screen_size[0], \ self.screen_size[1]))
def setscreen(self): if self.kivy: from kivy.config import Config Config.set('input', 'mouse', 'mouse,multitouch_on_demand') from kivy.uix.floatlayout import FloatLayout from kivy.core.window import Window from kivy.utils import platform as core_platform self.root = FloatLayout() if (self.xratio == 0) or (self.yratio == 0): if core_platform == 'android': self.screen_size = Window.size if self.screen_size[0] < self.screen_size[1]: x = self.screen_size[0] y = self.screen_size[0] / 4 * 3 self.screen_size = (x, y) else: self.screen_size = (800, 600) self.xratio = self.screen_size[0] / 800.0 self.yratio = self.screen_size[1] / 600.0 if core_platform == 'android': Window.softinput_mode = 'pan' else: Window.size = self.screen_size else: import ui if (self.xratio == 0) or (self.yratio == 0): ss1 = ui.get_screen_size()[0] ss3 = ui.get_screen_size()[1] notoptimal = True while notoptimal: if ss1 % 8 == 0: notoptimal = False else: ss1 -= 1 ss2 = (ss1 / 4) * 3 title_bar_height = int(ss3 / 600 * 90) if ss2 > ss3 - title_bar_height: ss2 = ss3 - title_bar_height notoptimal = True while notoptimal: if ss2 % 6 == 0: notoptimal = False else: ss2 -= 1 ss1 = (ss2 / 3) * 4 self.screen_size = (ss1, ss2) self.xratio = ss1 / 800 self.yratio = ss2 / 600 self.root = ui.View(frame=(0,0,self.screen_size[0], \ self.screen_size[1]))
def get_view(self, dbpath, tablename): self.schema_v = ui.TableView('grouped') self.data_v = ui.TableView() schema_view = self.schema_v data_view = self.data_v dbo = tableobjectsview(dbpath, tablename) self.ov = dataobjectview(dbpath, tablename) w, h = ui.get_screen_size() schema_view.name = tablename schema_view.data_source = dbo schema_view.delegate = dbo data_view.name = tablename data_view.data_source = self.ov data_view.delegate = self.ov seg = ui.SegmentedControl() seg.segments = ['Schema','Data'] seg.selected_index = 0 seg.action = self.test seg.width = w/3 seg.x = w/2 - (seg.width/2) seg.y = seg.height / 2 self.pbutton.y = seg.y self.nbutton.y = seg.y self.pbutton.x = seg.x - (seg.width/2) self.nbutton.x = seg.x + seg.width self.pbutton.width = seg.width/2 self.nbutton.width = seg.width/2 self.pbutton.hidden = True self.nbutton.hidden = True self.pbutton.action = self.prev self.nbutton.action = self.next self.nbutton.enabled, self.pbutton.enabled = self.ov.initial_button_config() t = ui.View(frame=(0,0,w,h)) t.background_color = (0.92,0.92,0.95) t.width = w t.height = h schema_view.width = w schema_view.height = t.height * 0.9 schema_view.y = 2 * seg.height data_view.width = w data_view.height = t.height * 0.9 data_view.y = 2 * seg.height data_view.hidden = True schema_view.hidden = False self.schema_v = schema_view self.data_v = data_view t.add_subview(self.schema_v) t.add_subview(self.data_v) t.add_subview(seg) t.add_subview(self.pbutton) t.add_subview(self.nbutton) return t