def _updateFont( self, x_center ): scale = self.getDisplayScaling() scaled_font_size = round( self.font_size * scale ) font = ckit.getStockedFont(self.font_name, scaled_font_size) ckit.TextWindow.setFontFromFontObject( self, font ) window_rect = self.getWindowRect() if x_center: self.setPosSize( (window_rect[0] + window_rect[2]) // 2, window_rect[1], self.width(), self.height(), ORIGIN_X_CENTER | ORIGIN_Y_TOP ) else: self.setPosSize( window_rect[0], window_rect[1], self.width(), self.height(), 0 )
def _updateFont(self, window_position="top_center_align"): scale = self.getDisplayScaling() scaled_font_size = round(self.font_size * scale) font = ckit.getStockedFont(self.font_name, scaled_font_size) window_rect = self.getWindowRect() if window_position == "top_center_align": # ウインドウの上端中央位置を基準にする ckit.TextWindow.setFontFromFontObject(self, font) self.setPosSize( (window_rect[0] + window_rect[2]) // 2, window_rect[1], self.width(), self.height(), ORIGIN_X_CENTER | ORIGIN_Y_TOP) elif window_position == "dpi_scaling": old_char_size = self.getCharSize() ckit.TextWindow.setFontFromFontObject(self, font) new_char_size = self.getCharSize() scale_for_position = (new_char_size[0] / old_char_size[0], new_char_size[1] / old_char_size[1]) # フォントサイズの変化に応じてモニター中での位置を調整する crossing_monitors = self._crossingMonitors(window_rect) if len(crossing_monitors) == 1: monitor_rect = crossing_monitors[0][1] scaled_pos = (int((window_rect[0] - monitor_rect[0]) * scale_for_position[0] + monitor_rect[0]), int((window_rect[1] - monitor_rect[1]) * scale_for_position[1] + monitor_rect[1])) self.setPosSize(scaled_pos[0], scaled_pos[1], self.width(), self.height(), 0) # モニターの表示範囲内に部分的に入るように調整する self._makeVisibleInMonitorRect(crossing_monitors[0][1])
def __init__(self, desktop, debug=False): self.initialized = False self.loadState() self.font_name = "MS Gothic" self.font_size = 12 # ウインドウの左上位置のDPIによってをフォントサイズ決定する dpi_scale = ckit.TextWindow.getDisplayScalingFromPosition( self.window_normal_x, self.window_normal_y) scaled_font_size = round(self.font_size * dpi_scale) ckit.TextWindow.__init__( self, x=self.window_normal_x, y=self.window_normal_y, width=self.window_normal_width, height=self.window_normal_height, font=ckit.getStockedFont(self.font_name, scaled_font_size), bg_color=(0, 0, 0), border_size=2, title_bar=True, title="CraftMemo", show=cmemo_ini.getint("CONSOLE", "visible", 1), sysmenu=True, #activate_handler = self._onActivate, close_handler=self._onClose, move_handler=self._onMove, size_handler=self._onSize, dpi_handler=self._onDpi, keydown_handler=self._onKeyDown, #char_handler = self._onChar, lbuttondown_handler=self._onLeftButtonDown, lbuttonup_handler=self._onLeftButtonUp, mbuttondown_handler=self._onMiddleButtonDown, mbuttonup_handler=self._onMiddleButtonUp, rbuttondown_handler=self._onRightButtonDown, rbuttonup_handler=self._onRightButtonUp, lbuttondoubleclick_handler=self._onLeftButtonDoubleClick, mousemove_handler=self._onMouseMove, mousewheel_handler=self._onMouseWheel, ) self.plane_scrollbar0 = ckit.ThemePlane3x3(self, 'scrollbar0.png', 2) self.plane_scrollbar1 = ckit.ThemePlane3x3(self, 'scrollbar1.png', 1) self.debug = debug self.log = Log() self.scroll_info = ckit.ScrollInfo() self.mouse_click_info = None self.selection = [[0, 0], [0, 0]] self.setTimer(self._onTimerJob, 10) self.initialized = True self.paint() # モニター境界付近でウインドウが作成された場合を考慮して、DPIを再確認する dpi_scale2 = self.getDisplayScaling() if dpi_scale2 != dpi_scale: self._updateFont(x_center=True)
def __init__(self, desktop, name, color): self.initialized = False self.txt_filename = os.path.join(desktop.data_path, 'data', name + ".txt") self.cfg_filename = os.path.join(desktop.data_path, 'data', name + ".cfg") self.setting = { "x": 0, "y": 0, "w": 8, "h": 1, "color": color, "mode": MemoWindow.MODE_NORMAL } try: fd = open(self.cfg_filename, "r", encoding="utf-8") self.setting.update(json.load(fd)) fd.close() new_memo = False except: new_memo = True self.font_name = "MS Gothic" self.font_size = 12 # ウインドウの左上位置のDPIによってをフォントサイズ決定する dpi_scale = ckit.TextWindow.getDisplayScalingFromPosition( self.setting["x"], self.setting["y"]) scaled_font_size = round(self.font_size * dpi_scale) ckit.TextWindow.__init__( self, x=self.setting["x"], y=self.setting["y"], width=self.setting["w"], height=self.setting["h"], origin=ORIGIN_X_LEFT | ORIGIN_Y_TOP, font=ckit.getStockedFont(self.font_name, scaled_font_size), show=False, resizable=False, title_bar=False, title="", border_size=2, minimizebox=False, maximizebox=False, tool=True, ncpaint=True, activate_handler=self._onActivate, close_handler=self.onClose, size_handler=self._onSize, dpi_handler=self._onDpi, keydown_handler=self.onKeyDown, lbuttondown_handler=self._onLeftButtonDown, rbuttondown_handler=self._onRightButtonDown, rbuttonup_handler=self._onRightButtonUp, lbuttondoubleclick_handler=self._onLeftButtonDoubleClick, nchittest_handler=self._onNcHitTest, ) if new_memo: window_rect = self.getWindowRect() x, y = desktop.findSpace((window_rect[2] - window_rect[0] + 4, window_rect[3] - window_rect[1] + 4)) self.setPosSize(x=x + 2, y=y + 2, width=self.width(), height=self.height(), origin=ORIGIN_X_LEFT | ORIGIN_Y_TOP) self.command = ckit.CommandMap(self) self.desktop = desktop self.name = name self.txt_mtime = 0 self.cfg_mtime = 0 self.data = "" self.undo = None self.mode = self.setting["mode"] self.bg_color = self.setting["color"] self.configure() self.setTimer(self.onTimerCheckFile, 1000) # アクティブ時の右下のしるし if not MemoWindow.img_active: MemoWindow.img_active = ckit.createThemeImage('active.png') self.plane_size = (13, 13) self.plane_active = ckit.ImagePlane(self, (0, 0), self.plane_size, 0) self.plane_active.setImage(MemoWindow.img_active) self.plane_active.show(False) self.bell_count = 0 self.initialized = True self.saveSetting() self.load(adjust_size=new_memo) # モニター境界付近でウインドウが作成された場合を考慮して、DPIを再確認する dpi_scale2 = self.getDisplayScaling() if dpi_scale2 != dpi_scale: self._updateFont(window_position="top_center_align")
def command_List(self, info): def activatePopup(): list_window.foreground() if not self.acquireUserInputOwnership(False, activatePopup): return try: items = list(self.memowindow_table.values()) if len(items) == 0: return items.sort(key=lambda item: item.getTimeStamp(), reverse=True) def build_item(memowindow): return (memowindow.getLeadingText(1000), memowindow) items = list(map(build_item, items)) initial_select = 0 max_width = 60 def onKeyDown(vk, mod): pass def onStatusMessage(width, select): return "" pos = pyauto.Input.getCursorPos() # リストウインドウの左上位置のDPIによってをフォントサイズ決定する dpi_scale = ckit.Window.getDisplayScalingFromPosition( pos[0], pos[1]) scaled_font_size = round(self.font_size * dpi_scale) font = ckit.getStockedFont(self.font_name, scaled_font_size) list_window = cmemo_listwindow.ListWindow( pos[0], pos[1], 5, 1, max_width, 16, self, font, False, "メモリスト", items, initial_select=0, keydown_hook=onKeyDown, onekey_search=False, statusbar_handler=onStatusMessage) cmemo_misc.adjustWindowPosition(list_window, pos) list_window.show(True) self.enable(False) list_window.messageLoop() result = list_window.getResult() self.enable(True) self.activate() list_window.destroy() if result < 0: return items[result][1].activate() items[result][1].visualBell() finally: self.releaseUserInputOwnership()