class KivyCardPile(CardPile): def __init__(self, name, player): super(KivyCardPile,self).__init__(name, player) self.displayed=False self.lock = threading.Lock() def initDisplay(self,xpos,ypos,scale,parentlayout,orientation): #ignores orientation self.displayed=True self.xpos=int(xpos) self.ypos=int(ypos) self.scale=scale self.layout= RelativeLayout() parentlayout.add_widget(self.layout) self.updateDisplay() def updateDisplay(self): self.layout.clear_widgets() card=self.peek() offset=0 if card.state == eCardState.good: offset=10 card2=self.peekpeek() card2.scatter.scale=self.scale card2.scatter.pos=(self.xpos,self.ypos) self.layout.add_widget(card2.scatter) card.scatter.scale=self.scale card.scatter.pos=(int(self.xpos+offset),int(self.ypos-offset)) self.layout.add_widget(card.scatter) def dealCard(self,newCardList,newState): if self.displayed: #Display the card underneath (the next top one) self.layout.clear_widgets() card=self.peekpeek() card.scatter.scale=self.scale card.scatter.pos=(self.xpos,self.ypos) self.layout.add_widget(card.scatter) super(KivyCardPile,self).dealCard(newCardList,newState) def append(self,card): #self.lock.acquire() print card super(KivyCardPile,self).append(card) offset=0 if card.state == eCardState.good: offset=10 if self.displayed: card.setDest(self.xpos+offset,self.ypos-offset,self.scale,self,True) def bringToFront(self): parent = self.layout.parent parent.remove_widget(self.layout) parent.add_widget(self.layout)
class SpecificExerciseStatisticsScreen(Screen): def __init__(self, **kwargs): super(SpecificExerciseStatisticsScreen, self).__init__(**kwargs) v_layout = BoxLayout(orientation='vertical', spacing=30) spinner_layout = BoxLayout(orientation='horizontal', spacing=30, size_hint_y=0.2) exercise_spinner_label = Label(text='Exercise:') self.exercise_spinner = Spinner() self.exercise_spinner.bind(text=self.draw_exercise) self.exercise_spinner.ex_names_and_types = {} spinner_layout.add_widget(exercise_spinner_label) spinner_layout.add_widget(self.exercise_spinner) v_layout.add_widget(spinner_layout) # self.drawing_layout = RelativeLayout() v_layout.add_widget(self.drawing_layout) # back_button = Button(text='Back', size_hint_y=0.2) back_button.on_press = self.goto_view_progress v_layout.add_widget(back_button) self.add_widget(v_layout) def goto_view_progress(self): self.parent.current = 'view_progress' def on_pre_enter(self): self.populate_spinner_with_exercises() def populate_spinner_with_exercises(self): self.exercise_spinner.text = 'Select Exercise' journal = App.get_running_app().journal ex_names_and_types = \ journal.get_dict_of_exercise_names_and_types() ex_names = [k for (k, v) in ex_names_and_types.items()] self.exercise_spinner.values = ex_names self.exercise_spinner.ex_names_and_types = ex_names_and_types def draw_exercise(self, *rest): ex_name = self.exercise_spinner.text ex_type = self.exercise_spinner.ex_names_and_types.get(ex_name) if ex_type: ex_statistics_widget = ex_type + "StatisticsWidget" ExStatWidgetClass = globals().get(ex_statistics_widget) if ExStatWidgetClass: journal = App.get_running_app().journal self.drawing_layout.clear_widgets() self.drawing_layout.add_widget( ExStatWidgetClass(ex_name, journal))
class ScrollableLabel(ScrollView): def __init__(self, **kwargs): super(ScrollableLabel, self).__init__(**kwargs) ###################################### self.ParentLayout = FloatLayout() self.ScrollWindow = RelativeLayout() self.ScrollLabel = Label() self.text = StringProperty('') ###################################### self.ScrollWindow.size_hint = (None, None) ###################################### def Set_ScrollWindow(self): self.ScrollWindow.clear_widgets() self.clear_widgets() self.width = self.ScrollWindow.width self.height = self.ScrollWindow.height self.x = 0 self.y = 0 self.do_scroll_x = False self.do_scroll_y = True self.ParentLayout.add_widget(self.ScrollWindow) self.ScrollWindow.add_widget(self) self.ScrollLabel.halign = 'left' self.ScrollLabel.valign = 'top' self.ScrollLabel.padding_x = 6 self.ScrollLabel.padding_y = 4 self.ScrollLabel.x = 0 self.ScrollLabel.y = 0 self.ScrollLabel.size_hint = (None, None) self.ScrollLabel.size = (self.width, 0) self.ScrollLabel.text_size = (self.width, None) self.ScrollLabel.color = (0, 0, 0, 1) self.ScrollLabel.texture_update() self.ScrollLabel.height = self.ScrollLabel.texture_size[1] self.add_widget(self.ScrollLabel)
class KivyApp(App): WID_MENU = 0 WID_MEMORIZE = 1 WID_VERSES = 2 WID_OPTIONS = 3 WID_ADD_VERSE = 4 WID_VERSE = 5 def __init__(self): App.__init__(self) self.root_widget = RelativeLayout() self.bg_texture = CoreImage('bg.jpg').texture self.bg_rect = Rectangle(texture=self.bg_texture, pos=self.root_widget.pos, size=Window.size) self.root_widget.canvas.add(self.bg_rect) Window.bind(size=self.on_size) self.determine_font_size() self.menu_widget = MenuWidget(self) self.verses = [] self.verses_widget = VersesWidget(self) self.options_widget = OptionsWidget(self) self.add_verse_widget = AddVerseWidget(self) self.memorize_widget = MemorizeWidget(self) self.verse_widget = VerseWidget(self) self.add_verse_popup = Popup(title='Add Verse', content=Label(text='Fetching verse...')) def on_pause(self): return True def on_resume(self): pass def on_size(self, width, height): self.bg_rect.size = Window.size def determine_font_size(self): pixel_count = Window.size[0] * Window.size[1] if pixel_count < 921600: self.font_size = 42 self.word_wrap = 5 elif pixel_count < 1440000: self.font_size = 57 self.word_wrap = 6 else: self.font_size = 72 self.word_wrap = 7 def get_verses(self): return self.verses def add_verse(self, book, chapter, verse): self.add_verse_popup.open() data = urllib2.urlopen( 'http://labs.bible.org/api/?type=json&passage=' + str(book) + '%20' + str(chapter) + ':' + str(verse)) json_data = json.load(data) self.verses.append( BibleVerse( str(book) + ' ' + str(chapter) + ': ' + str(verse), json_data[0]['text'])) self.add_verse_popup.dismiss() def remove_verse(self, verse): self.verses.remove(verse) def set_widget(self, widget): self.root_widget.clear_widgets() if widget == self.WID_VERSES: self.verses_widget.refresh() self.root_widget.add_widget(self.verses_widget) elif widget == self.WID_MENU: self.root_widget.add_widget(self.menu_widget) elif widget == self.WID_OPTIONS: self.root_widget.add_widget(self.options_widget) elif widget == self.WID_ADD_VERSE: self.root_widget.add_widget(self.add_verse_widget) elif widget == self.WID_MEMORIZE: self.memorize_widget.refresh() self.root_widget.add_widget(self.memorize_widget) elif widget == self.WID_VERSE: self.verse_widget.current_verse = 0 self.verse_widget.refresh() self.root_widget.add_widget(self.verse_widget) def build(self): self.title = 'Bible Verse Memory' self.set_widget(self.WID_MENU) return self.root_widget
class QzTable(Widget): g_min_size_x:int = 25 g_min_size_y:int = 15 def __init__(self, **kwargs): super(QzTable, self).__init__(**kwargs) self._debug = False self._first = False self.size_hint_min_x = 75 self.size_hint_min_y = 75 #------------------------------------------------ #EVENTS #------------------------------------------------ self.register_event_type('on_init_widget_event') self.register_event_type('on_cell_clicked_event') self.register_event_type('on_get_value') self.register_event_type('on_set_value') self.register_event_type('on_value_changed') #------------------------------------------------ #HELPERS #------------------------------------------------ self._dy:int = 0 #height after resizing self._dx:int = 0 #width after resizing self._top:int = 0 #top row displayed in the grid self._left:int = 0 #left col displayed in the grid self._bottom:int = 0 #bottom column displayed completely self._right:int = 0 #right column displayed completely self._col_idx = dict() self._row_idx = dict() #------------------------------------------------ #PROPERTIES #------------------------------------------------ self.multiple_col_selection = True self.multiple_row_selection = True self._slider_width:int = 35 self._col_header_height = 25 #column header height self._row_header_width = 50 #row header width self.default_row_height = 25 #Default row height self.default_col_width = 100 #Default column width self.show_row_number = True #Show row numbers in the row headers self.show_col_number = True #show the column number in the column header self._focus_col = -1 #selected column+ self._focus_row = -1 #selected row+ self._grid_cols:int = 1 #Number of grid columns+ self._grid_rows:int = 1 #Number of grid rows+ self._fixed_cols:int = 0 #Number of fixed columns+ self._fixed_rows:int = 0 #Number of fixed rows self._virtual_rows = 0 #rows in which data is accessed from other source self._col_widgets = list() #widgets used for the columns self._row_widgets = dict() #dictionary of list self._col_headers = list() #column text headers self._col_widths = list() #column widths self._sel_cols = list() #selected columns self._col_types = list() #column types self._row_heights = list() #row heights self._sel_rows = list() #selected rows self._row_headers = list() #row headers self._data = None #Data for the table. It may be self._virtual = False #virtual mode self._allow_col_sizing = True # Allow column sizing self._allow_row_sizing = True # Allow row sizing self._grid_cols = 1 self._grid_rows = 1 self.font_size = 12 #------------------------------------------------ #LAYOUT #------------------------------------------------ #set the vertical slider self._hslider = QzScrollBar(orientation = "horizontal", low_value = 0, high_value = self.grid_cols, base_value = 0, range = 1 ) self._hslider.size_hint_y = None self._hslider.height = self._slider_width self._hslider.bind(on_value_changed=self.handle_hscroll_value_changed) self._vslider = QzScrollBar(orientation = "vertical", low_value = 0, high_value = self.grid_cols, base_value = 0, range = 1) self._vslider.size_hint_x = None self._vslider.width = self._slider_width self._vslider.bind(on_value_changed=self.handle_vscroll_value_changed) """ self._hslider = Slider(min=0, max=self._grid_cols, value=0,step = 1, orientation ="horizontal", size_hint =( None,None) ,height = self._slider_width, value_track = True ) self._hslider.bind(on_touch_up = self.handle_hscroll_touch_up) #set the horizontal slider self._vslider = Slider(min=0, max=self._grid_rows, value=0,step = 1, orientation ="vertical", size_hint = (None,None), width = self._slider_width, value_track = True) self._vslider.bind(on_touch_up = self.handle_vscroll_touch_up) """ self._root_gb = GridLayout(cols = 2) #contains table and sliders self._table_vb = RelativeLayout() #column header + body self._btn_corner = None # the corner button #Add the root widget self.add_widget(self._root_gb) #table and sliders self._root_gb.add_widget(self._table_vb) self._root_gb.add_widget(self._vslider) self._root_gb.add_widget(self._hslider) self.resize_widgets(self.width,self.height) self.bind(size=self.update_layout) self.bind(pos=self.update_position) """ " Widget layout / rendering """ def resize_widgets(self,dx,dy): if self.parent != None: self._root_gb.pos = self.pos self._root_gb.size_hint = (None,None) self._root_gb.width = dx self._root_gb.height = dy self._table_vb.size_hint = (None,None) self._table_vb.height = dy - self._slider_width self._table_vb.width = dx - self._slider_width self._hslider.width = self._table_vb.width self._vslider.height = self._table_vb.height """ " Internal use only : print debug information in console """ def info(self,*args): if self._debug: print(args) def update_position(self,*args): self.resize_widgets(self.width,self.height) if self._first == False: self._first = True self.redraw(self.width,self.height) def update_size(self,rows:int,cols:int): self.grid_cols = cols self.grid_rows = rows if self._left >= self.grid_cols: self._left = self.grid_cols - 1 if self.top >= self.grid_rows: self._top = self.grid_rows - 1 def update_layout(self,*args): self.redraw(self.width,self.height) """ " """ def calc_col_header_width(self,dx,dy): return dx - self._slider_width def calc_body_width(self,dx,dy): return dx - self._slider_width - self.row_header_width def calc_row_header_height(self,dx,dy): return dy - self._slider_width - self.col_header_height def redraw(self,dx,dy): if dx < 0 : dx = self.width if dy < 0 : dy = self.height self.resize_widgets(dx,dy) if self.parent != None: self._dx = dx self._dy = dy self._table_vb.clear_widgets() self.draw_col_header(dx,dy) self.draw_row_header(dx,dy) self.update_headers_state(self._col_idx,self._row_idx) self.draw_cells(dx,dy) self._update_hscroll_new() self._update_vscroll_new() def draw_col_header(self,dx,dy): self._col_idx.clear() w = self.calc_col_header_width(dx,dy) #self._col_header_hb.height = self.col_header_height y = self.calc_row_header_height(dx,dy) self._btn_corner = Button() self._btn_corner.size_hint = (None,None) self._btn_corner.height = self.col_header_height self._btn_corner.width = self.row_header_width self._table_vb.add_widget(self._btn_corner) self._btn_corner.pos = (0,y) x = self.row_header_width l_cols = list(chain(range(0,self._fixed_cols,1), range(self._left,self._grid_cols))) for i in l_cols: cw = self._col_widths[i] self._right = i max = w - x if max <= self.g_min_size_x : self._right = i - 1 break if cw > max: cw = max btn = self.create_col_header_cell(x,y,cw,i) self._table_vb.add_widget(btn) self._col_idx[btn.column] = btn x = x + cw """ x = x position cw = column width i = data column index """ def create_col_header_cell(self,x,y,cw,i): tbtn = SizeButton(text = "" , font_size = self.font_size ) if self.show_col_number: tbtn.text = str(i) +" : "+ self._col_headers[i] else: tbtn.text = self._col_headers[i] tbtn.pos = (x,y) tbtn.size_hint_x = None tbtn.size_hint_y = None tbtn.height = self._col_header_height tbtn.horiz = True tbtn.vert = False tbtn.width = cw tbtn.column = i tbtn.row = -1 tbtn.state = "normal" tbtn.bind(on_release=self.handle_col_btn_release) tbtn.bind(size=self.handle_col_resize) return tbtn def get_col_widget(self,col): if col >= self._left and col <= self._right: for split in self._col_header_hb.children: if split.column == col: return split.children[0] else: return None return None def get_row_widget(self,row): if row >= self._left and row <= self._right: for split in self._col_header_hb.children: if split.row == row: return split.children[0] else: return None return None def draw_row_header(self,dx,dy): h = self.calc_row_header_height(dx,dy) y = 0 #y top to bottom self._row_idx.clear() l_rows = list(chain(range(0,self._fixed_rows,1),range(self._top,self._grid_rows,1))) for i in l_rows: rh = self._row_heights[i] self._bottom = i max = h - y if max <= self.g_min_size_y : self._bottom = i -1 break if rh > max: rh = max btn = self.create_row_header_cell( (h-y) - rh , rh,i) self._table_vb.add_widget(btn) self._row_idx[btn.column] = btn y = y + rh """ " y = y bottom up position of the cell " rh = row height " i = row number of the data """ def create_row_header_cell(self,y,rh,i): tbtn = SizeButton(text = "" ) tbtn.font_size = 12 tbtn.pos = (0,y) if self.show_row_number: tbtn.text = str(i) +":"+self._row_headers[i] else: tbtn.text =self._row_headers[i] tbtn.size_hint_x = None tbtn.size_hint_y = None tbtn.width = self.row_header_width tbtn.height = rh tbtn.column = -1 tbtn.row = i tbtn.bind(on_release=self.handle_row_btn_release) tbtn.bind(size=self.handle_row_resize) return tbtn """ " Draw the cells in the body of the table """ def draw_cells(self,dx,dy): lh = self.calc_row_header_height(dx,dy) lw = self.calc_col_header_width(dx,dy) #for each row y = 0 draw_top = self._top if draw_top < self.fixed_rows: draw_top = self.fixed_rows draw_left = self._left if draw_left < self._fixed_cols: draw_left = self.fixed_rows l_rows = list(chain(range(0,self._fixed_rows,1),range(draw_top,self._grid_rows,1))) l_cols = list(chain(range(0,self._fixed_cols,1),range(draw_left,self._grid_cols,1))) for row in l_rows: maxy = lh - y #No more space for rows if maxy <= self.g_min_size_y : break cy = self._row_heights[row] if cy > maxy: cy = maxy x = self._row_header_width for col in l_cols: maxx = lw - x cx = self._col_widths[col] if cx > 0: #get the widget template ww = self.get_widget_template(row,col) if maxx <= self.g_min_size_x : break if cx > maxx: cx = maxx wid:Widget = self.create_cell_widget(ww,x, (lh-y)-cy, cx,cy,col,row) self._table_vb.add_widget(wid) x = x + cx y = y + cy def get_widget_template(self,grid_row,grid_col)->object: #No widget found at row level : use the column widget if not grid_row in self._row_widgets: ww = self._col_widgets[grid_col] return ww #row found Use the row widget else: wrow = self._row_widgets[grid_row] return wrow[grid_col] """"" wtemplate: the template used to set the widget properties x : x relative position y : y relative position in widget dx : width dy : height cx : column cy : row """ def create_cell_widget(self, wtemplate,x,y, dx, dy, cx, cy): virtual : bool = False model :bool = False wclass = qzw.get_widget_class(wtemplate) NewWidget = type('NewWidget', (type(wtemplate),), {}) new_w = NewWidget() Gui.clone_widget(wtemplate,new_w) new_w.size_hint = (None,None) new_w.pos = (x,y) new_w.width = dx new_w.height = dy new_w.grid_x = cx new_w.grid_y = cy #the event handler has to set the value if self._virtual: self.trigger_get_value(new_w,cx,cy) virtual = True else: if self.virtual_rows > 0: if cy < self.virtual_rows: virtual = True self.trigger_get_value(new_w,cx,cy) if not self.data is None: if cy >= self.virtual_rows: if isinstance(self.data,pd.DataFrame): value = self.data.iloc[cy-self.virtual_rows,cx] elif isinstance(self.data,list): value = self.data[cy-self.virtual_rows][cx] elif isinstance(self.data,np.ndarray): value = self.data[cy-self.virtual_rows,cx] elif isinstance(self.data,TableModel): value = self.data.set_widget_value(self,new_w,cy,cx) model = True #raise the widget initialization event #@widget.event self.trigger_init_widget_event(new_w,cx,cy) #bind the touch event if hasattr(new_w,"touch_up"): #@widget.event new_w.bind(on_touch_up=self.handle_touch_up) if virtual == False and model == False: #this is not a cell widget if wclass == "": #if it has a text attribute set the value to the text if hasattr(wtemplate,"text"): new_w.text = str(value) else: pass else: if wclass != "": new_w.set_value(str(value)) #bind value change if wclass == "rw": #@widget.event new_w.on_value_changed=lambda value : self.trigger_value_changed(new_w,value) return new_w """---------------------------------------------------------------------------- " Internal event handlers ----------------------------------------------------------------------------""" def handle_touch_up(self,instance,touch): #check that the touch event occured in this widget if instance.collide_point(*touch.pos): self._focus_col = instance.grid_x self._focus_row = instance.grid_y self.trigger_cell_clicked_event(instance,instance.grid_x,instance.grid_y) return True """ " Internal handler for column selection """ def handle_col_btn_release(self,instance,*args): col = instance.column if instance.state == "down": self._sel_cols[col] = 1 else: self._sel_cols[col] = 0 if self.multiple_col_selection == False: self.clear_col_selection(skip=col) self._update_col_sel_widgets() """ " Internal handler for column resize """ def handle_col_resize(self,instance,*args): if self.parent != None: column = instance.column if self._col_widths[column] != int(instance.width): self._col_widths[column] = int(instance.width) self.redraw(self.width,self.height) """ " Internal handler for row resize """ def handle_row_resize(self,instance,*args): if self.parent != None: row = instance.row if self._row_heights[row] != int(instance.height): self._row_heights[row] = int(instance.height) self.redraw(self.width,self.height) """ " Internal handler for row selection """ def handle_row_btn_release(self,instance,*args): row = instance.row if instance.state =="down": self._sel_rows[row] = 1 else: self._sel_rows[row] = 0 if self.multiple_row_selection == False: self.clear_row_selection(skip=row) self._update_row_sel_widgets() """ " single column selection mode """ def clear_column_selection(self,skip:int=-1): if skip >= 0: for i in range(0,len(self._sel_cols)): if i != skip: self._sel_cols[i] = 0 else: for i in range(0,len(self._sel_cols)): self._sel_cols[i] = 0 """ " clear row selection " skip : do not de-select this row """ def clear_row_selection(self,skip:int=-1): if skip >= 0: for i in range(0,len(self._sel_rows)): if i!=skip: self._sel_rows[i] = 0 else: for i in range(0,len(self._sel_cols)): self._sel_cols[i] = 0 """ " Update the header state after redraw """ def update_headers_state(self,col_idx:dict,row_idx:dict): for idx in col_idx: btn = col_idx[idx] if self._sel_cols[idx] == 1: btn.state = "down" else: btn.state = "normal" btn.text = self._col_headers[idx] for idx in row_idx: btn = row_idx[idx] if self._sel_rows[idx] == 1: btn.state = "down" else: btn.state = "normal" """ " Obtain the widget for column i """ def get_col_widget(self,i): if i in self._col_idx: return self._col_idx[i] else: return None """ " Obtain the widget for row i """ def get_row_widget(self,i): if i in self._row_idx: return self._row_idx[i] else: return None """ " Updatee the grid view after the horizontal scroll is changed """ def handle_hscroll_touch_up(self,instance,touch): if instance.collide_point(*touch.pos): v = instance.value r = self._calculate_right() if v != self._left or r != self._right: self._left = int(v) self._right = int(r) self.redraw(self.width, self.height) """ " Update the grid view after the vertical scroll is changed """ def handle_vscroll_touch_up(self,instance,touch): if instance.collide_point(*touch.pos): v = abs(instance.value) b = self._calculate_bottom() if v != self._top or b != self._bottom: self._top = int(v) self._bottom = int(b) self.redraw(self.width, self.height) """ " Updatee the grid view after the horizontal scroll is changed """ def handle_hscroll_value_changed(self,instance,value): v = instance.base_value r = self._calculate_right1() #the scroll didn't move, the grid was resized instance.range = (r - self._left ) +1 if v != self._left or r != self._right: self._left = int(v) self.redraw(self.width, self.height) #adjust the slider range instance.range = ( self._right - self._left) +1 def handle_vscroll_value_changed(self,instance,value): v = instance.base_value b = self._calculate_bottom1() # the scroll didn't move, the grid was resized instance.range = (b - self._top ) +1 if v != self._top or b != self._bottom: self._top = int(v) self._bottom = int(b) self.redraw(self.width, self.height) instance.range = ( self._bottom - self._top )+1 """ " Event definition """ def trigger_init_widget_event(self, *args): widget = args[0] x = args[1] y = args[2] self.dispatch('on_init_widget_event', widget,x,y) def trigger_cell_clicked_event(self,*args): widget = args[0] column = args[1] row = args[2] self.dispatch('on_cell_clicked_event',widget,column,row) def trigger_get_value(self, widget,column , row): self.dispatch('on_get_value',widget,column,row) def trigger_set_value(self,*args): widget = args[0] value = args[1] column = args[2] row = args[3] self.dispatch('on_set_value',widget,value,column,row) def trigger_value_changed(self, widget,value): wclass = qzw.get_widget_class(widget) if wclass != "": col = widget.grid_x row = widget.grid_y else: col = self.focus_col row = self.focus_row self.dispatch('on_value_changed',col,row,value,widget) #----------------------------------------------------------------- #3 define the signature of the events def on_init_widget_event(self,widget,x,y): pass def on_cell_clicked_event(self,widget,x,y): pass def on_get_value(self,widget,column,row): return "" def on_get_data(self,column,row): return "" def on_set_value(self,widget,value,column,row): pass def on_value_changed(self,col,row,value,widget): self.grid_to_model(col,row,value,widget) """ Helper method: Pass the grid widget values to the data structure """ def grid_to_model(self,col,row,value,widget): if self.virtual: pass else: if row >= self.virtual_rows: if isinstance(self.data,pd.DataFrame): tt = self._col_types[col] type_value = qzw.convert_to_type(value,tt) self.data.iloc[row - self.virtual_rows,col] = type_value elif isinstance(self.data,list): tt = self._col_types[col] type_value = qzw.convert_to_type(value,tt) row = self.data[row -self.virtual_rows ] #only if it is a list of lists if isinstance(row,list): self.data[row -self.virtual_rows ][col] = type_value elif isinstance(self.data,np.ndarray): tt = self._col_types[col] type_value = qzw.convert_to_type(value,tt) self.data[row-self.virtual_rows,col] = type_value elif isinstance(self.data,TableModel): self.data.set_model_value(self,row,col,widget) """ "HELPER FUNCTIONS """ """ " Obtain the right-most column being displayed """ #@clean def _calculate_right(self)->int: right = 0 for key in self._col_idx: btn = self._col_idx[key] if btn.column > right: right = btn.column return int(right) """ " Obtain the bottom-most row being displayed """ #@clean def _calculate_bottom(self): bottom = 0 for key in self._row_idx: btn = self._row_idx[key] if btn.row > bottom: bottom = btn.row return int(bottom) def _calculate_right1(self)->int: right = 0 w = 0 maxw = self.calc_col_header_width(self.width,self.height) for i in range(self._left , self.grid_cols,1): w = w + self._col_widths[i] right = i if w > maxw: right = right -1 break return right def _calculate_bottom1(self)->int: bottom = 0 h = 0 maxh = self.calc_row_header_height(self.width,self.height) for i in range(self._top,self.grid_rows,1): h = h + self._row_heights[i] bottom = i if h > maxh: bottom = bottom - 1 break return bottom def _update_hscroll_new(self): #@clean if isinstance(self._hslider,QzScrollBar): self._hslider.low_value = 0 self._hslider.high_value = self.grid_cols self._hslider.range = int(self._right - self._left)+1 max = self.grid_rows - self._vslider.range if self._hslider.base_value > max: self._hslider.base_value = max def _update_vscroll_new(self): #@clean if isinstance(self._vslider,QzScrollBar): self._vslider.low_value = 0 self._vslider.high_value = self.grid_rows self._vslider.range = int(self._bottom - self._top ) +1 max = self.grid_rows - self._vslider.range if self._vslider.base_value > max: self._vslider.base_value = max def _check_list(self,l,axis): if axis == "c": if len(l) != self.grid_cols: raise Exception("list must match the number of columns : " +self.grid_cols) elif axis == "r": if len(l) != self.grid_rows: raise Exception("list must match the number of rows : "+self.grid_rows ) def set_widgets(self,col_widgets:Union[dict,list]): if isinstance(col_widgets,dict): for col_idx in col_widgets: value = col_widgets[col_idx] self._col_widgets[col_idx] = value elif isinstance(col_widgets,list): self._col_widgets = col_widgets def set_row_widgets(self,row,widget_s): #the row has not been created if not row in self._row_widgets: #create the row w_list = list() for i in range(0,self._grid_cols): w_list.append(qzw.CellLabel(background_color = (0.95,0.95,0.95,1))) self._row_widgets[row] = w_list #this is a widget, set the widget for the whole row if isinstance(widget_s,Widget): w_list = self._row_widgets[row] for i in range(len(w_list)): w_list[i] = widget_s #this is a dictionary, set the widget in the appropiate column elif isinstance(widget_s,dict): for col_idx in widget_s: value = widget_s[col_idx] self._col_widgets[col_idx] = value def set_types(self,col_types:Union[dict,list]): if isinstance(col_types,dict): for col_idx in col_types: tt = col_types[col_idx] self._col_types[col_idx] = tt #list : it assumes all the column types are passed elif isinstance(col_types,list): self._col_types = col_types def set_col_labels(self,col_labels:Union[dict,list]): if isinstance(col_labels,dict): for i in col_labels: value = col_labels[i] self._col_headers[i] = value elif isinstance(col_labels,list): self._col_headers = col_labels def set_col_widths(self,col_widths:Union[dict,list]): if isinstance(col_widths,dict): for i in col_widths: value = col_widths[i] self._col_widths[i] = value elif isinstance(col_widths,list): self._col_widths = col_widths def set_row_heights(self,row_heights:Union[dict,list]): if isinstance(row_heights,dict): for i in row_heights: value = row_heights[i] self._row_heights[i] = value elif isinstance(row_heights,list): self._row_widgets = row_heights def _update_col_sel_widgets(self): for idx in range(len(self._sel_cols)): val = self._sel_cols[idx] tbtn = self._col_idx[idx] if tbtn != None: if val == 1: tbtn.state = "down" else: tbtn.state = "normal" def _update_row_sel_widgets(self): for idx in range(len(self._sel_rows)): val = self._sel_rows[idx] tbtn = self._row_idx[idx] if tbtn != None: if val == 1: tbtn.state = "down" else: tbtn.state = "normal" def clear_row_selection(self): for i in range(len(self._sel_cols)): self._sel_cols[i] = 0 tbtn = self._row_idx[i] self._update_row_sel_widgets() def select_rows(self,low:int,high:int): for i in range(low,high+1): self._sel_rows[i] =1 tbtn = self._row_idx[i] tbtn.state = "normal" self._update_row_sel_widgets() def select_row_list(self,rows:list): for idx in rows: self._sel_cols[idx] = 1 tbtn = self._row_idx[idx] tbtn.state = "normal" self._update_row_sel_widgets() def select_columns(self,low:int,high:int): for i in range(low,high+1): self._sel_cols[i] = 1 tbtn = self._col_idx[i] tbtn.state = "normal" self._update_row_sel_widgets() def select_col_list(self,cols:list): for idx in cols: self._sel_rows[idx] = 1 tbtn = self._col_idx[idx] tbtn.state = "normal" self._update_col_sel_widgets() def clear_col_selection(self): for i in range(len(self._sel_rows)): self._sel_rows[i] = 0 self._update_col_sel_widgets() def get_selected_rows(self): list = [num for num in self._sel_rows if num == 1] return list def get_selected_cols(self): list = [num for num in self._sel_cols if num == 1] return list """ "PROPERTIES """ @property def virtual(self): return self._virtual @virtual.setter def virtual(self,value): self._virtual = value if value: self._virtual_rows = 0 @property def virtual_rows(self): return self._virtual_rows @virtual_rows.setter def virtual_rows(self,value): self._virtual_rows = value self.redraw(self.width,self.height) @property def allow_col_sizing(self): return self._allow_col_sizing @allow_col_sizing.setter def allow_row_sizing(self,value): self._allow_col_sizing = value for idx in self._col_idx: btn = self._col_idx[idx] btn.horiz = value @property def allow_row_sizing(self): return self._allow_row_sizing @allow_row_sizing.setter def allow_row_sizing(self,value): self.allow_row_sizing = value for idx in self._row_idx: btn = self._row_idx[idx] btn.vert = value @property def data(self): return self._data @data.setter def data(self, value): if self.virtual == False: if not value is None: self._data = value if isinstance(value, pd.DataFrame): self.grid_cols = value.shape[1] self.grid_rows = value.shape[0]+ self._virtual_rows self.resize_widgets(self.width,self.height) self.redraw(self.width,self.height) for idx,tt in enumerate(self._data.dtypes): if tt == object: tt = type("") self._col_types[idx] = tt d_cols = dict() for idx, col in enumerate(self._data.columns): d_cols[idx] = col self.set_col_labels(d_cols) elif isinstance(value, np.ndarray): self.grid_rows = self._data.shape[0] +self._virtual_rows self.grid_cols = self._data.shape[1] self.redraw(self.width,self.height) elif isinstance(value,list): self.grid_rows = len(value) +self._virtual_rows self.grid_cols = len(value[0]) self.redraw(self.width,self.height) elif isinstance(value,TableModel): self.grid_rows = self.data.get_rows() self.grid_cols = self.data.get_columns() self.set_types(self.data.get_types()) self.redraw(self.width,self.height) elif value is None: self._data = None self.fixed_cols = 0 self._fixed_rows = 0 self.grid_cols = 1 self.grid_rows = 1 + self.virtual_rows self.redraw(self.width,self.height) else: raise Exception("Invalid type") else: self._data = value @property def fixed_rows(self): return self._fixed_rows @fixed_rows.setter def fixed_rows(self,value): self._fixed_rows = value self.redraw(-1,-1) @property def fixed_cols(self): return self._fixed_cols @fixed_cols.setter def fixed_cols(self,value): self._fixed_cols = value self.redraw(-1,-1) @property def col_header_height(self): return self._col_header_height @col_header_height.setter def col_header_height(self,value): self._col_header_height = value @property def row_header_width(self): return self._row_header_width @row_header_width.setter def row_header_width(self,value): self._row_header_width = value @property def grid_cols(self): return self._grid_cols @grid_cols.setter def grid_cols(self,value): if value > len(self._col_headers): while len(self._col_headers) < value: self._col_headers.append("") #@debug lbl = qzw.CellLabel(color = (0.95,0.95,1,1),font_size = 12) #lbl = Label(color = (1,1,1,1)) self._col_widgets.append( lbl ) self._col_widths.append(self.default_col_width) self._sel_cols.append(0) self._col_types.append(type("")) for y in self._row_widgets: w_list = self._row_widgets[y] while len(w_list) < value: w_list.append(qzw.CellLabel) self._grid_cols = value if value < len(self._col_headers): self._col_headers = self._col_headers[:value] self._col_widgets = self._col_widgets[:value] self._col_widths = self._col_widths[:value] self._sel_cols = self._sel_cols[:value] self._grid_cols = value for y in self._row_widgets: w_list = self._row_widgets[y] w_list = w_list[:value] self._row_widgets[y] = w_list self._update_hscroll_new() @property def grid_rows(self): return self._grid_rows @grid_rows.setter def grid_rows(self,value): if value > len(self._row_heights): while len(self._row_heights) < value: self._row_heights.append(self.default_row_height) self._row_headers.append("") self._sel_rows.append(0) self._grid_rows = value if value < len(self._row_heights): self._row_heights = self._row_heights[:value] self._row_headers = self._row_headers[:value] self._sel_rows = self._sel_rows[:value] self._update_vscroll_new() @property def focus_col(self): return self._focus_col @property def focus_row(self): return self._focus_row @property def fixed_cols(self): return self._focus_col @fixed_cols.setter def set_fixed_cols(self, value): if value != self._fixed_cols: self._fixed_cols = value self.redraw(self.width,self.height)
class MapLayout(RelativeLayout): currentSize = 0 sizeOption = (1, 2, 4) def __init__(self, **kwargs): super(MapLayout, self).__init__(**kwargs) self.mainContainer = RelativeLayout(size_hint=(None, None), size=mainWindowSize) self.mainContainer.currentSize = self.currentSize self.mainContainer.sizeOption = self.sizeOption self.filterContainer = RelativeLayout(size_hint=(None, None), size=mainWindowSize) self.mapBound = ScrollView(size_hint=(None, None), size=mainWindowSize) self.MapArray = [] self.MapArray.append( Image(source='peta/content/Base Map 1.png', allow_stretch=True)) self.MapArray.append( Image(source='peta/content/Base Map 2.png', allow_stretch=True)) self.MapArray.append( Image(source='peta/content/Base Map 3.png', allow_stretch=True)) self.FilterArray = [] self.FilterArray.append( Image(source='peta/content/peta-batas-wilayah.png', allow_stretch=True, opacity=.5)) self.FilterArray.append( Image(source='peta/content/peta-jalan.png', allow_stretch=True, opacity=.5)) self.FilterArray.append( Image(source='peta/content/peta-air-bersih.png', allow_stretch=True, opacity=.6)) self.FilterArray.append( Image(source='peta/content/peta-gorong-gorong.png', allow_stretch=True, opacity=.5)) self.FilterArray.append( Image(source='peta/content/peta-sarana-publik.png', allow_stretch=True, opacity=.9)) self.filterContainer.add_widget(self.FilterArray[0]) self.mainContainer.add_widget(self.MapArray[0]) self.mainContainer.add_widget(self.filterContainer) self.mapBound.add_widget(self.mainContainer) def addJalan(self): #self.mainContainer.add_widget(self.FilterArray[1]) self.filterContainer.add_widget(self.FilterArray[1]) def removeJalan(self): #self.mainContainer.remove_widget(self.FilterArray[1]) self.filterContainer.remove_widget(self.FilterArray[1]) def addAir(self): #self.mainContainer.add_widget(self.FilterArray[2]) self.filterContainer.add_widget(self.FilterArray[2]) def removeAir(self): #self.mainContainer.remove_widget(self.FilterArray[2]) self.filterContainer.remove_widget(self.FilterArray[2]) def addGorong(self): #self.mainContainer.add_widget(self.FilterArray[3]) self.filterContainer.add_widget(self.FilterArray[3]) def removeGorong(self): #self.mainContainer.remove_widget(self.FilterArray[3]) self.filterContainer.remove_widget(self.FilterArray[3]) def addSarana(self): #self.mainContainer.add_widget(self.FilterArray[4]) self.filterContainer.add_widget(self.FilterArray[4]) def removeSarana(self): #self.mainContainer.remove_widget(self.FilterArray[4]) self.filterContainer.remove_widget(self.FilterArray[4]) def resetMap(self): self.filterContainer.clear_widgets() self.mainContainer.clear_widgets() self.filterContainer.add_widget(self.FilterArray[0]) self.mainContainer.add_widget(self.MapArray[0]) self.mainContainer.add_widget(self.filterContainer) self.mainContainer.currentSize = 0 anim = Animation(width=mainWindowSize[0], height=mainWindowSize[1], duration=0.01, t='in_out_sine') anim.start(self.mainContainer) anim.start(self.filterContainer) def zoomingIn(self): if self.mainContainer.currentSize + 1 < len( self.mainContainer.sizeOption): self.mainContainer.currentSize += 1 anim = Animation( width=mainWindowSize[0] * self.mainContainer.sizeOption[self.mainContainer.currentSize], height=mainWindowSize[1] * self.mainContainer.sizeOption[self.mainContainer.currentSize], duration=0.4, t='in_out_sine') anim.start(self.mainContainer) anim.start(self.filterContainer) if self.mainContainer.currentSize == 1: self.mainContainer.clear_widgets() self.mainContainer.add_widget(self.MapArray[1]) self.mainContainer.add_widget(self.filterContainer) elif self.mainContainer.currentSize == 2: self.mainContainer.clear_widgets() self.mainContainer.add_widget(self.MapArray[2]) self.mainContainer.add_widget(self.filterContainer) # log gv.logger.log_button('zoom in to :' + str(self.mainContainer.currentSize)) print self.mainContainer.currentSize def zoomingOut(self): if self.mainContainer.currentSize > 0: self.mainContainer.currentSize -= 1 anim = Animation( width=mainWindowSize[0] * self.mainContainer.sizeOption[self.mainContainer.currentSize], height=mainWindowSize[1] * self.mainContainer.sizeOption[self.mainContainer.currentSize], duration=0.4, t='in_out_sine') anim.start(self.mainContainer) anim.start(self.filterContainer) if self.mainContainer.currentSize == 1: self.mainContainer.clear_widgets() self.mainContainer.add_widget(self.MapArray[1]) self.mainContainer.add_widget(self.filterContainer) elif self.mainContainer.currentSize == 2: self.mainContainer.clear_widgets() self.mainContainer.add_widget(self.MapArray[2]) self.mainContainer.add_widget(self.filterContainer) # log gv.logger.log_button('zoom out to :' + str(self.mainContainer.currentSize)) print self.mainContainer.currentSize
class MenuScreen(Screen): def __init__(self, **kw): super(MenuScreen, self).__init__(**kw) self.layout = None self.carousel = None self.app = App.get_running_app() def on_enter(self, *args): self.layout = RelativeLayout() self.carousel = MenuCarousel(direction='right') w = EffectWidget() bg = Image(source='data/images/animation.zip', allow_stretch=True, keep_ratio=False) w.add_widget(bg) w.effects = [FXAAEffect()] self.carousel.add_widget(self.menu()) self.carousel.add_widget(self.new_game_menu()) self.layout.add_widget(w) self.layout.add_widget(self.carousel) self.add_widget(self.layout) Window.bind(mouse_pos=self.on_mouse_pos) def adv_menu(self): # Второй вариант кругового меню, не подходит menu_box = MenuRelativeLayout(size_hint=(None, None), size=(600, 600), pos_hint=({'center_x': .5, 'center_y': .5})) menu_top = Image(source=r'data/images/menu/menu_top.png', size_hint=(None, None), size=(426, 212), pos_hint=({'center_x': .5, 'top': 1})) menu_left = Image(source=r'data/images/menu/menu_left.png', size_hint=(None, None), size=(212, 426), pos_hint=({'x': 0, 'center_y': .5})) menu_right = Image(source=r'data/images/menu/menu_right.png', size_hint=(None, None), size=(212, 426), pos_hint=({'right': 1, 'center_y': .5})) menu_bottom = Image(source=r'data/images/menu/menu_bottom.png', size_hint=(None, None), size=(426, 212), pos_hint=({'center_x': .5, 'y': 0})) menu_center = Image(source=r'data/images/menu/center.png', size_hint=(None, None), size=(250, 250), pos_hint=({'center_x': .5, 'center_y': .5})) menu_box.add_widget(menu_top) menu_box.add_widget(menu_left) menu_box.add_widget(menu_right) menu_box.add_widget(menu_bottom) menu_box.add_widget(menu_center) return menu_box def menu(self): menu_box = GridLayout(cols=1, size_hint=(.4, .5), pos_hint=({'center_x': .5, 'center_y': .5}), spacing=10) continue_button = Button(text='Продолжить', size_hint_y=.2, disabled=True) start_button = Button(text='Новая игра', size_hint_y=.2, on_release=lambda x: self.carousel.load_next(mode='next')) load_button = Button(text='Загрузить игру', size_hint_y=.2, on_release=lambda x: ad.set_screen('iso_map', self.manager)) if config.game is None: load_button.disabled = True settings_button = Button(text='Настройки', size_hint_y=.2, on_release=lambda x: self.open_settings()) exit_button = Button(text='Выйти из игры', size_hint_y=.2, on_release=lambda x: self.close_app()) menu_box.add_widget(continue_button) menu_box.add_widget(start_button) menu_box.add_widget(load_button) menu_box.add_widget(settings_button) menu_box.add_widget(exit_button) return menu_box def new_game_menu(self): box = BoxLayout(orientation='vertical', size_hint=(.7, .8), pos_hint=({'center_x': .5, 'center_y': .5})) left_box = BoxLayout(orientation='vertical', size_hint_x=.3) right_box = BoxLayout(orientation='vertical', size_hint_x=.7) top_box = BoxLayout(orientation='horizontal', size_hint_y=.85) bottom_box = DescBottomLayout(size_hint_y=.15) map_lay = MapBoxLayout(orientation='horizontal', size_hint_y=.5) map_description = DescBoxLayout(orientation='horizontal', size_hint_y=.35) # ======================================= map_exs = MyMap() map_img = Image(source=map_exs.screen, size_hint_x=.8) left_map = Button(text='<', size_hint_x=.1) # , disabled=True right_map = Button(text='>', size_hint_x=.1) # , disabled=True map_lay.add_widget(left_map) map_lay.add_widget(map_img) map_lay.add_widget(right_map) # ======================================= desc_label = DescLabel(text='Описание', size_hint_y=.05, valign='bottom') desc_grid_left = GridLayout(cols=1, size_hint_x=.3, padding=10) desc_grid_right = GridLayout(cols=1, size_hint_x=.7, padding=10) desc_grid_left.add_widget(Label(text='Название карты:')) desc_grid_right.add_widget(Label(text=f'{map_exs.source.split("/")[-1]}')) desc_grid_left.add_widget(Label(text='Размер карты:')) desc_grid_right.add_widget(Label(text=f'{map_exs.map_width}x{map_exs.map_height}')) desc_grid_left.add_widget(Label(text='Игроков:')) desc_grid_right.add_widget(Label(text=f'{map_exs.players}')) map_description.add_widget(desc_grid_left) map_description.add_widget(desc_grid_right) # ======================================= right_box.add_widget(DescLabel(text='Выбор карты', size_hint_y=.1)) right_box.add_widget(map_lay) right_box.add_widget(desc_label) right_box.add_widget(map_description) # ======================================= left_box.add_widget(DescLabel(text='Настройки игры', size_hint_y=.1)) settings_box = SettingsLayout(size_hint_y=.9) left_box.add_widget(settings_box) # ======================================= bottom_box.add_widget(Button(size_hint=(.2, .7), pos_hint=({'x': 0, 'center_y': .5}), on_release=lambda x: self.carousel.load_previous(), text='<= Назад')) bottom_box.add_widget(Button(size_hint=(.3, .7), pos_hint=({'center_x': .5, 'center_y': .5}), on_release=lambda x: self.new_game(), text='Начать игру')) bottom_box.add_widget(Button(size_hint=(.2, .7), pos_hint=({'right': 1, 'center_y': .5}), on_release=lambda x: self.map_settings(), text='Настройки карты')) # ======================================= top_box.add_widget(left_box) top_box.add_widget(right_box) box.add_widget(top_box) box.add_widget(bottom_box) return box def new_game(self): # Создание новой игры game = Game() player1 = Player(player=True) # TODO: город добавить тут player1.add_city((17, 17), name='Персеполис') player2 = Player() player2.add_city((15, 20), name='Научград') self.add_obj_to_map(obj='Варвары', pos=ad.tile_to_world_adv((16, 22)), coords=(16, 22), player=player2) game.players = [player1, player2] config.game = game config.current_player = player1 ad.set_screen('main', self.manager) def add_obj_to_map(self, obj, pos, coords, player): unit = IsoMapUnit(name=obj, pos=pos, coords=coords, player=player) player.map_units.append(unit) config.map_gui_list.append(unit) def open_settings(self): self.app.destroy_settings() self.app.settings_cls = SettingsWithSidebar self.app.open_settings() def map_settings(self): popup = Popup(title='Настройки карты', content=Label(text='В разработке'), size_hint=(.4, .5)) popup.open() def close_app(self): self.app.stop() def on_mouse_pos(self, window, pos): ''' x, y = self.menu.pos menuX, menuY = pos posX = menuX-x posY = menuY-y cellX = self.menu.width / 3 cellY = self.menu.height / 3 print(f'{posX, posY} | {posX % cellX} | {posY % cellY}') ''' pass def on_leave(self, *args): self.layout.clear_widgets()
class MapLayout(RelativeLayout): currentSize = 0 sizeOption = (1, 2, 4) def __init__(self, **kwargs): super(MapLayout, self).__init__(**kwargs) self.mainContainer = RelativeLayout(size_hint=(None, None), size=mainWindowSize) self.mainContainer.currentSize = self.currentSize self.mainContainer.sizeOption = self.sizeOption self.filterContainer = RelativeLayout(size_hint=(None, None), size=mainWindowSize) self.mapBound = ScrollView(size_hint=(None, None), size=mainWindowSize) self.MapArray = [] self.MapArray.append(Image(source="peta/content/Base Map 1.png", allow_stretch=True)) self.MapArray.append(Image(source="peta/content/Base Map 2.png", allow_stretch=True)) self.MapArray.append(Image(source="peta/content/Base Map 3.png", allow_stretch=True)) self.FilterArray = [] self.FilterArray.append(Image(source="peta/content/peta-batas-wilayah.png", allow_stretch=True, opacity=0.5)) self.FilterArray.append(Image(source="peta/content/peta-jalan.png", allow_stretch=True, opacity=0.5)) self.FilterArray.append(Image(source="peta/content/peta-air-bersih.png", allow_stretch=True, opacity=0.6)) self.FilterArray.append(Image(source="peta/content/peta-gorong-gorong.png", allow_stretch=True, opacity=0.5)) self.FilterArray.append(Image(source="peta/content/peta-sarana-publik.png", allow_stretch=True, opacity=0.9)) self.filterContainer.add_widget(self.FilterArray[0]) self.mainContainer.add_widget(self.MapArray[0]) self.mainContainer.add_widget(self.filterContainer) self.mapBound.add_widget(self.mainContainer) def addJalan(self): # self.mainContainer.add_widget(self.FilterArray[1]) self.filterContainer.add_widget(self.FilterArray[1]) def removeJalan(self): # self.mainContainer.remove_widget(self.FilterArray[1]) self.filterContainer.remove_widget(self.FilterArray[1]) def addAir(self): # self.mainContainer.add_widget(self.FilterArray[2]) self.filterContainer.add_widget(self.FilterArray[2]) def removeAir(self): # self.mainContainer.remove_widget(self.FilterArray[2]) self.filterContainer.remove_widget(self.FilterArray[2]) def addGorong(self): # self.mainContainer.add_widget(self.FilterArray[3]) self.filterContainer.add_widget(self.FilterArray[3]) def removeGorong(self): # self.mainContainer.remove_widget(self.FilterArray[3]) self.filterContainer.remove_widget(self.FilterArray[3]) def addSarana(self): # self.mainContainer.add_widget(self.FilterArray[4]) self.filterContainer.add_widget(self.FilterArray[4]) def removeSarana(self): # self.mainContainer.remove_widget(self.FilterArray[4]) self.filterContainer.remove_widget(self.FilterArray[4]) def resetMap(self): self.filterContainer.clear_widgets() self.mainContainer.clear_widgets() self.filterContainer.add_widget(self.FilterArray[0]) self.mainContainer.add_widget(self.MapArray[0]) self.mainContainer.add_widget(self.filterContainer) self.mainContainer.currentSize = 0 anim = Animation(width=mainWindowSize[0], height=mainWindowSize[1], duration=0.01, t="in_out_sine") anim.start(self.mainContainer) anim.start(self.filterContainer) def zoomingIn(self): if self.mainContainer.currentSize + 1 < len(self.mainContainer.sizeOption): self.mainContainer.currentSize += 1 anim = Animation( width=mainWindowSize[0] * self.mainContainer.sizeOption[self.mainContainer.currentSize], height=mainWindowSize[1] * self.mainContainer.sizeOption[self.mainContainer.currentSize], duration=0.4, t="in_out_sine", ) anim.start(self.mainContainer) anim.start(self.filterContainer) if self.mainContainer.currentSize == 1: self.mainContainer.clear_widgets() self.mainContainer.add_widget(self.MapArray[1]) self.mainContainer.add_widget(self.filterContainer) elif self.mainContainer.currentSize == 2: self.mainContainer.clear_widgets() self.mainContainer.add_widget(self.MapArray[2]) self.mainContainer.add_widget(self.filterContainer) # log gv.logger.log_button("zoom in to :" + str(self.mainContainer.currentSize)) print self.mainContainer.currentSize def zoomingOut(self): if self.mainContainer.currentSize > 0: self.mainContainer.currentSize -= 1 anim = Animation( width=mainWindowSize[0] * self.mainContainer.sizeOption[self.mainContainer.currentSize], height=mainWindowSize[1] * self.mainContainer.sizeOption[self.mainContainer.currentSize], duration=0.4, t="in_out_sine", ) anim.start(self.mainContainer) anim.start(self.filterContainer) if self.mainContainer.currentSize == 1: self.mainContainer.clear_widgets() self.mainContainer.add_widget(self.MapArray[1]) self.mainContainer.add_widget(self.filterContainer) elif self.mainContainer.currentSize == 2: self.mainContainer.clear_widgets() self.mainContainer.add_widget(self.MapArray[2]) self.mainContainer.add_widget(self.filterContainer) # log gv.logger.log_button("zoom out to :" + str(self.mainContainer.currentSize)) print self.mainContainer.currentSize
class Data(Screen): def __init__(self, **kwargs): super(Data, self).__init__(**kwargs) ## TOGGLE BUTTON FUNCTION ## self.mataPencarianButton = Button( background_normal="data/lib/data-mata-pencaharian.png", background_down="data/lib/data-mata-pencaharian-hit.png", state="normal", size_hint=(None, None), size=(159, 165), ) self.pemelukAgamaButton = Button( background_normal="data/lib/data-pemeluk-agama.png", background_down="data/lib/data-pemeluk-agama-hit.png", state="normal", size_hint=(None, None), size=(159, 165), ) self.dataPendidikanButton = Button( background_normal="data/lib/data-pendidikan.png", background_down="data/lib/data-pendidikan-hit.png", state="normal", size_hint=(None, None), size=(159, 165), ) self.dataUmurButton = Button( background_normal="data/lib/data-struktur-umur.png", background_down="data/lib/data-struktur-umur-hit.png", state="normal", size_hint=(None, None), size=(159, 165), ) self.infografik = [] self.infografik.append( Image( source="data/content/data-mata-pencaharian-info.png", allow_stretch=True, size_hint=(0.9, 0.9), pos_hint={"x": 0, "y": 0}, ) ) # 0 self.infografik.append( Image( source="data/content/data-pemeluk-agama-info.png", allow_stretch=True, size_hint=(0.9, 0.9), pos_hint={"x": 0, "y": 0}, ) ) # 1 self.infografik.append( Image( source="data/content/data-tingkat-pendidikan-info.png", allow_stretch=True, size_hint=(0.9, 0.9), pos_hint={"x": 0, "y": 0}, ) ) # 2 self.infografik.append( Image( source="data/content/data-struktur-umur-info.png", allow_stretch=True, size_hint=(0.9, 0.9), pos_hint={"x": 0, "y": 0}, ) ) # 3 self.infografik.append(Image(source="data/content/BG01c.png", allow_stretch=True)) # 4 self.mataPencarianButton.bind(on_release=self.mataPencarian) self.pemelukAgamaButton.bind(on_release=self.pemelukAgama) self.dataPendidikanButton.bind(on_release=self.dataPendidikan) self.dataUmurButton.bind(on_release=self.dataStrukturUmur) ## Button Container ## self.bLayout = BoxLayout( size_hint=(None, None), orientation="horizontal", width=720, height=650, # pos_hint= {'y':0.05, 'x': 0.5}, pos=(610, 40), ) self.bLayout.add_widget(self.mataPencarianButton) self.bLayout.add_widget(self.pemelukAgamaButton) self.bLayout.add_widget(self.dataPendidikanButton) self.bLayout.add_widget(self.dataUmurButton) self.dataLayout = RelativeLayout() self.dataLayout.add_widget(self.infografik[4]) self.add_widget(self.dataLayout) self.add_widget(self.bLayout) self.zoomIdx = 0 ## Filter Button function method ## def mataPencarian(self, button=None, **args): self.dataLayout.clear_widgets() self.dataLayout.add_widget(self.infografik[0]) # log gv.logger.log_button("view :" + "Mata Pencaharian") def pemelukAgama(self, button=None, **args): self.dataLayout.clear_widgets() self.dataLayout.add_widget(self.infografik[1]) # log gv.logger.log_button("view :" + "Pemeluk Agama") def dataPendidikan(self, button=None, **args): self.dataLayout.clear_widgets() self.dataLayout.add_widget(self.infografik[2]) # log gv.logger.log_button("view :" + "Pendidikan") def dataStrukturUmur(self, button=None, **args): self.dataLayout.clear_widgets() self.dataLayout.add_widget(self.infografik[3]) # log gv.logger.log_button("view :" + "Struktur Umur") def reset(self): self.dataLayout.clear_widgets() self.dataLayout.add_widget(self.infografik[4])
class Data(Screen): def __init__(self, **kwargs): super(Data, self).__init__(**kwargs) ## TOGGLE BUTTON FUNCTION ## self.mataPencarianButton = Button( background_normal='data/lib/data-mata-pencaharian.png', background_down='data/lib/data-mata-pencaharian-hit.png', state='normal', size_hint=(None, None), size=(159, 165)) self.pemelukAgamaButton = Button( background_normal='data/lib/data-pemeluk-agama.png', background_down='data/lib/data-pemeluk-agama-hit.png', state='normal', size_hint=(None, None), size=(159, 165)) self.dataPendidikanButton = Button( background_normal='data/lib/data-pendidikan.png', background_down='data/lib/data-pendidikan-hit.png', state='normal', size_hint=(None, None), size=(159, 165)) self.dataUmurButton = Button( background_normal='data/lib/data-struktur-umur.png', background_down='data/lib/data-struktur-umur-hit.png', state='normal', size_hint=(None, None), size=(159, 165)) self.infografik = [] self.infografik.append( Image(source='data/content/data-mata-pencaharian-info.png', allow_stretch=True, size_hint=(.9, .9), pos_hint={ 'x': 0, 'y': 0 })) #0 self.infografik.append( Image(source='data/content/data-pemeluk-agama-info.png', allow_stretch=True, size_hint=(.9, .9), pos_hint={ 'x': 0, 'y': 0 })) #1 self.infografik.append( Image(source='data/content/data-tingkat-pendidikan-info.png', allow_stretch=True, size_hint=(.9, .9), pos_hint={ 'x': 0, 'y': 0 })) #2 self.infografik.append( Image(source='data/content/data-struktur-umur-info.png', allow_stretch=True, size_hint=(.9, .9), pos_hint={ 'x': 0, 'y': 0 })) #3 self.infografik.append( Image(source='data/content/BG01c.png', allow_stretch=True)) #4 self.mataPencarianButton.bind(on_release=self.mataPencarian) self.pemelukAgamaButton.bind(on_release=self.pemelukAgama) self.dataPendidikanButton.bind(on_release=self.dataPendidikan) self.dataUmurButton.bind(on_release=self.dataStrukturUmur) ## Button Container ## self.bLayout = BoxLayout( size_hint=(None, None), orientation='horizontal', width=720, height=650, #pos_hint= {'y':0.05, 'x': 0.5}, pos=(610, 40)) self.bLayout.add_widget(self.mataPencarianButton) self.bLayout.add_widget(self.pemelukAgamaButton) self.bLayout.add_widget(self.dataPendidikanButton) self.bLayout.add_widget(self.dataUmurButton) self.dataLayout = RelativeLayout() self.dataLayout.add_widget(self.infografik[4]) self.add_widget(self.dataLayout) self.add_widget(self.bLayout) self.zoomIdx = 0 ## Filter Button function method ## def mataPencarian(self, button=None, **args): self.dataLayout.clear_widgets() self.dataLayout.add_widget(self.infografik[0]) # log gv.logger.log_button('view :' + 'Mata Pencaharian') def pemelukAgama(self, button=None, **args): self.dataLayout.clear_widgets() self.dataLayout.add_widget(self.infografik[1]) # log gv.logger.log_button('view :' + 'Pemeluk Agama') def dataPendidikan(self, button=None, **args): self.dataLayout.clear_widgets() self.dataLayout.add_widget(self.infografik[2]) # log gv.logger.log_button('view :' + 'Pendidikan') def dataStrukturUmur(self, button=None, **args): self.dataLayout.clear_widgets() self.dataLayout.add_widget(self.infografik[3]) # log gv.logger.log_button('view :' + 'Struktur Umur') def reset(self): self.dataLayout.clear_widgets() self.dataLayout.add_widget(self.infografik[4])
class KivyCardList(CardList): def __init__(self, name, player): super(KivyCardList,self).__init__(name, player) self.displayed=False self.lock = threading.Lock() def initDisplay(self,xpos,ypos,scale,parentlayout,orientation): self.displayed=True self.xpos=xpos self.ypos=ypos self.scale=scale self.orientation=orientation self.layout= RelativeLayout() parentlayout.add_widget(self.layout) #self.ipos=(card.image.width*card.scatter.scale) self.updateDisplay() def updateDisplay(self): self.layout.clear_widgets() offsetx=0 offsety=0 for card in self: card.scatter.scale=self.scale card.scatter.pos=(self.xpos+offsetx,self.ypos+offsety) self.layout.add_widget(card.scatter) offsetx,offsety=self.getOffset(offsetx,offsety,card,card.scatter.scale) def moveFrom(self,index,newCardList,newState): if self.displayed: card=self[index] self.layout.remove_widget(card.scatter) super(KivyCardList,self).moveFrom(index,newCardList,newState) if self.displayed: #update remaining cards offsetx=0 offsety=0 for card in self: card.scatter.pos=(self.xpos+offsetx,self.ypos+offsety) offsetx,offsety=self.getOffset(offsetx,offsety,card,card.scatter.scale) def append(self,card): #self.lock.acquire() print card super(KivyCardList,self).append(card) if self.displayed: offsetx,offsety=self.getOffset(0,0,card,self.scale) offsetx=offsetx*(len(self)-1) offsety=offsety*(len(self)-1) card.setDest(self.xpos+offsetx,self.ypos+offsety,self.scale,self,True) def bringToFront(self): parent = self.layout.parent parent.remove_widget(self.layout) parent.add_widget(self.layout) def getOffset(self,currentx,currenty,card,scale): if self.orientation == eLayouts.vertical: return currentx,currenty-int(card.image.height*scale*0.3) return currentx+int(card.image.width*scale*0.6),currenty