def __init__(self): CombatMapGroup.textures = TextureGroup.get_group('wmap') self.idxs = array.array('L', open(config.resource('data', 'warfld.idx'), 'rb').read()) self.idxs.append(0) # utils.debug('idxs:', self.idxs) # utils.debug('idxs diff:', utils.diff(self.idxs)) # utils.debug('idxs len:', len(self.idxs) - 1) self.grpData = open(config.resource('data', 'warfld.grp'), 'rb').read() self._combatMaps = pyxlru.lru(config.combatMapCacheNum) self.blockByteSize = config.combatMapXMax * config.combatMapYMax * 2 * 2
def __init__(self): CombatMapGroup.textures = TextureGroup.get_group('wmap') self.idxs = array.array( 'L', open(config.resource('data', 'warfld.idx'), 'rb').read()) self.idxs.append(0) # utils.debug('idxs:', self.idxs) # utils.debug('idxs diff:', utils.diff(self.idxs)) # utils.debug('idxs len:', len(self.idxs) - 1) self.grpData = open(config.resource('data', 'warfld.grp'), 'rb').read() self._combatMaps = pyxlru.lru(config.combatMapCacheNum) self.blockByteSize = config.combatMapXMax * config.combatMapYMax * 2 * 2
def __init__(self, name): # print('load texture:', name) self.name = name self.idxs = load_idx_file(config.resource('data', name + '.idx')) self.grp = load_grp_file(config.resource('data', name + '.grp')) self.idxs.append(0) self.empty = object() self.textures = [self.empty] * (len(self.idxs) - 1) utils.debug(name, 'textures:', len(self.textures)) if config.textureGroupPreloadAll: self.load_all()
def __init__(self, filename, mode=MODE_READ): self.mode = mode idxName = config.resource('data', filename + '.idx') grpName = config.resource('data', filename + '.grp') if mode == self.MODE_READ: self.idxs = array.array('I', open(idxName, 'rb').read()) self.idxs.append(0) self.grpFile = open(grpName, 'rb') self.pos = -1 elif mode == self.MODE_WRITE: self.idxs = [] self.idxFile = open(idxName, 'wb') self.grpFile = open(grpName, 'wb')
def __init__(self, filename, mode=MODE_READ): self.mode = mode idxName = config.resource("data", filename + ".idx") grpName = config.resource("data", filename + ".grp") if mode == self.MODE_READ: self.idxs = array.array("I", open(idxName, "rb").read()) self.idxs.append(0) self.grpFile = open(grpName, "rb") self.pos = -1 elif mode == self.MODE_WRITE: self.idxs = [] self.idxFile = open(idxName, "wb") self.grpFile = open(grpName, "wb")
def __init__(self, parent): JDialog.__init__(self, parent) e = c.resource('entry') self.language = PyLanguageComboBox(c.config('SUPPORTED_LOCALES'), Locale.getDefault()) self.language.set_selection(c.config('DEFAULT_TEXT_LANGUAGE')) self.encoding = PyComboBox(c.SUPPORTED_ENCODINGS) self.para_start = PyComboBox([(x, x) for x in range(11)]) self.para_start.set_selection(c.config('DEFAULT_PARAGRAPH_START')) main_panel = PyGridBagPanel(title='') main_panel.add(JLabel(e['language']), gridx=0, gridy=0, anchor='LINE_START', weightx=0.5) main_panel.add(self.language, gridx=1, gridy=0, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.add(JLabel(e['encoding']), gridx=0, gridy=1, anchor='LINE_START', weightx=0.5) main_panel.add(self.encoding, gridx=1, gridy=1, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.add(JLabel(e['source_para_start']), gridx=0, gridy=2, anchor='LINE_START', weightx=0.5) main_panel.add(self.para_start, gridx=1, gridy=2, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.setPreferredSize(Dimension(300, 70)) button_panel=PyPanel([JButton(_d['save'], actionPerformed=self.action_ok), JButton(_d['discard'], actionPerformed=self.action_cancel)]) panel=PyGridBagPanel(title='') panel.add(main_panel) panel.add(button_panel, gridy=1) self.title = _d['text_input_title'] self.contentPane.add(panel)
def __init__(self, parent): JDialog.__init__(self, parent) e = c.resource('entry') self.encoding = PyComboBox(c.SUPPORTED_ENCODINGS) self.select_button = JButton(_d['select'], actionPerformed=self.action_select) self.font_label = JLabel(_d['select_font'] + ' : ' + _d['no_font_selected']) self.font = None self.font_name = JTextField(12) self.file_chooser = JFileChooser(c.config('DEFAULT_OPEN_DIRECTORY')) #self.file_chooser.locationRelativeTo = self main_panel = PyGridBagPanel(title='') main_panel.add(self.font_label, gridx=0, gridy=0, anchor='LINE_START', weightx=0.5) main_panel.add(self.select_button, gridx=1, gridy=0, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.add(JLabel(e['encoding']), gridx=0, gridy=1, anchor='LINE_START', weightx=0.5) main_panel.add(self.encoding, gridx=1, gridy=1, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.add(JLabel(_d['font_name']), gridx=0, gridy=2, anchor='LINE_START', weightx=0.5) main_panel.add(self.font_name, gridx=1, gridy=2, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.setPreferredSize(Dimension(300, 100)) button_panel=PyPanel([JButton(_d['import'], actionPerformed=self.action_ok), JButton(_d['discard'], actionPerformed=self.action_cancel)]) panel=PyGridBagPanel(title='') panel.add(main_panel) panel.add(button_panel, gridy=1) self.title = _d['font_import_title'] self.contentPane.add(panel)
def __init__(self, parent): JDialog.__init__(self, parent) self._parent = parent e = c.resource('entry') self.open_file_chooser = JFileChooser(c.config('DEFAULT_OPEN_DIRECTORY')) self.open_file_chooser.multiSelectionEnabled = 0 self.open_file_chooser.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY self.open_file_dir = c.config('DEFAULT_OPEN_DIRECTORY') self.open_file_label = JLabel(self.open_file_dir) self.save_file_chooser = JFileChooser(c.config('DEFAULT_SAVE_DIRECTORY')) self.save_file_chooser.multiSelectionEnabled = 0 self.save_file_chooser.fileSelectionMode = JFileChooser.DIRECTORIES_ONLY self.save_file_dir = c.config('DEFAULT_SAVE_DIRECTORY') self.save_file_label = JLabel(self.save_file_dir) self.language = PyLanguageComboBox(c.config('SUPPORTED_LOCALES'), Locale.getDefault()) self.language.set_selection(Locale.getDefault().language) if c.config('MIDLET_LOCALE') is not None and c.config('MIDLET_LOCALE') != '': midlet_locale = Locale(c.config('MIDLET_LOCALE')) else: midlet_locale = Locale.getDefault() self.midlet_language = PyLanguageComboBox(c.config('SUPPORTED_LOCALES')) self.midlet_language.set_selection(midlet_locale.language) main = PyGridBagPanel(title="") main.setPreferredSize(Dimension(400, 200)) lang_panel = PyBorderPanel(west=JLabel(e['language']), east=self.language, title="") main.add(lang_panel, gridx=0, gridy=0, fill="HORIZONTAL", anchor="LINE_START", weightx=0.5, weighty=0.5) midlet_lang_panel = PyBorderPanel(west=JLabel(_d['midlet_language']), east=self.midlet_language, title="") main.add(midlet_lang_panel, gridx=0, gridy=1, fill="HORIZONTAL", anchor="LINE_START", weightx=0.5, weighty=0.5) open_panel = PyBorderPanel(west=JLabel(_d['open_dir']), east=JButton(_d['select'], actionPerformed=self.action_set_open), south=self.open_file_label, title="") main.add(open_panel, gridx=0, gridy=2, fill="HORIZONTAL", anchor="LINE_START", weightx=0.5, weighty=0.5) save_panel = PyBorderPanel(west=JLabel(_d['save_dir']), east=JButton(_d['select'], actionPerformed=self.action_set_save), south=self.save_file_label, title="") main.add(save_panel, gridx=0, gridy=3, fill="HORIZONTAL", anchor="LINE_START", weightx=0.5, weighty=0.5) self.make_folder = JCheckBox() makefolder_panel = PyBorderPanel(west=JLabel(_d['make_dir']), east=self.make_folder, title="") main.add(makefolder_panel, gridx=0, gridy=4, fill="HORIZONTAL", anchor="LINE_START", weightx=0.5, weighty=0.5) self.make_folder.selected = c.config('MAKE_FOLDER') button_panel=PyPanel([JButton(_d['save'], actionPerformed=self.action_ok), JButton(_d['discard'], actionPerformed=self.action_cancel)]) panel=PyBorderPanel(south=button_panel, west=main) self.title = _d['interface_title'] self.contentPane.add(panel)
def __init__(self, parent): JDialog.__init__(self, parent) r = c.resource('about') b_panel=PyPanel([JButton("Ok", actionPerformed=self.action_ok)]) t_panel=PyPanel([ JLabel("@@PRODUCT@@ @@VERSION@@"), JLabel("Copyright (c) @@COPYRIGHT@@"), JLabel("@@URL@@"), ], layout=GridLayout(3, 1), title="") panel=PyBorderPanel(south=b_panel, center=t_panel) self.contentPane.setPreferredSize(Dimension(400, 100)) self.title = r['title'] self.contentPane.add(panel)
def __init__(self, parent): JDialog.__init__(self, parent) e = c.resource('entry') self.encoding = PyComboBox(c.SUPPORTED_ENCODINGS) self.select_button = JButton(_d['select'], actionPerformed=self.action_select) self.font_label = JLabel(_d['select_font'] + ' : ' + _d['no_font_selected']) self.font = None self.font_name = JTextField(12) self.chooser = JFontChooser(parent) self.chooser.locationRelativeTo = self self.rb_normal = JRadioButton() self.rb_antialiased = JRadioButton() self.rb_subpixel = JRadioButton() self.rb_subpixel_aa = JRadioButton() rb_group = ButtonGroup() rb_group.add(self.rb_normal) rb_group.add(self.rb_antialiased) rb_group.add(self.rb_subpixel) rb_group.add(self.rb_subpixel_aa) self.rb_normal.selected = 1 main_panel = PyGridBagPanel(title='') main_panel.add(self.font_label, gridx=0, gridy=0, anchor='LINE_START', weightx=0.5) main_panel.add(self.select_button, gridx=1, gridy=0, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.add(JLabel(_d['normal']), gridx=0, gridy=1, anchor='LINE_START', weightx=0.5) main_panel.add(self.rb_normal, gridx=1, gridy=1, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.add(JLabel(_d['antialiased']), gridx=0, gridy=2, anchor='LINE_START', weightx=0.5) main_panel.add(self.rb_antialiased, gridx=1, gridy=2, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.add(JLabel(_d['subpixel']), gridx=0, gridy=3, anchor='LINE_START', weightx=0.5) main_panel.add(self.rb_subpixel, gridx=1, gridy=3, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.add(JLabel(_d['subpixel_aa']), gridx=0, gridy=4, anchor='LINE_START', weightx=0.5) main_panel.add(self.rb_subpixel_aa, gridx=1, gridy=4, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.add(JLabel(e['encoding']), gridx=0, gridy=5, anchor='LINE_START', weightx=0.5) main_panel.add(self.encoding, gridx=1, gridy=5, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.add(JLabel(_d['font_name']), gridx=0, gridy=6, anchor='LINE_START', weightx=0.5) main_panel.add(self.font_name, gridx=1, gridy=6, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.setPreferredSize(Dimension(300, 150)) self.button_import = JButton(_d['import'], actionPerformed=self.action_ok, enabled=0) button_panel=PyPanel([self.button_import, JButton(_d['discard'], actionPerformed=self.action_cancel)]) panel=PyGridBagPanel(title='') panel.add(main_panel) panel.add(button_panel, gridy=1) self.title = _d['font_import_title'] self.contentPane.add(panel)
def play_music(name): if not config.musicEnable: return global currentName if name == currentName: return stop_music() filename = config.resource('sound', 'game{:02d}.ogg'.format(soundMap['start'])) try: pg.mixer.music.load(filename) pg.mixer.music.set_volume(config.musicVolume) pg.mixer.music.play() except pg.error: pass
def __init__(self, parent): JDialog.__init__(self, parent) e = c.resource('entry') self.font_list = font_list = JList(parent.bookshelf.font_fabric.list(), selectionMode=ListSelectionModel.SINGLE_SELECTION) font_list_pane=JScrollPane(font_list) font_list_pane.setPreferredSize(Dimension(150, 150)) font_panel = PyPanel([font_list_pane], title=e['font']) button_panel=PyPanel([JButton(_d['delete'], actionPerformed=self.action_ok), JButton(_d['cancel'], actionPerformed=self.action_cancel)]) panel=PyGridBagPanel(title='') panel.add(font_panel) panel.add(button_panel, gridy=1) self.title = _d['font_delete_title'] self.contentPane.add(panel)
def __init__(self, bookshelf, fo_file): self.bookshelf = bookshelf self.book = bookshelf.add_fo_book(fo_file) self.preview = None self.r = r = c.resource('entry') self.layout = BorderLayout() # result self.title = JTextField(fo_file.getName().split('.')[0], 12) self.font_name = PyComboBox([(n, n) for n in bookshelf.font_fabric.list()]) self.ilabel = PyLabel(None) self.ilabel.setPreferredSize(bookshelf.platform.canvasDimension) # defaults self.color_foreground = Color(c.config('DEFAULT_COLOR')) self.color_background = Color(c.config('DEFAULT_BACKGROUND_COLOR')) self.font_name.set_selection(c.config('DEFAULT_FONT_NAME')) self.button_color_foreground = PyColorButton(self.color_foreground, action=self.action_set_foreground) self.button_color_background = PyColorButton(self.color_background, action=self.action_set_background) buttons = PyPanel([JButton(r['preview'], actionPerformed=self.action_preview)]) result_panel = PyPanel([ PyLabel(r['name']), self.title, PyLabel(r['font']), self.font_name, PyLabel(r['color_foreground']), self.button_color_foreground, PyLabel(r['color_background']), self.button_color_background ], layout=GridLayout(4,2), title=r['result_title']) self.preview_button_up = JButton(r['up'], actionPerformed=self.action_up, enabled=0) self.preview_button_down = JButton(r['down'], actionPerformed=self.action_down, enabled=0) preview_buttons = PyPanel([ self.preview_button_up, self.preview_button_down]) buttons_panel = PyPanel([JButton(r['preview'], actionPerformed=self.action_preview)]) preview_panel = PyBorderPanel(south=preview_buttons, center=PyPanel([self.ilabel]), title=r['preview_title']) self.add(PyBorderPanel(north=result_panel), BorderLayout.WEST) self.add(preview_panel, BorderLayout.EAST) self.add(buttons_panel, BorderLayout.SOUTH)
def load_002(self, name): with open(config.resource('data', name + '.002'), 'rb') as file002: return array.array(TYPE_CODE, file002.read())
def __init__(self, name): super().__init__() self.name = name self.image = pg.image.load(config.resource('pic', name)) self.rect = pg.Rect((0, 0), self.image.get_size())
def __init__(self, name): super().__init__() self.name = name self.image = pg.image.load(config.resource("pic", name)) self.rect = pg.Rect((0, 0), self.image.get_size())
def open_grp(type, suffix, mode): return open(config.resource("data", "{}{}.grp".format(type, suffix)), mode)
def viewer(init=None): import os names = [] allT = {} for f in os.listdir(config.resource('data')): name, ext = os.path.splitext(f) if ext == '.grp': names.append(name) excludes = [ 'danger', 'sanger', 'ranger', 'alldef', 'allsin', 'allsinbk', 'warfld', 's1', 's2', 's3', 'r1', 'r2', 'r3', 'd1', 'd2', 'd3', 'r9', 'd9', 's9', ] for name in excludes: names.remove(name) names.sort() print(names) if init is None: idx = 0 else: idx = names.index(init) pg.display.init() pg.font.init() screen = pg.display.set_mode((800, 600), 0, 32) font = fonts.get_default_font(16) def draw(idx_new): nonlocal idx idx = idx_new % len(names) name = names[idx] if name not in allT: allT[name] = TextureGroup(name) textures = allT[name] print(len(textures.idxs) - 1) utils.clear_surface(screen) w, h = screen.get_size() x, y = 0, 0 rowMaxH = 0 margin = 2 for id, texture in textures.iter_all(): image = texture.image w1, h1 = image.get_size() if x + w1 < w: screen.blit(image, (x, y)) rowMaxH = max(rowMaxH, h1) else: x = 0 y += rowMaxH + margin if y >= screen.get_height(): break rowMaxH = 0 screen.blit(image, (x, y)) screen.blit(font.render(str(id), 1, (0, 0xff, 0)), (x, y)) x += w1 + margin textSize = font.size(name) rect = pg.Rect((0, 0), (textSize[0], textSize[1])) rect.right = screen.get_width() - 10 rect.bottom = screen.get_height() - 10 screen.blit(font.render(name, 1, (0xff, 0xff, 0xff)), rect) pg.display.update() tm = pg.time.Clock() draw(idx) while 1: for event in pg.event.get(): if event.type == pg.QUIT \ or event.type == pg.KEYDOWN and event.key == pg.K_ESCAPE: return if event.type == pg.KEYDOWN: if event.key == pg.K_RIGHT: draw(idx + 1) elif event.key == pg.K_LEFT: draw(idx - 1) tm.tick(config.FPS)
from javax.swing import * from java.awt import BorderLayout, GridLayout, GridBagLayout, GridBagConstraints, Dimension, Color from java.awt.event import ActionListener, KeyEvent from javax.swing.event import ListSelectionListener from bookshelf.gui import JTabbedPaneWithCloseIcons from bookshelf.builder import MidletBuilder, ReaderPackage, PlatformPackage from bookshelf.preview import * from bookshelf.makefont import JFontChooser, FontFabric from java.io import ObjectOutputStream, FileOutputStream from java.util import Locale from java.lang import String import config as c from gui import * import sys _d = c.resource('dialogs') def confirm(dialog, title, message): if JOptionPane.showConfirmDialog(dialog.contentPane, message, title, JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION: return 1 return 0 def confirm_dialog(dialog, title=_d['settings_save_title'], message=_d['settings_save_message']): return confirm(dialog, title, message) def confirm_dialog_no_restart(dialog, title=_d['settings_save_title'], message=_d['settings_save_message_no_restart']): return confirm(dialog, title, message) class About(JDialog): def __init__(self, parent): JDialog.__init__(self, parent)
def __init__(self, bookshelf): JFrame.__init__(self, windowClosing=lambda event: sys.exit(0)) self.size = (500, 420) self.bookshelf = bookshelf self.max_entries = 32 self.formatters = {'.txt':BookView, '.fo':FopView} # resources self.r = r = c.resource('window') # title self.set_title() # menu File self.menu_open = PyMenuItem(r['item_open'], action=self.action_open, key='ctrl O') self.menu_save = PyMenuItem(r['item_save'], action=self.action_save, key='ctrl S', enabled=0) self.menu_close = PyMenuItem(r['item_close'], action=self.action_close, enabled=0) self.menu_exit = PyMenuItem(r['item_exit'], action=self.action_exit) menu_file = JMenu(r['menu_file']) for m in [self.menu_open, self.menu_save, self.menu_close, self.menu_exit]: menu_file.add(m) # submenu Rotation group_rotation = ButtonGroup() menu_rotation = JMenu(r['menu_rotation']) self.menu_item_rotation_0 = JCheckBoxMenuItem(r['item_rotation_0'], actionPerformed=self.action_rotation_0, selected=(c.config('SCREEN_ROTATION') == 0)) for menu_item in [ self.menu_item_rotation_0, JCheckBoxMenuItem(r['item_rotation_90'], actionPerformed=self.action_rotation_90, selected=(c.config('SCREEN_ROTATION') == 90)), JCheckBoxMenuItem(r['item_rotation_270'], actionPerformed=self.action_rotation_270, selected=(c.config('SCREEN_ROTATION') == 270))]: menu_rotation.add(menu_item) group_rotation.add(menu_item) # menu Settings menu_settings = JMenu(r['menu_settings']) for menu_item in [ PyMenuItem(r['item_phone'], action=self.action_select_phone), PyMenuItem(r['item_interface'], action=self.action_interface_settings), PyMenuItem(r['item_text_input'], action=self.action_text_input_settings), PyMenuItem(r['item_output'], action=self.action_output_settings), menu_rotation, PyMenuItem(r['item_plugin'], action=self.action_plugin_settings)]: menu_settings.add(menu_item) # menu Fonts menu_fonts = JMenu(r['menu_fonts']) for menu_item in [ PyMenuItem(r['item_import_system'], action=self.action_import_system_font), PyMenuItem(r['item_import_palm'], action=self.action_import_palm_font), PyMenuItem(r['item_delete'], action=self.action_delete_font), ]: menu_fonts.add(menu_item) # menu Help menu_help = JMenu(r['menu_help']) for menu_item in [ PyMenuItem(r['item_about'], action=self.action_about)]: menu_help.add(menu_item) # menu menu = JMenuBar() menu.add(menu_file) menu.add(menu_settings) menu.add(menu_fonts) menu.add(Box.createHorizontalGlue()) menu.add(menu_help) self.JMenuBar = menu # entry pane self.tabbed_pane = JTabbedPaneWithCloseIcons() self.tabbed_pane.actionListener = ActionListenerProxy(self.action_close) # file chooser self.open_file_chooser = JFileChooser(c.config('DEFAULT_OPEN_DIRECTORY')) self.open_file_chooser.multiSelectionEnabled = 1 self.save_file_chooser = JFileChooser(c.config('DEFAULT_SAVE_DIRECTORY')) self.save_file_chooser.multiSelectionEnabled = 0
def get_font(name, size): key = (name, size) if key not in _fontCache: font = Font(config.resource('font', name), size) _fontCache[key] = font return _fontCache[key]
def __init__(self, parent, font_fabric): JDialog.__init__(self, parent) self.e = e = c.resource('entry') self.font_name = PyComboBox([(n, n) for n in font_fabric.list()]) self.font_name.set_selection(c.config('DEFAULT_FONT_NAME')) self.interline = PyComboBox([(x, x) for x in range(c.MAX_INTERLINE_SPACING)]) self.interline.set_selection(c.config('DEFAULT_INTERLINE_SPACING')) self.para_indent = PyComboBox([(x, x) for x in range(c.MAX_PARA_INDENT)]) self.para_indent.set_selection(c.config('DEFAULT_PARAGRAPH_INDENT')) self.hyphenate = JCheckBox() self.hyphenate.selected = c.config('DEFAULT_HYPHENATE_TEXT') self.justify = JCheckBox() self.justify.selected = c.config('DEFAULT_JUSTIFY_TEXT') self.screen_border = JCheckBox() self.screen_border.selected = c.config('DEFAULT_SCREEN_BORDER') self.color_foreground = Color(c.config('DEFAULT_COLOR')) self.color_background = Color(c.config('DEFAULT_BACKGROUND_COLOR')) self.button_color_foreground = PyColorButton(self.color_foreground, action=self.action_set_foreground) self.button_color_background = PyColorButton(self.color_background, action=self.action_set_background) main_panel = PyGridBagPanel(title='') main_panel.add(JLabel(e['font']), gridx=0, gridy=0, anchor='LINE_START', weightx=0.5) main_panel.add(self.font_name, gridx=1, gridy=0, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.add(JLabel(e['interline_spacing']), gridx=0, gridy=1, anchor='LINE_START', weightx=0.5) main_panel.add(self.interline, gridx=1, gridy=1, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.add(JLabel(e['result_para_start']), gridx=0, gridy=2, anchor='LINE_START', weightx=0.5) main_panel.add(self.para_indent, gridx=1, gridy=2, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.add(JLabel(e['justify']), gridx=0, gridy=3, anchor='LINE_START', weightx=0.5) main_panel.add(self.justify, gridx=1, gridy=3, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.add(JLabel(e['hyphenate']), gridx=0, gridy=4, anchor='LINE_START', weightx=0.5) main_panel.add(self.hyphenate, gridx=1, gridy=4, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.add(JLabel(e['screen_border']), gridx=0, gridy=5, anchor='LINE_START', weightx=0.5) main_panel.add(self.screen_border, gridx=1, gridy=5, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.add(JLabel(e['color_foreground']), gridx=0, gridy=6, anchor='LINE_START', weightx=0.5) main_panel.add(self.button_color_foreground, gridx=1, gridy=6, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.add(JLabel(e['color_background']), gridx=0, gridy=7, anchor='LINE_START', weightx=0.5) main_panel.add(self.button_color_background, gridx=1, gridy=7, anchor='LINE_END', weightx=0.1, fill='HORIZONTAL') main_panel.setPreferredSize(Dimension(300, 170)) button_panel=PyPanel([JButton(_d['save'], actionPerformed=self.action_ok), JButton(_d['discard'], actionPerformed=self.action_cancel)]) panel=PyGridBagPanel(title='') panel.add(main_panel) panel.add(button_panel, gridy=1) self.title = _d['output_title'] self.contentPane.add(panel)
def __init__(self, bookshelf, text_file): self.bookshelf = bookshelf self.book = bookshelf.add_book(text_file) self.preview = None self.r = r = c.resource('entry') self.layout = BorderLayout() # source self.renderer = None self.language = PyLanguageComboBox(c.config('SUPPORTED_LOCALES')) self.encoding = PyComboBox(c.SUPPORTED_ENCODINGS) self.para_start = PyComboBox([(x, x) for x in range(11)]) # result self.title = JTextField(text_file.getName().split('.')[0], 12) self.font_name = PyComboBox([(n, n) for n in bookshelf.font_fabric.list()]) self.interline = PyComboBox([(x, x) for x in range(-c.MAX_INTERLINE_SPACING, c.MAX_INTERLINE_SPACING)]) self.para_indent = PyComboBox([(x, x) for x in range(c.MAX_PARA_INDENT)]) self.hyphenate = JCheckBox() self.justify = JCheckBox() self.screen_border = JCheckBox() # defaults self.color_foreground = Color(c.config('DEFAULT_COLOR')) self.color_background = Color(c.config('DEFAULT_BACKGROUND_COLOR')) self.button_color_foreground = PyColorButton(self.color_foreground, action=self.action_set_foreground) self.button_color_background = PyColorButton(self.color_background, action=self.action_set_background) if c.config('DEFAULT_TEXT_LANGUAGE') is not None: default_text_language = c.config('DEFAULT_TEXT_LANGUAGE') else: default_text_language = Locale.getDefault().language self.encoding.set_selection(c.config('DEFAULT_TEXT_ENCODING')) self.para_start.set_selection(c.config('DEFAULT_PARAGRAPH_START')) self.language.set_selection(default_text_language) self.para_indent.set_selection(c.config('DEFAULT_PARAGRAPH_INDENT')) self.font_name.set_selection(c.config('DEFAULT_FONT_NAME')) self.hyphenate.selected = c.config('DEFAULT_HYPHENATE_TEXT') self.justify.selected = c.config('DEFAULT_JUSTIFY_TEXT') self.screen_border.selected = c.config('DEFAULT_SCREEN_BORDER') self.interline.set_selection(c.config('DEFAULT_INTERLINE_SPACING')) self.ilabel = PyLabel(None) self.ilabel.setPreferredSize(bookshelf.platform.canvasDimension) buttons = PyPanel([JButton(r['preview'], actionPerformed=self.action_preview)]) result_panel = PyPanel([ PyLabel(r['name']), self.title, PyLabel(r['font']), self.font_name, PyLabel(r['interline_spacing']), self.interline, PyLabel(r['result_para_start']), self.para_indent, PyLabel(r['justify']), self.justify, PyLabel(r['hyphenate']), self.hyphenate, PyLabel(r['screen_border']), self.screen_border, PyLabel(r['color_foreground']), self.button_color_foreground, PyLabel(r['color_background']), self.button_color_background ], layout=GridLayout(9,2), title=r['result_title']) source_panel = PyPanel([ PyLabel(r['language']), self.language, PyLabel(r['encoding']), self.encoding, PyLabel(r['source_para_start']), self.para_start ], layout=GridLayout(3,2), title=r['source_title']) self.preview_button_up = JButton(r['up'], actionPerformed=self.action_up, enabled=0) self.preview_button_down = JButton(r['down'], actionPerformed=self.action_down, enabled=0) preview_buttons = PyPanel([ self.preview_button_up, self.preview_button_down]) buttons_panel = PyPanel([JButton(r['preview'], actionPerformed=self.action_preview)]) preview_panel = PyBorderPanel(south=preview_buttons, center=PyPanel([self.ilabel]), title=r['preview_title']) self.add(PyBorderPanel(north=result_panel, south=source_panel), BorderLayout.WEST) self.add(preview_panel, BorderLayout.EAST) self.add(buttons_panel, BorderLayout.SOUTH)
def open_grp(type, suffix, mode): return open(config.resource('data', '{}{}.grp'.format(type, suffix)), mode)